Skip to content

Commit f1d942b

Browse files
committed
Add field to FunctionCx for passing caller location.
1 parent d47043b commit f1d942b

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/librustc_codegen_ssa/mir/block.rs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,14 +1004,18 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
10041004
bx: &mut Bx,
10051005
span: Span,
10061006
) -> OperandRef<'tcx, Bx::Value> {
1007-
let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
1008-
let caller = bx.tcx().sess.source_map().lookup_char_pos(topmost.lo());
1009-
let const_loc = bx.tcx().const_caller_location((
1010-
Symbol::intern(&caller.file.name.to_string()),
1011-
caller.line as u32,
1012-
caller.col_display as u32 + 1,
1013-
));
1014-
OperandRef::from_const(bx, const_loc)
1007+
if let Some(l) = self.caller_location {
1008+
bx.load_operand(l)
1009+
} else {
1010+
let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
1011+
let caller = bx.tcx().sess.source_map().lookup_char_pos(topmost.lo());
1012+
let const_loc = bx.tcx().const_caller_location((
1013+
Symbol::intern(&caller.file.name.to_string()),
1014+
caller.line as u32,
1015+
caller.col_display as u32 + 1,
1016+
));
1017+
OperandRef::from_const(bx, const_loc)
1018+
}
10151019
}
10161020

10171021
fn get_personality_slot(

src/librustc_codegen_ssa/mir/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ pub struct FunctionCx<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> {
7777
/// All `VarDebuginfo` from the MIR body, partitioned by `Local`.
7878
/// This is `None` if no variable debuginfo/names are needed.
7979
per_local_var_debug_info: Option<IndexVec<mir::Local, Vec<&'tcx mir::VarDebugInfo<'tcx>>>>,
80+
81+
/// Caller location propagated if this function has `#[track_caller]`.
82+
caller_location: Option<PlaceRef<'tcx, Bx::Value>>,
8083
}
8184

8285
impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
@@ -172,6 +175,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
172175
locals: IndexVec::new(),
173176
debug_context,
174177
per_local_var_debug_info: debuginfo::per_local_var_debug_info(cx.tcx(), mir_body),
178+
caller_location: None,
175179
};
176180

177181
let memory_locals = analyze::non_ssa_locals(&fx);

0 commit comments

Comments
 (0)