diff options
| author | Stuart Cook <Zalathar@users.noreply.github.com> | 2025-07-31 15:42:00 +1000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-31 15:42:00 +1000 |
| commit | 5c123c25e36121730634aa59f8a66a5469d4d73f (patch) | |
| tree | 61ca676c3d931b89e0c713d9d6a98a6566cc5f94 /compiler/rustc_codegen_llvm/src/coverageinfo | |
| parent | 8628b78f24c01026d01b82afd3ec91a2019fe647 (diff) | |
| parent | 2e6f4a59226fd82c526df0f61fefc6fea44e7750 (diff) | |
| download | rust-5c123c25e36121730634aa59f8a66a5469d4d73f.tar.gz rust-5c123c25e36121730634aa59f8a66a5469d4d73f.zip | |
Rollup merge of #144663 - Zalathar:empty-span, r=petrochenkov
coverage: Re-land "Enlarge empty spans during MIR instrumentation" This allows us to assume that coverage spans will only be discarded during codegen in very unusual situations. --- This seemingly-simple change has a rather messy history: - rust-lang/rust#140847 - rust-lang/rust#141650 - rust-lang/rust#144298 - rust-lang/rust#144480 Since then, a number of related changes have landed that should make it reasonable to try again: - rust-lang/rust#144530 - rust-lang/rust#144560 - rust-lang/rust#144616 In particular, we have multiple fixes/mitigations, and a confirmed regression test for the original bug that is not triggered by re-landing the changes in this PR.
Diffstat (limited to 'compiler/rustc_codegen_llvm/src/coverageinfo')
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/spans.rs | 28 |
1 files changed, 4 insertions, 24 deletions
diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/spans.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/spans.rs index 39a59560c9d..574463be7ff 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/spans.rs +++ b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/spans.rs @@ -39,7 +39,10 @@ impl Coords { /// or other expansions), and if it does happen then skipping a span or function is /// better than an ICE or `llvm-cov` failure that the user might have no way to avoid. pub(crate) fn make_coords(source_map: &SourceMap, file: &SourceFile, span: Span) -> Option<Coords> { - let span = ensure_non_empty_span(source_map, span)?; + if span.is_empty() { + debug_assert!(false, "can't make coords from empty span: {span:?}"); + return None; + } let lo = span.lo(); let hi = span.hi(); @@ -70,29 +73,6 @@ pub(crate) fn make_coords(source_map: &SourceMap, file: &SourceFile, span: Span) }) } -fn ensure_non_empty_span(source_map: &SourceMap, span: Span) -> Option<Span> { - if !span.is_empty() { - return Some(span); - } - - // The span is empty, so try to enlarge it to cover an adjacent '{' or '}'. - source_map - .span_to_source(span, |src, start, end| try { - // Adjusting span endpoints by `BytePos(1)` is normally a bug, - // but in this case we have specifically checked that the character - // we're skipping over is one of two specific ASCII characters, so - // adjusting by exactly 1 byte is correct. - if src.as_bytes().get(end).copied() == Some(b'{') { - Some(span.with_hi(span.hi() + BytePos(1))) - } else if start > 0 && src.as_bytes()[start - 1] == b'}' { - Some(span.with_lo(span.lo() - BytePos(1))) - } else { - None - } - }) - .ok()? -} - /// If `llvm-cov` sees a source region that is improperly ordered (end < start), /// it will immediately exit with a fatal error. To prevent that from happening, /// discard regions that are improperly ordered, or might be interpreted in a |
