[const prop] Fix "alloc id without corresponding allocation" ICE

Fixes #66345
This commit is contained in:
Wesley Wiser 2019-11-23 12:25:03 -05:00
parent c5e762fd88
commit 2b6815a69e
6 changed files with 32 additions and 10 deletions

View file

@ -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;
}

View file

@ -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);
// ...

View file

@ -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;
// ...
// }

View file

@ -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);

View file

@ -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;

View 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: () });
}