[llvm-branch-commits] [clang] [llvm] [Coverage][Single] Enable Branch coverage for `BinLAnd` and `BinLOr` (PR #113113)

NAKAMURA Takumi via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Sat Dec 21 09:13:27 PST 2024


https://github.com/chapuni updated https://github.com/llvm/llvm-project/pull/113113

>From 16e2bb8b73bcde1c2618bb358a905a9f463c1217 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi <geek4civic at gmail.com>
Date: Sun, 20 Oct 2024 16:24:26 +0900
Subject: [PATCH 1/3] [Coverage][Single] Enable Branch coverage for `BinLAnd`
 and `BinLOr`

---
 clang/lib/CodeGen/CGExprScalar.cpp       | 83 +++++++++++++++++++-----
 clang/lib/CodeGen/CGStmt.cpp             |  4 --
 clang/lib/CodeGen/CodeGenFunction.cpp    | 43 ++++++++++--
 clang/lib/CodeGen/CoverageMappingGen.cpp |  6 --
 4 files changed, 104 insertions(+), 32 deletions(-)

diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp
index 11d4ec8a267605..83962ba96aa484 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -4918,6 +4918,9 @@ Value *ScalarExprEmitter::VisitBinAssign(const BinaryOperator *E) {
 }
 
 Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) {
+  auto HasLHSSkip = CGF.getIsCounterPair(E);
+  auto HasRHSSkip = CGF.getIsCounterPair(E->getRHS());
+
   // Perform vector logical and on comparisons with zero vectors.
   if (E->getType()->isVectorType()) {
     CGF.incrementProfileCounter(E);
@@ -4964,11 +4967,17 @@ Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) {
           CodeGenFunction::isInstrumentedCondition(E->getRHS())) {
         CGF.maybeUpdateMCDCCondBitmap(E->getRHS(), RHSCond);
         llvm::BasicBlock *FBlock = CGF.createBasicBlock("land.end");
+        llvm::BasicBlock *RHSSkip =
+            (HasRHSSkip.second ? CGF.createBasicBlock("land.rhsskip") : FBlock);
         llvm::BasicBlock *RHSBlockCnt = CGF.createBasicBlock("land.rhscnt");
-        Builder.CreateCondBr(RHSCond, RHSBlockCnt, FBlock);
+        Builder.CreateCondBr(RHSCond, RHSBlockCnt, RHSSkip);
         CGF.EmitBlock(RHSBlockCnt);
-        CGF.incrementProfileCounter(E->getRHS());
+        CGF.incrementProfileCounter(false, E->getRHS());
         CGF.EmitBranch(FBlock);
+        if (HasRHSSkip.second) {
+          CGF.EmitBlock(RHSSkip);
+          CGF.incrementProfileCounter(true, E->getRHS());
+        }
         CGF.EmitBlock(FBlock);
       }
 
@@ -4997,12 +5006,21 @@ Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) {
   llvm::BasicBlock *ContBlock = CGF.createBasicBlock("land.end");
   llvm::BasicBlock *RHSBlock  = CGF.createBasicBlock("land.rhs");
 
+  llvm::BasicBlock *LHSFalseBlock =
+      (HasLHSSkip.second ? CGF.createBasicBlock("land.lhsskip") : ContBlock);
+
   CodeGenFunction::ConditionalEvaluation eval(CGF);
 
   // Branch on the LHS first.  If it is false, go to the failure (cont) block.
-  CGF.EmitBranchOnBoolExpr(E->getLHS(), RHSBlock, ContBlock,
+  CGF.EmitBranchOnBoolExpr(E->getLHS(), RHSBlock, LHSFalseBlock,
                            CGF.getProfileCount(E->getRHS()));
 
+  if (HasLHSSkip.second) {
+    CGF.EmitBlock(LHSFalseBlock);
+    CGF.incrementProfileCounter(true, E);
+    CGF.EmitBranch(ContBlock);
+  }
+
   // Any edges into the ContBlock are now from an (indeterminate number of)
   // edges from this first condition.  All of these values will be false.  Start
   // setting up the PHI node in the Cont Block for this.
@@ -5014,7 +5032,7 @@ Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) {
 
   eval.begin(CGF);
   CGF.EmitBlock(RHSBlock);
-  CGF.incrementProfileCounter(E);
+  CGF.incrementProfileCounter(false, E);
   Value *RHSCond = CGF.EvaluateExprAsBool(E->getRHS());
   eval.end(CGF);
 
@@ -5024,15 +5042,24 @@ Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) {
   // If we're generating for profiling or coverage, generate a branch on the
   // RHS to a block that increments the RHS true counter needed to track branch
   // condition coverage.
+  llvm::BasicBlock *ContIncoming = RHSBlock;
   if (InstrumentRegions &&
       CodeGenFunction::isInstrumentedCondition(E->getRHS())) {
     CGF.maybeUpdateMCDCCondBitmap(E->getRHS(), RHSCond);
     llvm::BasicBlock *RHSBlockCnt = CGF.createBasicBlock("land.rhscnt");
-    Builder.CreateCondBr(RHSCond, RHSBlockCnt, ContBlock);
+    llvm::BasicBlock *RHSBlockSkip =
+        (HasRHSSkip.second ? CGF.createBasicBlock("land.rhsskip") : ContBlock);
+    Builder.CreateCondBr(RHSCond, RHSBlockCnt, RHSBlockSkip);
     CGF.EmitBlock(RHSBlockCnt);
-    CGF.incrementProfileCounter(E->getRHS());
+    CGF.incrementProfileCounter(false, E->getRHS());
     CGF.EmitBranch(ContBlock);
     PN->addIncoming(RHSCond, RHSBlockCnt);
+    if (HasRHSSkip.second) {
+      CGF.EmitBlock(RHSBlockSkip);
+      CGF.incrementProfileCounter(true, E->getRHS());
+      CGF.EmitBranch(ContBlock);
+      ContIncoming = RHSBlockSkip;
+    }
   }
 
   // Emit an unconditional branch from this block to ContBlock.
@@ -5042,7 +5069,7 @@ Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) {
     CGF.EmitBlock(ContBlock);
   }
   // Insert an entry into the phi node for the edge with the value of RHSCond.
-  PN->addIncoming(RHSCond, RHSBlock);
+  PN->addIncoming(RHSCond, ContIncoming);
 
   CGF.MCDCLogOpStack.pop_back();
   // If the top of the logical operator nest, update the MCDC bitmap.
@@ -5060,6 +5087,9 @@ Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) {
 }
 
 Value *ScalarExprEmitter::VisitBinLOr(const BinaryOperator *E) {
+  auto HasLHSSkip = CGF.getIsCounterPair(E);
+  auto HasRHSSkip = CGF.getIsCounterPair(E->getRHS());
+
   // Perform vector logical or on comparisons with zero vectors.
   if (E->getType()->isVectorType()) {
     CGF.incrementProfileCounter(E);
@@ -5088,7 +5118,7 @@ Value *ScalarExprEmitter::VisitBinLOr(const BinaryOperator *E) {
   bool LHSCondVal;
   if (CGF.ConstantFoldsToSimpleInteger(E->getLHS(), LHSCondVal)) {
     if (!LHSCondVal) { // If we have 0 || X, just emit X.
-      CGF.incrementProfileCounter(E);
+      CGF.incrementProfileCounter(false, E);
 
       // If the top of the logical operator nest, reset the MCDC temp to 0.
       if (CGF.MCDCLogOpStack.empty())
@@ -5106,11 +5136,17 @@ Value *ScalarExprEmitter::VisitBinLOr(const BinaryOperator *E) {
           CodeGenFunction::isInstrumentedCondition(E->getRHS())) {
         CGF.maybeUpdateMCDCCondBitmap(E->getRHS(), RHSCond);
         llvm::BasicBlock *FBlock = CGF.createBasicBlock("lor.end");
+        llvm::BasicBlock *RHSSkip =
+            (HasRHSSkip.second ? CGF.createBasicBlock("lor.rhsskip") : FBlock);
         llvm::BasicBlock *RHSBlockCnt = CGF.createBasicBlock("lor.rhscnt");
-        Builder.CreateCondBr(RHSCond, FBlock, RHSBlockCnt);
+        Builder.CreateCondBr(RHSCond, RHSSkip, RHSBlockCnt);
         CGF.EmitBlock(RHSBlockCnt);
-        CGF.incrementProfileCounter(E->getRHS());
+        CGF.incrementProfileCounter(false, E->getRHS());
         CGF.EmitBranch(FBlock);
+        if (HasRHSSkip.second) {
+          CGF.EmitBlock(RHSSkip);
+          CGF.incrementProfileCounter(true, E->getRHS());
+        }
         CGF.EmitBlock(FBlock);
       }
 
@@ -5138,14 +5174,22 @@ Value *ScalarExprEmitter::VisitBinLOr(const BinaryOperator *E) {
 
   llvm::BasicBlock *ContBlock = CGF.createBasicBlock("lor.end");
   llvm::BasicBlock *RHSBlock = CGF.createBasicBlock("lor.rhs");
+  llvm::BasicBlock *LHSTrueBlock =
+      (HasLHSSkip.second ? CGF.createBasicBlock("lor.lhsskip") : ContBlock);
 
   CodeGenFunction::ConditionalEvaluation eval(CGF);
 
   // Branch on the LHS first.  If it is true, go to the success (cont) block.
-  CGF.EmitBranchOnBoolExpr(E->getLHS(), ContBlock, RHSBlock,
+  CGF.EmitBranchOnBoolExpr(E->getLHS(), LHSTrueBlock, RHSBlock,
                            CGF.getCurrentProfileCount() -
                                CGF.getProfileCount(E->getRHS()));
 
+  if (HasLHSSkip.second) {
+    CGF.EmitBlock(LHSTrueBlock);
+    CGF.incrementProfileCounter(true, E);
+    CGF.EmitBranch(ContBlock);
+  }
+
   // Any edges into the ContBlock are now from an (indeterminate number of)
   // edges from this first condition.  All of these values will be true.  Start
   // setting up the PHI node in the Cont Block for this.
@@ -5159,7 +5203,7 @@ Value *ScalarExprEmitter::VisitBinLOr(const BinaryOperator *E) {
 
   // Emit the RHS condition as a bool value.
   CGF.EmitBlock(RHSBlock);
-  CGF.incrementProfileCounter(E);
+  CGF.incrementProfileCounter(false, E);
   Value *RHSCond = CGF.EvaluateExprAsBool(E->getRHS());
 
   eval.end(CGF);
@@ -5170,21 +5214,30 @@ Value *ScalarExprEmitter::VisitBinLOr(const BinaryOperator *E) {
   // If we're generating for profiling or coverage, generate a branch on the
   // RHS to a block that increments the RHS true counter needed to track branch
   // condition coverage.
+  llvm::BasicBlock *ContIncoming = RHSBlock;
   if (InstrumentRegions &&
       CodeGenFunction::isInstrumentedCondition(E->getRHS())) {
     CGF.maybeUpdateMCDCCondBitmap(E->getRHS(), RHSCond);
     llvm::BasicBlock *RHSBlockCnt = CGF.createBasicBlock("lor.rhscnt");
-    Builder.CreateCondBr(RHSCond, ContBlock, RHSBlockCnt);
+    llvm::BasicBlock *RHSTrueBlock =
+        (HasRHSSkip.second ? CGF.createBasicBlock("lor.rhsskip") : ContBlock);
+    Builder.CreateCondBr(RHSCond, RHSTrueBlock, RHSBlockCnt);
     CGF.EmitBlock(RHSBlockCnt);
-    CGF.incrementProfileCounter(E->getRHS());
+    CGF.incrementProfileCounter(false, E->getRHS());
     CGF.EmitBranch(ContBlock);
     PN->addIncoming(RHSCond, RHSBlockCnt);
+    if (HasRHSSkip.second) {
+      CGF.EmitBlock(RHSTrueBlock);
+      CGF.incrementProfileCounter(true, E->getRHS());
+      CGF.EmitBranch(ContBlock);
+      ContIncoming = RHSTrueBlock;
+    }
   }
 
   // Emit an unconditional branch from this block to ContBlock.  Insert an entry
   // into the phi node for the edge with the value of RHSCond.
   CGF.EmitBlock(ContBlock);
-  PN->addIncoming(RHSCond, RHSBlock);
+  PN->addIncoming(RHSCond, ContIncoming);
 
   CGF.MCDCLogOpStack.pop_back();
   // If the top of the logical operator nest, update the MCDC bitmap.
diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp
index e28048d0ec4d90..ee42560b8870dc 100644
--- a/clang/lib/CodeGen/CGStmt.cpp
+++ b/clang/lib/CodeGen/CGStmt.cpp
@@ -43,10 +43,6 @@ using namespace CodeGen;
 //                              Statement Emission
 //===----------------------------------------------------------------------===//
 
-namespace llvm {
-extern cl::opt<bool> EnableSingleByteCoverage;
-} // namespace llvm
-
 void CodeGenFunction::EmitStopPoint(const Stmt *S) {
   if (CGDebugInfo *DI = getDebugInfo()) {
     SourceLocation Loc;
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp
index fcd225b0dc7f45..7f3f4bdbdbbc1d 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -1762,6 +1762,7 @@ void CodeGenFunction::EmitBranchToCounterBlock(
     return EmitBranchOnBoolExpr(Cond, TrueBlock, FalseBlock, TrueCount, LH);
 
   const Stmt *CntrStmt = (CntrIdx ? CntrIdx : Cond);
+  auto HasSkip = getIsCounterPair(CntrStmt);
 
   llvm::BasicBlock *ThenBlock = nullptr;
   llvm::BasicBlock *ElseBlock = nullptr;
@@ -1770,6 +1771,10 @@ void CodeGenFunction::EmitBranchToCounterBlock(
   // Create the block we'll use to increment the appropriate counter.
   llvm::BasicBlock *CounterIncrBlock = createBasicBlock("lop.rhscnt");
 
+  llvm::BasicBlock *SkipIncrBlock =
+      (HasSkip.second ? createBasicBlock("lop.rhsskip") : nullptr);
+  llvm::BasicBlock *SkipNextBlock = nullptr;
+
   // Set block pointers according to Logical-AND (BO_LAnd) semantics. This
   // means we need to evaluate the condition and increment the counter on TRUE:
   //
@@ -1783,8 +1788,9 @@ void CodeGenFunction::EmitBranchToCounterBlock(
   //   goto TrueBlock;
 
   if (LOp == BO_LAnd) {
+    SkipNextBlock = FalseBlock;
     ThenBlock = CounterIncrBlock;
-    ElseBlock = FalseBlock;
+    ElseBlock = (SkipIncrBlock ? SkipIncrBlock : SkipNextBlock);
     NextBlock = TrueBlock;
   }
 
@@ -1801,7 +1807,8 @@ void CodeGenFunction::EmitBranchToCounterBlock(
   //   goto FalseBlock;
 
   else if (LOp == BO_LOr) {
-    ThenBlock = TrueBlock;
+    SkipNextBlock = TrueBlock;
+    ThenBlock = (SkipIncrBlock ? SkipIncrBlock : SkipNextBlock);
     ElseBlock = CounterIncrBlock;
     NextBlock = FalseBlock;
   } else {
@@ -1811,11 +1818,17 @@ void CodeGenFunction::EmitBranchToCounterBlock(
   // Emit Branch based on condition.
   EmitBranchOnBoolExpr(Cond, ThenBlock, ElseBlock, TrueCount, LH);
 
+  if (SkipIncrBlock) {
+    EmitBlock(SkipIncrBlock);
+    incrementProfileCounter(true, CntrStmt);
+    EmitBranch(SkipNextBlock);
+  }
+
   // Emit the block containing the counter increment(s).
   EmitBlock(CounterIncrBlock);
 
   // Increment corresponding counter; if index not provided, use Cond as index.
-  incrementProfileCounter(CntrStmt);
+  incrementProfileCounter(false, CntrStmt);
 
   // Go to the next block.
   EmitBranch(NextBlock);
@@ -1834,6 +1847,8 @@ void CodeGenFunction::EmitBranchOnBoolExpr(
   Cond = Cond->IgnoreParens();
 
   if (const BinaryOperator *CondBOp = dyn_cast<BinaryOperator>(Cond)) {
+    auto HasSkip = getIsCounterPair(CondBOp);
+
     // Handle X && Y in a condition.
     if (CondBOp->getOpcode() == BO_LAnd) {
       MCDCLogOpStack.push_back(CondBOp);
@@ -1865,6 +1880,8 @@ void CodeGenFunction::EmitBranchOnBoolExpr(
       // Emit the LHS as a conditional.  If the LHS conditional is false, we
       // want to jump to the FalseBlock.
       llvm::BasicBlock *LHSTrue = createBasicBlock("land.lhs.true");
+      llvm::BasicBlock *LHSFalse =
+          (HasSkip.second ? createBasicBlock("land.lhsskip") : FalseBlock);
       // The counter tells us how often we evaluate RHS, and all of TrueCount
       // can be propagated to that branch.
       uint64_t RHSCount = getProfileCount(CondBOp->getRHS());
@@ -1875,12 +1892,17 @@ void CodeGenFunction::EmitBranchOnBoolExpr(
         // Propagate the likelihood attribute like __builtin_expect
         // __builtin_expect(X && Y, 1) -> X and Y are likely
         // __builtin_expect(X && Y, 0) -> only Y is unlikely
-        EmitBranchOnBoolExpr(CondBOp->getLHS(), LHSTrue, FalseBlock, RHSCount,
+        EmitBranchOnBoolExpr(CondBOp->getLHS(), LHSTrue, LHSFalse, RHSCount,
                              LH == Stmt::LH_Unlikely ? Stmt::LH_None : LH);
+        if (HasSkip.second) {
+          EmitBlock(LHSFalse);
+          incrementProfileCounter(true, CondBOp);
+          EmitBranch(FalseBlock);
+        }
         EmitBlock(LHSTrue);
       }
 
-      incrementProfileCounter(CondBOp);
+      incrementProfileCounter(false, CondBOp);
       setCurrentProfileCount(getProfileCount(CondBOp->getRHS()));
 
       // Any temporaries created here are conditional.
@@ -1920,6 +1942,8 @@ void CodeGenFunction::EmitBranchOnBoolExpr(
       }
       // Emit the LHS as a conditional.  If the LHS conditional is true, we
       // want to jump to the TrueBlock.
+      llvm::BasicBlock *LHSTrue =
+          (HasSkip.second ? createBasicBlock("lor.lhsskip") : TrueBlock);
       llvm::BasicBlock *LHSFalse = createBasicBlock("lor.lhs.false");
       // We have the count for entry to the RHS and for the whole expression
       // being true, so we can divy up True count between the short circuit and
@@ -1934,12 +1958,17 @@ void CodeGenFunction::EmitBranchOnBoolExpr(
         // __builtin_expect(X || Y, 1) -> only Y is likely
         // __builtin_expect(X || Y, 0) -> both X and Y are unlikely
         ApplyDebugLocation DL(*this, Cond);
-        EmitBranchOnBoolExpr(CondBOp->getLHS(), TrueBlock, LHSFalse, LHSCount,
+        EmitBranchOnBoolExpr(CondBOp->getLHS(), LHSTrue, LHSFalse, LHSCount,
                              LH == Stmt::LH_Likely ? Stmt::LH_None : LH);
+        if (HasSkip.second) {
+          EmitBlock(LHSTrue);
+          incrementProfileCounter(true, CondBOp);
+          EmitBranch(TrueBlock);
+        }
         EmitBlock(LHSFalse);
       }
 
-      incrementProfileCounter(CondBOp);
+      incrementProfileCounter(false, CondBOp);
       setCurrentProfileCount(getProfileCount(CondBOp->getRHS()));
 
       // Any temporaries created here are conditional.
diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp
index 6abf0b333b246b..9179410c706217 100644
--- a/clang/lib/CodeGen/CoverageMappingGen.cpp
+++ b/clang/lib/CodeGen/CoverageMappingGen.cpp
@@ -2185,9 +2185,6 @@ struct CounterCoverageMappingBuilder
     extendRegion(E->getRHS());
     propagateCounts(getRegionCounter(E), E->getRHS());
 
-    if (llvm::EnableSingleByteCoverage)
-      return;
-
     // Track RHS True/False Decision.
     const auto DecisionRHS = MCDCBuilder.back();
 
@@ -2246,9 +2243,6 @@ struct CounterCoverageMappingBuilder
     extendRegion(E->getRHS());
     propagateCounts(getRegionCounter(E), E->getRHS());
 
-    if (llvm::EnableSingleByteCoverage)
-      return;
-
     // Track RHS True/False Decision.
     const auto DecisionRHS = MCDCBuilder.back();
 

>From ad997c2f539ab2622e61c106bb3d646930777712 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi <geek4civic at gmail.com>
Date: Wed, 23 Oct 2024 14:39:35 +0000
Subject: [PATCH 2/3] Fix cases when LHS is skipped

---
 clang/lib/CodeGen/CGExprScalar.cpp | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp
index de85d4ad63833e..fd67622fe81548 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -4949,7 +4949,7 @@ Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) {
   bool LHSCondVal;
   if (CGF.ConstantFoldsToSimpleInteger(E->getLHS(), LHSCondVal)) {
     if (LHSCondVal) { // If we have 1 && X, just emit X.
-      CGF.incrementProfileCounter(E);
+      CGF.incrementProfileCounter(false, E, true);
 
       // If the top of the logical operator nest, reset the MCDC temp to 0.
       if (CGF.MCDCLogOpStack.empty())
@@ -4993,7 +4993,12 @@ Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) {
 
     // 0 && RHS: If it is safe, just elide the RHS, and return 0/false.
     if (!CGF.ContainsLabel(E->getRHS())) {
+      CGF.markStmtAsUsed(false, E);
+      if (HasLHSSkip.second)
+        CGF.incrementProfileCounter(true, E);
+
       CGF.markStmtMaybeUsed(E->getRHS());
+
       return llvm::Constant::getNullValue(ResTy);
     }
   }
@@ -5119,7 +5124,7 @@ Value *ScalarExprEmitter::VisitBinLOr(const BinaryOperator *E) {
   bool LHSCondVal;
   if (CGF.ConstantFoldsToSimpleInteger(E->getLHS(), LHSCondVal)) {
     if (!LHSCondVal) { // If we have 0 || X, just emit X.
-      CGF.incrementProfileCounter(false, E);
+      CGF.incrementProfileCounter(false, E, true);
 
       // If the top of the logical operator nest, reset the MCDC temp to 0.
       if (CGF.MCDCLogOpStack.empty())
@@ -5163,7 +5168,12 @@ Value *ScalarExprEmitter::VisitBinLOr(const BinaryOperator *E) {
 
     // 1 || RHS: If it is safe, just elide the RHS, and return 1/true.
     if (!CGF.ContainsLabel(E->getRHS())) {
+      CGF.markStmtAsUsed(false, E);
+      if (HasLHSSkip.second)
+        CGF.incrementProfileCounter(true, E);
+
       CGF.markStmtMaybeUsed(E->getRHS());
+
       return llvm::ConstantInt::get(ResTy, 1);
     }
   }

>From 4b58cb135371efccd573617f4e4e37055e477b0e Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi <geek4civic at gmail.com>
Date: Thu, 21 Nov 2024 00:23:18 +0900
Subject: [PATCH 3/3] Update single tests

---
 .../Inputs/branch-c-general-single.proftext   | 30 +++++++-
 .../Inputs/branch-c-general-single.yaml       | 12 +--
 .../tools/llvm-cov/Inputs/branch-c-general.c  | 44 +++++------
 .../branch-logical-mixed-single.proftext      | 66 ++++++++++++++++-
 .../Inputs/branch-logical-mixed-single.yaml   |  4 +-
 .../llvm-cov/Inputs/branch-logical-mixed.cpp  | 74 +++++++++----------
 .../Inputs/branch-macros-single.proftext      | 28 ++++++-
 .../llvm-cov/Inputs/branch-macros-single.yaml |  8 +-
 .../tools/llvm-cov/Inputs/branch-macros.cpp   | 40 +++++-----
 .../tools/llvm-cov/branch-logical-mixed.test  |  2 +-
 llvm/test/tools/llvm-cov/branch-macros.test   |  2 +-
 11 files changed, 211 insertions(+), 99 deletions(-)

diff --git a/llvm/test/tools/llvm-cov/Inputs/branch-c-general-single.proftext b/llvm/test/tools/llvm-cov/Inputs/branch-c-general-single.proftext
index 1606f292c1786a..0f897833602415 100644
--- a/llvm/test/tools/llvm-cov/Inputs/branch-c-general-single.proftext
+++ b/llvm/test/tools/llvm-cov/Inputs/branch-c-general-single.proftext
@@ -36,7 +36,7 @@ boolean_operators
 # Func Hash:
 1245693242827665
 # Num Counters:
-14
+26
 # Counter Values:
 1
 1
@@ -52,12 +52,24 @@ boolean_operators
 1
 1
 1
+1
+1
+1
+0
+1
+1
+1
+1
+1
+1
+1
+0
 
 boolop_loops
 # Func Hash:
 12402604614320574815
 # Num Counters:
-13
+21
 # Counter Values:
 1
 1
@@ -72,6 +84,14 @@ boolop_loops
 1
 1
 1
+0
+1
+1
+1
+0
+1
+1
+1
 
 branch-c-general.c:static_func
 # Func Hash:
@@ -98,7 +118,7 @@ conditionals
 # Func Hash:
 4904767535850050386
 # Num Counters:
-20
+24
 # Counter Values:
 1
 1
@@ -119,6 +139,10 @@ conditionals
 0
 1
 1
+0
+1
+1
+0
 1
 
 do_fallthrough
diff --git a/llvm/test/tools/llvm-cov/Inputs/branch-c-general-single.yaml b/llvm/test/tools/llvm-cov/Inputs/branch-c-general-single.yaml
index 2d6324fad688cb..ec5ab0a105ced8 100644
--- a/llvm/test/tools/llvm-cov/Inputs/branch-c-general-single.yaml
+++ b/llvm/test/tools/llvm-cov/Inputs/branch-c-general-single.yaml
@@ -16,7 +16,7 @@ Sections:
     Type:            SHT_PROGBITS
     Flags:           [ SHF_GNU_RETAIN ]
     AddressAlign:    0x8
-    Content:         83AD05A5F1438E680C01000052D33558163C11444C551E9517F40F4F01010101052A0111150E02030113001A2005010013001A05001C001F05002000A1808080080500210B04050109000E2009350009000E09000F009080808008090010020609010B000C200D39000B000C0D000D008E808080080D000E0010350106008C8080800835000C0406350010001520113D00100015110016009780808008110017020611010B000C201541000B000C15000D008E8080800815000E00103D0106008C808080083D000C02063D010B000C201945000B000C19000D008E8080800819000E0010100201005B050109000A050009000F21000E000F1D00100091808080081D00110013050109000A050009000F2D000E000F29001000918080800829001100131002010001
+    Content:         83AD05A5F1438E682801000052D33558163C11444C551E9517F40F4F01010101052E0111150E02030113001A2005010013001A05001C001F05002000A1808080080500210B04050109000E2009350009000E09000F009080808008090010020609010B000C200D39000B000C0D000D008E808080080D000E0010350106008C8080800835000C0406350010001520113D00100015110016009780808008110017020611010B000C201541000B000C15000D008E8080800815000E00103D0106008C808080083D000C02063D010B000C201945000B000C19000D008E8080800819000E0010100201005B050109000A050009000F2021000009000A21000E000F202551000E000F1D00100091808080081D00110013050109000A050009000F20002D0009000A2D000E000F205D31000E000F29001000918080800829001100131002010001
   - Name:            '__llvm_covfun (2)'
     Type:            SHT_PROGBITS
     Flags:           [ SHF_GNU_RETAIN ]
@@ -41,12 +41,12 @@ Sections:
     Type:            SHT_PROGBITS
     Flags:           [ SHF_GNU_RETAIN ]
     AddressAlign:    0x8
-    Content:         59A48AA8899AA3587B00000091E33C8FF36C04004C551E9517F40F4F01010101051601B4011A0C02030213001A2005010013001A05001C001F05002000A1808080080500210804050109000E0900120013100101005D050109000E1100120013100101005D050109000E0500090017210012001719001B001C1001010063050109000E0500090017310012001729001B001C1002010063
+    Content:         59A48AA8899AA358C100000091E33C8FF36C04004C551E9517F40F4F01010101052001B4011A0C02030213001A2005010013001A05001C001F05002000A1808080080500210804050109000E2039090009000E0900120013203D0D00120013100101005D050109000E2011410009000E110012001320154500120013100101005D050109000E05000900172049210009000E2100120017204D250012001719001B001C20551D001B001C1001010063050109000E05000900172031590009000E310012001720355D0012001729001B001C202D65001B001C1002010063
   - Name:            '__llvm_covfun (7)'
     Type:            SHT_PROGBITS
     Flags:           [ SHF_GNU_RETAIN ]
     AddressAlign:    0x8
-    Content:         F5953D044B505D139D0000005FD132562FE71EAC4C551E9517F40F4F010107010501110111011D011D012901291A01C201150D02100201000103010A000B03000A001509000F0015050016018580808008050105000810010100010B010A00110B000A001C150015001C11001D018580808008110105000810010100011301110012130011001C210016001C1D001E00211D0022002310010100611B010A00111B000A001C2D0015001C29001E002129002200231001010061
+    Content:         F5953D044B505D13D50000005FD132562FE71EAC4C551E9517F40F4F010107010501110111011D011D012901292201C201150D02100201000103010A000B03000A0015200935000A000B09000F0015200D39000F0015050016018580808008050105000810010100010B010A00110B000A001C203D15000A0011150015001C2041190015001C11001D018580808008110105000810010100011301110012130011001C20214500110012210016001C2025490016001C1D001E00211D0022002310010100611B010A00111B000A001C204D2D000A00112D0015001C2051310015001C29001E002129002200231001010061
   - Name:            '__llvm_covfun (8)'
     Type:            SHT_PROGBITS
     Flags:           [ SHF_GNU_RETAIN ]
@@ -112,7 +112,7 @@ Symbols:
     Type:            STT_OBJECT
     Section:         '__llvm_covfun (1)'
     Binding:         STB_WEAK
-    Size:            0x128
+    Size:            0x144
     Other:           [ STV_HIDDEN ]
   - Name:            __covrec_6973C52804C74904u
     Type:            STT_OBJECT
@@ -142,13 +142,13 @@ Symbols:
     Type:            STT_OBJECT
     Section:         '__llvm_covfun (6)'
     Binding:         STB_WEAK
-    Size:            0x97
+    Size:            0xDD
     Other:           [ STV_HIDDEN ]
   - Name:            __covrec_135D504B043D95F5u
     Type:            STT_OBJECT
     Section:         '__llvm_covfun (7)'
     Binding:         STB_WEAK
-    Size:            0xB9
+    Size:            0xF1
     Other:           [ STV_HIDDEN ]
   - Name:            __covrec_795CF1BD69C3E520u
     Type:            STT_OBJECT
diff --git a/llvm/test/tools/llvm-cov/Inputs/branch-c-general.c b/llvm/test/tools/llvm-cov/Inputs/branch-c-general.c
index 6b7f2c96ec8007..6c62e33d02bac7 100644
--- a/llvm/test/tools/llvm-cov/Inputs/branch-c-general.c
+++ b/llvm/test/tools/llvm-cov/Inputs/branch-c-general.c
@@ -23,10 +23,10 @@ void conditionals() {           // CHECK: @LINE|{{.*}}conditionals()
     } else {
       if (i) {}                 // CHECK: Branch ([[@LINE]]:11): [True: [[C16:16|1]], False: 1]
     }
-                                // BRCOV: Branch ([[@LINE+1]]:9): [True: [[C100]], Folded]
-    if (1 && i) {}              // BRCOV: Branch ([[@LINE]]:14): [True: [[C99:99|1]], False: 1]
-    if (0 || i) {}              // BRCOV: Branch ([[@LINE]]:9): [Folded, False: [[C100]]]
-  }                             // BRCOV: Branch ([[@LINE-1]]:14): [True: [[C99]], False: 1]
+                                // CHECK: Branch ([[@LINE+1]]:9): [True: [[C100]], Folded]
+    if (1 && i) {}              // CHECK: Branch ([[@LINE]]:14): [True: [[C99:99|1]], False: 1]
+    if (0 || i) {}              // CHECK: Branch ([[@LINE]]:9): [Folded, False: [[C100]]]
+  }                             // CHECK: Branch ([[@LINE-1]]:14): [True: [[C99]], False: 1]
 
 }
 
@@ -180,30 +180,30 @@ void big_switch() {             // CHECK: @LINE|{{.*}}big_switch()
 void boolean_operators() {      // CHECK: @LINE|{{.*}}boolean_operators()
   int v;
   for (int i = 0; i < 100; ++i) {
-    v = i % 3 || i;             // BRCOV: Branch ([[@LINE]]:9): [True: [[C66:66|1]], False: [[C34:34|1]]]
-                                // BRCOV: Branch ([[@LINE-1]]:18): [True: [[C33]], False: 1]
-    v = i % 3 && i;             // BRCOV: Branch ([[@LINE]]:9): [True: [[C66]], False: [[C34]]]
-                                // BRCOV: Branch ([[@LINE-1]]:18): [True: [[C66]], False: 0]
-    v = i % 3 || i % 2 || i;    // BRCOV: Branch ([[@LINE]]:9): [True: [[C66]], False: [[C34]]]
-                                // BRCOV: Branch ([[@LINE-1]]:18): [True: [[C17]], False: [[C17]]]
-    v = i % 2 && i % 3 && i;    // BRCOV: Branch ([[@LINE-2]]:27): [True: [[C16]], False: 1]
-  }                             // BRCOV: Branch ([[@LINE-1]]:9): [True: [[C50]], False: [[C50]]]
-                                // BRCOV: Branch ([[@LINE-2]]:18): [True: [[C33]], False: [[C17]]]
-}                               // BRCOV: Branch ([[@LINE-3]]:27): [True: [[C33]], False: 0]
+    v = i % 3 || i;             // CHECK: Branch ([[@LINE]]:9): [True: [[C66:66|1]], False: [[C34:34|1]]]
+                                // CHECK: Branch ([[@LINE-1]]:18): [True: [[C33]], False: 1]
+    v = i % 3 && i;             // CHECK: Branch ([[@LINE]]:9): [True: [[C66]], False: [[C34]]]
+                                // CHECK: Branch ([[@LINE-1]]:18): [True: [[C66]], False: 0]
+    v = i % 3 || i % 2 || i;    // CHECK: Branch ([[@LINE]]:9): [True: [[C66]], False: [[C34]]]
+                                // CHECK: Branch ([[@LINE-1]]:18): [True: [[C17]], False: [[C17]]]
+    v = i % 2 && i % 3 && i;    // CHECK: Branch ([[@LINE-2]]:27): [True: [[C16]], False: 1]
+  }                             // CHECK: Branch ([[@LINE-1]]:9): [True: [[C50]], False: [[C50]]]
+                                // CHECK: Branch ([[@LINE-2]]:18): [True: [[C33]], False: [[C17]]]
+}                               // CHECK: Branch ([[@LINE-3]]:27): [True: [[C33]], False: 0]
 
 void boolop_loops() {           // CHECK: @LINE|{{.*}}boolop_loops()
   int i = 100;
 
-  while (i && i > 50)           // BRCOV: Branch ([[@LINE]]:10): [True: [[C51]], False: 0]
-    i--;                        // BRCOV: Branch ([[@LINE-1]]:15): [True: [[C50]], False: 1]
+  while (i && i > 50)           // CHECK: Branch ([[@LINE]]:10): [True: [[C51]], False: 0]
+    i--;                        // CHECK: Branch ([[@LINE-1]]:15): [True: [[C50]], False: 1]
 
-  while ((i % 2) || (i > 0))    // BRCOV: Branch ([[@LINE]]:10): [True: [[C25]], False: [[C26:26|1]]]
-    i--;                        // BRCOV: Branch ([[@LINE-1]]:21): [True: [[C25]], False: 1]
+  while ((i % 2) || (i > 0))    // CHECK: Branch ([[@LINE]]:10): [True: [[C25]], False: [[C26:26|1]]]
+    i--;                        // CHECK: Branch ([[@LINE-1]]:21): [True: [[C25]], False: 1]
 
-  for (i = 100; i && i > 50; --i);  // BRCOV: Branch ([[@LINE]]:17): [True: [[C51]], False: 0]
-                                    // BRCOV: Branch ([[@LINE-1]]:22): [True: [[C50]], False: 1]
-  for (; (i % 2) || (i > 0); --i);  // BRCOV: Branch ([[@LINE]]:10): [True: [[C25]], False: [[C26]]]
-                                    // BRCOV: Branch ([[@LINE-1]]:21): [True: [[C25]], False: 1]
+  for (i = 100; i && i > 50; --i);  // CHECK: Branch ([[@LINE]]:17): [True: [[C51]], False: 0]
+                                    // CHECK: Branch ([[@LINE-1]]:22): [True: [[C50]], False: 1]
+  for (; (i % 2) || (i > 0); --i);  // CHECK: Branch ([[@LINE]]:10): [True: [[C25]], False: [[C26]]]
+                                    // CHECK: Branch ([[@LINE-1]]:21): [True: [[C25]], False: 1]
 }
 
 void conditional_operator() {   // CHECK: @LINE|{{.*}}conditional_operator()
diff --git a/llvm/test/tools/llvm-cov/Inputs/branch-logical-mixed-single.proftext b/llvm/test/tools/llvm-cov/Inputs/branch-logical-mixed-single.proftext
index 798e150d80a1ae..7ebf85a88e869f 100644
--- a/llvm/test/tools/llvm-cov/Inputs/branch-logical-mixed-single.proftext
+++ b/llvm/test/tools/llvm-cov/Inputs/branch-logical-mixed-single.proftext
@@ -4,7 +4,7 @@ _Z4funcii
 # Func Hash:
 8468630735863722633
 # Num Counters:
-63
+127
 # Counter Values:
 4
 0
@@ -65,6 +65,70 @@ _Z4funcii
 4
 1
 3
+1
+1
+2
+0
+2
+2
+4
+0
+4
+0
+3
+0
+3
+1
+4
+0
+4
+0
+4
+0
+1
+2
+1
+2
+1
+0
+0
+3
+1
+0
+3
+0
+1
+0
+2
+1
+1
+0
+2
+1
+1
+0
+3
+1
+2
+1
+0
+0
+3
+0
+1
+0
+0
+3
+1
+0
+1
+2
+1
+0
+1
+2
+1
+0
 4
 0
 3
diff --git a/llvm/test/tools/llvm-cov/Inputs/branch-logical-mixed-single.yaml b/llvm/test/tools/llvm-cov/Inputs/branch-logical-mixed-single.yaml
index 0c36f48789a510..0fc3196210b09f 100644
--- a/llvm/test/tools/llvm-cov/Inputs/branch-logical-mixed-single.yaml
+++ b/llvm/test/tools/llvm-cov/Inputs/branch-logical-mixed-single.yaml
@@ -11,7 +11,7 @@ Sections:
     Type:            SHT_PROGBITS
     Flags:           [ SHF_GNU_RETAIN ]
     AddressAlign:    0x8
-    Content:         F0A0ED2C305C0BB33C02000089B21C19C99E86758F2950E06FBD46E8010100610108194302100701000101010C000E01000C010E01000C020E01000C030E01000C040E25010C000E1D010C000E15010C000E0D010C000E05010C000E100101000101010C000E01000C010E01000C020E01000C030E01000C040E4D010C000E45010C000E3D010C000E35010C000E2D010C000E100101000101010C011001000C031001000C051001000C071001000C091001000D000F69010D000F65010C011065000D000F71010D000F61010C011061000D000F79010D000F5D010C01105D000D000F8101010D000F59010C011059000D000F8901010D000F55010C011055000D000F9101010D000F100101000101010C011001000C031001000C051001000C071001000C091001000D000FAD01010D000FA901010C0110A901000D000FB501010D000FA501010C0110A501000D000FBD01010D000FA101010C0110A101000D000FC501010D000F9D01010C01109D01000D000FCD01010D000F9901010C01109901000D000FD501010D000F1001010001010107000820DD01ED0100070008DD010009018580808008DD0101050016ED010017028580808008ED01020500161001010001010107000820E101F10100070008E1010009018580808008E10101050016F1010017028580808008F101020500161001010001010107000820E501F50100070008E5010009018580808008E50101050016F5010017028580808008F501020500161001010001010107000820E901F90100070008E9010009018580808008E90101050016F9010017028580808008F90102050016
+    Content:         F0A0ED2C305C0BB36F03000089B21C19C99E86758F2950E06FBD46E801010085010108194302100701000101010C000E01000C010E01000C020E01000C030E01000C040E2025ED01000C000E25010C000E2029F101000C000E1D010C000E2021F901000C000E15010C000E20198102000C000E0D010C000E20118902000C000E05010C000E20099102000C000E100101000101010C000E01000C010E01000C020E01000C030E01000C040E2095024D000C000E4D010C000E20990251000C000E45010C000E20A10249000C000E3D010C000E20A90241000C000E35010C000E20B10239000C000E2D010C000E20B90231000C000E100101000101010C011001000C031001000C051001000C071001000C091001000D000F2069BD02000D000F69010D000F206DC102000D000F65010C011065000D000F2071C502000D000F71010D000F2075C902000D000F61010C011061000D000F2079D502000D000F79010D000F207DD902000D000F5D010C01105D000D000F208101E502000D000F8101010D000F208501E902000D000F59010C011059000D000F208901F502000D000F8901010D000F208D01F902000D000F55010C011055000D000F2091018503000D000F9101010D000F2095018903000D000F100101000101010C011001000C031001000C051001000C071001000C091001000D000F209503AD01000D000FAD01010D000F209903B101000D000FA901010C0110A901000D000F209D03B501000D000FB501010D000F20A103B901000D000FA501010C0110A501000D000F20AD03BD01000D000FBD01010D000F20B103C101000D000FA101010C0110A101000D000F20BD03C501000D000FC501010D000F20C103C901000D000F9D01010C01109D01000D000F20CD03CD01000D000FCD01010D000F20D103D101000D000F9901010C01109901000D000F20DD03D501000D000FD501010D000F20E103D901000D000F1001010001010107000820DD01ED0300070008DD010009018580808008DD0101050016ED030017028580808008ED03020500161001010001010107000820E101F10300070008E1010009018580808008E10101050016F1030017028580808008F103020500161001010001010107000820E501F50300070008E5010009018580808008E50101050016F5030017028580808008F503020500161001010001010107000820E901F90300070008E9010009018580808008E90101050016F9030017028580808008F90302050016
   - Name:            '__llvm_covfun (1)'
     Type:            SHT_PROGBITS
     Flags:           [ SHF_GNU_RETAIN ]
@@ -46,7 +46,7 @@ Symbols:
     Type:            STT_OBJECT
     Section:         __llvm_covfun
     Binding:         STB_WEAK
-    Size:            0x258
+    Size:            0x38B
     Other:           [ STV_HIDDEN ]
   - Name:            __covrec_DB956436E78DD5FAu
     Type:            STT_OBJECT
diff --git a/llvm/test/tools/llvm-cov/Inputs/branch-logical-mixed.cpp b/llvm/test/tools/llvm-cov/Inputs/branch-logical-mixed.cpp
index 7665a88466ac89..1ed55c7475e5ae 100644
--- a/llvm/test/tools/llvm-cov/Inputs/branch-logical-mixed.cpp
+++ b/llvm/test/tools/llvm-cov/Inputs/branch-logical-mixed.cpp
@@ -13,45 +13,45 @@ void func(int a, int b) {
   bool b4 = a > b;
   bool b5 = a != b;
 
-  bool c = b0 &&           // BRCOV: Branch ([[@LINE]]:12): [True: [[C3:3|1]], False: 1]
-           b1 &&           // BRCOV: Branch ([[@LINE]]:12): [True: [[C2:2|1]], False: 1]
-           b2 &&           // BRCOV: Branch ([[@LINE]]:12): [True: [[C2]], False: 0]
-           b3 &&           // BRCOV: Branch ([[@LINE]]:12): [True: 0, False: [[C2]]]
-           b4 &&           // BRCOV: Branch ([[@LINE]]:12): [True: 0, False: 0]
-           b5;             // BRCOV: Branch ([[@LINE]]:12): [True: 0, False: 0]
+  bool c = b0 &&           // CHECK: Branch ([[@LINE]]:12): [True: [[C3:3|1]], False: 1]
+           b1 &&           // CHECK: Branch ([[@LINE]]:12): [True: [[C2:2|1]], False: 1]
+           b2 &&           // CHECK: Branch ([[@LINE]]:12): [True: [[C2]], False: 0]
+           b3 &&           // CHECK: Branch ([[@LINE]]:12): [True: 0, False: [[C2]]]
+           b4 &&           // CHECK: Branch ([[@LINE]]:12): [True: 0, False: 0]
+           b5;             // CHECK: Branch ([[@LINE]]:12): [True: 0, False: 0]
 
-  bool d = b0 ||           // BRCOV: Branch ([[@LINE]]:12): [True: [[C3]], False: 1]
-           b1 ||           // BRCOV: Branch ([[@LINE]]:12): [True: 0, False: 1]
-           b2 ||           // BRCOV: Branch ([[@LINE]]:12): [True: 1, False: 0]
-           b3 ||           // BRCOV: Branch ([[@LINE]]:12): [True: 0, False: 0]
-           b4 ||           // BRCOV: Branch ([[@LINE]]:12): [True: 0, False: 0]
-           b5;             // BRCOV: Branch ([[@LINE]]:12): [True: 0, False: 0]
+  bool d = b0 ||           // CHECK: Branch ([[@LINE]]:12): [True: [[C3]], False: 1]
+           b1 ||           // CHECK: Branch ([[@LINE]]:12): [True: 0, False: 1]
+           b2 ||           // CHECK: Branch ([[@LINE]]:12): [True: 1, False: 0]
+           b3 ||           // CHECK: Branch ([[@LINE]]:12): [True: 0, False: 0]
+           b4 ||           // CHECK: Branch ([[@LINE]]:12): [True: 0, False: 0]
+           b5;             // CHECK: Branch ([[@LINE]]:12): [True: 0, False: 0]
 
-  bool e = (b0  &&         // BRCOV: Branch ([[@LINE]]:13): [True: [[C3]], False: 1]
-            b5) ||         // BRCOV: Branch ([[@LINE]]:13): [True: 1, False: [[C2]]]
-           (b1  &&         // BRCOV: Branch ([[@LINE]]:13): [True: [[C2]], False: 1]
-            b4) ||         // BRCOV: Branch ([[@LINE]]:13): [True: 0, False: [[C2]]]
-           (b2  &&         // BRCOV: Branch ([[@LINE]]:13): [True: [[C3]], False: 0]
-            b3) ||         // BRCOV: Branch ([[@LINE]]:13): [True: 0, False: [[C3]]]
-           (b3  &&         // BRCOV: Branch ([[@LINE]]:13): [True: 0, False: [[C3]]]
-            b2) ||         // BRCOV: Branch ([[@LINE]]:13): [True: 0, False: 0]
-           (b4  &&         // BRCOV: Branch ([[@LINE]]:13): [True: 1, False: [[C2]]]
-            b1) ||         // BRCOV: Branch ([[@LINE]]:13): [True: 0, False: 1]
-           (b5  &&         // BRCOV: Branch ([[@LINE]]:13): [True: 1, False: [[C2]]]
-            b0);           // BRCOV: Branch ([[@LINE]]:13): [True: 0, False: 1]
+  bool e = (b0  &&         // CHECK: Branch ([[@LINE]]:13): [True: [[C3]], False: 1]
+            b5) ||         // CHECK: Branch ([[@LINE]]:13): [True: 1, False: [[C2]]]
+           (b1  &&         // CHECK: Branch ([[@LINE]]:13): [True: [[C2]], False: 1]
+            b4) ||         // CHECK: Branch ([[@LINE]]:13): [True: 0, False: [[C2]]]
+           (b2  &&         // CHECK: Branch ([[@LINE]]:13): [True: [[C3]], False: 0]
+            b3) ||         // CHECK: Branch ([[@LINE]]:13): [True: 0, False: [[C3]]]
+           (b3  &&         // CHECK: Branch ([[@LINE]]:13): [True: 0, False: [[C3]]]
+            b2) ||         // CHECK: Branch ([[@LINE]]:13): [True: 0, False: 0]
+           (b4  &&         // CHECK: Branch ([[@LINE]]:13): [True: 1, False: [[C2]]]
+            b1) ||         // CHECK: Branch ([[@LINE]]:13): [True: 0, False: 1]
+           (b5  &&         // CHECK: Branch ([[@LINE]]:13): [True: 1, False: [[C2]]]
+            b0);           // CHECK: Branch ([[@LINE]]:13): [True: 0, False: 1]
 
-  bool f = (b0  ||         // BRCOV: Branch ([[@LINE]]:13): [True: [[C3]], False: 1]
-            b5) &&         // BRCOV: Branch ([[@LINE]]:13): [True: 1, False: 0]
-           (b1  ||         // BRCOV: Branch ([[@LINE]]:13): [True: [[C2]], False: [[C2]]]
-            b4) &&         // BRCOV: Branch ([[@LINE]]:13): [True: 1, False: 1]
-           (b2  ||         // BRCOV: Branch ([[@LINE]]:13): [True: [[C3]], False: 0]
-            b3) &&         // BRCOV: Branch ([[@LINE]]:13): [True: 0, False: 0]
-           (b3  ||         // BRCOV: Branch ([[@LINE]]:13): [True: 0, False: [[C3]]]
-            b2) &&         // BRCOV: Branch ([[@LINE]]:13): [True: [[C3]], False: 0]
-           (b4  ||         // BRCOV: Branch ([[@LINE]]:13): [True: 1, False: [[C2]]]
-            b1) &&         // BRCOV: Branch ([[@LINE]]:13): [True: [[C2]], False: 0]
-           (b5  ||         // BRCOV: Branch ([[@LINE]]:13): [True: 1, False: [[C2]]]
-            b0);           // BRCOV: Branch ([[@LINE]]:13): [True: [[C2]], False: 0]
+  bool f = (b0  ||         // CHECK: Branch ([[@LINE]]:13): [True: [[C3]], False: 1]
+            b5) &&         // CHECK: Branch ([[@LINE]]:13): [True: 1, False: 0]
+           (b1  ||         // CHECK: Branch ([[@LINE]]:13): [True: [[C2]], False: [[C2]]]
+            b4) &&         // CHECK: Branch ([[@LINE]]:13): [True: 1, False: 1]
+           (b2  ||         // CHECK: Branch ([[@LINE]]:13): [True: [[C3]], False: 0]
+            b3) &&         // CHECK: Branch ([[@LINE]]:13): [True: 0, False: 0]
+           (b3  ||         // CHECK: Branch ([[@LINE]]:13): [True: 0, False: [[C3]]]
+            b2) &&         // CHECK: Branch ([[@LINE]]:13): [True: [[C3]], False: 0]
+           (b4  ||         // CHECK: Branch ([[@LINE]]:13): [True: 1, False: [[C2]]]
+            b1) &&         // CHECK: Branch ([[@LINE]]:13): [True: [[C2]], False: 0]
+           (b5  ||         // CHECK: Branch ([[@LINE]]:13): [True: 1, False: [[C2]]]
+            b0);           // CHECK: Branch ([[@LINE]]:13): [True: [[C2]], False: 0]
 
   if (c)                   // CHECK: Branch ([[@LINE]]:7): [True: 0, False: [[C4]]]
     printf("case0\n");
@@ -63,7 +63,7 @@ void func(int a, int b) {
   else
     printf("case3\n");
 
-  if (e)                   // CHECK: Branch ([[@LINE]]:7): [True: 1, False: [[C3:3|1]]]
+  if (e)                   // CHECK: Branch ([[@LINE]]:7): [True: 1, False: [[C3]]]
     printf("case4\n");
   else
     printf("case5\n");
diff --git a/llvm/test/tools/llvm-cov/Inputs/branch-macros-single.proftext b/llvm/test/tools/llvm-cov/Inputs/branch-macros-single.proftext
index 29dc4ef3bf5c24..1643936583df4f 100644
--- a/llvm/test/tools/llvm-cov/Inputs/branch-macros-single.proftext
+++ b/llvm/test/tools/llvm-cov/Inputs/branch-macros-single.proftext
@@ -4,7 +4,7 @@ _Z4funcii
 # Func Hash:
 456046650042366162
 # Num Counters:
-19
+37
 # Counter Values:
 3
 1
@@ -25,12 +25,30 @@ _Z4funcii
 0
 0
 0
+2
+1
+2
+1
+2
+1
+2
+1
+2
+1
+3
+0
+3
+0
+3
+0
+3
+0
 
 _Z5func2ii
 # Func Hash:
 14151920320560143107
 # Num Counters:
-9
+15
 # Counter Values:
 3
 3
@@ -40,7 +58,13 @@ _Z5func2ii
 0
 1
 0
+2
+1
 3
+2
+1
+0
+1
 
 main
 # Func Hash:
diff --git a/llvm/test/tools/llvm-cov/Inputs/branch-macros-single.yaml b/llvm/test/tools/llvm-cov/Inputs/branch-macros-single.yaml
index 7545e311af7abb..2951ae89d2b8de 100644
--- a/llvm/test/tools/llvm-cov/Inputs/branch-macros-single.yaml
+++ b/llvm/test/tools/llvm-cov/Inputs/branch-macros-single.yaml
@@ -11,12 +11,12 @@ Sections:
     Type:            SHT_PROGBITS
     Flags:           [ SHF_GNU_RETAIN ]
     AddressAlign:    0x8
-    Content:         F0A0ED2C305C0BB33F010000D238C8100334540693E696313ECE8F5D15010101010101010101010101010101010101010101001501101911020C010C0011140015001A100101005C1C010C0011100101006224010C001210010100682C010C0012100101006E34010C0012100101007401010A000B01000A001001000A001501000A001A45000F00103D00140015350019001A2D001E001F10010104550201050F001701000F00170105060F00170301070F001F3C00100015440019001E014C0910001501540A100016015C0B1000160201050F001701000F0017010D060F00170301070F001F64001000156C0019001E017409100015017C0A1000160201050F001701000F00170115060F00170301070F001F8401001000158C010019001E019401091000150201050F001701000F0017011D060F00170301070F001F9C0100100015A4010019001E0201050F001701000F00170125060F0017
+    Content:         F0A0ED2C305C0BB3AB010000D238C8100334540693E696313ECE8F5D15010101010101010101010101010101010101010101001A01101911020C010C0011140015001A100101005C1C010C0011100101006224010C001210010100682C010C0012100101006E34010C0012100101007401010A000B01000A001001000A001501000A001A204575000A000B45000F0010204979000F00103D001400152041810100140015350019001A203989010019001A2D001E001F20319101001E001F10010104550301050F001701000F001720054D000F00170205060F0017200951000F00170301070F001F3C00100015440019001E014C0910001501540A100016015C0B1000160301050F001701000F0017200D55000F0017020D060F0017201159000F00170301070F001F64001000156C0019001E017409100015017C0A1000160301050F001701000F001720155D000F00170215060F0017201961000F00170301070F001F8401001000158C010019001E019401091000150301050F001701000F0017201D65000F0017021D060F0017202169000F00170301070F001F9C0100100015A4010019001E0301050F001701000F001720256D000F00170225060F0017202971000F0017
   - Name:            '__llvm_covfun (1)'
     Type:            SHT_PROGBITS
     Flags:           [ SHF_GNU_RETAIN ]
     AddressAlign:    0x8
-    Content:         B01D983FC67363959E000000039B9E2C8DB865C493E696313ECE8F5D0D01010101010101010101010101000401241A07020C010E0014140018001D1001010365011C0B1000160405080F002624001000152C0018001D3400200025013C0A1000160305070F001F44001000154C0019001E0115060F00170121050F00170154091000150205050F001705000F00170119060F00170401070F001F01000F001F5C00100015640019001E0201050F001701000F0017010D060F0017
+    Content:         B01D983FC6736395C1000000039B9E2C8DB865C493E696313ECE8F5D0D01010101010101010101010101000401241A07020C010E0014140018001D1001010365011C0B1000160505080F0026203909000F002624001000152C0018001D3400200025013C0A1000160305070F001F44001000154C0019001E0115060F00170129050F00170154091000150305050F001705000F001720192D000F00170219060F0017201D31000F00170401070F001F01000F001F5C00100015640019001E0301050F001701000F0017200D21000F0017020D060F0017201125000F0017
   - Name:            '__llvm_covfun (2)'
     Type:            SHT_PROGBITS
     Flags:           [ SHF_GNU_RETAIN ]
@@ -52,13 +52,13 @@ Symbols:
     Type:            STT_OBJECT
     Section:         __llvm_covfun
     Binding:         STB_WEAK
-    Size:            0x15B
+    Size:            0x1C7
     Other:           [ STV_HIDDEN ]
   - Name:            __covrec_956373C63F981DB0u
     Type:            STT_OBJECT
     Section:         '__llvm_covfun (1)'
     Binding:         STB_WEAK
-    Size:            0xBA
+    Size:            0xDD
     Other:           [ STV_HIDDEN ]
   - Name:            __covrec_DB956436E78DD5FAu
     Type:            STT_OBJECT
diff --git a/llvm/test/tools/llvm-cov/Inputs/branch-macros.cpp b/llvm/test/tools/llvm-cov/Inputs/branch-macros.cpp
index e2abe748d86dc8..47ed2b610fb998 100644
--- a/llvm/test/tools/llvm-cov/Inputs/branch-macros.cpp
+++ b/llvm/test/tools/llvm-cov/Inputs/branch-macros.cpp
@@ -14,31 +14,31 @@
 
 // CHECK: |{{ +}}[[C3:3|1]]|bool func(
 bool func(int a, int b) {
-  bool c = COND1 && COND2; // BRCOV: |  |  |  Branch ([[@LINE-12]]:15): [True: 1, False: [[C2:2|1]]]
-                           // BRCOV: |  |  |  Branch ([[@LINE-12]]:15): [True: 0, False: 1]
-  bool d = COND3;          // BRCOV: |  |  |  |  |  Branch ([[@LINE-14]]:15): [True: 1, False: [[C2]]]
-                           // BRCOV: |  |  |  |  |  Branch ([[@LINE-14]]:15): [True: 0, False: 1]
-  bool e = MACRO1;         // BRCOV: |  |  |  |  |  |  |  Branch ([[@LINE-16]]:15): [True: 1, False: [[C2]]]
-                           // BRCOV: |  |  |  |  |  |  |  Branch ([[@LINE-16]]:15): [True: 0, False: 1]
-  bool f = MACRO2;         // BRCOV: |  |  |  |  |  |  |  |  |  Branch ([[@LINE-18]]:15): [True: 1, False: [[C2]]]
-                           // BRCOV: |  |  |  |  |  |  |  |  |  Branch ([[@LINE-18]]:15): [True: 0, False: 1]
-  bool g = MACRO3;         // BRCOV: |  |  |  |  |  |  |  |  |  |  |  Branch ([[@LINE-20]]:15): [True: 1, False: [[C2]]]
-                           // BRCOV: |  |  |  |  |  |  |  |  |  |  |  Branch ([[@LINE-20]]:15): [True: 0, False: 1]
+  bool c = COND1 && COND2; // CHECK: |  |  |  Branch ([[@LINE-12]]:15): [True: 1, False: [[C2:2|1]]]
+                           // CHECK: |  |  |  Branch ([[@LINE-12]]:15): [True: 0, False: 1]
+  bool d = COND3;          // CHECK: |  |  |  |  |  Branch ([[@LINE-14]]:15): [True: 1, False: [[C2]]]
+                           // CHECK: |  |  |  |  |  Branch ([[@LINE-14]]:15): [True: 0, False: 1]
+  bool e = MACRO1;         // CHECK: |  |  |  |  |  |  |  Branch ([[@LINE-16]]:15): [True: 1, False: [[C2]]]
+                           // CHECK: |  |  |  |  |  |  |  Branch ([[@LINE-16]]:15): [True: 0, False: 1]
+  bool f = MACRO2;         // CHECK: |  |  |  |  |  |  |  |  |  Branch ([[@LINE-18]]:15): [True: 1, False: [[C2]]]
+                           // CHECK: |  |  |  |  |  |  |  |  |  Branch ([[@LINE-18]]:15): [True: 0, False: 1]
+  bool g = MACRO3;         // CHECK: |  |  |  |  |  |  |  |  |  |  |  Branch ([[@LINE-20]]:15): [True: 1, False: [[C2]]]
+                           // CHECK: |  |  |  |  |  |  |  |  |  |  |  Branch ([[@LINE-20]]:15): [True: 0, False: 1]
   return c && d && e && f && g;
-                           // BRCOV: |  Branch ([[@LINE-1]]:10): [True: 0, False: [[C3]]]
-                           // BRCOV: |  Branch ([[@LINE-2]]:15): [True: 0, False: 0]
-                           // BRCOV: |  Branch ([[@LINE-3]]:20): [True: 0, False: 0]
-                           // BRCOV: |  Branch ([[@LINE-4]]:25): [True: 0, False: 0]
-                           // BRCOV: |  Branch ([[@LINE-5]]:30): [True: 0, False: 0]
+                           // CHECK: |  Branch ([[@LINE-1]]:10): [True: 0, False: [[C3]]]
+                           // CHECK: |  Branch ([[@LINE-2]]:15): [True: 0, False: 0]
+                           // CHECK: |  Branch ([[@LINE-3]]:20): [True: 0, False: 0]
+                           // CHECK: |  Branch ([[@LINE-4]]:25): [True: 0, False: 0]
+                           // CHECK: |  Branch ([[@LINE-5]]:30): [True: 0, False: 0]
 }
 
 
 bool func2(int a, int b) {
-    bool h = MACRO3 || COND4;  // BRCOV: |  |  |  |  |  |  |  |  |  |  |  Branch ([[@LINE-32]]:15): [True: 1, False: [[C2]]]
-                               // BRCOV: |  |  |  |  |  |  |  |  |  |  |  Branch ([[@LINE-32]]:15): [True: 0, False: 1]
-                               // BRCOV: |  |  |  |  |  |  |  Branch ([[@LINE-34]]:15): [True: 1, False: [[C2]]]
-                               // BRCOV: |  |  |  |  |  |  |  Branch ([[@LINE-34]]:15): [True: 0, False: 1]
-                               // BRCOV: |  |  |  Branch ([[@LINE-33]]:15): [True: 1, False: [[C2]]]
+    bool h = MACRO3 || COND4;  // CHECK: |  |  |  |  |  |  |  |  |  |  |  Branch ([[@LINE-32]]:15): [True: 1, False: [[C2]]]
+                               // CHECK: |  |  |  |  |  |  |  |  |  |  |  Branch ([[@LINE-32]]:15): [True: 0, False: 1]
+                               // CHECK: |  |  |  |  |  |  |  Branch ([[@LINE-34]]:15): [True: 1, False: [[C2]]]
+                               // CHECK: |  |  |  |  |  |  |  Branch ([[@LINE-34]]:15): [True: 0, False: 1]
+                               // CHECK: |  |  |  Branch ([[@LINE-33]]:15): [True: 1, False: [[C2]]]
   return h;
 }
 
diff --git a/llvm/test/tools/llvm-cov/branch-logical-mixed.test b/llvm/test/tools/llvm-cov/branch-logical-mixed.test
index b03cabeb01855b..2e3a78ef4559de 100644
--- a/llvm/test/tools/llvm-cov/branch-logical-mixed.test
+++ b/llvm/test/tools/llvm-cov/branch-logical-mixed.test
@@ -1,5 +1,5 @@
 // RUN: llvm-profdata merge %S/Inputs/branch-logical-mixed.proftext -o %t.profdata
-// RUN: llvm-cov show --show-branches=count %S/Inputs/branch-logical-mixed.o32l -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs | FileCheck %S/Inputs/branch-logical-mixed.cpp -check-prefixes=CHECK,BRCOV
+// RUN: llvm-cov show --show-branches=count %S/Inputs/branch-logical-mixed.o32l -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs | FileCheck %S/Inputs/branch-logical-mixed.cpp
 // RUN: llvm-cov report --show-branch-summary %S/Inputs/branch-logical-mixed.o32l -instr-profile %t.profdata -show-functions -path-equivalence=/tmp,%S/Inputs %S/Inputs/branch-logical-mixed.cpp
 | FileCheck %s -check-prefix=REPORT
 
diff --git a/llvm/test/tools/llvm-cov/branch-macros.test b/llvm/test/tools/llvm-cov/branch-macros.test
index a4790afc534228..57666a96646d8e 100644
--- a/llvm/test/tools/llvm-cov/branch-macros.test
+++ b/llvm/test/tools/llvm-cov/branch-macros.test
@@ -1,5 +1,5 @@
 // RUN: llvm-profdata merge %S/Inputs/branch-macros.proftext -o %t.profdata
-// RUN: llvm-cov show --show-expansions --show-branches=count %S/Inputs/branch-macros.o32l -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs | FileCheck %S/Inputs/branch-macros.cpp -check-prefixes=CHECK,BRCOV
+// RUN: llvm-cov show --show-expansions --show-branches=count %S/Inputs/branch-macros.o32l -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs | FileCheck %S/Inputs/branch-macros.cpp
 // RUN: llvm-cov report --show-branch-summary %S/Inputs/branch-macros.o32l -instr-profile %t.profdata -show-functions -path-equivalence=/tmp,%S/Inputs %S/Inputs/branch-macros.cpp | FileCheck %s -check-prefix=REPORT
 
 // RUN: yaml2obj %S/Inputs/branch-macros-single.yaml -o %t.o



More information about the llvm-branch-commits mailing list