Skip to content

Commit d4bfca3

Browse files
authored
[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.
1 parent 7276352 commit d4bfca3

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
@@ -239,9 +239,12 @@ struct MapRegionCounters : public RecursiveASTVisitor<MapRegionCounters> {
239239
if (MCDCMaxCond == 0)
240240
return true;
241241

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

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

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

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

0 commit comments

Comments
 (0)