Skip to content

Commit 9274829

Browse files
whentojumptstellar
authored andcommitted
[clang][CodeGen] Keep processing the rest of AST after encountering unsupported MC/DC expressions (#82464)
Currently, upon seeing unsupported decisions (more than 6 conditions, or split nesting), the post-visitor hook dataTraverseStmtPost() returns a false. As a result, in the rest of tree even supported decisions will be skipped as well. Like in the below code: { // CompoundStmt a && b; // 1: BinaryOperator (supported) a && foo(b && c); // 2: BinaryOperator (not yet supported due to split // nesting) a && b; // 3: BinaryOperator (supported) } Decision 3 will not be processed at all. And only one "Decision" region will be emitted. Compiler explorer example: https://godbolt.org/z/Px61sesoo We hope to process such cases and emit two "Decision" regions (1 and 3) in the above example. (cherry picked from commit d4bfca3)
1 parent c8b11e9 commit 9274829

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

clang/lib/CodeGen/CodeGenPGO.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,12 @@ struct MapRegionCounters : public RecursiveASTVisitor<MapRegionCounters> {
240240
if (MCDCMaxCond == 0)
241241
return true;
242242

243-
/// At the top of the logical operator nest, reset the number of conditions.
244-
if (LogOpStack.empty())
243+
/// At the top of the logical operator nest, reset the number of conditions,
244+
/// also forget previously seen split nesting cases.
245+
if (LogOpStack.empty()) {
245246
NumCond = 0;
247+
SplitNestedLogicalOp = false;
248+
}
246249

247250
if (const Expr *E = dyn_cast<Expr>(S)) {
248251
const BinaryOperator *BinOp = dyn_cast<BinaryOperator>(E->IgnoreParens());
@@ -293,7 +296,7 @@ struct MapRegionCounters : public RecursiveASTVisitor<MapRegionCounters> {
293296
"contains an operation with a nested boolean expression. "
294297
"Expression will not be covered");
295298
Diag.Report(S->getBeginLoc(), DiagID);
296-
return false;
299+
return true;
297300
}
298301

299302
/// Was the maximum number of conditions encountered?
@@ -304,7 +307,7 @@ struct MapRegionCounters : public RecursiveASTVisitor<MapRegionCounters> {
304307
"number of conditions (%0) exceeds max (%1). "
305308
"Expression will not be covered");
306309
Diag.Report(S->getBeginLoc(), DiagID) << NumCond << MCDCMaxCond;
307-
return false;
310+
return true;
308311
}
309312

310313
// Otherwise, allocate the number of bytes required for the bitmap

0 commit comments

Comments
 (0)