about summary refs log tree commit diff
path: root/tests/codegen
diff options
context:
space:
mode:
authorMatthias Krüger <matthias.krueger@famsik.de>2024-11-02 08:33:10 +0100
committerGitHub <noreply@github.com>2024-11-02 08:33:10 +0100
commita513e0e9837979cf1e186f154a7b37e193c7e3a5 (patch)
treed7b5dd8392124471fc8f2156262ed6abe78ca1b9 /tests/codegen
parentbb544f863f94c9842cbee5b0b86cc07184ef71ad (diff)
parentd2aa91054b360046bbb065336d7ffc7ccfd63b43 (diff)
downloadrust-a513e0e9837979cf1e186f154a7b37e193c7e3a5.tar.gz
rust-a513e0e9837979cf1e186f154a7b37e193c7e3a5.zip
Rollup merge of #132170 - veera-sivarajan:codegen-tests, r=jieyouxu
Add a Few Codegen Tests

Closes #86109
Closes #64219

Those issues somehow got fixed over time.

So, this PR adds a couple of codegen tests to ensure we don't regress in the future.
Diffstat (limited to 'tests/codegen')
-rw-r--r--tests/codegen/issues/issue-64219-fn-ptr-call-returning-never-is-noreturn.rs19
-rw-r--r--tests/codegen/issues/issue-86109-eliminate-div-by-zero-check.rs26
2 files changed, 45 insertions, 0 deletions
diff --git a/tests/codegen/issues/issue-64219-fn-ptr-call-returning-never-is-noreturn.rs b/tests/codegen/issues/issue-64219-fn-ptr-call-returning-never-is-noreturn.rs
new file mode 100644
index 00000000000..86d020e1751
--- /dev/null
+++ b/tests/codegen/issues/issue-64219-fn-ptr-call-returning-never-is-noreturn.rs
@@ -0,0 +1,19 @@
+//! Test for https://github.com/rust-lang/rust/issues/64219
+//! Check if `noreturn` attribute is applied on calls to
+//! function pointers returning `!` (never type).
+
+#![crate_type = "lib"]
+
+extern "C" {
+    static FOO: fn() -> !;
+}
+
+// CHECK-LABEL: @foo
+#[no_mangle]
+pub unsafe fn foo() {
+    // CHECK: call
+    // CHECK-SAME: [[NUM:#[0-9]+$]]
+    FOO();
+}
+
+// CHECK: attributes [[NUM]] = {{{.*}} noreturn {{.*}}}
diff --git a/tests/codegen/issues/issue-86109-eliminate-div-by-zero-check.rs b/tests/codegen/issues/issue-86109-eliminate-div-by-zero-check.rs
new file mode 100644
index 00000000000..a8fab61b13e
--- /dev/null
+++ b/tests/codegen/issues/issue-86109-eliminate-div-by-zero-check.rs
@@ -0,0 +1,26 @@
+//@ compile-flags: -O
+//! Test for https://github.com/rust-lang/rust/issues/86109
+//! Check LLVM can eliminate the impossible division by zero check by
+//! ensuring there is no call (to panic) instruction.
+//!
+//! This has been fixed since `rustc 1.70.0`.
+
+#![crate_type = "lib"]
+
+type T = i16;
+
+// CHECK-LABEL: @foo
+#[no_mangle]
+pub fn foo(start: T) -> T {
+    // CHECK-NOT: panic
+    if start <= 0 {
+        return 0;
+    }
+    let mut count = 0;
+    for i in start..10_000 {
+        if 752 % i != 0 {
+            count += 1;
+        }
+    }
+    count
+}