Skip to content

Commit 02bdfab

Browse files
committed
Assert that the #[track_caller] ABI is correct before relying on it.
1 parent fdccc25 commit 02bdfab

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/librustc_codegen_ssa/mir/block.rs

+4
Original file line numberDiff line numberDiff line change
@@ -765,6 +765,10 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
765765
let needs_location =
766766
instance.map(|i| i.def.requires_caller_location(self.cx.tcx())).unwrap_or_default();
767767
if needs_location {
768+
assert_eq!(
769+
fn_abi.args.len(), args.len() + 1,
770+
"#[track_caller] fn's must have 1 more argument in their ABI than in their MIR",
771+
);
768772
let location = self.get_caller_location(&mut bx, span);
769773
let last_arg = &fn_abi.args.last().unwrap();
770774
self.codegen_argument(&mut bx, location, &mut llargs, last_arg);

src/librustc_codegen_ssa/mir/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -431,9 +431,13 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
431431
bx.store_fn_arg(arg, &mut llarg_idx, tmp);
432432
LocalRef::Place(tmp)
433433
}
434-
}).collect();
434+
}).collect::<Vec<_>>();
435435

436436
if fx.instance.def.requires_caller_location(bx.tcx()) {
437+
assert_eq!(
438+
fx.fn_abi.args.len(), args.len() + 1,
439+
"#[track_caller] fn's must have 1 more argument in their ABI than in their MIR",
440+
);
437441
let arg = &fx.fn_abi.args.last().unwrap();
438442
let place = PlaceRef::alloca(bx, arg.layout);
439443
bx.store_fn_arg(arg, &mut llarg_idx, place);

0 commit comments

Comments
 (0)