From 8eff226c98bdcfcd1366120699a42e0c4c73375c Mon Sep 17 00:00:00 2001 From: NAKAMURA Takumi Date: Sun, 2 Feb 2025 22:00:48 +0900 Subject: [MC/DC] Prune MCDCLogOpStack and use CGF.isMCDCDecisionExpr `MCDCLogOpStack` is used only for detection of the Decision root. It can be detected with `MCDC::State::DecisionByStmt`. --- clang/lib/CodeGen/CodeGenFunction.cpp | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'clang/lib/CodeGen/CodeGenFunction.cpp') diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index bbef277..3a6b97a 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -1851,8 +1851,6 @@ void CodeGenFunction::EmitBranchOnBoolExpr( if (const BinaryOperator *CondBOp = dyn_cast(Cond)) { // Handle X && Y in a condition. if (CondBOp->getOpcode() == BO_LAnd) { - MCDCLogOpStack.push_back(CondBOp); - // If we have "1 && X", simplify the code. "0 && X" would have constant // folded if the case was simple enough. bool ConstantBool = false; @@ -1862,7 +1860,6 @@ void CodeGenFunction::EmitBranchOnBoolExpr( incrementProfileCounter(CondBOp); EmitBranchToCounterBlock(CondBOp->getRHS(), BO_LAnd, TrueBlock, FalseBlock, TrueCount, LH); - MCDCLogOpStack.pop_back(); return; } @@ -1873,7 +1870,6 @@ void CodeGenFunction::EmitBranchOnBoolExpr( // br(X && 1) -> br(X). EmitBranchToCounterBlock(CondBOp->getLHS(), BO_LAnd, TrueBlock, FalseBlock, TrueCount, LH, CondBOp); - MCDCLogOpStack.pop_back(); return; } @@ -1903,13 +1899,10 @@ void CodeGenFunction::EmitBranchOnBoolExpr( EmitBranchToCounterBlock(CondBOp->getRHS(), BO_LAnd, TrueBlock, FalseBlock, TrueCount, LH); eval.end(*this); - MCDCLogOpStack.pop_back(); return; } if (CondBOp->getOpcode() == BO_LOr) { - MCDCLogOpStack.push_back(CondBOp); - // If we have "0 || X", simplify the code. "1 || X" would have constant // folded if the case was simple enough. bool ConstantBool = false; @@ -1919,7 +1912,6 @@ void CodeGenFunction::EmitBranchOnBoolExpr( incrementProfileCounter(CondBOp); EmitBranchToCounterBlock(CondBOp->getRHS(), BO_LOr, TrueBlock, FalseBlock, TrueCount, LH); - MCDCLogOpStack.pop_back(); return; } @@ -1930,7 +1922,6 @@ void CodeGenFunction::EmitBranchOnBoolExpr( // br(X || 0) -> br(X). EmitBranchToCounterBlock(CondBOp->getLHS(), BO_LOr, TrueBlock, FalseBlock, TrueCount, LH, CondBOp); - MCDCLogOpStack.pop_back(); return; } // Emit the LHS as a conditional. If the LHS conditional is true, we @@ -1963,7 +1954,6 @@ void CodeGenFunction::EmitBranchOnBoolExpr( RHSCount, LH); eval.end(*this); - MCDCLogOpStack.pop_back(); return; } } @@ -2048,7 +2038,7 @@ void CodeGenFunction::EmitBranchOnBoolExpr( // If not at the top of the logical operator nest, update MCDC temp with the // boolean result of the evaluated condition. - if (!MCDCLogOpStack.empty()) { + { const Expr *MCDCBaseExpr = Cond; // When a nested ConditionalOperator (ternary) is encountered in a boolean // expression, MC/DC tracks the result of the ternary, and this is tied to @@ -2058,7 +2048,9 @@ void CodeGenFunction::EmitBranchOnBoolExpr( if (ConditionalOp) MCDCBaseExpr = ConditionalOp; - maybeUpdateMCDCCondBitmap(MCDCBaseExpr, CondV); + if (isMCDCBranchExpr(stripCond(MCDCBaseExpr)) && + !isMCDCDecisionExpr(stripCond(Cond))) + maybeUpdateMCDCCondBitmap(MCDCBaseExpr, CondV); } llvm::MDNode *Weights = nullptr; -- cgit v1.1