Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tmiasko opened this issue Jul 4, 2024 · 0 comments
Open

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

tmiasko opened this issue Jul 4, 2024 · 0 comments
Labels
A-mir-opt Area: MIR optimizations C-bug Category: This is a bug. F-extern_types `#![feature(extern_types)]` I-miscompile Issue: Correct Rust code lowers to incorrect machine code I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-opsem Relevant to the opsem team

Comments

@tmiasko
Copy link
Contributor

tmiasko commented Jul 4, 2024

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
@tmiasko tmiasko added T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness C-bug Category: This is a bug. requires-nightly This issue requires a nightly compiler in some way. A-mir-opt Area: MIR optimizations F-extern_types `#![feature(extern_types)]` T-opsem Relevant to the opsem team labels Jul 4, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 4, 2024
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jul 4, 2024
@workingjubilee workingjubilee added I-miscompile Issue: Correct Rust code lowers to incorrect machine code I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness and removed I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness labels Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-mir-opt Area: MIR optimizations C-bug Category: This is a bug. F-extern_types `#![feature(extern_types)]` I-miscompile Issue: Correct Rust code lowers to incorrect machine code I-unsound Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-opsem Relevant to the opsem team
Projects
None yet
Development

No branches or pull requests

4 participants