Skip to content

Commit 205f4ca

Browse files
committed
tests: add ui fail/pass tests and llvm ir tail codegen tests
1 parent a96bd57 commit 205f4ca

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

tests/codegen/become-musttail.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//@ compile-flags: -C opt-level=0 -Cpanic=abort -C no-prepopulate-passes
2+
//@ needs-unwind
3+
4+
#![crate_type = "lib"]
5+
#![feature(explicit_tail_calls)]
6+
7+
// CHECK-LABEL: define {{.*}}@fibonacci(
8+
#[no_mangle]
9+
#[inline(never)]
10+
pub fn fibonacci(n: u64, a: u64, b: u64) -> u64 {
11+
// CHECK: musttail call {{.*}}@fibonacci(
12+
// CHECK-NEXT: ret u64
13+
match n {
14+
0 => a,
15+
1 => b,
16+
_ => become fibonacci(n - 1, b, a + b),
17+
}
18+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//@ run-fail
2+
3+
use std::hint::black_box;
4+
5+
pub fn count(curr: u64, top: u64) -> u64 {
6+
if black_box(curr) >= top {
7+
curr
8+
} else {
9+
count(curr + 1, top)
10+
}
11+
}
12+
13+
fn main() {
14+
println!("{}",
15+
count(0, black_box(1000000)));
16+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//@ run-pass
2+
#![expect(incomplete_features)]
3+
#![feature(explicit_tail_calls)]
4+
5+
use std::hint::black_box;
6+
7+
pub fn count(curr: u64, top: u64) -> u64 {
8+
if black_box(curr) >= top {
9+
curr
10+
} else {
11+
become count(curr + 1, top)
12+
}
13+
}
14+
15+
fn main() {
16+
println!("{}", count(0, black_box(1000000)));
17+
}

0 commit comments

Comments
 (0)