diff options
| author | Zalathar <Zalathar@users.noreply.github.com> | 2025-05-09 20:57:17 +1000 |
|---|---|---|
| committer | Zalathar <Zalathar@users.noreply.github.com> | 2025-05-10 00:24:03 +1000 |
| commit | 078144fdfa7ae627d43cd919d660a71bef1e4658 (patch) | |
| tree | 8188e89378f1b0055d8d572cd8a037bb0f74e5e2 /compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs | |
| parent | 8cd8b23b9e4b1f05373831644b005b21a13a9c69 (diff) | |
| download | rust-078144fdfa7ae627d43cd919d660a71bef1e4658.tar.gz rust-078144fdfa7ae627d43cd919d660a71bef1e4658.zip | |
coverage: Detect unused local file IDs to avoid an LLVM assertion
This case can't actually happen yet (other than via a testing flag), because currently all of a function's spans must belong to the same file and expansion. But this will be an important edge case when adding expansion region support.
Diffstat (limited to 'compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs')
| -rw-r--r-- | compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs index f6000e72840..c207df2fb0b 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs +++ b/compiler/rustc_codegen_llvm/src/coverageinfo/ffi.rs @@ -155,6 +155,20 @@ pub(crate) struct Regions { impl Regions { /// Returns true if none of this structure's tables contain any regions. pub(crate) fn has_no_regions(&self) -> bool { + // Every region has a span, so if there are no spans then there are no regions. + self.all_cov_spans().next().is_none() + } + + pub(crate) fn all_cov_spans(&self) -> impl Iterator<Item = &CoverageSpan> { + macro_rules! iter_cov_spans { + ( $( $regions:expr ),* $(,)? ) => { + std::iter::empty() + $( + .chain( $regions.iter().map(|region| ®ion.cov_span) ) + )* + } + } + let Self { code_regions, expansion_regions, @@ -163,11 +177,13 @@ impl Regions { mcdc_decision_regions, } = self; - code_regions.is_empty() - && expansion_regions.is_empty() - && branch_regions.is_empty() - && mcdc_branch_regions.is_empty() - && mcdc_decision_regions.is_empty() + iter_cov_spans!( + code_regions, + expansion_regions, + branch_regions, + mcdc_branch_regions, + mcdc_decision_regions, + ) } } |
