-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #73613 - oli-obk:const_prop_miscompile, r=wesleywiser
The const propagator cannot trace references. Thus we avoid propagation of a local the moment we encounter references to it. fixes #73609 cc @RalfJung r? @wesleywiser
- Loading branch information
Showing
8 changed files
with
204 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#![feature(raw_ref_op)] | ||
|
||
// EMIT_MIR rustc.foo.ConstProp.diff | ||
fn foo() { | ||
let mut u = (1,); | ||
*&mut u.0 = 5; | ||
let y = { u.0 } == 5; | ||
} | ||
|
||
// EMIT_MIR rustc.bar.ConstProp.diff | ||
fn bar() { | ||
let mut v = (1,); | ||
unsafe { | ||
*&raw mut v.0 = 5; | ||
} | ||
let y = { v.0 } == 5; | ||
} | ||
|
||
fn main() { | ||
foo(); | ||
bar(); | ||
} |
75 changes: 75 additions & 0 deletions
75
src/test/mir-opt/const_prop_miscompile/rustc.bar.ConstProp.diff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
- // MIR for `bar` before ConstProp | ||
+ // MIR for `bar` after ConstProp | ||
|
||
fn bar() -> () { | ||
let mut _0: (); // return place in scope 0 at $DIR/const_prop_miscompile.rs:11:10: 11:10 | ||
let mut _1: (i32,); // in scope 0 at $DIR/const_prop_miscompile.rs:12:9: 12:14 | ||
let _2: (); // in scope 0 at $DIR/const_prop_miscompile.rs:13:5: 15:6 | ||
let mut _3: *mut i32; // in scope 0 at $DIR/const_prop_miscompile.rs:14:10: 14:22 | ||
let mut _5: i32; // in scope 0 at $DIR/const_prop_miscompile.rs:16:13: 16:20 | ||
scope 1 { | ||
debug v => _1; // in scope 1 at $DIR/const_prop_miscompile.rs:12:9: 12:14 | ||
let _4: bool; // in scope 1 at $DIR/const_prop_miscompile.rs:16:9: 16:10 | ||
scope 2 { | ||
} | ||
scope 3 { | ||
debug y => _4; // in scope 3 at $DIR/const_prop_miscompile.rs:16:9: 16:10 | ||
} | ||
} | ||
|
||
bb0: { | ||
StorageLive(_1); // scope 0 at $DIR/const_prop_miscompile.rs:12:9: 12:14 | ||
- _1 = (const 1i32,); // scope 0 at $DIR/const_prop_miscompile.rs:12:17: 12:21 | ||
+ _1 = const (1i32,); // scope 0 at $DIR/const_prop_miscompile.rs:12:17: 12:21 | ||
// ty::Const | ||
- // + ty: i32 | ||
+ // + ty: (i32,) | ||
// + val: Value(Scalar(0x00000001)) | ||
// mir::Constant | ||
- // + span: $DIR/const_prop_miscompile.rs:12:18: 12:19 | ||
- // + literal: Const { ty: i32, val: Value(Scalar(0x00000001)) } | ||
+ // + span: $DIR/const_prop_miscompile.rs:12:17: 12:21 | ||
+ // + literal: Const { ty: (i32,), val: Value(Scalar(0x00000001)) } | ||
StorageLive(_2); // scope 1 at $DIR/const_prop_miscompile.rs:13:5: 15:6 | ||
StorageLive(_3); // scope 2 at $DIR/const_prop_miscompile.rs:14:10: 14:22 | ||
_3 = &raw mut (_1.0: i32); // scope 2 at $DIR/const_prop_miscompile.rs:14:10: 14:22 | ||
(*_3) = const 5i32; // scope 2 at $DIR/const_prop_miscompile.rs:14:9: 14:26 | ||
// ty::Const | ||
// + ty: i32 | ||
// + val: Value(Scalar(0x00000005)) | ||
// mir::Constant | ||
// + span: $DIR/const_prop_miscompile.rs:14:25: 14:26 | ||
// + literal: Const { ty: i32, val: Value(Scalar(0x00000005)) } | ||
StorageDead(_3); // scope 2 at $DIR/const_prop_miscompile.rs:14:26: 14:27 | ||
_2 = const (); // scope 2 at $DIR/const_prop_miscompile.rs:13:5: 15:6 | ||
// ty::Const | ||
// + ty: () | ||
// + val: Value(Scalar(<ZST>)) | ||
// mir::Constant | ||
// + span: $DIR/const_prop_miscompile.rs:13:5: 15:6 | ||
// + literal: Const { ty: (), val: Value(Scalar(<ZST>)) } | ||
StorageDead(_2); // scope 1 at $DIR/const_prop_miscompile.rs:15:5: 15:6 | ||
StorageLive(_4); // scope 1 at $DIR/const_prop_miscompile.rs:16:9: 16:10 | ||
StorageLive(_5); // scope 1 at $DIR/const_prop_miscompile.rs:16:13: 16:20 | ||
_5 = (_1.0: i32); // scope 1 at $DIR/const_prop_miscompile.rs:16:15: 16:18 | ||
_4 = Eq(move _5, const 5i32); // scope 1 at $DIR/const_prop_miscompile.rs:16:13: 16:25 | ||
// ty::Const | ||
// + ty: i32 | ||
// + val: Value(Scalar(0x00000005)) | ||
// mir::Constant | ||
// + span: $DIR/const_prop_miscompile.rs:16:24: 16:25 | ||
// + literal: Const { ty: i32, val: Value(Scalar(0x00000005)) } | ||
StorageDead(_5); // scope 1 at $DIR/const_prop_miscompile.rs:16:24: 16:25 | ||
_0 = const (); // scope 0 at $DIR/const_prop_miscompile.rs:11:10: 17:2 | ||
// ty::Const | ||
// + ty: () | ||
// + val: Value(Scalar(<ZST>)) | ||
// mir::Constant | ||
// + span: $DIR/const_prop_miscompile.rs:11:10: 17:2 | ||
// + literal: Const { ty: (), val: Value(Scalar(<ZST>)) } | ||
StorageDead(_4); // scope 1 at $DIR/const_prop_miscompile.rs:17:1: 17:2 | ||
StorageDead(_1); // scope 0 at $DIR/const_prop_miscompile.rs:17:1: 17:2 | ||
return; // scope 0 at $DIR/const_prop_miscompile.rs:17:2: 17:2 | ||
} | ||
} | ||
|
63 changes: 63 additions & 0 deletions
63
src/test/mir-opt/const_prop_miscompile/rustc.foo.ConstProp.diff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
- // MIR for `foo` before ConstProp | ||
+ // MIR for `foo` after ConstProp | ||
|
||
fn foo() -> () { | ||
let mut _0: (); // return place in scope 0 at $DIR/const_prop_miscompile.rs:4:10: 4:10 | ||
let mut _1: (i32,); // in scope 0 at $DIR/const_prop_miscompile.rs:5:9: 5:14 | ||
let mut _2: &mut i32; // in scope 0 at $DIR/const_prop_miscompile.rs:6:6: 6:14 | ||
let mut _4: i32; // in scope 0 at $DIR/const_prop_miscompile.rs:7:13: 7:20 | ||
scope 1 { | ||
debug u => _1; // in scope 1 at $DIR/const_prop_miscompile.rs:5:9: 5:14 | ||
let _3: bool; // in scope 1 at $DIR/const_prop_miscompile.rs:7:9: 7:10 | ||
scope 2 { | ||
debug y => _3; // in scope 2 at $DIR/const_prop_miscompile.rs:7:9: 7:10 | ||
} | ||
} | ||
|
||
bb0: { | ||
StorageLive(_1); // scope 0 at $DIR/const_prop_miscompile.rs:5:9: 5:14 | ||
- _1 = (const 1i32,); // scope 0 at $DIR/const_prop_miscompile.rs:5:17: 5:21 | ||
+ _1 = const (1i32,); // scope 0 at $DIR/const_prop_miscompile.rs:5:17: 5:21 | ||
// ty::Const | ||
- // + ty: i32 | ||
+ // + ty: (i32,) | ||
// + val: Value(Scalar(0x00000001)) | ||
// mir::Constant | ||
- // + span: $DIR/const_prop_miscompile.rs:5:18: 5:19 | ||
- // + literal: Const { ty: i32, val: Value(Scalar(0x00000001)) } | ||
+ // + span: $DIR/const_prop_miscompile.rs:5:17: 5:21 | ||
+ // + literal: Const { ty: (i32,), val: Value(Scalar(0x00000001)) } | ||
StorageLive(_2); // scope 1 at $DIR/const_prop_miscompile.rs:6:6: 6:14 | ||
_2 = &mut (_1.0: i32); // scope 1 at $DIR/const_prop_miscompile.rs:6:6: 6:14 | ||
(*_2) = const 5i32; // scope 1 at $DIR/const_prop_miscompile.rs:6:5: 6:18 | ||
// ty::Const | ||
// + ty: i32 | ||
// + val: Value(Scalar(0x00000005)) | ||
// mir::Constant | ||
// + span: $DIR/const_prop_miscompile.rs:6:17: 6:18 | ||
// + literal: Const { ty: i32, val: Value(Scalar(0x00000005)) } | ||
StorageDead(_2); // scope 1 at $DIR/const_prop_miscompile.rs:6:18: 6:19 | ||
StorageLive(_3); // scope 1 at $DIR/const_prop_miscompile.rs:7:9: 7:10 | ||
StorageLive(_4); // scope 1 at $DIR/const_prop_miscompile.rs:7:13: 7:20 | ||
_4 = (_1.0: i32); // scope 1 at $DIR/const_prop_miscompile.rs:7:15: 7:18 | ||
_3 = Eq(move _4, const 5i32); // scope 1 at $DIR/const_prop_miscompile.rs:7:13: 7:25 | ||
// ty::Const | ||
// + ty: i32 | ||
// + val: Value(Scalar(0x00000005)) | ||
// mir::Constant | ||
// + span: $DIR/const_prop_miscompile.rs:7:24: 7:25 | ||
// + literal: Const { ty: i32, val: Value(Scalar(0x00000005)) } | ||
StorageDead(_4); // scope 1 at $DIR/const_prop_miscompile.rs:7:24: 7:25 | ||
_0 = const (); // scope 0 at $DIR/const_prop_miscompile.rs:4:10: 8:2 | ||
// ty::Const | ||
// + ty: () | ||
// + val: Value(Scalar(<ZST>)) | ||
// mir::Constant | ||
// + span: $DIR/const_prop_miscompile.rs:4:10: 8:2 | ||
// + literal: Const { ty: (), val: Value(Scalar(<ZST>)) } | ||
StorageDead(_3); // scope 1 at $DIR/const_prop_miscompile.rs:8:1: 8:2 | ||
StorageDead(_1); // scope 0 at $DIR/const_prop_miscompile.rs:8:1: 8:2 | ||
return; // scope 0 at $DIR/const_prop_miscompile.rs:8:2: 8:2 | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters