Skip to content

Commit c849a0d

Browse files
committed
Add a repro example for not propagating constants of partially const initialized variables
1 parent 09c817e commit c849a0d

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// compile-flags: -O
2+
3+
// EMIT_MIR rustc.main.ConstProp.diff
4+
fn main() {
5+
let mut x: (i32, i32) = foo();
6+
x.1 = 99;
7+
x.0 = 42;
8+
let y = x.1;
9+
}
10+
11+
#[inline(never)]
12+
fn foo() -> (i32, i32) {
13+
unimplemented!()
14+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
- // MIR for `main` before ConstProp
2+
+ // MIR for `main` after ConstProp
3+
4+
fn main() -> () {
5+
let mut _0: (); // return place in scope 0 at $DIR/mutable_variable_aggregate_partial_read.rs:4:11: 4:11
6+
let mut _1: (i32, i32) as UserTypeProjection { base: UserType(0), projs: [] }; // in scope 0 at $DIR/mutable_variable_aggregate_partial_read.rs:5:9: 5:14
7+
scope 1 {
8+
debug x => _1; // in scope 1 at $DIR/mutable_variable_aggregate_partial_read.rs:5:9: 5:14
9+
let _2: i32; // in scope 1 at $DIR/mutable_variable_aggregate_partial_read.rs:8:9: 8:10
10+
scope 2 {
11+
debug y => _2; // in scope 2 at $DIR/mutable_variable_aggregate_partial_read.rs:8:9: 8:10
12+
}
13+
}
14+
15+
bb0: {
16+
StorageLive(_1); // scope 0 at $DIR/mutable_variable_aggregate_partial_read.rs:5:9: 5:14
17+
_1 = const foo() -> bb1; // scope 0 at $DIR/mutable_variable_aggregate_partial_read.rs:5:29: 5:34
18+
// ty::Const
19+
// + ty: fn() -> (i32, i32) {foo}
20+
// + val: Value(Scalar(<ZST>))
21+
// mir::Constant
22+
// + span: $DIR/mutable_variable_aggregate_partial_read.rs:5:29: 5:32
23+
// + literal: Const { ty: fn() -> (i32, i32) {foo}, val: Value(Scalar(<ZST>)) }
24+
}
25+
26+
bb1: {
27+
(_1.1: i32) = const 99i32; // scope 1 at $DIR/mutable_variable_aggregate_partial_read.rs:6:5: 6:13
28+
// ty::Const
29+
// + ty: i32
30+
// + val: Value(Scalar(0x00000063))
31+
// mir::Constant
32+
// + span: $DIR/mutable_variable_aggregate_partial_read.rs:6:11: 6:13
33+
// + literal: Const { ty: i32, val: Value(Scalar(0x00000063)) }
34+
(_1.0: i32) = const 42i32; // scope 1 at $DIR/mutable_variable_aggregate_partial_read.rs:7:5: 7:13
35+
// ty::Const
36+
// + ty: i32
37+
// + val: Value(Scalar(0x0000002a))
38+
// mir::Constant
39+
// + span: $DIR/mutable_variable_aggregate_partial_read.rs:7:11: 7:13
40+
// + literal: Const { ty: i32, val: Value(Scalar(0x0000002a)) }
41+
StorageLive(_2); // scope 1 at $DIR/mutable_variable_aggregate_partial_read.rs:8:9: 8:10
42+
_2 = (_1.1: i32); // scope 1 at $DIR/mutable_variable_aggregate_partial_read.rs:8:13: 8:16
43+
_0 = const (); // scope 0 at $DIR/mutable_variable_aggregate_partial_read.rs:4:11: 9:2
44+
// ty::Const
45+
// + ty: ()
46+
// + val: Value(Scalar(<ZST>))
47+
// mir::Constant
48+
// + span: $DIR/mutable_variable_aggregate_partial_read.rs:4:11: 9:2
49+
// + literal: Const { ty: (), val: Value(Scalar(<ZST>)) }
50+
StorageDead(_2); // scope 1 at $DIR/mutable_variable_aggregate_partial_read.rs:9:1: 9:2
51+
StorageDead(_1); // scope 0 at $DIR/mutable_variable_aggregate_partial_read.rs:9:1: 9:2
52+
return; // scope 0 at $DIR/mutable_variable_aggregate_partial_read.rs:9:2: 9:2
53+
}
54+
}
55+

0 commit comments

Comments
 (0)