Skip to content

Commit

Permalink
Auto merge of #78434 - jonas-schievink:disable-miropt, r=wesleywiser
Browse files Browse the repository at this point in the history
Disable "optimization to avoid load of address" in InstCombine

Same as #78195, fixes #78192 (again).
  • Loading branch information
bors committed Oct 27, 2020
2 parents 56d288f + 0be35cf commit 2a71e45
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 3 deletions.
5 changes: 5 additions & 0 deletions compiler/rustc_mir/src/transform/instcombine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ impl OptimizationFinder<'b, 'tcx> {
}

fn find_deref_of_address(&mut self, rvalue: &Rvalue<'tcx>, location: Location) -> Option<()> {
// FIXME(#78192): This optimization can result in unsoundness.
if !self.tcx.sess.opts.debugging_opts.unsound_mir_opts {
return None;
}

// Look for the sequence
//
// _2 = &_1;
Expand Down
2 changes: 1 addition & 1 deletion src/test/mir-opt/const_prop/ref_deref.main.ConstProp.diff
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// + span: $DIR/ref_deref.rs:5:6: 5:10
// + literal: Const { ty: &i32, val: Unevaluated(WithOptConstParam { did: DefId(0:3 ~ ref_deref[317d]::main), const_param_did: None }, [], Some(promoted[0])) }
_2 = _4; // scope 0 at $DIR/ref_deref.rs:5:6: 5:10
- _1 = (*_4); // scope 0 at $DIR/ref_deref.rs:5:5: 5:10
- _1 = (*_2); // scope 0 at $DIR/ref_deref.rs:5:5: 5:10
+ _1 = const 4_i32; // scope 0 at $DIR/ref_deref.rs:5:5: 5:10
StorageDead(_2); // scope 0 at $DIR/ref_deref.rs:5:10: 5:11
StorageDead(_1); // scope 0 at $DIR/ref_deref.rs:5:10: 5:11
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// + span: $DIR/ref_deref_project.rs:5:6: 5:17
// + literal: Const { ty: &(i32, i32), val: Unevaluated(WithOptConstParam { did: DefId(0:3 ~ ref_deref_project[317d]::main), const_param_did: None }, [], Some(promoted[0])) }
_2 = &((*_4).1: i32); // scope 0 at $DIR/ref_deref_project.rs:5:6: 5:17
_1 = ((*_4).1: i32); // scope 0 at $DIR/ref_deref_project.rs:5:5: 5:17
_1 = (*_2); // scope 0 at $DIR/ref_deref_project.rs:5:5: 5:17
StorageDead(_2); // scope 0 at $DIR/ref_deref_project.rs:5:17: 5:18
StorageDead(_1); // scope 0 at $DIR/ref_deref_project.rs:5:17: 5:18
_0 = const (); // scope 0 at $DIR/ref_deref_project.rs:4:11: 6:2
Expand Down
2 changes: 1 addition & 1 deletion src/test/mir-opt/inst_combine_deref.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// compile-flags: -O
// compile-flags: -O -Zunsound-mir-opts
// EMIT_MIR inst_combine_deref.simple_opt.InstCombine.diff
fn simple_opt() -> u64 {
let x = 5;
Expand Down
17 changes: 17 additions & 0 deletions src/test/ui/issues/issue-78192.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// run-pass

#![allow(unused_assignments)]

fn main() {
let a = 1u32;
let b = 2u32;

let mut c: *const u32 = &a;
let d: &u32 = &b;

let x = unsafe { &*c };
c = d;
let z = *x;

assert_eq!(1, z);
}

0 comments on commit 2a71e45

Please sign in to comment.