-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[MC/DC][Coverage] Loosen the limit of NumConds from 6 #82448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
d168e0c
35b19ea
8c777eb
56042d3
5432aec
3ee8a61
2fd504a
1f0f3fc
06c0801
aa5b2f5
e3de647
753d0ad
17cbac7
1a4ffa7
b5ecfcc
0ffad9c
c96fd2c
357a693
83d104c
14c795e
b6c1174
cf936f6
662bdd6
ac16655
90bf8e9
9eb6951
86d67c6
01abca2
183c706
dd6f8be
cdd5531
54e6044
b1a7100
39802c5
f54c64d
a6f7eef
0dd7ead
cf837ae
9e14c2a
04f18ae
3ff3eb7
296f5c5
722424b
183bc52
83088f1
40872f5
be5b28b
450d86b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -195,6 +195,10 @@ class SourceMappingRegion { | |
return std::holds_alternative<mcdc::BranchParameters>(MCDCParams); | ||
} | ||
|
||
const auto &getMCDCBranchParams() const { | ||
return mcdc::getParams<const mcdc::BranchParameters>(MCDCParams); | ||
} | ||
|
||
bool isMCDCDecision() const { | ||
return std::holds_alternative<mcdc::DecisionParameters>(MCDCParams); | ||
} | ||
|
@@ -204,6 +208,8 @@ class SourceMappingRegion { | |
} | ||
|
||
const mcdc::Parameters &getMCDCParams() const { return MCDCParams; } | ||
|
||
void resetMCDCParams() { MCDCParams = mcdc::Parameters(); } | ||
}; | ||
|
||
/// Spelling locations for the start and end of a source region. | ||
|
@@ -748,6 +754,7 @@ struct MCDCCoverageBuilder { | |
|
||
llvm::SmallVector<mcdc::ConditionIDs> DecisionStack; | ||
MCDC::State &MCDCState; | ||
const Stmt *DecisionStmt = nullptr; | ||
mcdc::ConditionID NextID = 0; | ||
bool NotMapped = false; | ||
|
||
|
@@ -777,7 +784,8 @@ struct MCDCCoverageBuilder { | |
|
||
/// Set the given condition's ID. | ||
void setCondID(const Expr *Cond, mcdc::ConditionID ID) { | ||
MCDCState.BranchByStmt[CodeGenFunction::stripCond(Cond)].ID = ID; | ||
MCDCState.BranchByStmt[CodeGenFunction::stripCond(Cond)] = {ID, | ||
DecisionStmt}; | ||
} | ||
|
||
/// Return the ID of a given condition. | ||
|
@@ -808,6 +816,11 @@ struct MCDCCoverageBuilder { | |
if (NotMapped) | ||
return; | ||
|
||
if (NextID == 0) { | ||
DecisionStmt = E; | ||
assert(MCDCState.DecisionByStmt.contains(E)); | ||
} | ||
|
||
const mcdc::ConditionIDs &ParentDecision = DecisionStack.back(); | ||
|
||
// If the operator itself has an assigned ID, this means it represents a | ||
|
@@ -2122,20 +2135,70 @@ struct CounterCoverageMappingBuilder | |
subtractCounters(ParentCount, TrueCount)); | ||
} | ||
|
||
void createDecision(const BinaryOperator *E) { | ||
void createOrCancelDecision(const BinaryOperator *E, unsigned Since) { | ||
unsigned NumConds = MCDCBuilder.getTotalConditionsAndReset(E); | ||
if (NumConds == 0) | ||
return; | ||
|
||
// Extract [ID, Conds] to construct the graph. | ||
llvm::SmallVector<mcdc::ConditionIDs> CondIDs(NumConds); | ||
for (const auto &SR : ArrayRef(SourceRegions).slice(Since)) { | ||
if (SR.isMCDCBranch()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: can you use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think |
||
auto [ID, Conds] = SR.getMCDCBranchParams(); | ||
CondIDs[ID] = Conds; | ||
} | ||
} | ||
|
||
// Construct the graph and calculate `Indices`. | ||
mcdc::TVIdxBuilder Builder(CondIDs); | ||
unsigned NumTVs = Builder.NumTestVectors; | ||
unsigned MaxTVs = CVM.getCodeGenModule().getCodeGenOpts().MCDCMaxTVs; | ||
assert(MaxTVs < mcdc::TVIdxBuilder::HardMaxTVs); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should it be I'm asking because There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Than I would probably make it |
||
|
||
if (NumTVs > MaxTVs) { | ||
// NumTVs exceeds MaxTVs -- warn and cancel the Decision. | ||
cancelDecision(E, Since, NumTVs, MaxTVs); | ||
return; | ||
} | ||
|
||
// Update the state for CodeGenPGO | ||
assert(MCDCState.DecisionByStmt.contains(E)); | ||
MCDCState.DecisionByStmt[E] = { | ||
MCDCState.BitmapBits, // Top | ||
std::move(Builder.Indices), | ||
}; | ||
|
||
auto DecisionParams = mcdc::DecisionParameters{ | ||
MCDCState.DecisionByStmt[E].BitmapIdx, | ||
MCDCState.BitmapBits += NumTVs, // Tail | ||
NumConds, | ||
}; | ||
|
||
// Create MCDC Decision Region. | ||
createDecisionRegion(E, DecisionParams); | ||
} | ||
|
||
// Warn and cancel the Decision. | ||
void cancelDecision(const BinaryOperator *E, unsigned Since, int NumTVs, | ||
int MaxTVs) { | ||
auto &Diag = CVM.getCodeGenModule().getDiags(); | ||
unsigned DiagID = | ||
Diag.getCustomDiagID(DiagnosticsEngine::Warning, | ||
"unsupported MC/DC boolean expression; " | ||
"number of test vectors (%0) exceeds max (%1). " | ||
"Expression will not be covered"); | ||
Diag.Report(E->getBeginLoc(), DiagID) << NumTVs << MaxTVs; | ||
|
||
// Restore MCDCBranch to Branch. | ||
for (auto &SR : MutableArrayRef(SourceRegions).slice(Since)) { | ||
assert(!SR.isMCDCDecision() && "Decision shouldn't be seen here"); | ||
if (SR.isMCDCBranch()) | ||
SR.resetMCDCParams(); | ||
} | ||
|
||
// Tell CodeGenPGO not to instrument. | ||
MCDCState.DecisionByStmt.erase(E); | ||
} | ||
|
||
/// Check if E belongs to system headers. | ||
bool isExprInSystemHeader(const BinaryOperator *E) const { | ||
return (!SystemHeadersCoverage && | ||
|
@@ -2152,6 +2215,8 @@ struct CounterCoverageMappingBuilder | |
|
||
bool IsRootNode = MCDCBuilder.isIdle(); | ||
|
||
unsigned SourceRegionsSince = SourceRegions.size(); | ||
|
||
// Keep track of Binary Operator and assign MCDC condition IDs. | ||
MCDCBuilder.pushAndAssignIDs(E); | ||
|
||
|
@@ -2190,7 +2255,7 @@ struct CounterCoverageMappingBuilder | |
|
||
// Create MCDC Decision Region if at top-level (root). | ||
if (IsRootNode) | ||
createDecision(E); | ||
createOrCancelDecision(E, SourceRegionsSince); | ||
} | ||
|
||
// Determine whether the right side of OR operation need to be visited. | ||
|
@@ -2211,6 +2276,8 @@ struct CounterCoverageMappingBuilder | |
|
||
bool IsRootNode = MCDCBuilder.isIdle(); | ||
|
||
unsigned SourceRegionsSince = SourceRegions.size(); | ||
|
||
// Keep track of Binary Operator and assign MCDC condition IDs. | ||
MCDCBuilder.pushAndAssignIDs(E); | ||
|
||
|
@@ -2253,7 +2320,7 @@ struct CounterCoverageMappingBuilder | |
|
||
// Create MCDC Decision Region if at top-level (root). | ||
if (IsRootNode) | ||
createDecision(E); | ||
createOrCancelDecision(E, SourceRegionsSince); | ||
} | ||
|
||
void VisitLambdaExpr(const LambdaExpr *LE) { | ||
|
Uh oh!
There was an error while loading. Please reload this page.