Skip to content

Commit a513e0e

Browse files
authored
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.
2 parents bb544f8 + d2aa910 commit a513e0e

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//! Test for https://github.com/rust-lang/rust/issues/64219
2+
//! Check if `noreturn` attribute is applied on calls to
3+
//! function pointers returning `!` (never type).
4+
5+
#![crate_type = "lib"]
6+
7+
extern "C" {
8+
static FOO: fn() -> !;
9+
}
10+
11+
// CHECK-LABEL: @foo
12+
#[no_mangle]
13+
pub unsafe fn foo() {
14+
// CHECK: call
15+
// CHECK-SAME: [[NUM:#[0-9]+$]]
16+
FOO();
17+
}
18+
19+
// CHECK: attributes [[NUM]] = {{{.*}} noreturn {{.*}}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//@ compile-flags: -O
2+
//! Test for https://github.com/rust-lang/rust/issues/86109
3+
//! Check LLVM can eliminate the impossible division by zero check by
4+
//! ensuring there is no call (to panic) instruction.
5+
//!
6+
//! This has been fixed since `rustc 1.70.0`.
7+
8+
#![crate_type = "lib"]
9+
10+
type T = i16;
11+
12+
// CHECK-LABEL: @foo
13+
#[no_mangle]
14+
pub fn foo(start: T) -> T {
15+
// CHECK-NOT: panic
16+
if start <= 0 {
17+
return 0;
18+
}
19+
let mut count = 0;
20+
for i in start..10_000 {
21+
if 752 % i != 0 {
22+
count += 1;
23+
}
24+
}
25+
count
26+
}

0 commit comments

Comments
 (0)