Skip to content

Commit 1d27267

Browse files
committed
Auto merge of #78195 - tmiasko:instcombine, r=jonas-schievink
Disable "optimization to avoid load of address" in InstCombine The transformation is incorrect #78192. Disable it.
2 parents 22e6b9c + e200a4a commit 1d27267

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-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;

0 commit comments

Comments
 (0)