about summary refs log tree commit diff
path: root/tests/mir-opt/lower_array_len.array_bound.NormalizeArrayLen.panic-unwind.diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-06-14 14:20:59 +0000
committerbors <bors@rust-lang.org>2023-06-14 14:20:59 +0000
commitafa9fef70904bee316d5a73275397d7c4e7c8c4b (patch)
treef4c520b318d66dbbcfd1c1aeb5962ff8154386c2 /tests/mir-opt/lower_array_len.array_bound.NormalizeArrayLen.panic-unwind.diff
parent7b0eac438ace0ba305b4633328b00474fbbf5120 (diff)
parentf67809ac1dca66e98c0999634212532974e43b97 (diff)
downloadrust-afa9fef70904bee316d5a73275397d7c4e7c8c4b.tar.gz
rust-afa9fef70904bee316d5a73275397d7c4e7c8c4b.zip
Auto merge of #112418 - ferrocene:pa-mir-opt-panic, r=ozkanonur,saethlin
Add support for targets without unwinding in `mir-opt`, and improve `--bless` for it

The main goal of this PR is to add support for targets without unwinding support in the `mir-opt` test suite, by adding the `EMIT_MIR_FOR_EACH_PANIC_STRATEGY` comment. Similarly to 32bit vs 64bit, when that comment is present, blessed output files will have the `.panic-unwind` or `.panic-abort` suffix, and the right one will be chosen depending on the target's panic strategy.

The `EMIT_MIR_FOR_EACH_PANIC_STRATEGY` comment replaced all the `ignore-wasm32` comments in the `mir-opt` test suite, as those comments were added due to `wasm32` being a target without unwinding support. The comment was also added on other tests that were only executed on x86 but were still panic strategy dependent.

The `mir-opt` suite was then blessed, which caused a ton of churn as most of the existing output files had to be renamed and (mostly) duplicated with the abort strategy.

---

After [asking on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/mir-opt.20tests.20and.20panic.3Dabort), the main concern about this change is it'd make blessing the `mir-opt` suite even harder, as you'd need to both bless it with an unwinding target and an aborting target. This exacerbated the current situation, where you'd need to bless it with a 32bit and a 64bit target already.

Because of that, this PR also makes significant enhancements to `--bless` for the `mir-opt` suite, where it will automatically bless the suite four times with different targets, while requiring minimal cross-compilation.

To handle the 32bit vs 64bit blessing, there is now an hardcoded list of target mapping between 32bit and 64bit. The goal of the list is to find a related target that will *probably* work without requiring additional cross-compilation toolchains on the system. If a mapping is found, bootstrap will bless the suite with both targets, otherwise just with the current target.

To handle the panic strategy blessing (abort vs unwind), I had to resort to what I call "synthetic targets". For each of the target we're blessing (so either the current one, or a 32bit and a 64bit depending on the previous paragraph), bootstrap will extract the JSON spec of the target and change it to include `"panic-strategy": "abort"`. It will then build the standard library with this synthetic target, and bless the `mir-opt` suite with it.

As a result of these changes, blessing the `mir-opt` suite will actually bless it two or four times with different targets, ensuring all possible variants are actually blessed.

---

This PR is best reviewed commit-by-commit.

