coverage: Unexpand spans with find_ancestor_inside_same_ctxt
This commit is contained in:
parent
df5d53585a
commit
be6b059169
2 changed files with 6 additions and 22 deletions
|
@ -23,7 +23,7 @@ use rustc_middle::mir::{
|
||||||
use rustc_middle::ty::TyCtxt;
|
use rustc_middle::ty::TyCtxt;
|
||||||
use rustc_span::def_id::LocalDefId;
|
use rustc_span::def_id::LocalDefId;
|
||||||
use rustc_span::source_map::SourceMap;
|
use rustc_span::source_map::SourceMap;
|
||||||
use rustc_span::{ExpnKind, Span, Symbol};
|
use rustc_span::{Span, Symbol};
|
||||||
|
|
||||||
/// Inserts `StatementKind::Coverage` statements that either instrument the binary with injected
|
/// Inserts `StatementKind::Coverage` statements that either instrument the binary with injected
|
||||||
/// counters, via intrinsic `llvm.instrprof.increment`, and/or inject metadata used during codegen
|
/// counters, via intrinsic `llvm.instrprof.increment`, and/or inject metadata used during codegen
|
||||||
|
@ -346,21 +346,10 @@ fn get_body_span<'tcx>(
|
||||||
let mut body_span = hir_body.value.span;
|
let mut body_span = hir_body.value.span;
|
||||||
|
|
||||||
if tcx.is_closure(def_id.to_def_id()) {
|
if tcx.is_closure(def_id.to_def_id()) {
|
||||||
// If the MIR function is a closure, and if the closure body span
|
// If the current function is a closure, and its "body" span was created
|
||||||
// starts from a macro, but it's content is not in that macro, try
|
// by macro expansion or compiler desugaring, try to walk backwards to
|
||||||
// to find a non-macro callsite, and instrument the spans there
|
// the pre-expansion call site or body.
|
||||||
// instead.
|
body_span = body_span.source_callsite();
|
||||||
loop {
|
|
||||||
let expn_data = body_span.ctxt().outer_expn_data();
|
|
||||||
if expn_data.is_root() {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if let ExpnKind::Macro { .. } = expn_data.kind {
|
|
||||||
body_span = expn_data.call_site;
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
body_span
|
body_span
|
||||||
|
|
|
@ -204,10 +204,5 @@ fn filtered_terminator_span(terminator: &Terminator<'_>) -> Option<Span> {
|
||||||
/// etc.).
|
/// etc.).
|
||||||
#[inline]
|
#[inline]
|
||||||
fn unexpand_into_body_span(span: Span, body_span: Span) -> Option<Span> {
|
fn unexpand_into_body_span(span: Span, body_span: Span) -> Option<Span> {
|
||||||
use rustc_span::source_map::original_sp;
|
span.find_ancestor_inside_same_ctxt(body_span)
|
||||||
|
|
||||||
// FIXME(#118525): Consider switching from `original_sp` to `Span::find_ancestor_inside`,
|
|
||||||
// which is similar but gives slightly different results in some edge cases.
|
|
||||||
let original_span = original_sp(span, body_span).with_ctxt(body_span.ctxt());
|
|
||||||
body_span.contains(original_span).then_some(original_span)
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue