@@ -182,7 +182,17 @@ class SourceMappingRegion {
182
182
183
183
bool isBranch () const { return FalseCount.has_value (); }
184
184
185
- bool isMCDCDecision () const { return MCDCParams.NumConditions != 0 ; }
185
+ bool isMCDCDecision () const {
186
+ const auto *DecisionParams =
187
+ std::get_if<mcdc::DecisionParameters>(&MCDCParams);
188
+ assert (!DecisionParams || DecisionParams->NumConditions > 0 );
189
+ return DecisionParams;
190
+ }
191
+
192
+ const auto &getMCDCDecisionParams () const {
193
+ return CounterMappingRegion::getParams<const mcdc::DecisionParameters>(
194
+ MCDCParams);
195
+ }
186
196
187
197
const mcdc::Parameters &getMCDCParams () const { return MCDCParams; }
188
198
};
@@ -480,13 +490,13 @@ class CoverageMappingBuilder {
480
490
SR.ColumnEnd ));
481
491
} else if (Region.isBranch ()) {
482
492
MappingRegions.push_back (CounterMappingRegion::makeBranchRegion (
483
- Region.getCounter (), Region.getFalseCounter (),
484
- Region. getMCDCParams (), *CovFileID , SR.LineStart , SR.ColumnStart ,
485
- SR. LineEnd , SR. ColumnEnd ));
493
+ Region.getCounter (), Region.getFalseCounter (), *CovFileID,
494
+ SR. LineStart , SR. ColumnStart , SR.LineEnd , SR.ColumnEnd ,
495
+ Region. getMCDCParams () ));
486
496
} else if (Region.isMCDCDecision ()) {
487
497
MappingRegions.push_back (CounterMappingRegion::makeDecisionRegion (
488
- Region.getMCDCParams (), *CovFileID, SR.LineStart , SR. ColumnStart ,
489
- SR.LineEnd , SR.ColumnEnd ));
498
+ Region.getMCDCDecisionParams (), *CovFileID, SR.LineStart ,
499
+ SR.ColumnStart , SR. LineEnd , SR.ColumnEnd ));
490
500
} else {
491
501
MappingRegions.push_back (CounterMappingRegion::makeRegion (
492
502
Region.getCounter (), *CovFileID, SR.LineStart , SR.ColumnStart ,
@@ -863,8 +873,7 @@ struct CounterCoverageMappingBuilder
863
873
std::optional<SourceLocation> StartLoc = std::nullopt,
864
874
std::optional<SourceLocation> EndLoc = std::nullopt,
865
875
std::optional<Counter> FalseCount = std::nullopt,
866
- mcdc::ConditionID ID = 0 , mcdc::ConditionID TrueID = 0 ,
867
- mcdc::ConditionID FalseID = 0 ) {
876
+ const mcdc::Parameters &BranchParams = std::monostate()) {
868
877
869
878
if (StartLoc && !FalseCount) {
870
879
MostRecentLocation = *StartLoc;
@@ -883,9 +892,7 @@ struct CounterCoverageMappingBuilder
883
892
StartLoc = std::nullopt;
884
893
if (EndLoc && EndLoc->isInvalid ())
885
894
EndLoc = std::nullopt;
886
- RegionStack.emplace_back (Count, FalseCount,
887
- mcdc::Parameters{0 , 0 , ID, TrueID, FalseID},
888
- StartLoc, EndLoc);
895
+ RegionStack.emplace_back (Count, FalseCount, BranchParams, StartLoc, EndLoc);
889
896
890
897
return RegionStack.size () - 1 ;
891
898
}
@@ -894,8 +901,8 @@ struct CounterCoverageMappingBuilder
894
901
std::optional<SourceLocation> StartLoc = std::nullopt,
895
902
std::optional<SourceLocation> EndLoc = std::nullopt) {
896
903
897
- RegionStack.emplace_back (mcdc::Parameters {BitmapIdx, Conditions}, StartLoc ,
898
- EndLoc);
904
+ RegionStack.emplace_back (mcdc::DecisionParameters {BitmapIdx, Conditions},
905
+ StartLoc, EndLoc);
899
906
900
907
return RegionStack.size () - 1 ;
901
908
}
@@ -1040,9 +1047,11 @@ struct CounterCoverageMappingBuilder
1040
1047
// function's SourceRegions) because it doesn't apply to any other source
1041
1048
// code other than the Condition.
1042
1049
if (CodeGenFunction::isInstrumentedCondition (C)) {
1050
+ mcdc::Parameters BranchParams;
1043
1051
mcdc::ConditionID ID = MCDCBuilder.getCondID (C);
1044
- mcdc::ConditionID TrueID = IDPair.TrueID ;
1045
- mcdc::ConditionID FalseID = IDPair.FalseID ;
1052
+ if (ID > 0 )
1053
+ BranchParams =
1054
+ mcdc::BranchParameters{ID, IDPair.TrueID , IDPair.FalseID };
1046
1055
1047
1056
// If a condition can fold to true or false, the corresponding branch
1048
1057
// will be removed. Create a region with both counters hard-coded to
@@ -1052,11 +1061,11 @@ struct CounterCoverageMappingBuilder
1052
1061
// CodeGenFunction.c always returns false, but that is very heavy-handed.
1053
1062
if (ConditionFoldsToBool (C))
1054
1063
popRegions (pushRegion (Counter::getZero (), getStart (C), getEnd (C),
1055
- Counter::getZero (), ID, TrueID, FalseID ));
1064
+ Counter::getZero (), BranchParams ));
1056
1065
else
1057
1066
// Otherwise, create a region with the True counter and False counter.
1058
- popRegions (pushRegion (TrueCnt, getStart (C), getEnd (C), FalseCnt, ID,
1059
- TrueID, FalseID ));
1067
+ popRegions (pushRegion (TrueCnt, getStart (C), getEnd (C), FalseCnt,
1068
+ BranchParams ));
1060
1069
}
1061
1070
}
1062
1071
@@ -1147,12 +1156,9 @@ struct CounterCoverageMappingBuilder
1147
1156
// we've seen this region.
1148
1157
if (StartLocs.insert (Loc).second ) {
1149
1158
if (I.isBranch ())
1150
- SourceRegions.emplace_back (
1151
- I.getCounter (), I.getFalseCounter (),
1152
- mcdc::Parameters{0 , 0 , I.getMCDCParams ().ID ,
1153
- I.getMCDCParams ().TrueID ,
1154
- I.getMCDCParams ().FalseID },
1155
- Loc, getEndOfFileOrMacro (Loc), I.isBranch ());
1159
+ SourceRegions.emplace_back (I.getCounter (), I.getFalseCounter (),
1160
+ I.getMCDCParams (), Loc,
1161
+ getEndOfFileOrMacro (Loc), I.isBranch ());
1156
1162
else
1157
1163
SourceRegions.emplace_back (I.getCounter (), Loc,
1158
1164
getEndOfFileOrMacro (Loc));
@@ -2118,9 +2124,10 @@ static void dump(llvm::raw_ostream &OS, StringRef FunctionName,
2118
2124
OS << " File " << R.FileID << " , " << R.LineStart << " :" << R.ColumnStart
2119
2125
<< " -> " << R.LineEnd << " :" << R.ColumnEnd << " = " ;
2120
2126
2121
- if (R.Kind == CounterMappingRegion::MCDCDecisionRegion) {
2122
- OS << " M:" << R.MCDCParams .BitmapIdx ;
2123
- OS << " , C:" << R.MCDCParams .NumConditions ;
2127
+ if (const auto *DecisionParams =
2128
+ std::get_if<mcdc::DecisionParameters>(&R.MCDCParams )) {
2129
+ OS << " M:" << DecisionParams->BitmapIdx ;
2130
+ OS << " , C:" << DecisionParams->NumConditions ;
2124
2131
} else {
2125
2132
Ctx.dump (R.Count , OS);
2126
2133
@@ -2131,9 +2138,10 @@ static void dump(llvm::raw_ostream &OS, StringRef FunctionName,
2131
2138
}
2132
2139
}
2133
2140
2134
- if (R.Kind == CounterMappingRegion::MCDCBranchRegion) {
2135
- OS << " [" << R.MCDCParams .ID << " ," << R.MCDCParams .TrueID ;
2136
- OS << " ," << R.MCDCParams .FalseID << " ] " ;
2141
+ if (const auto *BranchParams =
2142
+ std::get_if<mcdc::BranchParameters>(&R.MCDCParams )) {
2143
+ OS << " [" << BranchParams->ID << " ," << BranchParams->TrueID ;
2144
+ OS << " ," << BranchParams->FalseID << " ] " ;
2137
2145
}
2138
2146
2139
2147
if (R.Kind == CounterMappingRegion::ExpansionRegion)
0 commit comments