Skip to content

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

Open
@tmiasko

Description

@tmiasko
Contributor

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

Activity

added
T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness
C-bugCategory: This is a bug.
requires-nightlyThis issue requires a nightly compiler in some way.
A-mir-optArea: MIR optimizations
T-opsemRelevant to the opsem team
on Jul 4, 2024
added
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Jul 4, 2024
removed
needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.
on Jul 4, 2024
added
I-miscompileIssue: Correct Rust code lowers to incorrect machine code
I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness
and removed
I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness
on Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

        Participants

        @saethlin@workingjubilee@rustbot@tmiasko

        Issue actions

          Miscompilation of a program projecting field of an extern type · Issue #127336 · rust-lang/rust