You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
use std::mem::ManuallyDrop;fnmain(){letmut v = 0u8;let p = &rawmut v;letmut md = ManuallyDrop::new(unsafe{&mut*p });unsafe{ManuallyDrop::drop(&mut md);*p = 1;}let _keep = md;}
Runs fine when run with:
RUSTFLAGS='-Zmir-enable-passes=+Inline' cargo +nightly miri run
But reports UB when run with:
RUSTFLAGS='-Zmir-enable-passes=+Inline,+ScalarReplacementOfAggregates' cargo +nightly miri run
Bisection points to #150446, of course. I think we were should have updated a lot of MIR optimizations to handle MaybeDangling, because they've been doing a lot more aliasing analysis than I thought.
Note that the change here with #150446 is not new UB, it's less. This program (with optimizations off) used to encounter UB and now it doesn't. We changed the semantics to permit some programs that were previously forbidden and MIR opts still assume those programs are forbidden.
Activity
apiraino commentedon Oct 13, 2026
cc @WaffleLapkin
Rollup merge of rust-lang#164568 - tmiasko:sroa-dangling, r=saethlin
Unrolled build for #164568 in rollup 164609