Skip to content

Commit 8aa7ce6

Browse files
committed
Fix tail call implementation to work with updated codegen_argument signature
- Add lifetime_ends_after_call parameter to match new signature - Update codegen test patterns to match LLVM IR output format - Tests now pass and verify that 'become' generates tail call instructions
1 parent cdd4424 commit 8aa7ce6

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,14 +378,21 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
378378
};
379379

380380
let mut llargs = Vec::with_capacity(args.len());
381+
let mut lifetime_ends_after_call = Vec::new();
381382

382383
// Process arguments
383384
for arg in args {
384385
let op = self.codegen_operand(bx, &arg.node);
385386
let arg_idx = llargs.len();
386387

387388
if arg_idx < fn_abi.args.len() {
388-
self.codegen_argument(bx, op, &mut llargs, &fn_abi.args[arg_idx]);
389+
self.codegen_argument(
390+
bx,
391+
op,
392+
&mut llargs,
393+
&fn_abi.args[arg_idx],
394+
&mut lifetime_ends_after_call,
395+
);
389396
} else {
390397
// This can happen in case of C-variadic functions
391398
let is_immediate = match op.val {

tests/codegen/tail-call-become.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,53 +4,53 @@
44
#![feature(explicit_tail_calls)]
55
#![crate_type = "lib"]
66

7-
// CHECK-LABEL: @with_tail
7+
// CHECK-LABEL: define {{.*}}@{{.*}}with_tail{{.*}}
88
pub fn with_tail(n: u32) -> u32 {
9-
// CHECK: tail call noundef i32 @{{.*}}with_tail{{.*}}(i32 noundef %{{.*}})
9+
// CHECK: tail call {{.*}}@{{.*}}with_tail{{.*}}
1010
if n == 0 { 0 } else { become with_tail(n - 1) }
1111
}
1212

13-
// CHECK-LABEL: @no_tail
13+
// CHECK-LABEL: define {{.*}}@{{.*}}no_tail{{.*}}
1414
pub fn no_tail(n: u32) -> u32 {
1515
// CHECK-NOT: tail call
16-
// CHECK: call noundef i32 @{{.*}}no_tail{{.*}}(i32 noundef %{{.*}})
16+
// CHECK: call {{.*}}@{{.*}}no_tail{{.*}}
1717
if n == 0 { 0 } else { no_tail(n - 1) }
1818
}
1919

20-
// CHECK-LABEL: @even_with_tail
20+
// CHECK-LABEL: define {{.*}}@{{.*}}even_with_tail{{.*}}
2121
pub fn even_with_tail(n: u32) -> bool {
22-
// CHECK: tail call noundef {{.*}} @{{.*}}odd_with_tail{{.*}}(i32 noundef %{{.*}})
22+
// CHECK: tail call {{.*}}@{{.*}}odd_with_tail{{.*}}
2323
match n {
2424
0 => true,
2525
_ => become odd_with_tail(n - 1),
2626
}
2727
}
2828

29-
// CHECK-LABEL: @odd_with_tail
29+
// CHECK-LABEL: define {{.*}}@{{.*}}odd_with_tail{{.*}}
3030
pub fn odd_with_tail(n: u32) -> bool {
31-
// CHECK: tail call noundef {{.*}} @{{.*}}even_with_tail{{.*}}(i32 noundef %{{.*}})
31+
// CHECK: tail call {{.*}}@{{.*}}even_with_tail{{.*}}
3232
match n {
3333
0 => false,
3434
_ => become even_with_tail(n - 1),
3535
}
3636
}
3737

38-
// CHECK-LABEL: @even_no_tail
38+
// CHECK-LABEL: define {{.*}}@{{.*}}even_no_tail{{.*}}
3939
pub fn even_no_tail(n: u32) -> bool {
4040
// CHECK-NOT: tail call
41-
// CHECK: call noundef {{.*}} @{{.*}}odd_no_tail{{.*}}(i32 noundef %{{.*}})
41+
// CHECK: call {{.*}}@{{.*}}odd_no_tail{{.*}}
4242
match n {
4343
0 => true,
4444
_ => odd_no_tail(n - 1),
4545
}
4646
}
4747

48-
// CHECK-LABEL: @odd_no_tail
48+
// CHECK-LABEL: define {{.*}}@{{.*}}odd_no_tail{{.*}}
4949
pub fn odd_no_tail(n: u32) -> bool {
5050
// CHECK-NOT: tail call
51-
// CHECK: call noundef {{.*}} @{{.*}}even_no_tail{{.*}}(i32 noundef %{{.*}})
51+
// CHECK: call {{.*}}@{{.*}}even_no_tail{{.*}}
5252
match n {
5353
0 => false,
5454
_ => even_no_tail(n - 1),
5555
}
56-
}
56+
}

tests/ui/explicit-tail-calls/llvm-ir-tail-call.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ fn main() {
3232
let result = deep_recursion(50_000);
3333
assert_eq!(result, 0);
3434
println!("Successfully completed 50,000 recursive calls with tail call optimization");
35-
}
35+
}

0 commit comments

Comments
 (0)