@@ -3,9 +3,7 @@ use std::collections::BTreeSet;
3
3
use rustc_data_structures:: graph:: DirectedGraph ;
4
4
use rustc_index:: bit_set:: BitSet ;
5
5
use rustc_index:: IndexVec ;
6
- use rustc_middle:: mir:: coverage:: {
7
- BlockMarkerId , BranchSpan , ConditionInfo , CoverageKind , MCDCBranchSpan ,
8
- } ;
6
+ use rustc_middle:: mir:: coverage:: { BlockMarkerId , BranchSpan , ConditionInfo , CoverageKind } ;
9
7
use rustc_middle:: mir:: { self , BasicBlock , StatementKind } ;
10
8
use rustc_span:: Span ;
11
9
@@ -15,23 +13,13 @@ use crate::coverage::spans::{
15
13
} ;
16
14
use crate :: coverage:: ExtractedHirInfo ;
17
15
18
- #[ derive( Clone , Debug ) ]
16
+ #[ derive( Clone , Copy , Debug ) ]
19
17
pub ( super ) enum BcbMappingKind {
20
18
/// Associates an ordinary executable code span with its corresponding BCB.
21
19
Code ( BasicCoverageBlock ) ,
22
-
23
- // Ordinary branch mappings are stored separately, so they don't have a
24
- // variant in this enum.
25
20
//
26
- /// Associates a mcdc branch span with condition info besides fields for normal branch.
27
- MCDCBranch {
28
- true_bcb : BasicCoverageBlock ,
29
- false_bcb : BasicCoverageBlock ,
30
- /// If `None`, this actually represents a normal branch mapping inserted
31
- /// for code that was too complex for MC/DC.
32
- condition_info : Option < ConditionInfo > ,
33
- decision_depth : u16 ,
34
- } ,
21
+ // Branch and MC/DC mappings are more complex, so they are represented
22
+ // separately.
35
23
}
36
24
37
25
#[ derive( Debug ) ]
@@ -50,6 +38,18 @@ pub(super) struct BcbBranchPair {
50
38
pub ( super ) false_bcb : BasicCoverageBlock ,
51
39
}
52
40
41
+ /// Associates an MC/DC branch span with condition info besides fields for normal branch.
42
+ #[ derive( Debug ) ]
43
+ pub ( super ) struct MCDCBranch {
44
+ pub ( super ) span : Span ,
45
+ pub ( super ) true_bcb : BasicCoverageBlock ,
46
+ pub ( super ) false_bcb : BasicCoverageBlock ,
47
+ /// If `None`, this actually represents a normal branch mapping inserted
48
+ /// for code that was too complex for MC/DC.
49
+ pub ( super ) condition_info : Option < ConditionInfo > ,
50
+ pub ( super ) decision_depth : u16 ,
51
+ }
52
+
53
53
/// Associates an MC/DC decision with its join BCBs.
54
54
#[ derive( Debug ) ]
55
55
pub ( super ) struct MCDCDecision {
@@ -65,6 +65,7 @@ pub(super) struct CoverageSpans {
65
65
pub ( super ) mappings : Vec < BcbMapping > ,
66
66
pub ( super ) branch_pairs : Vec < BcbBranchPair > ,
67
67
test_vector_bitmap_bytes : u32 ,
68
+ pub ( super ) mcdc_branches : Vec < MCDCBranch > ,
68
69
pub ( super ) mcdc_decisions : Vec < MCDCDecision > ,
69
70
}
70
71
@@ -89,6 +90,7 @@ pub(super) fn generate_coverage_spans(
89
90
) -> Option < CoverageSpans > {
90
91
let mut mappings = vec ! [ ] ;
91
92
let mut branch_pairs = vec ! [ ] ;
93
+ let mut mcdc_branches = vec ! [ ] ;
92
94
let mut mcdc_decisions = vec ! [ ] ;
93
95
94
96
if hir_info. is_async_fn {
@@ -104,15 +106,20 @@ pub(super) fn generate_coverage_spans(
104
106
105
107
branch_pairs. extend ( extract_branch_pairs ( mir_body, hir_info, basic_coverage_blocks) ) ;
106
108
107
- mappings . extend ( extract_mcdc_mappings (
109
+ extract_mcdc_mappings (
108
110
mir_body,
109
111
hir_info. body_span ,
110
112
basic_coverage_blocks,
113
+ & mut mcdc_branches,
111
114
& mut mcdc_decisions,
112
- ) ) ;
115
+ ) ;
113
116
}
114
117
115
- if mappings. is_empty ( ) && branch_pairs. is_empty ( ) && mcdc_decisions. is_empty ( ) {
118
+ if mappings. is_empty ( )
119
+ && branch_pairs. is_empty ( )
120
+ && mcdc_branches. is_empty ( )
121
+ && mcdc_decisions. is_empty ( )
122
+ {
116
123
return None ;
117
124
}
118
125
@@ -122,19 +129,19 @@ pub(super) fn generate_coverage_spans(
122
129
bcb_has_mappings. insert ( bcb) ;
123
130
} ;
124
131
125
- for BcbMapping { kind, span : _ } in & mappings {
126
- match * kind {
132
+ for & BcbMapping { kind, span : _ } in & mappings {
133
+ match kind {
127
134
BcbMappingKind :: Code ( bcb) => insert ( bcb) ,
128
- BcbMappingKind :: MCDCBranch { true_bcb, false_bcb, .. } => {
129
- insert ( true_bcb) ;
130
- insert ( false_bcb) ;
131
- }
132
135
}
133
136
}
134
137
for & BcbBranchPair { true_bcb, false_bcb, .. } in & branch_pairs {
135
138
insert ( true_bcb) ;
136
139
insert ( false_bcb) ;
137
140
}
141
+ for & MCDCBranch { true_bcb, false_bcb, .. } in & mcdc_branches {
142
+ insert ( true_bcb) ;
143
+ insert ( false_bcb) ;
144
+ }
138
145
139
146
// Determine the length of the test vector bitmap.
140
147
let test_vector_bitmap_bytes = mcdc_decisions
@@ -150,6 +157,7 @@ pub(super) fn generate_coverage_spans(
150
157
mappings,
151
158
branch_pairs,
152
159
test_vector_bitmap_bytes,
160
+ mcdc_branches,
153
161
mcdc_decisions,
154
162
} )
155
163
}
@@ -217,11 +225,10 @@ pub(super) fn extract_mcdc_mappings(
217
225
mir_body : & mir:: Body < ' _ > ,
218
226
body_span : Span ,
219
227
basic_coverage_blocks : & CoverageGraph ,
228
+ mcdc_branches : & mut impl Extend < MCDCBranch > ,
220
229
mcdc_decisions : & mut impl Extend < MCDCDecision > ,
221
- ) -> Vec < BcbMapping > {
222
- let Some ( branch_info) = mir_body. coverage_branch_info . as_deref ( ) else {
223
- return vec ! [ ] ;
224
- } ;
230
+ ) {
231
+ let Some ( branch_info) = mir_body. coverage_branch_info . as_deref ( ) else { return } ;
225
232
226
233
let block_markers = resolve_block_markers ( branch_info, mir_body) ;
227
234
@@ -242,25 +249,19 @@ pub(super) fn extract_mcdc_mappings(
242
249
Some ( ( span, true_bcb, false_bcb) )
243
250
} ;
244
251
245
- let mcdc_branch_filter_map = |& MCDCBranchSpan {
246
- span : raw_span,
247
- true_marker,
248
- false_marker,
249
- condition_info,
250
- decision_depth,
251
- } | {
252
- check_branch_bcb ( raw_span, true_marker, false_marker) . map ( |( span, true_bcb, false_bcb) | {
253
- BcbMapping {
254
- kind : BcbMappingKind :: MCDCBranch {
255
- true_bcb,
256
- false_bcb,
257
- condition_info,
258
- decision_depth,
259
- } ,
260
- span,
261
- }
262
- } )
263
- } ;
252
+ mcdc_branches. extend ( branch_info. mcdc_branch_spans . iter ( ) . filter_map (
253
+ |& mir:: coverage:: MCDCBranchSpan {
254
+ span : raw_span,
255
+ condition_info,
256
+ true_marker,
257
+ false_marker,
258
+ decision_depth,
259
+ } | {
260
+ let ( span, true_bcb, false_bcb) =
261
+ check_branch_bcb ( raw_span, true_marker, false_marker) ?;
262
+ Some ( MCDCBranch { span, true_bcb, false_bcb, condition_info, decision_depth } )
263
+ } ,
264
+ ) ) ;
264
265
265
266
let mut next_bitmap_idx = 0 ;
266
267
@@ -286,8 +287,4 @@ pub(super) fn extract_mcdc_mappings(
286
287
} )
287
288
} ,
288
289
) ) ;
289
-
290
- std:: iter:: empty ( )
291
- . chain ( branch_info. mcdc_branch_spans . iter ( ) . filter_map ( mcdc_branch_filter_map) )
292
- . collect :: < Vec < _ > > ( )
293
290
}
0 commit comments