about summary refs log tree commit diff
path: root/tests/mir-opt/lower_array_len.array_len.NormalizeArrayLen.panic-abort.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_len.NormalizeArrayLen.panic-abort.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_len.NormalizeArrayLen.panic-abort.diff')
-rw-r--r--tests/mir-opt/lower_array_len.array_len.NormalizeArrayLen.panic-abort.diff26
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/mir-opt/lower_array_len.array_len.NormalizeArrayLen.panic-abort.diff b/tests/mir-opt/lower_array_len.array_len.NormalizeArrayLen.panic-abort.diff
new file mode 100644
index 00000000000..66feff62f42
--- /dev/null
+++ b/tests/mir-opt/lower_array_len.array_len.NormalizeArrayLen.panic-abort.diff
@@ -0,0 +1,26 @@
+- // MIR for `array_len` before NormalizeArrayLen
++ // MIR for `array_len` after NormalizeArrayLen
+  
+  fn array_len(_1: &[u8; N]) -> usize {
+      debug arr => _1;                     // in scope 0 at $DIR/lower_array_len.rs:+0:34: +0:37
+      let mut _0: usize;                   // return place in scope 0 at $DIR/lower_array_len.rs:+0:52: +0:57
+      let mut _2: &[u8];                   // in scope 0 at $DIR/lower_array_len.rs:+1:5: +1:14
+      let mut _3: &[u8; N];                // in scope 0 at $DIR/lower_array_len.rs:+1:5: +1:14
+  
+      bb0: {
+          StorageLive(_2);                 // scope 0 at $DIR/lower_array_len.rs:+1:5: +1:14
+          StorageLive(_3);                 // scope 0 at $DIR/lower_array_len.rs:+1:5: +1:14
+          _3 = &(*_1);                     // scope 0 at $DIR/lower_array_len.rs:+1:5: +1:14
+          _2 = move _3 as &[u8] (Pointer(Unsize)); // scope 0 at $DIR/lower_array_len.rs:+1:5: +1:14
+          StorageDead(_3);                 // scope 0 at $DIR/lower_array_len.rs:+1:7: +1:8
+-         _0 = Len((*_2));                 // scope 0 at $DIR/lower_array_len.rs:+1:5: +1:14
++         _0 = const N;                    // scope 0 at $DIR/lower_array_len.rs:+1:5: +1:14
+          goto -> bb1;                     // scope 0 at $DIR/lower_array_len.rs:+1:5: +1:14
+      }
+  
+      bb1: {
+          StorageDead(_2);                 // scope 0 at $DIR/lower_array_len.rs:+1:13: +1:14
+          return;                          // scope 0 at $DIR/lower_array_len.rs:+2:2: +2:2
+      }
+  }
+