about summary refs log tree commit diff
path: root/tests/codegen/issues
diff options
context:
space:
mode:
authorVeera <sveera.2001@gmail.com>2024-10-26 03:58:30 +0000
committerVeera <sveera.2001@gmail.com>2024-11-02 05:33:56 +0000
commitd2aa91054b360046bbb065336d7ffc7ccfd63b43 (patch)
treeb1e5ed4f845a355b6b4df7f2bfa8f17add7054b0 /tests/codegen/issues
parentc1db4dc24267a707409c9bf2e67cf3c7323975c8 (diff)
downloadrust-d2aa91054b360046bbb065336d7ffc7ccfd63b43.tar.gz
rust-d2aa91054b360046bbb065336d7ffc7ccfd63b43.zip
Add a Few Codegen Tests
Diffstat (limited to 'tests/codegen/issues')
-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
+}