@@ -102,6 +102,7 @@ pub enum RegionKind {
102102
103103 /// A DecisionRegion represents a top-level boolean expression and is
104104 /// associated with a variable length bitmap index and condition number.
105+ /// FIXME(dprn): Remove unused variables.
105106 #[ allow( dead_code) ]
106107 MCDCDecisionRegion = 5 ,
107108
@@ -110,6 +111,28 @@ pub enum RegionKind {
110111 MCDCBranchRegion = 6 ,
111112}
112113
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+
113136/// This struct provides LLVM's representation of a "CoverageMappingRegion", encoded into the
114137/// coverage map, in accordance with the
115138/// [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 {
155178 end_col : u32 ,
156179
157180 kind : RegionKind ,
181+
182+ mcdc_params : MCDCParameters ,
158183}
159184
160185impl CounterMappingRegion {
@@ -181,6 +206,7 @@ impl CounterMappingRegion {
181206 start_col,
182207 end_line,
183208 end_col,
209+ None ,
184210 ) ,
185211 }
186212 }
@@ -203,9 +229,11 @@ impl CounterMappingRegion {
203229 end_line,
204230 end_col,
205231 kind : RegionKind :: CodeRegion ,
232+ mcdc_params : Default :: default ( ) ,
206233 }
207234 }
208235
236+ /// - `mcdc_params` should be None when MCDC is disabled.
209237 pub ( crate ) fn branch_region (
210238 counter : Counter ,
211239 false_counter : Counter ,
@@ -214,7 +242,13 @@ impl CounterMappingRegion {
214242 start_col : u32 ,
215243 end_line : u32 ,
216244 end_col : u32 ,
245+ mcdc_params : Option < MCDCParameters > ,
217246 ) -> Self {
247+ let ( kind, mcdc_params) = match mcdc_params {
248+ None => ( RegionKind :: BranchRegion , Default :: default ( ) ) ,
249+ Some ( params) => ( RegionKind :: MCDCBranchRegion , params) ,
250+ } ;
251+
218252 Self {
219253 counter,
220254 false_counter,
@@ -224,7 +258,36 @@ impl CounterMappingRegion {
224258 start_col,
225259 end_line,
226260 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+ } ,
228291 }
229292 }
230293
@@ -249,6 +312,7 @@ impl CounterMappingRegion {
249312 end_line,
250313 end_col,
251314 kind : RegionKind :: ExpansionRegion ,
315+ mcdc_params : Default :: default ( ) ,
252316 }
253317 }
254318
@@ -272,6 +336,7 @@ impl CounterMappingRegion {
272336 end_line,
273337 end_col,
274338 kind : RegionKind :: SkippedRegion ,
339+ mcdc_params : Default :: default ( ) ,
275340 }
276341 }
277342
@@ -296,6 +361,7 @@ impl CounterMappingRegion {
296361 end_line,
297362 end_col : ( 1_u32 << 31 ) | end_col,
298363 kind : RegionKind :: GapRegion ,
364+ mcdc_params : Default :: default ( ) ,
299365 }
300366 }
301367}
0 commit comments