Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[const prop] Fix "alloc id without corresponding allocation" ICE
Fixes #66345
  • Loading branch information
wesleywiser committed Nov 23, 2019
1 parent c5e762f commit 2b6815a
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 10 deletions.
4 changes: 1 addition & 3 deletions src/librustc_mir/transform/const_prop.rs
Expand Up @@ -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;
}

Expand Down
6 changes: 3 additions & 3 deletions src/test/mir-opt/const_prop/const_prop_fails_gracefully.rs
Expand Up @@ -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);
// ...
Expand Down
2 changes: 1 addition & 1 deletion src/test/mir-opt/const_prop/ref_deref.rs
Expand Up @@ -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;
// ...
// }
Expand Down
2 changes: 1 addition & 1 deletion src/test/mir-opt/const_prop/reify_fn_ptr.rs
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/test/mir-opt/const_prop/slice_len.rs
Expand Up @@ -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;
Expand Down
24 changes: 24 additions & 0 deletions src/test/ui/consts/issue-66345.rs
@@ -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: () });
}

0 comments on commit 2b6815a

Please sign in to comment.