From 99165ce1f76573729530c241036a0514ca1cf232 Mon Sep 17 00:00:00 2001 From: Adam Perry Date: Fri, 6 Dec 2019 16:09:40 -0800 Subject: [PATCH] Caller location is propagated via immediates rather than memory. --- src/librustc_codegen_ssa/mir/block.rs | 6 ++---- src/librustc_codegen_ssa/mir/mod.rs | 15 +++++++++++---- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/librustc_codegen_ssa/mir/block.rs b/src/librustc_codegen_ssa/mir/block.rs index b33cca2ee8d..5d25f7022c5 100644 --- a/src/librustc_codegen_ssa/mir/block.rs +++ b/src/librustc_codegen_ssa/mir/block.rs @@ -1016,9 +1016,7 @@ fn get_caller_location( bx: &mut Bx, span: Span, ) -> OperandRef<'tcx, Bx::Value> { - if let Some(l) = self.caller_location { - bx.load_operand(l) - } else { + self.caller_location.unwrap_or_else(|| { let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span); let caller = bx.tcx().sess.source_map().lookup_char_pos(topmost.lo()); let const_loc = bx.tcx().const_caller_location(( @@ -1027,7 +1025,7 @@ fn get_caller_location( caller.col_display as u32 + 1, )); OperandRef::from_const(bx, const_loc) - } + }) } fn get_personality_slot( diff --git a/src/librustc_codegen_ssa/mir/mod.rs b/src/librustc_codegen_ssa/mir/mod.rs index 6be6e13cc1d..5e4da8f2125 100644 --- a/src/librustc_codegen_ssa/mir/mod.rs +++ b/src/librustc_codegen_ssa/mir/mod.rs @@ -79,7 +79,7 @@ pub struct FunctionCx<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> { per_local_var_debug_info: Option>>>, /// Caller location propagated if this function has `#[track_caller]`. - caller_location: Option>, + caller_location: Option>, } impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { @@ -434,10 +434,17 @@ fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( fx.fn_abi.args.len(), args.len() + 1, "#[track_caller] fn's must have 1 more argument in their ABI than in their MIR", ); + let arg = &fx.fn_abi.args.last().unwrap(); - let place = PlaceRef::alloca(bx, arg.layout); - bx.store_fn_arg(arg, &mut llarg_idx, place); - fx.caller_location = Some(place); + match arg.mode { + PassMode::Direct(_) => (), + _ => panic!("caller location must be PassMode::Direct, found {:?}", arg.mode), + } + + fx.caller_location = Some(OperandRef { + val: OperandValue::Immediate(bx.get_param(llarg_idx)), + layout: arg.layout, + }); } args -- GitLab