@@ -182,7 +182,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
182
182
183
183
// Allocate variable and temp allocas
184
184
fx. locals = {
185
- let args = arg_local_refs ( & mut bx, & fx, & memory_locals) ;
185
+ let args = arg_local_refs ( & mut bx, & mut fx, & memory_locals) ;
186
186
187
187
let mut allocate_local = |local| {
188
188
let decl = & mir_body. local_decls [ local] ;
@@ -324,14 +324,14 @@ fn create_funclets<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
324
324
/// indirect.
325
325
fn arg_local_refs < ' a , ' tcx , Bx : BuilderMethods < ' a , ' tcx > > (
326
326
bx : & mut Bx ,
327
- fx : & FunctionCx < ' a , ' tcx , Bx > ,
327
+ fx : & mut FunctionCx < ' a , ' tcx , Bx > ,
328
328
memory_locals : & BitSet < mir:: Local > ,
329
329
) -> Vec < LocalRef < ' tcx , Bx :: Value > > {
330
330
let mir = fx. mir ;
331
331
let mut idx = 0 ;
332
332
let mut llarg_idx = fx. fn_abi . ret . is_indirect ( ) as usize ;
333
333
334
- mir. args_iter ( ) . enumerate ( ) . map ( |( arg_index, local) | {
334
+ let args = mir. args_iter ( ) . enumerate ( ) . map ( |( arg_index, local) | {
335
335
let arg_decl = & mir. local_decls [ local] ;
336
336
337
337
if Some ( local) == mir. spread_arg {
@@ -427,7 +427,20 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
427
427
bx. store_fn_arg ( arg, & mut llarg_idx, tmp) ;
428
428
LocalRef :: Place ( tmp)
429
429
}
430
- } ) . collect ( )
430
+ } ) . collect :: < Vec < _ > > ( ) ;
431
+
432
+ if fx. instance . def . requires_caller_location ( bx. tcx ( ) ) {
433
+ assert_eq ! (
434
+ fx. fn_abi. args. len( ) , args. len( ) + 1 ,
435
+ "#[track_caller] fn's must have 1 more argument in their ABI than in their MIR" ,
436
+ ) ;
437
+ let arg = & fx. fn_abi . args . last ( ) . unwrap ( ) ;
438
+ let place = PlaceRef :: alloca ( bx, arg. layout ) ;
439
+ bx. store_fn_arg ( arg, & mut llarg_idx, place) ;
440
+ fx. caller_location = Some ( place) ;
441
+ }
442
+
443
+ args
431
444
}
432
445
433
446
mod analyze;
0 commit comments