Skip to content

Commit 211105d

Browse files
committed
Add field to FunctionCx for passing caller location.
1 parent c0b9b7a commit 211105d

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/librustc_codegen_ssa/mir/block.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -995,13 +995,17 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
995995
bx: &mut Bx,
996996
span: Span,
997997
) -> OperandRef<'tcx, Bx::Value> {
998-
let caller = bx.tcx().sess.source_map().lookup_char_pos(span.lo());
999-
let const_loc = bx.tcx().const_caller_location((
1000-
Symbol::intern(&caller.file.name.to_string()),
1001-
caller.line as u32,
1002-
caller.col_display as u32 + 1,
1003-
));
1004-
OperandRef::from_const(bx, const_loc)
998+
if let Some(l) = self.caller_location {
999+
bx.load_operand(l)
1000+
} else {
1001+
let caller = bx.tcx().sess.source_map().lookup_char_pos(span.lo());
1002+
let const_loc = bx.tcx().const_caller_location((
1003+
Symbol::intern(&caller.file.name.to_string()),
1004+
caller.line as u32,
1005+
caller.col_display as u32 + 1,
1006+
));
1007+
OperandRef::from_const(bx, const_loc)
1008+
}
10051009
}
10061010

10071011
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
@@ -75,6 +75,9 @@ pub struct FunctionCx<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> {
7575
locals: IndexVec<mir::Local, LocalRef<'tcx, Bx::Value>>,
7676

7777
per_local_var_debug_info: Option<IndexVec<mir::Local, Vec<debuginfo::VarDebugInfo<'tcx>>>>,
78+
79+
/// Caller location propagated if this function has `#[track_caller]`.
80+
caller_location: Option<PlaceRef<'tcx, Bx::Value>>,
7881
}
7982

8083
impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
@@ -176,6 +179,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
176179
locals: IndexVec::new(),
177180
debug_context,
178181
per_local_var_debug_info: debuginfo::per_local_var_debug_info(cx.tcx(), mir),
182+
caller_location: None,
179183
};
180184

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

0 commit comments

Comments
 (0)