Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a7fc463

Browse files
committedMar 19, 2025
Auto merge of #138693 - matthiaskrgr:rollup-ejq8mwp, r=matthiaskrgr
Rollup of 10 pull requests Successful merges: - #136177 (clarify BufRead::{fill_buf, consume} docs) - #138654 (Remove the regex dependency from coretests) - #138655 (rustc-dev-guide sync) - #138656 (Remove double nesting in post-merge workflow) - #138658 (CI: mirror alpine and centos images to ghcr) - #138659 (coverage: Don't store a body span in `FunctionCoverageInfo`) - #138661 (Revert: Add *_value methods to proc_macro lib) - #138670 (Remove existing AFIDT implementation) - #138674 (Various codegen_llvm cleanups) - #138684 (use then in docs for `fuse` to enhance readability) r? `@ghost` `@rustbot` modify labels: rollup
2 parents c4b38a5 + 3b7faca commit a7fc463

File tree

74 files changed

+517
-923
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+517
-923
lines changed
 

‎compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/covfun.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,14 @@ fn fill_region_tables<'tcx>(
105105
ids_info: &'tcx CoverageIdsInfo,
106106
covfun: &mut CovfunRecord<'tcx>,
107107
) {
108-
// Currently a function's mappings must all be in the same file as its body span.
108+
// Currently a function's mappings must all be in the same file, so use the
109+
// first mapping's span to determine the file.
109110
let source_map = tcx.sess.source_map();
110-
let source_file = source_map.lookup_source_file(fn_cov_info.body_span.lo());
111+
let Some(first_span) = (try { fn_cov_info.mappings.first()?.span }) else {
112+
debug_assert!(false, "function has no mappings: {:?}", covfun.mangled_function_name);
113+
return;
114+
};
115+
let source_file = source_map.lookup_source_file(first_span.lo());
111116

112117
// Look up the global file ID for that file.
113118
let global_file_id = global_file_table.global_file_id_for_file(&source_file);
@@ -118,9 +123,8 @@ fn fill_region_tables<'tcx>(
118123
let ffi::Regions { code_regions, branch_regions, mcdc_branch_regions, mcdc_decision_regions } =
119124
&mut covfun.regions;
120125

121-
let make_cov_span = |span: Span| {
122-
spans::make_coverage_span(local_file_id, source_map, fn_cov_info, &source_file, span)
123-
};
126+
let make_cov_span =
127+
|span: Span| spans::make_coverage_span(local_file_id, source_map, &source_file, span);
124128
let discard_all = tcx.sess.coverage_discard_all_spans_in_codegen();
125129

126130
// For each counter/region pair in this function+file, convert it to a

‎compiler/rustc_codegen_llvm/src/coverageinfo/mapgen/spans.rs

+7-23
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use rustc_middle::mir::coverage::FunctionCoverageInfo;
21
use rustc_span::source_map::SourceMap;
32
use rustc_span::{BytePos, Pos, SourceFile, Span};
43
use tracing::debug;
@@ -19,11 +18,10 @@ use crate::coverageinfo::mapgen::LocalFileId;
1918
pub(crate) fn make_coverage_span(
2019
file_id: LocalFileId,
2120
source_map: &SourceMap,
22-
fn_cov_info: &FunctionCoverageInfo,
2321
file: &SourceFile,
2422
span: Span,
2523
) -> Option<ffi::CoverageSpan> {
26-
let span = ensure_non_empty_span(source_map, fn_cov_info, span)?;
24+
let span = ensure_non_empty_span(source_map, span)?;
2725

2826
let lo = span.lo();
2927
let hi = span.hi();
@@ -55,36 +53,22 @@ pub(crate) fn make_coverage_span(
5553
})
5654
}
5755

58-
fn ensure_non_empty_span(
59-
source_map: &SourceMap,
60-
fn_cov_info: &FunctionCoverageInfo,
61-
span: Span,
62-
) -> Option<Span> {
56+
fn ensure_non_empty_span(source_map: &SourceMap, span: Span) -> Option<Span> {
6357
if !span.is_empty() {
6458
return Some(span);
6559
}
6660

67-
let lo = span.lo();
68-
let hi = span.hi();
69-
70-
// The span is empty, so try to expand it to cover an adjacent '{' or '}',
71-
// but only within the bounds of the body span.
72-
let try_next = hi < fn_cov_info.body_span.hi();
73-
let try_prev = fn_cov_info.body_span.lo() < lo;
74-
if !(try_next || try_prev) {
75-
return None;
76-
}
77-
61+
// The span is empty, so try to enlarge it to cover an adjacent '{' or '}'.
7862
source_map
7963
.span_to_source(span, |src, start, end| try {
8064
// Adjusting span endpoints by `BytePos(1)` is normally a bug,
8165
// but in this case we have specifically checked that the character
8266
// we're skipping over is one of two specific ASCII characters, so
8367
// adjusting by exactly 1 byte is correct.
84-
if try_next && src.as_bytes()[end] == b'{' {
85-
Some(span.with_hi(hi + BytePos(1)))
86-
} else if try_prev && src.as_bytes()[start - 1] == b'}' {
87-
Some(span.with_lo(lo - BytePos(1)))
68+
if src.as_bytes().get(end).copied() == Some(b'{') {
69+
Some(span.with_hi(span.hi() + BytePos(1)))
70+
} else if start > 0 && src.as_bytes()[start - 1] == b'}' {
71+
Some(span.with_lo(span.lo() - BytePos(1)))
8872
} else {
8973
None
9074
}
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.