Skip to content

Commit f28d833

Browse files
Add a Few Codegen Tests
1 parent c1db4dc commit f28d833

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

tests/codegen/issues/issue-64219.rs

Lines changed: 19 additions & 0 deletions
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 {{.*}}}

tests/codegen/issues/issue-86109.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
#![crate_type = "lib"]
7+
8+
type T = i16;
9+
10+
// CHECK-LABEL: @foo
11+
#[no_mangle]
12+
pub fn foo(start: T) -> T {
13+
// CHECK-NOT: call
14+
// CHECK: ret
15+
if start <= 0 {
16+
return 0;
17+
}
18+
let mut count = 0;
19+
for i in start..10_000 {
20+
if 752 % i != 0 {
21+
count += 1;
22+
}
23+
}
24+
count
25+
}

0 commit comments

Comments
 (0)