explicit tail call tests with indirect operands in LLVM, small test for indexing into a function table as described by RFC 3407
This commit is contained in:
parent
7cd950546b
commit
916fb6a464
3 changed files with 64 additions and 2 deletions
42
tests/crashes/144293-indirect-ops-llvm.rs
Normal file
42
tests/crashes/144293-indirect-ops-llvm.rs
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
//@ known-bug: #144293
|
||||
// Same as recursion-etc but eggs LLVM emission into giving indirect arguments.
|
||||
#![expect(incomplete_features)]
|
||||
#![feature(explicit_tail_calls)]
|
||||
|
||||
use std::hint::black_box;
|
||||
|
||||
struct U64Wrapper {
|
||||
pub x: u64,
|
||||
pub arbitrary: String,
|
||||
}
|
||||
|
||||
fn count(curr: U64Wrapper, top: U64Wrapper) -> U64Wrapper {
|
||||
if black_box(curr.x) >= top.x {
|
||||
curr
|
||||
} else {
|
||||
become count(
|
||||
U64Wrapper {
|
||||
x: curr.x + 1,
|
||||
arbitrary: curr.arbitrary,
|
||||
},
|
||||
top,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!(
|
||||
"{}",
|
||||
count(
|
||||
U64Wrapper {
|
||||
x: 0,
|
||||
arbitrary: "hello!".into()
|
||||
},
|
||||
black_box(U64Wrapper {
|
||||
x: 1000000,
|
||||
arbitrary: "goodbye!".into()
|
||||
})
|
||||
)
|
||||
.x
|
||||
);
|
||||
}
|
||||
|
|
@ -1,5 +1,3 @@
|
|||
// FIXME(explicit_tail_calls): enable this test once rustc_codegen_ssa supports tail calls
|
||||
//@ ignore-test: tail calls are not implemented in rustc_codegen_ssa yet, so this causes 🧊
|
||||
//@ run-pass
|
||||
#![expect(incomplete_features)]
|
||||
#![feature(explicit_tail_calls)]
|
||||
|
|
|
|||
22
tests/ui/explicit-tail-calls/indexer.rs
Normal file
22
tests/ui/explicit-tail-calls/indexer.rs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
//@ run-pass
|
||||
// Indexing taken from
|
||||
// https://github.com/phi-go/rfcs/blob/guaranteed-tco/text%2F0000-explicit-tail-calls.md#tail-call-elimination
|
||||
// no other test has utilized the "function table"
|
||||
// described in the RFC aside from this one at this point.
|
||||
#![expect(incomplete_features)]
|
||||
#![feature(explicit_tail_calls)]
|
||||
|
||||
fn f0(_: usize) {}
|
||||
fn f1(_: usize) {}
|
||||
fn f2(_: usize) {}
|
||||
|
||||
fn indexer(idx: usize) {
|
||||
let v: [fn(usize); 3] = [f0, f1, f2];
|
||||
become v[idx](idx)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
for idx in 0..3 {
|
||||
indexer(idx);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue