-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
coverage: Allow each coverage statement to have multiple code regions #115301
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
59a11af
coverage: Mappings for unused functions can all be zero
Zalathar e29db47
coverage: Encapsulate coverage spans
Zalathar 1355e1f
coverage: Update comments/logs that referred to `CoverageSpan`
Zalathar ee9d00f
coverage: Let each coverage statement hold a vector of code regions
Zalathar 86a66c8
coverage: Store each BCB's code regions in one coverage statement
Zalathar b1cf0c8
coverage: Remove code for making expression copies of BCB counters
Zalathar 053c4f9
coverage: Remove `next_id` methods from counter/expression IDs
Zalathar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,9 +89,7 @@ impl<'ll, 'tcx> CodegenCx<'ll, 'tcx> { | |
/// `function_coverage_map` (keyed by function `Instance`) during codegen. | ||
/// But in this case, since the unused function was _not_ previously | ||
/// codegenned, collect the coverage `CodeRegion`s from the MIR and add | ||
/// them. The first `CodeRegion` is used to add a single counter, with the | ||
/// same counter ID used in the injected `instrprof.increment` intrinsic | ||
/// call. Since the function is never called, all other `CodeRegion`s can be | ||
/// them. Since the function is never called, all of its `CodeRegion`s can be | ||
/// added as `unreachable_region`s. | ||
fn define_unused_fn(&self, def_id: DefId) { | ||
let instance = declare_unused_fn(self, def_id); | ||
|
@@ -110,25 +108,15 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> { | |
.entry(instance) | ||
.or_insert_with(|| FunctionCoverage::new(bx.tcx(), instance)); | ||
|
||
let Coverage { kind, code_region } = coverage.clone(); | ||
match kind { | ||
let Coverage { kind, code_regions } = coverage; | ||
match *kind { | ||
CoverageKind::Counter { function_source_hash, id } => { | ||
debug!( | ||
"ensuring function source hash is set for instance={:?}; function_source_hash={}", | ||
instance, function_source_hash, | ||
); | ||
func_coverage.set_function_source_hash(function_source_hash); | ||
|
||
if let Some(code_region) = code_region { | ||
// Note: Some counters do not have code regions, but may still be referenced | ||
// from expressions. In that case, don't add the counter to the coverage map, | ||
// but do inject the counter intrinsic. | ||
debug!( | ||
"adding counter to coverage_map: instance={:?}, id={:?}, region={:?}", | ||
instance, id, code_region, | ||
); | ||
func_coverage.add_counter(id, code_region); | ||
} | ||
func_coverage.add_counter(id, code_regions); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We now call |
||
// We need to explicitly drop the `RefMut` before calling into `instrprof_increment`, | ||
// as that needs an exclusive borrow. | ||
drop(coverage_map); | ||
|
@@ -146,20 +134,10 @@ impl<'tcx> CoverageInfoBuilderMethods<'tcx> for Builder<'_, '_, 'tcx> { | |
bx.instrprof_increment(fn_name, hash, num_counters, index); | ||
} | ||
CoverageKind::Expression { id, lhs, op, rhs } => { | ||
debug!( | ||
"adding counter expression to coverage_map: instance={:?}, id={:?}, {:?} {:?} {:?}; region: {:?}", | ||
instance, id, lhs, op, rhs, code_region, | ||
); | ||
func_coverage.add_counter_expression(id, lhs, op, rhs, code_region); | ||
func_coverage.add_counter_expression(id, lhs, op, rhs, code_regions); | ||
} | ||
CoverageKind::Unreachable => { | ||
let code_region = | ||
code_region.expect("unreachable regions always have code regions"); | ||
debug!( | ||
"adding unreachable code to coverage_map: instance={:?}, at {:?}", | ||
instance, code_region, | ||
); | ||
func_coverage.add_unreachable_region(code_region); | ||
func_coverage.add_unreachable_regions(code_regions); | ||
} | ||
} | ||
} | ||
|
@@ -227,14 +205,9 @@ fn add_unused_function_coverage<'tcx>( | |
let tcx = cx.tcx; | ||
|
||
let mut function_coverage = FunctionCoverage::unused(tcx, instance); | ||
for (index, &code_region) in tcx.covered_code_regions(def_id).iter().enumerate() { | ||
if index == 0 { | ||
// Insert at least one real counter so the LLVM CoverageMappingReader will find expected | ||
// definitions. | ||
function_coverage.add_counter(UNUSED_FUNCTION_COUNTER_ID, code_region.clone()); | ||
} else { | ||
function_coverage.add_unreachable_region(code_region.clone()); | ||
} | ||
for &code_region in tcx.covered_code_regions(def_id) { | ||
let code_region = std::slice::from_ref(code_region); | ||
function_coverage.add_unreachable_regions(code_region); | ||
} | ||
|
||
if let Some(coverage_context) = cx.coverage_context() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These
debug!
invocations have been replaced with#[instrument(...)]
tracing on the methods being called.