@@ -102,6 +102,7 @@ pub enum RegionKind {
102
102
103
103
/// A DecisionRegion represents a top-level boolean expression and is
104
104
/// associated with a variable length bitmap index and condition number.
105
+ /// FIXME(dprn): Remove unused variables.
105
106
#[ allow( dead_code) ]
106
107
MCDCDecisionRegion = 5 ,
107
108
@@ -110,6 +111,28 @@ pub enum RegionKind {
110
111
MCDCBranchRegion = 6 ,
111
112
}
112
113
114
+ /// This struct provides LLVM's representation of "MCDCParameters" that may be defined for a
115
+ /// Coverage Mapping Region.
116
+ ///
117
+ /// Correspond to struct `llvm::coverage::CounterMappingRegion::MCDCParameters`
118
+ ///
119
+ /// Must match The layout of `LLVMRustMCDCParameters`
120
+ #[ derive( Copy , Clone , Debug , Default ) ]
121
+ #[ repr( C ) ]
122
+ pub struct MCDCParameters {
123
+ /// Byte Index of Bitmap Coverage Object for a Decision Region.
124
+ bitmap_idx : u32 ,
125
+
126
+ /// Number of Conditions used for a Decision Region.
127
+ num_conditions : u32 ,
128
+
129
+ /// IDs used to represent a branch region and other branch regions
130
+ /// evaluated based on True and False branches.
131
+ id : u32 ,
132
+ true_id : u32 ,
133
+ false_id : u32 ,
134
+ }
135
+
113
136
/// This struct provides LLVM's representation of a "CoverageMappingRegion", encoded into the
114
137
/// coverage map, in accordance with the
115
138
/// [LLVM Code Coverage Mapping Format](https://github.com/rust-lang/llvm-project/blob/rustc/13.0-2021-09-30/llvm/docs/CoverageMappingFormat.rst#llvm-code-coverage-mapping-format).
@@ -155,6 +178,8 @@ pub struct CounterMappingRegion {
155
178
end_col : u32 ,
156
179
157
180
kind : RegionKind ,
181
+
182
+ mcdc_params : MCDCParameters ,
158
183
}
159
184
160
185
impl CounterMappingRegion {
@@ -181,6 +206,7 @@ impl CounterMappingRegion {
181
206
start_col,
182
207
end_line,
183
208
end_col,
209
+ None ,
184
210
) ,
185
211
}
186
212
}
@@ -203,9 +229,11 @@ impl CounterMappingRegion {
203
229
end_line,
204
230
end_col,
205
231
kind : RegionKind :: CodeRegion ,
232
+ mcdc_params : Default :: default ( ) ,
206
233
}
207
234
}
208
235
236
+ /// - `mcdc_params` should be None when MCDC is disabled.
209
237
pub ( crate ) fn branch_region (
210
238
counter : Counter ,
211
239
false_counter : Counter ,
@@ -214,7 +242,13 @@ impl CounterMappingRegion {
214
242
start_col : u32 ,
215
243
end_line : u32 ,
216
244
end_col : u32 ,
245
+ mcdc_params : Option < MCDCParameters > ,
217
246
) -> Self {
247
+ let ( kind, mcdc_params) = match mcdc_params {
248
+ None => ( RegionKind :: BranchRegion , Default :: default ( ) ) ,
249
+ Some ( params) => ( RegionKind :: MCDCBranchRegion , params) ,
250
+ } ;
251
+
218
252
Self {
219
253
counter,
220
254
false_counter,
@@ -224,7 +258,36 @@ impl CounterMappingRegion {
224
258
start_col,
225
259
end_line,
226
260
end_col,
227
- kind : RegionKind :: BranchRegion ,
261
+ kind,
262
+ mcdc_params,
263
+ }
264
+ }
265
+
266
+ #[ allow( dead_code) ]
267
+ pub ( crate ) fn decision_region (
268
+ bitmap_idx : u32 ,
269
+ num_conditions : u32 ,
270
+ file_id : u32 ,
271
+ start_line : u32 ,
272
+ start_col : u32 ,
273
+ end_line : u32 ,
274
+ end_col : u32 ,
275
+ ) -> Self {
276
+ Self {
277
+ counter : Counter :: ZERO ,
278
+ false_counter : Counter :: ZERO ,
279
+ file_id,
280
+ expanded_file_id : 0 ,
281
+ start_line,
282
+ start_col,
283
+ end_line,
284
+ end_col,
285
+ kind : RegionKind :: MCDCDecisionRegion ,
286
+ mcdc_params : MCDCParameters {
287
+ bitmap_idx,
288
+ num_conditions,
289
+ .. Default :: default ( )
290
+ } ,
228
291
}
229
292
}
230
293
@@ -249,6 +312,7 @@ impl CounterMappingRegion {
249
312
end_line,
250
313
end_col,
251
314
kind : RegionKind :: ExpansionRegion ,
315
+ mcdc_params : Default :: default ( ) ,
252
316
}
253
317
}
254
318
@@ -272,6 +336,7 @@ impl CounterMappingRegion {
272
336
end_line,
273
337
end_col,
274
338
kind : RegionKind :: SkippedRegion ,
339
+ mcdc_params : Default :: default ( ) ,
275
340
}
276
341
}
277
342
@@ -296,6 +361,7 @@ impl CounterMappingRegion {
296
361
end_line,
297
362
end_col : ( 1_u32 << 31 ) | end_col,
298
363
kind : RegionKind :: GapRegion ,
364
+ mcdc_params : Default :: default ( ) ,
299
365
}
300
366
}
301
367
}
0 commit comments