r? `@jyn514`
cc `@saethlin` `@oli-obk`
Diffstat (limited to 'tests/mir-opt/lower_array_len.array_bound.NormalizeArrayLen.panic-unwind.diff')
-rw-r--r--tests/mir-opt/lower_array_len.array_bound.NormalizeArrayLen.panic-unwind.diff64
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/mir-opt/lower_array_len.array_bound.NormalizeArrayLen.panic-unwind.diff b/tests/mir-opt/lower_array_len.array_bound.NormalizeArrayLen.panic-unwind.diff
new file mode 100644
index 00000000000..59de067f4a4
--- /dev/null
+++ b/tests/mir-opt/lower_array_len.array_bound.NormalizeArrayLen.panic-unwind.diff
@@ -0,0 +1,64 @@
+- // MIR for `array_bound` before NormalizeArrayLen
++ // MIR for `array_bound` after NormalizeArrayLen
+  
+  fn array_bound(_1: usize, _2: &[u8; N]) -> u8 {
+      debug index => _1;                   // in scope 0 at $DIR/lower_array_len.rs:+0:36: +0:41
+      debug slice => _2;                   // in scope 0 at $DIR/lower_array_len.rs:+0:50: +0:55
+      let mut _0: u8;                      // return place in scope 0 at $DIR/lower_array_len.rs:+0:70: +0:72
+      let mut _3: bool;                    // in scope 0 at $DIR/lower_array_len.rs:+1:8: +1:27
+      let mut _4: usize;                   // in scope 0 at $DIR/lower_array_len.rs:+1:8: +1:13
+      let mut _5: usize;                   // in scope 0 at $DIR/lower_array_len.rs:+1:16: +1:27
+      let mut _6: &[u8];                   // in scope 0 at $DIR/lower_array_len.rs:+1:16: +1:27
+      let mut _7: &[u8; N];                // in scope 0 at $DIR/lower_array_len.rs:+1:16: +1:27
+      let _8: usize;                       // in scope 0 at $DIR/lower_array_len.rs:+2:15: +2:20
+      let mut _9: usize;                   // in scope 0 at $DIR/lower_array_len.rs:+2:9: +2:21
+      let mut _10: bool;                   // in scope 0 at $DIR/lower_array_len.rs:+2:9: +2:21
+  
+      bb0: {
+          StorageLive(_3);                 // scope 0 at $DIR/lower_array_len.rs:+1:8: +1:27
+          StorageLive(_4);                 // scope 0 at $DIR/lower_array_len.rs:+1:8: +1:13
+          _4 = _1;                         // scope 0 at $DIR/lower_array_len.rs:+1:8: +1:13
+          StorageLive(_5);                 // scope 0 at $DIR/lower_array_len.rs:+1:16: +1:27
+          StorageLive(_6);                 // scope 0 at $DIR/lower_array_len.rs:+1:16: +1:27
+          StorageLive(_7);                 // scope 0 at $DIR/lower_array_len.rs:+1:16: +1:27
+          _7 = &(*_2);                     // scope 0 at $DIR/lower_array_len.rs:+1:16: +1:27
+          _6 = move _7 as &[u8] (Pointer(Unsize)); // scope 0 at $DIR/lower_array_len.rs:+1:16: +1:27
+          StorageDead(_7);                 // scope 0 at $DIR/lower_array_len.rs:+1:20: +1:21
+-         _5 = Len((*_6));                 // scope 0 at $DIR/lower_array_len.rs:+1:16: +1:27
++         _5 = const N;                    // scope 0 at $DIR/lower_array_len.rs:+1:16: +1:27
+          goto -> bb1;                     // scope 0 at $DIR/lower_array_len.rs:+1:16: +1:27
+      }
+  
+      bb1: {
+          StorageDead(_6);                 // scope 0 at $DIR/lower_array_len.rs:+1:26: +1:27
+          _3 = Lt(move _4, move _5);       // scope 0 at $DIR/lower_array_len.rs:+1:8: +1:27
+          StorageDead(_5);                 // scope 0 at $DIR/lower_array_len.rs:+1:26: +1:27
+          StorageDead(_4);                 // scope 0 at $DIR/lower_array_len.rs:+1:26: +1:27
+          switchInt(move _3) -> [0: bb4, otherwise: bb2]; // scope 0 at $DIR/lower_array_len.rs:+1:8: +1:27
+      }
+  
+      bb2: {
+          StorageLive(_8);                 // scope 0 at $DIR/lower_array_len.rs:+2:15: +2:20
+          _8 = _1;                         // scope 0 at $DIR/lower_array_len.rs:+2:15: +2:20
+          _9 = Len((*_2));                 // scope 0 at $DIR/lower_array_len.rs:+2:9: +2:21
+          _10 = Lt(_8, _9);                // scope 0 at $DIR/lower_array_len.rs:+2:9: +2:21
+          assert(move _10, "index out of bounds: the length is {} but the index is {}", move _9, _8) -> bb3; // scope 0 at $DIR/lower_array_len.rs:+2:9: +2:21
+      }
+  
+      bb3: {
+          _0 = (*_2)[_8];                  // scope 0 at $DIR/lower_array_len.rs:+2:9: +2:21
+          StorageDead(_8);                 // scope 0 at $DIR/lower_array_len.rs:+3:5: +3:6
+          goto -> bb5;                     // scope 0 at $DIR/lower_array_len.rs:+1:5: +5:6
+      }
+  
+      bb4: {
+          _0 = const 42_u8;                // scope 0 at $DIR/lower_array_len.rs:+4:9: +4:11
+          goto -> bb5;                     // scope 0 at $DIR/lower_array_len.rs:+1:5: +5:6
+      }
+  
+      bb5: {
+          StorageDead(_3);                 // scope 0 at $DIR/lower_array_len.rs:+5:5: +5:6
+          return;                          // scope 0 at $DIR/lower_array_len.rs:+6:2: +6:2
+      }
+  }
+