diff options
| author | Veera <sveera.2001@gmail.com> | 2024-10-26 03:58:30 +0000 |
|---|---|---|
| committer | Veera <sveera.2001@gmail.com> | 2024-11-02 05:33:56 +0000 |
| commit | d2aa91054b360046bbb065336d7ffc7ccfd63b43 (patch) | |
| tree | b1e5ed4f845a355b6b4df7f2bfa8f17add7054b0 /tests/codegen/issues | |
| parent | c1db4dc24267a707409c9bf2e67cf3c7323975c8 (diff) | |
| download | rust-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.rs | 19 | ||||
| -rw-r--r-- | tests/codegen/issues/issue-86109-eliminate-div-by-zero-check.rs | 26 |
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 +} |
