about summary refs log tree commit diff
diff options
context:
space:
mode:
authorWesley Wiser <wwiser@gmail.com>2019-11-23 12:25:03 -0500
committerWesley Wiser <wwiser@gmail.com>2019-11-23 15:11:59 -0500
commit2b6815a69e618a96a221d8db24ace87d10ae69f0 (patch)
tree336668e7da24bff52ad57f0089cb85ab21a4cf3c
parentc5e762fd8845658bf5d70dc714d16f2a1ec75c3f (diff)
downloadrust-2b6815a69e618a96a221d8db24ace87d10ae69f0.tar.gz
rust-2b6815a69e618a96a221d8db24ace87d10ae69f0.zip
[const prop] Fix "alloc id without corresponding allocation" ICE
Fixes #66345
-rw-r--r--src/librustc_mir/transform/const_prop.rs4
-rw-r--r--src/test/mir-opt/const_prop/const_prop_fails_gracefully.rs6
-rw-r--r--src/test/mir-opt/const_prop/ref_deref.rs2
-rw-r--r--src/test/mir-opt/const_prop/reify_fn_ptr.rs2
-rw-r--r--src/test/mir-opt/const_prop/slice_len.rs4
-rw-r--r--src/test/ui/consts/issue-66345.rs24
6 files changed, 32 insertions, 10 deletions
diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs
index 4333e5c5142..f7572f36684 100644
--- a/src/librustc_mir/transform/const_prop.rs
+++ b/src/librustc_mir/transform/const_prop.rs
@@ -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;
         }
 
diff --git a/src/test/mir-opt/const_prop/const_prop_fails_gracefully.rs b/src/test/mir-opt/const_prop/const_prop_fails_gracefully.rs
index 34d4a534ad9..3f82b81a47d 100644
--- a/src/test/mir-opt/const_prop/const_prop_fails_gracefully.rs
+++ b/src/test/mir-opt/const_prop/const_prop_fails_gracefully.rs
@@ -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);
 //      ...
diff --git a/src/test/mir-opt/const_prop/ref_deref.rs b/src/test/mir-opt/const_prop/ref_deref.rs
index 2d04822c0e7..d45ffdc8775 100644
--- a/src/test/mir-opt/const_prop/ref_deref.rs
+++ b/src/test/mir-opt/const_prop/ref_deref.rs
@@ -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;
 //     ...
 // }
diff --git a/src/test/mir-opt/const_prop/reify_fn_ptr.rs b/src/test/mir-opt/const_prop/reify_fn_ptr.rs
index ad7f195676a..4d6fe905b0c 100644
--- a/src/test/mir-opt/const_prop/reify_fn_ptr.rs
+++ b/src/test/mir-opt/const_prop/reify_fn_ptr.rs
@@ -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);
diff --git a/src/test/mir-opt/const_prop/slice_len.rs b/src/test/mir-opt/const_prop/slice_len.rs
index 05595ce147c..d6ff76b34b9 100644
--- a/src/test/mir-opt/const_prop/slice_len.rs
+++ b/src/test/mir-opt/const_prop/slice_len.rs
@@ -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;
diff --git a/src/test/ui/consts/issue-66345.rs b/src/test/ui/consts/issue-66345.rs
new file mode 100644
index 00000000000..7d0de73007c
--- /dev/null
+++ b/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: () });
+}