diff options
| author | Rich Kadel <richkadel@google.com> | 2021-04-24 15:29:44 -0700 |
|---|---|---|
| committer | Rich Kadel <richkadel@google.com> | 2021-04-24 15:41:56 -0700 |
| commit | 31cba57ea56e7444c75d62b3a1bebad8f5f74432 (patch) | |
| tree | 518131eb79a31c7315144071ff96745d206556c1 /compiler/rustc_mir/src/transform/coverage/mod.rs | |
| parent | 2b68027841af952d624a5ce509834237f8eda7e3 (diff) | |
| download | rust-31cba57ea56e7444c75d62b3a1bebad8f5f74432.tar.gz rust-31cba57ea56e7444c75d62b3a1bebad8f5f74432.zip | |
Fix coverage ICE because fn_sig can have a span that crosses file boundaries
Fixes: #83792 MIR `InstrumentCoverage` assumed the `FnSig` span was contained within a single file, but this is not always the case. Some macro constructions can result in a span that starts in one `SourceFile` and ends in a different one. The `FnSig` span is included in coverage results as long as that span is in the same `SourceFile` and the same macro context, but by assuming the `FnSig` span's `hi()` and `lo()` were in the same file, I took this for granted, and checked only that the `FnSig` `hi()` was in the same `SourceFile` as the `body_span`. I actually drop the `hi()` though, and extend the `FnSig` span to the `body_span.lo()`, so I really should have simply checked that the `FnSig` span's `lo()` was in the `SourceFile` of the `body_span`.
Diffstat (limited to 'compiler/rustc_mir/src/transform/coverage/mod.rs')
| -rw-r--r-- | compiler/rustc_mir/src/transform/coverage/mod.rs | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/compiler/rustc_mir/src/transform/coverage/mod.rs b/compiler/rustc_mir/src/transform/coverage/mod.rs index 60757178bec..3ef03ec21ad 100644 --- a/compiler/rustc_mir/src/transform/coverage/mod.rs +++ b/compiler/rustc_mir/src/transform/coverage/mod.rs @@ -112,7 +112,7 @@ impl<'a, 'tcx> Instrumentor<'a, 'tcx> { let source_file = source_map.lookup_source_file(body_span.lo()); let fn_sig_span = match some_fn_sig.filter(|fn_sig| { fn_sig.span.ctxt() == body_span.ctxt() - && Lrc::ptr_eq(&source_file, &source_map.lookup_source_file(fn_sig.span.hi())) + && Lrc::ptr_eq(&source_file, &source_map.lookup_source_file(fn_sig.span.lo())) }) { Some(fn_sig) => fn_sig.span.with_hi(body_span.lo()), None => body_span.shrink_to_lo(), |
