about summary refs log tree commit diff
path: root/src/test/codegen
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2021-01-15 23:30:51 +0100
committerGitHub <noreply@github.com>2021-01-15 23:30:51 +0100
commitb7a9d6a51ff548a0ffbef8b537127ced7ad527ef (patch)
tree80eefae88b2253d1340a30db94169f8753e0d22c /src/test/codegen
parentbc39d4d9c514e5fdb40a5782e6ca08924f979c35 (diff)
parenta0c585713174711b00f56c0f2ffe480ab878e8dc (diff)
downloadrust-b7a9d6a51ff548a0ffbef8b537127ced7ad527ef.tar.gz
rust-b7a9d6a51ff548a0ffbef8b537127ced7ad527ef.zip
Rollup merge of #77693 - bugadani:issue-59352, r=oli-obk
Add test for #59352

Issue #59352 reported an optimization regression with rustc 1.32.0+. That regression could be tracked to a change that caused a function to miss the size limit of llvm's inlining, which results in an unreachable panicing branch being generated.
Enabling mir inline solves the issue, but is currently only done for `mir-opt-level>=2`.

This PR adds a test that can serve as a regression test for #59352, if/when mir inlining gets mature enough for opt-level 1, or some other optimization can remove the panic.
Diffstat (limited to 'src/test/codegen')
-rw-r--r--src/test/codegen/issue-59352.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/test/codegen/issue-59352.rs b/src/test/codegen/issue-59352.rs
new file mode 100644
index 00000000000..28bb8591232
--- /dev/null
+++ b/src/test/codegen/issue-59352.rs
@@ -0,0 +1,18 @@
+// This test is a mirror of mir-opt/issues/issue-59352.rs. The LLVM inliner doesn't inline
+// `char::method::is_digit()` and `char::method::to_digit()`, probably because of their size.
+//
+// Currently, the MIR optimizer isn't capable of removing the unreachable panic in this test case.
+// Once the optimizer can do that, mir-opt/issues/issue-59352.rs will need to be updated and this
+// test case should be removed as it will become redundant.
+
+// mir-opt-level=2 enables inlining and enables LLVM to optimize away the unreachable panic call.
+// compile-flags: -O -Z mir-opt-level=2
+
+#![crate_type = "rlib"]
+
+// CHECK-LABEL: @num_to_digit
+#[no_mangle]
+pub fn num_to_digit(num: char) -> u32 {
+    // CHECK-NOT: panic
+    if num.is_digit(8) { num.to_digit(8).unwrap() } else { 0 }
+}