about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCamille GILLOT <gillot.camille@gmail.com>2023-10-31 17:34:06 +0000
committerCamille GILLOT <gillot.camille@gmail.com>2023-11-01 16:49:18 +0000
commita2e151ca4b3a90d3314997bc895fe9ce95a3ae0e (patch)
treef54de74a22d21a121419a51a1cecdc3e264a9cf1
parentc2f49e9edf2bae4eaede9af13f5dfb80aacb04d1 (diff)
downloadrust-a2e151ca4b3a90d3314997bc895fe9ce95a3ae0e.tar.gz
rust-a2e151ca4b3a90d3314997bc895fe9ce95a3ae0e.zip
Make ui into mir-opt test.
-rw-r--r--tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-abort.diff127
-rw-r--r--tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-unwind.diff92
-rw-r--r--tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-abort.diff127
-rw-r--r--tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-unwind.diff92
-rw-r--r--tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.rs15
-rw-r--r--tests/ui/mir/issue-117368-print-invalid-constant.rs11
6 files changed, 453 insertions, 11 deletions
diff --git a/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-abort.diff b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-abort.diff
new file mode 100644
index 00000000000..e521b789b60
--- /dev/null
+++ b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-abort.diff
@@ -0,0 +1,127 @@
+- // MIR for `main` before GVN
++ // MIR for `main` after GVN
+  
+  fn main() -> () {
+      let mut _0: ();
+      let _1: std::alloc::Layout;
+      let mut _2: std::option::Option<std::alloc::Layout>;
+      let mut _3: *mut u8;
+      let mut _4: *mut [u8];
+      let mut _5: std::ptr::NonNull<[u8]>;
+      let mut _6: std::result::Result<std::ptr::NonNull<[u8]>, std::alloc::AllocError>;
+      let mut _7: &std::alloc::Global;
+      let mut _8: std::alloc::Layout;
+      scope 1 {
+          debug layout => _1;
+          let mut _9: &std::alloc::Global;
+          scope 2 {
+              debug ptr => _3;
+          }
+          scope 5 (inlined <std::alloc::Global as Allocator>::allocate) {
+              debug self => _9;
+              debug layout => _1;
+          }
+          scope 6 (inlined #[track_caller] Result::<NonNull<[u8]>, std::alloc::AllocError>::unwrap) {
+              debug self => _6;
+              let mut _12: isize;
+              let _13: std::alloc::AllocError;
+              let mut _14: !;
+              let _15: &str;
+              let mut _16: &dyn std::fmt::Debug;
+              let mut _17: &std::alloc::AllocError;
+              scope 7 {
+                  debug t => _5;
+              }
+              scope 8 {
+                  debug e => const std::alloc::AllocError;
+              }
+          }
+          scope 9 (inlined NonNull::<[u8]>::as_ptr) {
+              debug self => _5;
+              let mut _18: *const [u8];
+          }
+      }
+      scope 3 (inlined #[track_caller] Option::<Layout>::unwrap) {
+          debug self => _2;
+          let mut _10: isize;
+          let mut _11: !;
+          scope 4 {
+              debug val => _1;
+          }
+      }
+  
+      bb0: {
+          StorageLive(_2);
+-         _2 = Option::<Layout>::None;
++         _2 = const Option::<Layout>::None;
+          StorageLive(_10);
+          _10 = const 0_isize;
+          switchInt(const 0_isize) -> [0: bb1, 1: bb3, otherwise: bb2];
+      }
+  
+      bb1: {
+          _11 = core::panicking::panic(const "called `Option::unwrap()` on a `None` value") -> unwind unreachable;
+      }
+  
+      bb2: {
+          unreachable;
+      }
+  
+      bb3: {
+-         _1 = move ((_2 as Some).0: std::alloc::Layout);
++         _1 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(4 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x00000000): ptr::alignment::AlignmentEnum32) }};
+          StorageDead(_10);
+          StorageDead(_2);
+          StorageLive(_3);
+          StorageLive(_4);
+          StorageLive(_5);
+          StorageLive(_6);
+          _9 = const _;
+-         _6 = std::alloc::Global::alloc_impl(_9, _1, const false) -> [return: bb4, unwind unreachable];
++         _6 = std::alloc::Global::alloc_impl(const {ALLOC1: &std::alloc::Global}, const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(4 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x00000000): ptr::alignment::AlignmentEnum32) }}, const false) -> [return: bb4, unwind unreachable];
+      }
+  
+      bb4: {
+          StorageLive(_12);
+          StorageLive(_15);
+          _12 = discriminant(_6);
+          switchInt(move _12) -> [0: bb7, 1: bb5, otherwise: bb6];
+      }
+  
+      bb5: {
+          _15 = const "called `Result::unwrap()` on an `Err` value";
+          StorageLive(_16);
+          StorageLive(_17);
+          _17 = &_13;
+          _16 = move _17 as &dyn std::fmt::Debug (PointerCoercion(Unsize));
+          StorageDead(_17);
+          _14 = result::unwrap_failed(move _15, move _16) -> unwind unreachable;
+      }
+  
+      bb6: {
+          unreachable;
+      }
+  
+      bb7: {
+          _5 = move ((_6 as Ok).0: std::ptr::NonNull<[u8]>);
+          StorageDead(_15);
+          StorageDead(_12);
+          StorageDead(_6);
+          StorageLive(_18);
+          _18 = (_5.0: *const [u8]);
+          _4 = move _18 as *mut [u8] (PtrToPtr);
+          StorageDead(_18);
+          StorageDead(_5);
+          _3 = move _4 as *mut u8 (PtrToPtr);
+          StorageDead(_4);
+          StorageDead(_3);
+          return;
+      }
+  }
++ 
++ ALLOC0 (size: 8, align: 4) {
++     00 00 00 00 __ __ __ __                         │ ....░░░░
++ }
++ 
++ ALLOC1 (size: 0, align: 1) {}
+  
diff --git a/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-unwind.diff b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-unwind.diff
new file mode 100644
index 00000000000..6966762a1b8
--- /dev/null
+++ b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.32bit.panic-unwind.diff
@@ -0,0 +1,92 @@
+- // MIR for `main` before GVN
++ // MIR for `main` after GVN
+  
+  fn main() -> () {
+      let mut _0: ();
+      let _1: std::alloc::Layout;
+      let mut _2: std::option::Option<std::alloc::Layout>;
+      let mut _3: *mut u8;
+      let mut _4: *mut [u8];
+      let mut _5: std::ptr::NonNull<[u8]>;
+      let mut _6: std::result::Result<std::ptr::NonNull<[u8]>, std::alloc::AllocError>;
+      let mut _7: &std::alloc::Global;
+      let mut _8: std::alloc::Layout;
+      scope 1 {
+          debug layout => _1;
+          let mut _9: &std::alloc::Global;
+          scope 2 {
+              debug ptr => _3;
+          }
+          scope 5 (inlined <std::alloc::Global as Allocator>::allocate) {
+              debug self => _9;
+              debug layout => _1;
+          }
+          scope 6 (inlined NonNull::<[u8]>::as_ptr) {
+              debug self => _5;
+              let mut _12: *const [u8];
+          }
+      }
+      scope 3 (inlined #[track_caller] Option::<Layout>::unwrap) {
+          debug self => _2;
+          let mut _10: isize;
+          let mut _11: !;
+          scope 4 {
+              debug val => _1;
+          }
+      }
+  
+      bb0: {
+          StorageLive(_2);
+-         _2 = Option::<Layout>::None;
++         _2 = const Option::<Layout>::None;
+          StorageLive(_10);
+          _10 = const 0_isize;
+          switchInt(const 0_isize) -> [0: bb2, 1: bb4, otherwise: bb3];
+      }
+  
+      bb1: {
+          StorageDead(_6);
+          StorageLive(_12);
+          _12 = (_5.0: *const [u8]);
+          _4 = move _12 as *mut [u8] (PtrToPtr);
+          StorageDead(_12);
+          StorageDead(_5);
+          _3 = move _4 as *mut u8 (PtrToPtr);
+          StorageDead(_4);
+          StorageDead(_3);
+          return;
+      }
+  
+      bb2: {
+          _11 = core::panicking::panic(const "called `Option::unwrap()` on a `None` value") -> unwind continue;
+      }
+  
+      bb3: {
+          unreachable;
+      }
+  
+      bb4: {
+-         _1 = move ((_2 as Some).0: std::alloc::Layout);
++         _1 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(4 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x00000000): ptr::alignment::AlignmentEnum32) }};
+          StorageDead(_10);
+          StorageDead(_2);
+          StorageLive(_3);
+          StorageLive(_4);
+          StorageLive(_5);
+          StorageLive(_6);
+          _9 = const _;
+-         _6 = std::alloc::Global::alloc_impl(_9, _1, const false) -> [return: bb5, unwind continue];
++         _6 = std::alloc::Global::alloc_impl(const {ALLOC1: &std::alloc::Global}, const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(4 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x00000000): ptr::alignment::AlignmentEnum32) }}, const false) -> [return: bb5, unwind continue];
+      }
+  
+      bb5: {
+          _5 = Result::<NonNull<[u8]>, std::alloc::AllocError>::unwrap(move _6) -> [return: bb1, unwind continue];
+      }
+  }
++ 
++ ALLOC0 (size: 8, align: 4) {
++     00 00 00 00 __ __ __ __                         │ ....░░░░
++ }
++ 
++ ALLOC1 (size: 0, align: 1) {}
+  
diff --git a/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-abort.diff b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-abort.diff
new file mode 100644
index 00000000000..f6c4b785bf1
--- /dev/null
+++ b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-abort.diff
@@ -0,0 +1,127 @@
+- // MIR for `main` before GVN
++ // MIR for `main` after GVN
+  
+  fn main() -> () {
+      let mut _0: ();
+      let _1: std::alloc::Layout;
+      let mut _2: std::option::Option<std::alloc::Layout>;
+      let mut _3: *mut u8;
+      let mut _4: *mut [u8];
+      let mut _5: std::ptr::NonNull<[u8]>;
+      let mut _6: std::result::Result<std::ptr::NonNull<[u8]>, std::alloc::AllocError>;
+      let mut _7: &std::alloc::Global;
+      let mut _8: std::alloc::Layout;
+      scope 1 {
+          debug layout => _1;
+          let mut _9: &std::alloc::Global;
+          scope 2 {
+              debug ptr => _3;
+          }
+          scope 5 (inlined <std::alloc::Global as Allocator>::allocate) {
+              debug self => _9;
+              debug layout => _1;
+          }
+          scope 6 (inlined #[track_caller] Result::<NonNull<[u8]>, std::alloc::AllocError>::unwrap) {
+              debug self => _6;
+              let mut _12: isize;
+              let _13: std::alloc::AllocError;
+              let mut _14: !;
+              let _15: &str;
+              let mut _16: &dyn std::fmt::Debug;
+              let mut _17: &std::alloc::AllocError;
+              scope 7 {
+                  debug t => _5;
+              }
+              scope 8 {
+                  debug e => const std::alloc::AllocError;
+              }
+          }
+          scope 9 (inlined NonNull::<[u8]>::as_ptr) {
+              debug self => _5;
+              let mut _18: *const [u8];
+          }
+      }
+      scope 3 (inlined #[track_caller] Option::<Layout>::unwrap) {
+          debug self => _2;
+          let mut _10: isize;
+          let mut _11: !;
+          scope 4 {
+              debug val => _1;
+          }
+      }
+  
+      bb0: {
+          StorageLive(_2);
+-         _2 = Option::<Layout>::None;
++         _2 = const Option::<Layout>::None;
+          StorageLive(_10);
+          _10 = const 0_isize;
+          switchInt(const 0_isize) -> [0: bb1, 1: bb3, otherwise: bb2];
+      }
+  
+      bb1: {
+          _11 = core::panicking::panic(const "called `Option::unwrap()` on a `None` value") -> unwind unreachable;
+      }
+  
+      bb2: {
+          unreachable;
+      }
+  
+      bb3: {
+-         _1 = move ((_2 as Some).0: std::alloc::Layout);
++         _1 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(8 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x0000000000000000): ptr::alignment::AlignmentEnum64) }};
+          StorageDead(_10);
+          StorageDead(_2);
+          StorageLive(_3);
+          StorageLive(_4);
+          StorageLive(_5);
+          StorageLive(_6);
+          _9 = const _;
+-         _6 = std::alloc::Global::alloc_impl(_9, _1, const false) -> [return: bb4, unwind unreachable];
++         _6 = std::alloc::Global::alloc_impl(const {ALLOC1: &std::alloc::Global}, const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(8 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x0000000000000000): ptr::alignment::AlignmentEnum64) }}, const false) -> [return: bb4, unwind unreachable];
+      }
+  
+      bb4: {
+          StorageLive(_12);
+          StorageLive(_15);
+          _12 = discriminant(_6);
+          switchInt(move _12) -> [0: bb7, 1: bb5, otherwise: bb6];
+      }
+  
+      bb5: {
+          _15 = const "called `Result::unwrap()` on an `Err` value";
+          StorageLive(_16);
+          StorageLive(_17);
+          _17 = &_13;
+          _16 = move _17 as &dyn std::fmt::Debug (PointerCoercion(Unsize));
+          StorageDead(_17);
+          _14 = result::unwrap_failed(move _15, move _16) -> unwind unreachable;
+      }
+  
+      bb6: {
+          unreachable;
+      }
+  
+      bb7: {
+          _5 = move ((_6 as Ok).0: std::ptr::NonNull<[u8]>);
+          StorageDead(_15);
+          StorageDead(_12);
+          StorageDead(_6);
+          StorageLive(_18);
+          _18 = (_5.0: *const [u8]);
+          _4 = move _18 as *mut [u8] (PtrToPtr);
+          StorageDead(_18);
+          StorageDead(_5);
+          _3 = move _4 as *mut u8 (PtrToPtr);
+          StorageDead(_4);
+          StorageDead(_3);
+          return;
+      }
+  }
++ 
++ ALLOC0 (size: 16, align: 8) {
++     00 00 00 00 00 00 00 00 __ __ __ __ __ __ __ __ │ ........░░░░░░░░
++ }
++ 
++ ALLOC1 (size: 0, align: 1) {}
+  
diff --git a/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-unwind.diff b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-unwind.diff
new file mode 100644
index 00000000000..6501cb85e8a
--- /dev/null
+++ b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.main.GVN.64bit.panic-unwind.diff
@@ -0,0 +1,92 @@
+- // MIR for `main` before GVN
++ // MIR for `main` after GVN
+  
+  fn main() -> () {
+      let mut _0: ();
+      let _1: std::alloc::Layout;
+      let mut _2: std::option::Option<std::alloc::Layout>;
+      let mut _3: *mut u8;
+      let mut _4: *mut [u8];
+      let mut _5: std::ptr::NonNull<[u8]>;
+      let mut _6: std::result::Result<std::ptr::NonNull<[u8]>, std::alloc::AllocError>;
+      let mut _7: &std::alloc::Global;
+      let mut _8: std::alloc::Layout;
+      scope 1 {
+          debug layout => _1;
+          let mut _9: &std::alloc::Global;
+          scope 2 {
+              debug ptr => _3;
+          }
+          scope 5 (inlined <std::alloc::Global as Allocator>::allocate) {
+              debug self => _9;
+              debug layout => _1;
+          }
+          scope 6 (inlined NonNull::<[u8]>::as_ptr) {
+              debug self => _5;
+              let mut _12: *const [u8];
+          }
+      }
+      scope 3 (inlined #[track_caller] Option::<Layout>::unwrap) {
+          debug self => _2;
+          let mut _10: isize;
+          let mut _11: !;
+          scope 4 {
+              debug val => _1;
+          }
+      }
+  
+      bb0: {
+          StorageLive(_2);
+-         _2 = Option::<Layout>::None;
++         _2 = const Option::<Layout>::None;
+          StorageLive(_10);
+          _10 = const 0_isize;
+          switchInt(const 0_isize) -> [0: bb2, 1: bb4, otherwise: bb3];
+      }
+  
+      bb1: {
+          StorageDead(_6);
+          StorageLive(_12);
+          _12 = (_5.0: *const [u8]);
+          _4 = move _12 as *mut [u8] (PtrToPtr);
+          StorageDead(_12);
+          StorageDead(_5);
+          _3 = move _4 as *mut u8 (PtrToPtr);
+          StorageDead(_4);
+          StorageDead(_3);
+          return;
+      }
+  
+      bb2: {
+          _11 = core::panicking::panic(const "called `Option::unwrap()` on a `None` value") -> unwind continue;
+      }
+  
+      bb3: {
+          unreachable;
+      }
+  
+      bb4: {
+-         _1 = move ((_2 as Some).0: std::alloc::Layout);
++         _1 = const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(8 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x0000000000000000): ptr::alignment::AlignmentEnum64) }};
+          StorageDead(_10);
+          StorageDead(_2);
+          StorageLive(_3);
+          StorageLive(_4);
+          StorageLive(_5);
+          StorageLive(_6);
+          _9 = const _;
+-         _6 = std::alloc::Global::alloc_impl(_9, _1, const false) -> [return: bb5, unwind continue];
++         _6 = std::alloc::Global::alloc_impl(const {ALLOC1: &std::alloc::Global}, const Layout {{ size: Indirect { alloc_id: ALLOC0, offset: Size(8 bytes) }: usize, align: std::ptr::Alignment(Scalar(0x0000000000000000): ptr::alignment::AlignmentEnum64) }}, const false) -> [return: bb5, unwind continue];
+      }
+  
+      bb5: {
+          _5 = Result::<NonNull<[u8]>, std::alloc::AllocError>::unwrap(move _6) -> [return: bb1, unwind continue];
+      }
+  }
++ 
++ ALLOC0 (size: 16, align: 8) {
++     00 00 00 00 00 00 00 00 __ __ __ __ __ __ __ __ │ ........░░░░░░░░
++ }
++ 
++ ALLOC1 (size: 0, align: 1) {}
+  
diff --git a/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.rs b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.rs
new file mode 100644
index 00000000000..c92424f2983
--- /dev/null
+++ b/tests/mir-opt/pre-codegen/issue_117368_print_invalid_constant.rs
@@ -0,0 +1,15 @@
+// Verify that we do not ICE when printing an invalid constant.
+// EMIT_MIR_FOR_EACH_BIT_WIDTH
+// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
+
+#![feature(allocator_api)]
+
+use std::alloc::{Allocator, Global, Layout};
+
+// EMIT_MIR issue_117368_print_invalid_constant.main.GVN.diff
+fn main() {
+    // CHECK-LABEL: fn main(
+    // CHECK: debug layout => const Layout
+    let layout: Layout = None.unwrap();
+    let ptr: *mut u8 = Global.allocate(layout).unwrap().as_ptr() as _;
+}
diff --git a/tests/ui/mir/issue-117368-print-invalid-constant.rs b/tests/ui/mir/issue-117368-print-invalid-constant.rs
deleted file mode 100644
index d9610391941..00000000000
--- a/tests/ui/mir/issue-117368-print-invalid-constant.rs
+++ /dev/null
@@ -1,11 +0,0 @@
-// build-pass
-// compile-flags:-Zmir-opt-level=4 --emit=mir
-
-#![feature(allocator_api)]
-
-use std::alloc::{Allocator, Global, Layout};
-
-fn main() {
-    let layout: Layout = None.unwrap();
-    let ptr: *mut u8 = Global.allocate(layout).unwrap().as_ptr() as _;
-}