Skip to content

Miscompilation of a program projecting field of an extern type #127336

Open
@tmiasko

Description

@tmiasko

Since #118534 projecting a field of an extern type at non-zero offset panics. MIR transformations do not understand this:

$ cat a.rs
#![feature(extern_types)]
extern "C" {
    type Opaque;
}
fn main() {
    let a = [0u8; 1];
    let b: &(u8, Opaque) = unsafe { &*(&a as *const _ as *const (u8, Opaque)) };
    let _ = &b.1;
}
$ rustc a.rs -Zmir-opt-level=1 && ./a
$ rustc a.rs -Zmir-opt-level=0 && ./a
thread 'main' panicked at library/core/src/panicking.rs:221:5:
attempted to compute the size or alignment of extern type `Opaque`
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread caused non-unwinding panic. aborting.
Aborted

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-mir-optArea: MIR optimizationsC-bugCategory: This is a bug.F-extern_types`#![feature(extern_types)]`I-miscompileIssue: Correct Rust code lowers to incorrect machine codeI-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-opsemRelevant to the opsem teamrequires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions