- Notifications
You must be signed in to change notification settings - Fork 14.1k
Open
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-rustlantisA miscompilation found by RustlantisA miscompilation found by RustlantisI-miscompileIssue: Correct Rust code lowers to incorrect machine codeIssue: Correct Rust code lowers to incorrect machine codeI-prioritizeIssue: Indicates that prioritization has been requested for this issue.Issue: Indicates that prioritization has been requested for this issue.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.This issue may need triage. Remove it if it has been sufficiently triaged.
Description
#![feature(custom_mir, core_intrinsics)] extern crate core; use core::intrinsics::mir::*; fn main() { println!("{}", oof()); } #[custom_mir(dialect = "runtime", phase = "initial")] fn oof() -> isize { mir! { let _2: isize; let _3: f64; let _4: isize; let _6: isize; let _7: isize; let _9: isize; let _10: isize; let _8: isize; let _13: char; let _14: i8; let _16: &'static mut char; let _21: u64; let _25: *const i8; let _32: &'static mut char; let _35: isize; let _68: isize; { _7 = isize::MIN; _9 = isize::MIN; _10 = isize::MIN; _8 = 0; _2 = isize::MAX; Goto(bb2) } bb2 = { _4 = _7 & _8; _6 = !_4; _8 = _2 >> _6; _4 = _9 & _7; _7 = !_8; _16 = &mut _13; Goto(bb4) } bb4 = { _6 = _7 | _10; _8 = _6 << _7; _3 = _8 as f64; _25 = core::ptr::addr_of!(_14); _9 = 0; _10 = !_4; _35 = _3 as isize; _32 = _16; _21 = 1; match _21 { 0_u64 => bb4, _ => bb29, } } bb29 = { _7 = _10 & _6; _2 = _6; *_25 = 1; match *_25 { 1 => bb39, _ => bb2 } } bb39 = { _68 = _7 & _35; Call(*_32 = fn17(_25), ReturnTo(bb56), UnwindUnreachable()) } bb56 = { RET = _68; Return() } } } fn fn17(_: *const i8) -> char { 'a' }Compile with
rustc +nightly -Zmir-opt-level=0 -Copt-level=1 -o $OUT -Cno-prepopulate-passes -Cpasses=sroa,instcombine And the executable will print
-9223372036854775808 But if run with Miri:
MIRIFLAGS="-Zmiri-tree-borrows -Zmiri-no-short-fd-operations" cargo +nightly miri run It will print 0.
Metadata
Metadata
Assignees
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.A-rustlantisA miscompilation found by RustlantisA miscompilation found by RustlantisI-miscompileIssue: Correct Rust code lowers to incorrect machine codeIssue: Correct Rust code lowers to incorrect machine codeI-prioritizeIssue: Indicates that prioritization has been requested for this issue.Issue: Indicates that prioritization has been requested for this issue.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.needs-triageThis issue may need triage. Remove it if it has been sufficiently triaged.This issue may need triage. Remove it if it has been sufficiently triaged.