diff options
| author | Ralf Jung <post@ralfj.de> | 2023-10-28 16:16:15 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2023-10-28 16:16:15 +0200 |
| commit | 04fa124feb6e3f78fe9bea9fac7b4cbd033c9160 (patch) | |
| tree | 31b24ddfb93998aa682372ebf5122275ffa7747b /compiler/rustc_codegen_cranelift/src/common.rs | |
| parent | 351d532a27c56f7af82feaa7d612c412fd5c221c (diff) | |
| download | rust-04fa124feb6e3f78fe9bea9fac7b4cbd033c9160.tar.gz rust-04fa124feb6e3f78fe9bea9fac7b4cbd033c9160.zip | |
share the track_caller handling within a mir::Body
Diffstat (limited to 'compiler/rustc_codegen_cranelift/src/common.rs')
| -rw-r--r-- | compiler/rustc_codegen_cranelift/src/common.rs | 37 |
1 files changed, 5 insertions, 32 deletions
diff --git a/compiler/rustc_codegen_cranelift/src/common.rs b/compiler/rustc_codegen_cranelift/src/common.rs index 38dba016c23..63562d33508 100644 --- a/compiler/rustc_codegen_cranelift/src/common.rs +++ b/compiler/rustc_codegen_cranelift/src/common.rs @@ -430,38 +430,11 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> { } } - // Note: must be kept in sync with get_caller_location from cg_ssa - pub(crate) fn get_caller_location(&mut self, mut source_info: mir::SourceInfo) -> CValue<'tcx> { - let span_to_caller_location = |fx: &mut FunctionCx<'_, '_, 'tcx>, span: Span| { - let const_loc = fx.tcx.span_as_caller_location(span); - crate::constant::codegen_const_value(fx, const_loc, fx.tcx.caller_location_ty()) - }; - - // Walk up the `SourceScope`s, in case some of them are from MIR inlining. - // If so, the starting `source_info.span` is in the innermost inlined - // function, and will be replaced with outer callsite spans as long - // as the inlined functions were `#[track_caller]`. - loop { - let scope_data = &self.mir.source_scopes[source_info.scope]; - - if let Some((callee, callsite_span)) = scope_data.inlined { - // Stop inside the most nested non-`#[track_caller]` function, - // before ever reaching its caller (which is irrelevant). - if !callee.def.requires_caller_location(self.tcx) { - return span_to_caller_location(self, source_info.span); - } - source_info.span = callsite_span; - } - - // Skip past all of the parents with `inlined: None`. - match scope_data.inlined_parent_scope { - Some(parent) => source_info.scope = parent, - None => break, - } - } - - // No inlined `SourceScope`s, or all of them were `#[track_caller]`. - self.caller_location.unwrap_or_else(|| span_to_caller_location(self, source_info.span)) + pub(crate) fn get_caller_location(&mut self, source_info: mir::SourceInfo) -> CValue<'tcx> { + self.mir.caller_location_span(source_info, self.caller_location, self.tcx, |span| { + let const_loc = self.tcx.span_as_caller_location(span); + crate::constant::codegen_const_value(self, const_loc, self.tcx.caller_location_ty()) + }) } pub(crate) fn anonymous_str(&mut self, msg: &str) -> Value { |
