Skip to content

Commit 2b6815a

Browse files
committed
[const prop] Fix "alloc id without corresponding allocation" ICE
Fixes #66345
1 parent c5e762f commit 2b6815a

File tree

6 files changed

+32
-10
lines changed

6 files changed

+32
-10
lines changed

src/librustc_mir/transform/const_prop.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -649,9 +649,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
649649
}
650650

651651
fn should_const_prop(&mut self, op: OpTy<'tcx>) -> bool {
652-
if self.tcx.sess.opts.debugging_opts.mir_opt_level >= 2 {
653-
return true;
654-
} else if self.tcx.sess.opts.debugging_opts.mir_opt_level == 0 {
652+
if self.tcx.sess.opts.debugging_opts.mir_opt_level == 0 {
655653
return false;
656654
}
657655

src/test/mir-opt/const_prop/const_prop_fails_gracefully.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ fn main() {
2323
// START rustc.main.ConstProp.after.mir
2424
// bb0: {
2525
// ...
26-
// _4 = const Scalar(AllocId(1).0x0) : &i32;
27-
// _3 = const Scalar(AllocId(1).0x0) : &i32;
28-
// _2 = const Value(Scalar(AllocId(1).0x0)) : *const i32;
26+
// _4 = const main::FOO;
27+
// _3 = _4;
28+
// _2 = move _3 as *const i32 (Misc);
2929
// ...
3030
// _1 = move _2 as usize (Misc);
3131
// ...

src/test/mir-opt/const_prop/ref_deref.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ fn main() {
1414
// START rustc.main.ConstProp.after.mir
1515
// bb0: {
1616
// ...
17-
// _2 = const Scalar(AllocId(0).0x0) : &i32;
17+
// _2 = &(promoted[0]: i32);
1818
// _1 = const 4i32;
1919
// ...
2020
// }

src/test/mir-opt/const_prop/reify_fn_ptr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ fn main() {
1616
// START rustc.main.ConstProp.after.mir
1717
// bb0: {
1818
// ...
19-
// _3 = const main;
19+
// _3 = const main as fn() (Pointer(ReifyFnPointer));
2020
// _2 = move _3 as usize (Misc);
2121
// ...
2222
// _1 = move _2 as *const fn() (Misc);

src/test/mir-opt/const_prop/slice_len.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ fn main() {
2424
// START rustc.main.ConstProp.after.mir
2525
// bb0: {
2626
// ...
27-
// _4 = const Scalar(AllocId(0).0x0) : &[u32; 3];
28-
// _3 = const Scalar(AllocId(0).0x0) : &[u32; 3];
27+
// _4 = &(promoted[0]: [u32; 3]);
28+
// _3 = _4;
2929
// _2 = move _3 as &[u32] (Pointer(Unsize));
3030
// ...
3131
// _6 = const 1usize;

src/test/ui/consts/issue-66345.rs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// run-pass
2+
// compile-flags: -Z mir-opt-level=3
3+
4+
// Checks that the compiler does not ICE when passing references to field of by-value struct
5+
// with -Z mir-opt-level=3
6+
7+
fn do_nothing(_: &()) {}
8+
9+
pub struct Foo {
10+
bar: (),
11+
}
12+
13+
pub fn by_value_1(foo: Foo) {
14+
do_nothing(&foo.bar);
15+
}
16+
17+
pub fn by_value_2<T>(foo: Foo) {
18+
do_nothing(&foo.bar);
19+
}
20+
21+
fn main() {
22+
by_value_1(Foo { bar: () });
23+
by_value_2::<()>(Foo { bar: () });
24+
}

0 commit comments

Comments
 (0)