[const prop] Fix "alloc id without corresponding allocation" ICE
Fixes #66345
This commit is contained in:
parent
c5e762fd88
commit
2b6815a69e
6 changed files with 32 additions and 10 deletions
|
|
@ -649,9 +649,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
|
|||
}
|
||||
|
||||
fn should_const_prop(&mut self, op: OpTy<'tcx>) -> bool {
|
||||
if self.tcx.sess.opts.debugging_opts.mir_opt_level >= 2 {
|
||||
return true;
|
||||
} else if self.tcx.sess.opts.debugging_opts.mir_opt_level == 0 {
|
||||
if self.tcx.sess.opts.debugging_opts.mir_opt_level == 0 {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,9 +23,9 @@ fn main() {
|
|||
// START rustc.main.ConstProp.after.mir
|
||||
// bb0: {
|
||||
// ...
|
||||
// _4 = const Scalar(AllocId(1).0x0) : &i32;
|
||||
// _3 = const Scalar(AllocId(1).0x0) : &i32;
|
||||
// _2 = const Value(Scalar(AllocId(1).0x0)) : *const i32;
|
||||
// _4 = const main::FOO;
|
||||
// _3 = _4;
|
||||
// _2 = move _3 as *const i32 (Misc);
|
||||
// ...
|
||||
// _1 = move _2 as usize (Misc);
|
||||
// ...
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ fn main() {
|
|||
// START rustc.main.ConstProp.after.mir
|
||||
// bb0: {
|
||||
// ...
|
||||
// _2 = const Scalar(AllocId(0).0x0) : &i32;
|
||||
// _2 = &(promoted[0]: i32);
|
||||
// _1 = const 4i32;
|
||||
// ...
|
||||
// }
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ fn main() {
|
|||
// START rustc.main.ConstProp.after.mir
|
||||
// bb0: {
|
||||
// ...
|
||||
// _3 = const main;
|
||||
// _3 = const main as fn() (Pointer(ReifyFnPointer));
|
||||
// _2 = move _3 as usize (Misc);
|
||||
// ...
|
||||
// _1 = move _2 as *const fn() (Misc);
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@ fn main() {
|
|||
// START rustc.main.ConstProp.after.mir
|
||||
// bb0: {
|
||||
// ...
|
||||
// _4 = const Scalar(AllocId(0).0x0) : &[u32; 3];
|
||||
// _3 = const Scalar(AllocId(0).0x0) : &[u32; 3];
|
||||
// _4 = &(promoted[0]: [u32; 3]);
|
||||
// _3 = _4;
|
||||
// _2 = move _3 as &[u32] (Pointer(Unsize));
|
||||
// ...
|
||||
// _6 = const 1usize;
|
||||
|
|
|
|||
24
src/test/ui/consts/issue-66345.rs
Normal file
24
src/test/ui/consts/issue-66345.rs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
// run-pass
|
||||
// compile-flags: -Z mir-opt-level=3
|
||||
|
||||
// Checks that the compiler does not ICE when passing references to field of by-value struct
|
||||
// with -Z mir-opt-level=3
|
||||
|
||||
fn do_nothing(_: &()) {}
|
||||
|
||||
pub struct Foo {
|
||||
bar: (),
|
||||
}
|
||||
|
||||
pub fn by_value_1(foo: Foo) {
|
||||
do_nothing(&foo.bar);
|
||||
}
|
||||
|
||||
pub fn by_value_2<T>(foo: Foo) {
|
||||
do_nothing(&foo.bar);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
by_value_1(Foo { bar: () });
|
||||
by_value_2::<()>(Foo { bar: () });
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue