[clang] [llvm] [clang][CoverageMapping] Refactor when setting MC/DC True/False (PR #78202)

NAKAMURA Takumi via cfe-commits cfe-commits at lists.llvm.org
Tue Jan 16 22:57:39 PST 2024


================
@@ -1822,20 +1817,28 @@ struct CounterCoverageMappingBuilder
   }
 
   void VisitBinLAnd(const BinaryOperator *E) {
-    // Keep track of Binary Operator and assign MCDC condition IDs
+    bool IsRootNode = MCDCBuilder.isIdle();
+
+    // Keep track of Binary Operator and assign MCDC condition IDs.
     MCDCBuilder.pushAndAssignIDs(E);
 
     extendRegion(E->getLHS());
     propagateCounts(getRegion().getCounter(), E->getLHS());
     handleFileExit(getEnd(E->getLHS()));
 
+    // Track LHS True/False Decision.
+    auto DecisionLHS = MCDCBuilder.pop();
+
     // Counter tracks the right hand side of a logical and operator.
     extendRegion(E->getRHS());
     propagateCounts(getRegionCounter(E), E->getRHS());
 
-    // Process Binary Operator and create MCDC Decision Region if top-level
+    // Track RHS True/False Decision.
+    const auto &DecisionRHS = MCDCBuilder.back();
----------------
chapuni wrote:

This might crash if it would be moved before `propagateCounts(getRHS)`, since the stack might be reallocated in children.
Could it be rewritten with passing by value (instead of by ref) for safety in the future?

https://github.com/llvm/llvm-project/pull/78202


More information about the cfe-commits mailing list