@@ -53,7 +53,6 @@ pub(super) struct MCDCDecision {
53
53
}
54
54
55
55
pub ( super ) struct CoverageSpans {
56
- bcb_has_mappings : BitSet < BasicCoverageBlock > ,
57
56
pub ( super ) code_mappings : Vec < CodeMapping > ,
58
57
pub ( super ) branch_pairs : Vec < BranchPair > ,
59
58
test_vector_bitmap_bytes : u32 ,
@@ -62,24 +61,18 @@ pub(super) struct CoverageSpans {
62
61
}
63
62
64
63
impl CoverageSpans {
65
- pub ( super ) fn bcb_has_coverage_spans ( & self , bcb : BasicCoverageBlock ) -> bool {
66
- self . bcb_has_mappings . contains ( bcb)
67
- }
68
-
69
64
pub ( super ) fn test_vector_bitmap_bytes ( & self ) -> u32 {
70
65
self . test_vector_bitmap_bytes
71
66
}
72
67
}
73
68
74
69
/// Extracts coverage-relevant spans from MIR, and associates them with
75
70
/// their corresponding BCBs.
76
- ///
77
- /// Returns `None` if no coverage-relevant spans could be extracted.
78
71
pub ( super ) fn generate_coverage_spans (
79
72
mir_body : & mir:: Body < ' _ > ,
80
73
hir_info : & ExtractedHirInfo ,
81
74
basic_coverage_blocks : & CoverageGraph ,
82
- ) -> Option < CoverageSpans > {
75
+ ) -> CoverageSpans {
83
76
let mut code_mappings = vec ! [ ] ;
84
77
let mut branch_pairs = vec ! [ ] ;
85
78
let mut mcdc_branches = vec ! [ ] ;
@@ -107,32 +100,6 @@ pub(super) fn generate_coverage_spans(
107
100
) ;
108
101
}
109
102
110
- if code_mappings. is_empty ( )
111
- && branch_pairs. is_empty ( )
112
- && mcdc_branches. is_empty ( )
113
- && mcdc_decisions. is_empty ( )
114
- {
115
- return None ;
116
- }
117
-
118
- // Identify which BCBs have one or more mappings.
119
- let mut bcb_has_mappings = BitSet :: new_empty ( basic_coverage_blocks. num_nodes ( ) ) ;
120
- let mut insert = |bcb| {
121
- bcb_has_mappings. insert ( bcb) ;
122
- } ;
123
-
124
- for & CodeMapping { span : _, bcb } in & code_mappings {
125
- insert ( bcb) ;
126
- }
127
- for & BranchPair { true_bcb, false_bcb, .. } in & branch_pairs {
128
- insert ( true_bcb) ;
129
- insert ( false_bcb) ;
130
- }
131
- for & MCDCBranch { true_bcb, false_bcb, .. } in & mcdc_branches {
132
- insert ( true_bcb) ;
133
- insert ( false_bcb) ;
134
- }
135
-
136
103
// Determine the length of the test vector bitmap.
137
104
let test_vector_bitmap_bytes = mcdc_decisions
138
105
. iter ( )
@@ -142,14 +109,57 @@ pub(super) fn generate_coverage_spans(
142
109
. max ( )
143
110
. unwrap_or ( 0 ) ;
144
111
145
- Some ( CoverageSpans {
146
- bcb_has_mappings,
112
+ CoverageSpans {
147
113
code_mappings,
148
114
branch_pairs,
149
115
test_vector_bitmap_bytes,
150
116
mcdc_branches,
151
117
mcdc_decisions,
152
- } )
118
+ }
119
+ }
120
+
121
+ impl CoverageSpans {
122
+ pub ( super ) fn all_bcbs_with_counter_mappings (
123
+ & self ,
124
+ basic_coverage_blocks : & CoverageGraph , // Only used for allocating a correctly-sized set
125
+ ) -> BitSet < BasicCoverageBlock > {
126
+ // Fully destructure self to make sure we don't miss any fields that have mappings.
127
+ let Self {
128
+ code_mappings,
129
+ branch_pairs,
130
+ test_vector_bitmap_bytes : _,
131
+ mcdc_branches,
132
+ mcdc_decisions,
133
+ } = self ;
134
+
135
+ // Identify which BCBs have one or more mappings.
136
+ let mut bcbs_with_counter_mappings = BitSet :: new_empty ( basic_coverage_blocks. num_nodes ( ) ) ;
137
+ let mut insert = |bcb| {
138
+ bcbs_with_counter_mappings. insert ( bcb) ;
139
+ } ;
140
+
141
+ for & CodeMapping { span : _, bcb } in code_mappings {
142
+ insert ( bcb) ;
143
+ }
144
+ for & BranchPair { true_bcb, false_bcb, .. } in branch_pairs {
145
+ insert ( true_bcb) ;
146
+ insert ( false_bcb) ;
147
+ }
148
+ for & MCDCBranch { true_bcb, false_bcb, .. } in mcdc_branches {
149
+ insert ( true_bcb) ;
150
+ insert ( false_bcb) ;
151
+ }
152
+
153
+ // MC/DC decisions refer to BCBs, but don't require those BCBs to have counters.
154
+ if bcbs_with_counter_mappings. is_empty ( ) {
155
+ debug_assert ! (
156
+ mcdc_decisions. is_empty( ) ,
157
+ "A function with no counter mappings shouldn't have any decisions: {mcdc_decisions:?}" ,
158
+ ) ;
159
+ }
160
+
161
+ bcbs_with_counter_mappings
162
+ }
153
163
}
154
164
155
165
fn resolve_block_markers (
0 commit comments