From d2aa91054b360046bbb065336d7ffc7ccfd63b43 Mon Sep 17 00:00:00 2001 From: Veera Date: Sat, 26 Oct 2024 03:58:30 +0000 Subject: [PATCH] Add a Few Codegen Tests --- ...fn-ptr-call-returning-never-is-noreturn.rs | 19 ++++++++++++++ ...issue-86109-eliminate-div-by-zero-check.rs | 26 +++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 tests/codegen/issues/issue-64219-fn-ptr-call-returning-never-is-noreturn.rs create mode 100644 tests/codegen/issues/issue-86109-eliminate-div-by-zero-check.rs 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 +}