Skip to content

Commit 2a71e45

Browse files
committed
Auto merge of #78434 - jonas-schievink:disable-miropt, r=wesleywiser
Disable "optimization to avoid load of address" in InstCombine Same as #78195, fixes #78192 (again).
2 parents 56d288f + 0be35cf commit 2a71e45

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

compiler/rustc_mir/src/transform/instcombine.rs

+5
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ impl OptimizationFinder<'b, 'tcx> {
119119
}
120120

121121
fn find_deref_of_address(&mut self, rvalue: &Rvalue<'tcx>, location: Location) -> Option<()> {
122+
// FIXME(#78192): This optimization can result in unsoundness.
123+
if !self.tcx.sess.opts.debugging_opts.unsound_mir_opts {
124+
return None;
125+
}
126+
122127
// Look for the sequence
123128
//
124129
// _2 = &_1;

src/test/mir-opt/const_prop/ref_deref.main.ConstProp.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// + span: $DIR/ref_deref.rs:5:6: 5:10
2020
// + literal: Const { ty: &i32, val: Unevaluated(WithOptConstParam { did: DefId(0:3 ~ ref_deref[317d]::main), const_param_did: None }, [], Some(promoted[0])) }
2121
_2 = _4; // scope 0 at $DIR/ref_deref.rs:5:6: 5:10
22-
- _1 = (*_4); // scope 0 at $DIR/ref_deref.rs:5:5: 5:10
22+
- _1 = (*_2); // scope 0 at $DIR/ref_deref.rs:5:5: 5:10
2323
+ _1 = const 4_i32; // scope 0 at $DIR/ref_deref.rs:5:5: 5:10
2424
StorageDead(_2); // scope 0 at $DIR/ref_deref.rs:5:10: 5:11
2525
StorageDead(_1); // scope 0 at $DIR/ref_deref.rs:5:10: 5:11

src/test/mir-opt/const_prop/ref_deref_project.main.ConstProp.diff

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// + span: $DIR/ref_deref_project.rs:5:6: 5:17
2020
// + literal: Const { ty: &(i32, i32), val: Unevaluated(WithOptConstParam { did: DefId(0:3 ~ ref_deref_project[317d]::main), const_param_did: None }, [], Some(promoted[0])) }
2121
_2 = &((*_4).1: i32); // scope 0 at $DIR/ref_deref_project.rs:5:6: 5:17
22-
_1 = ((*_4).1: i32); // scope 0 at $DIR/ref_deref_project.rs:5:5: 5:17
22+
_1 = (*_2); // scope 0 at $DIR/ref_deref_project.rs:5:5: 5:17
2323
StorageDead(_2); // scope 0 at $DIR/ref_deref_project.rs:5:17: 5:18
2424
StorageDead(_1); // scope 0 at $DIR/ref_deref_project.rs:5:17: 5:18
2525
_0 = const (); // scope 0 at $DIR/ref_deref_project.rs:4:11: 6:2

src/test/mir-opt/inst_combine_deref.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// compile-flags: -O
1+
// compile-flags: -O -Zunsound-mir-opts
22
// EMIT_MIR inst_combine_deref.simple_opt.InstCombine.diff
33
fn simple_opt() -> u64 {
44
let x = 5;

src/test/ui/issues/issue-78192.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// run-pass
2+
3+
#![allow(unused_assignments)]
4+
5+
fn main() {
6+
let a = 1u32;
7+
let b = 2u32;
8+
9+
let mut c: *const u32 = &a;
10+
let d: &u32 = &b;
11+
12+
let x = unsafe { &*c };
13+
c = d;
14+
let z = *x;
15+
16+
assert_eq!(1, z);
17+
}

0 commit comments

Comments
 (0)