[llvm-branch-commits] [clang] [MC/DC] Enable nested expressions (PR #125413)
NAKAMURA Takumi via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Feb 27 21:56:58 PST 2025
================
@@ -275,49 +276,57 @@ struct MapRegionCounters : public RecursiveASTVisitor<MapRegionCounters> {
// an AST Stmt node. MC/DC will use it to to signal when the top of a
// logical operation (boolean expression) nest is encountered.
bool dataTraverseStmtPost(Stmt *S) {
- /// If MC/DC is not enabled, MCDCMaxCond will be set to 0. Do nothing.
- if (MCDCMaxCond == 0)
+ if (DecisionStack.empty())
return true;
- if (const Expr *E = dyn_cast<Expr>(S)) {
- const BinaryOperator *BinOp = dyn_cast<BinaryOperator>(E->IgnoreParens());
- if (BinOp && BinOp->isLogicalOp()) {
- assert(LogOpStack.back() == BinOp);
- LogOpStack.pop_back();
-
- /// At the top of logical operator nest:
- if (LogOpStack.empty()) {
- /// Was the "split-nested" logical operator case encountered?
- if (SplitNestedLogicalOp) {
- unsigned DiagID = Diag.getCustomDiagID(
- DiagnosticsEngine::Warning,
- "unsupported MC/DC boolean expression; "
- "contains an operation with a nested boolean expression. "
- "Expression will not be covered");
- Diag.Report(S->getBeginLoc(), DiagID);
- return true;
- }
-
- /// Was the maximum number of conditions encountered?
- if (NumCond > MCDCMaxCond) {
- unsigned DiagID = Diag.getCustomDiagID(
- DiagnosticsEngine::Warning,
- "unsupported MC/DC boolean expression; "
- "number of conditions (%0) exceeds max (%1). "
- "Expression will not be covered");
- Diag.Report(S->getBeginLoc(), DiagID) << NumCond << MCDCMaxCond;
- return true;
- }
-
- // Otherwise, allocate the Decision.
- MCDCState.DecisionByStmt[BinOp].ID = MCDCState.DecisionByStmt.size();
- }
- return true;
+ /// If MC/DC is not enabled, MCDCMaxCond will be set to 0. Do nothing.
+ assert(MCDCMaxCond > 0);
+
+ auto &StackTop = DecisionStack.back();
+
+ if (StackTop.DecisionExpr != S) {
+ if (StackTop.Leaves.contains(S)) {
+ assert(StackTop.Split);
+ StackTop.Split = false;
}
+
+ return true;
+ }
+
+ /// Allocate the entry (with Valid=false)
+ auto &DecisionEntry =
+ MCDCState
+ .DecisionByStmt[CodeGenFunction::stripCond(StackTop.DecisionExpr)];
+
+ /// Was the "split-nested" logical operator case encountered?
+ if (false && DecisionStack.size() > 1) {
----------------
chapuni wrote:
This is the option for deprecating this warning, "warn if nested level >= n" or deprecate. @evodius96 Opinions?
https://github.com/llvm/llvm-project/pull/125413
More information about the llvm-branch-commits
mailing list