Skip to content

Commit 6d78047

Browse files
committed
Added GapRegions to support non-coverage counters
1 parent aa9747d commit 6d78047

File tree

3 files changed

+310
-138
lines changed

3 files changed

+310
-138
lines changed

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,32 @@ impl CoverageMapGenerator {
127127
virtual_file_mapping.push(filenames_index as u32);
128128
}
129129
debug!("Adding counter {:?} to map for {:?}", counter, region,);
130-
mapping_regions.push(CounterMappingRegion::code_region(
131-
counter,
132-
current_file_id,
133-
start_line,
134-
start_col,
135-
end_line,
136-
end_col,
137-
));
130+
if start_line == end_line && start_col == end_col {
131+
// The MIR `InstrumentCoverage` pass generates empty spans _ONLY_ for `BasicBlocks`
132+
// that contribute to the counts of `CoverageKind::Expression`s, but don't represent
133+
// specific source code to count.
134+
//
135+
// Make empty spans `GapRegion`s so their region executions counts are still
136+
// available to any expressions that might reference them, but they don't affect
137+
// the line execution count (as long as the line has at least one other counter).
138+
mapping_regions.push(CounterMappingRegion::gap_region(
139+
counter,
140+
current_file_id,
141+
start_line,
142+
start_col,
143+
end_line,
144+
end_col,
145+
));
146+
} else {
147+
mapping_regions.push(CounterMappingRegion::code_region(
148+
counter,
149+
current_file_id,
150+
start_line,
151+
start_col,
152+
end_line,
153+
end_col,
154+
));
155+
}
138156
}
139157

140158
// Encode and append the current function's coverage mapping data

0 commit comments

Comments
 (0)