diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp index 1bad7a722da07a..35d3776241b7e2 100644 --- a/clang/lib/CodeGen/CGExpr.cpp +++ b/clang/lib/CodeGen/CGExpr.cpp @@ -5146,8 +5146,9 @@ std::optional HandleConditionalOperatorLValueSimpleCase( if (!CGF.ContainsLabel(Dead)) { // If the true case is live, we need to track its region. - if (CondExprBool) - CGF.incrementProfileCounter(E); + CGF.incrementProfileCounter(CondExprBool ? CGF.UseExecPath + : CGF.UseSkipPath, + E, /*UseBoth=*/true); CGF.markStmtMaybeUsed(Dead); // If a throw expression we emit it and return an undefined lvalue // because it can't be used. @@ -5186,7 +5187,7 @@ ConditionalInfo EmitConditionalBlocks(CodeGenFunction &CGF, // Any temporaries created here are conditional. CGF.EmitBlock(Info.lhsBlock); - CGF.incrementProfileCounter(E); + CGF.incrementProfileCounter(CGF.UseExecPath, E); eval.begin(CGF); Info.LHS = BranchGenFunc(CGF, E->getTrueExpr()); eval.end(CGF); @@ -5197,6 +5198,7 @@ ConditionalInfo EmitConditionalBlocks(CodeGenFunction &CGF, // Any temporaries created here are conditional. CGF.EmitBlock(Info.rhsBlock); + CGF.incrementProfileCounter(CGF.UseSkipPath, E); eval.begin(CGF); Info.RHS = BranchGenFunc(CGF, E->getFalseExpr()); eval.end(CGF); diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp index 2ad6587089f101..16a257c2d02635 100644 --- a/clang/lib/CodeGen/CGExprAgg.cpp +++ b/clang/lib/CodeGen/CGExprAgg.cpp @@ -36,10 +36,6 @@ using namespace CodeGen; // Aggregate Expression Emitter //===----------------------------------------------------------------------===// -namespace llvm { -extern cl::opt EnableSingleByteCoverage; -} // namespace llvm - namespace { class AggExprEmitter : public StmtVisitor { CodeGenFunction &CGF; @@ -1293,10 +1289,7 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) { eval.begin(CGF); CGF.EmitBlock(LHSBlock); - if (llvm::EnableSingleByteCoverage) - CGF.incrementProfileCounter(E->getTrueExpr()); - else - CGF.incrementProfileCounter(E); + CGF.incrementProfileCounter(CGF.UseExecPath, E); Visit(E->getTrueExpr()); eval.end(CGF); @@ -1311,8 +1304,7 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) { eval.begin(CGF); CGF.EmitBlock(RHSBlock); - if (llvm::EnableSingleByteCoverage) - CGF.incrementProfileCounter(E->getFalseExpr()); + CGF.incrementProfileCounter(CGF.UseSkipPath, E); Visit(E->getFalseExpr()); eval.end(CGF); @@ -1321,8 +1313,6 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) { E->getType()); CGF.EmitBlock(ContBlock); - if (llvm::EnableSingleByteCoverage) - CGF.incrementProfileCounter(E); } void AggExprEmitter::VisitChooseExpr(const ChooseExpr *CE) { diff --git a/clang/lib/CodeGen/CGExprComplex.cpp b/clang/lib/CodeGen/CGExprComplex.cpp index ac31dff11b585e..5ea6a6834167ac 100644 --- a/clang/lib/CodeGen/CGExprComplex.cpp +++ b/clang/lib/CodeGen/CGExprComplex.cpp @@ -26,10 +26,6 @@ using namespace CodeGen; // Complex Expression Emitter //===----------------------------------------------------------------------===// -namespace llvm { -extern cl::opt EnableSingleByteCoverage; -} // namespace llvm - typedef CodeGenFunction::ComplexPairTy ComplexPairTy; /// Return the complex type that we are meant to emit. @@ -1379,11 +1375,7 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) { eval.begin(CGF); CGF.EmitBlock(LHSBlock); - if (llvm::EnableSingleByteCoverage) - CGF.incrementProfileCounter(E->getTrueExpr()); - else - CGF.incrementProfileCounter(E); - + CGF.incrementProfileCounter(CGF.UseExecPath, E); ComplexPairTy LHS = Visit(E->getTrueExpr()); LHSBlock = Builder.GetInsertBlock(); CGF.EmitBranch(ContBlock); @@ -1391,13 +1383,10 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) { eval.begin(CGF); CGF.EmitBlock(RHSBlock); - if (llvm::EnableSingleByteCoverage) - CGF.incrementProfileCounter(E->getFalseExpr()); + CGF.incrementProfileCounter(CGF.UseSkipPath, E); ComplexPairTy RHS = Visit(E->getFalseExpr()); RHSBlock = Builder.GetInsertBlock(); CGF.EmitBlock(ContBlock); - if (llvm::EnableSingleByteCoverage) - CGF.incrementProfileCounter(E); eval.end(CGF); // Create a PHI node for the real part. diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp index 0f27bd00422dce..09d024e9e83a37 100644 --- a/clang/lib/CodeGen/CGExprScalar.cpp +++ b/clang/lib/CodeGen/CGExprScalar.cpp @@ -4951,6 +4951,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); @@ -4979,7 +4982,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(CGF.UseExecPath, E, /*UseBoth=*/true); // If the top of the logical operator nest, reset the MCDC temp to 0. if (CGF.MCDCLogOpStack.empty()) @@ -4997,11 +5000,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(CGF.UseExecPath, E->getRHS()); CGF.EmitBranch(FBlock); + if (HasRHSSkip.second) { + CGF.EmitBlock(RHSSkip); + CGF.incrementProfileCounter(CGF.UseSkipPath, E->getRHS()); + } CGF.EmitBlock(FBlock); } else CGF.markStmtMaybeUsed(E->getRHS()); @@ -5017,7 +5026,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(CGF.UseSkipPath, E); + CGF.markStmtMaybeUsed(E->getRHS()); + return llvm::Constant::getNullValue(ResTy); } } @@ -5031,12 +5045,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(CGF.UseSkipPath, 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. @@ -5048,7 +5071,7 @@ Value *ScalarExprEmitter::VisitBinLAnd(const BinaryOperator *E) { eval.begin(CGF); CGF.EmitBlock(RHSBlock); - CGF.incrementProfileCounter(E); + CGF.incrementProfileCounter(CGF.UseExecPath, E); Value *RHSCond = CGF.EvaluateExprAsBool(E->getRHS()); eval.end(CGF); @@ -5058,15 +5081,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(CGF.UseExecPath, E->getRHS()); CGF.EmitBranch(ContBlock); PN->addIncoming(RHSCond, RHSBlockCnt); + if (HasRHSSkip.second) { + CGF.EmitBlock(RHSBlockSkip); + CGF.incrementProfileCounter(CGF.UseSkipPath, E->getRHS()); + CGF.EmitBranch(ContBlock); + ContIncoming = RHSBlockSkip; + } } // Emit an unconditional branch from this block to ContBlock. @@ -5076,7 +5108,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. @@ -5094,6 +5126,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); @@ -5122,7 +5157,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(CGF.UseExecPath, E, /*UseBoth=*/true); // If the top of the logical operator nest, reset the MCDC temp to 0. if (CGF.MCDCLogOpStack.empty()) @@ -5140,11 +5175,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(CGF.UseExecPath, E->getRHS()); CGF.EmitBranch(FBlock); + if (HasRHSSkip.second) { + CGF.EmitBlock(RHSSkip); + CGF.incrementProfileCounter(CGF.UseSkipPath, E->getRHS()); + } CGF.EmitBlock(FBlock); } else CGF.markStmtMaybeUsed(E->getRHS()); @@ -5160,7 +5201,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(CGF.UseSkipPath, E); + CGF.markStmtMaybeUsed(E->getRHS()); + return llvm::ConstantInt::get(ResTy, 1); } } @@ -5173,14 +5219,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(CGF.UseSkipPath, 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. @@ -5194,7 +5248,7 @@ Value *ScalarExprEmitter::VisitBinLOr(const BinaryOperator *E) { // Emit the RHS condition as a bool value. CGF.EmitBlock(RHSBlock); - CGF.incrementProfileCounter(E); + CGF.incrementProfileCounter(CGF.UseExecPath, E); Value *RHSCond = CGF.EvaluateExprAsBool(E->getRHS()); eval.end(CGF); @@ -5205,21 +5259,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(CGF.UseExecPath, E->getRHS()); CGF.EmitBranch(ContBlock); PN->addIncoming(RHSCond, RHSBlockCnt); + if (HasRHSSkip.second) { + CGF.EmitBlock(RHSTrueBlock); + CGF.incrementProfileCounter(CGF.UseSkipPath, 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. @@ -5278,13 +5341,9 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) { // If the dead side doesn't have labels we need, just emit the Live part. if (!CGF.ContainsLabel(dead)) { - if (CondExprBool) { - if (llvm::EnableSingleByteCoverage) { - CGF.incrementProfileCounter(lhsExpr); - CGF.incrementProfileCounter(rhsExpr); - } - CGF.incrementProfileCounter(E); - } + CGF.incrementProfileCounter(CondExprBool ? CGF.UseExecPath + : CGF.UseSkipPath, + E, /*UseBoth=*/true); Value *Result = Visit(live); CGF.markStmtMaybeUsed(dead); @@ -5359,17 +5418,13 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) { // If this is a really simple expression (like x ? 4 : 5), emit this as a // select instead of as control flow. We can only do this if it is cheap and // safe to evaluate the LHS and RHS unconditionally. - if (isCheapEnoughToEvaluateUnconditionally(lhsExpr, CGF) && + if (!llvm::EnableSingleByteCoverage && + isCheapEnoughToEvaluateUnconditionally(lhsExpr, CGF) && isCheapEnoughToEvaluateUnconditionally(rhsExpr, CGF)) { llvm::Value *CondV = CGF.EvaluateExprAsBool(condExpr); llvm::Value *StepV = Builder.CreateZExtOrBitCast(CondV, CGF.Int64Ty); - if (llvm::EnableSingleByteCoverage) { - CGF.incrementProfileCounter(lhsExpr); - CGF.incrementProfileCounter(rhsExpr); - CGF.incrementProfileCounter(E); - } else - CGF.incrementProfileCounter(E, StepV); + CGF.incrementProfileCounter(E, StepV); llvm::Value *LHS = Visit(lhsExpr); llvm::Value *RHS = Visit(rhsExpr); @@ -5401,11 +5456,7 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) { if (CGF.MCDCLogOpStack.empty()) CGF.maybeUpdateMCDCTestVectorBitmap(condExpr); - if (llvm::EnableSingleByteCoverage) - CGF.incrementProfileCounter(lhsExpr); - else - CGF.incrementProfileCounter(E); - + CGF.incrementProfileCounter(CGF.UseExecPath, E); eval.begin(CGF); Value *LHS = Visit(lhsExpr); eval.end(CGF); @@ -5421,9 +5472,7 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) { if (CGF.MCDCLogOpStack.empty()) CGF.maybeUpdateMCDCTestVectorBitmap(condExpr); - if (llvm::EnableSingleByteCoverage) - CGF.incrementProfileCounter(rhsExpr); - + CGF.incrementProfileCounter(CGF.UseSkipPath, E); eval.begin(CGF); Value *RHS = Visit(rhsExpr); eval.end(CGF); @@ -5442,11 +5491,6 @@ VisitAbstractConditionalOperator(const AbstractConditionalOperator *E) { PN->addIncoming(LHS, LHSBlock); PN->addIncoming(RHS, RHSBlock); - // When single byte coverage mode is enabled, add a counter to continuation - // block. - if (llvm::EnableSingleByteCoverage) - CGF.incrementProfileCounter(E); - return PN; } diff --git a/clang/lib/CodeGen/CGStmt.cpp b/clang/lib/CodeGen/CGStmt.cpp index e9a8500cc19933..f9ab84a0eae168 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 EnableSingleByteCoverage; -} // namespace llvm - void CodeGenFunction::EmitStopPoint(const Stmt *S) { if (CGDebugInfo *DI = getDebugInfo()) { SourceLocation Loc; @@ -870,8 +866,8 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) { // If the skipped block has no labels in it, just emit the executed block. // This avoids emitting dead code and simplifies the CFG substantially. if (S.isConstexpr() || !ContainsLabel(Skipped)) { - if (CondConstant) - incrementProfileCounter(&S); + incrementProfileCounter(CondConstant ? UseExecPath : UseSkipPath, &S, + /*UseBoth=*/true); if (Executed) { RunCleanupsScope ExecutedScope(*this); EmitStmt(Executed); @@ -881,14 +877,14 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) { } } + auto HasSkip = getIsCounterPair(&S); + // Otherwise, the condition did not fold, or we couldn't elide it. Just emit // the conditional branch. llvm::BasicBlock *ThenBlock = createBasicBlock("if.then"); llvm::BasicBlock *ContBlock = createBasicBlock("if.end"); - llvm::BasicBlock *ElseBlock = ContBlock; - if (Else) - ElseBlock = createBasicBlock("if.else"); - + llvm::BasicBlock *ElseBlock = + (Else || HasSkip.second ? createBasicBlock("if.else") : ContBlock); // Prefer the PGO based weights over the likelihood attribute. // When the build isn't optimized the metadata isn't used, so don't generate // it. @@ -921,10 +917,7 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) { // Emit the 'then' code. EmitBlock(ThenBlock); - if (llvm::EnableSingleByteCoverage) - incrementProfileCounter(S.getThen()); - else - incrementProfileCounter(&S); + incrementProfileCounter(UseExecPath, &S); { RunCleanupsScope ThenScope(*this); EmitStmt(S.getThen()); @@ -938,9 +931,9 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) { auto NL = ApplyDebugLocation::CreateEmpty(*this); EmitBlock(ElseBlock); } - // When single byte coverage mode is enabled, add a counter to else block. - if (llvm::EnableSingleByteCoverage) - incrementProfileCounter(Else); + // Add a counter to else block unless it has CounterExpr. + if (HasSkip.second) + incrementProfileCounter(UseSkipPath, &S); { RunCleanupsScope ElseScope(*this); EmitStmt(Else); @@ -950,15 +943,14 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) { auto NL = ApplyDebugLocation::CreateEmpty(*this); EmitBranch(ContBlock); } + } else if (HasSkip.second) { + EmitBlock(ElseBlock); + incrementProfileCounter(UseSkipPath, &S); + EmitBranch(ContBlock); } // Emit the continuation block for code after the if. EmitBlock(ContBlock, true); - - // When single byte coverage mode is enabled, add a counter to continuation - // block. - if (llvm::EnableSingleByteCoverage) - incrementProfileCounter(&S); } bool CodeGenFunction::checkIfLoopMustProgress(const Expr *ControllingExpression, @@ -1069,15 +1061,11 @@ void CodeGenFunction::EmitWhileStmt(const WhileStmt &S, SourceLocToDebugLoc(R.getEnd()), checkIfLoopMustProgress(S.getCond(), hasEmptyLoopBody(S))); - // When single byte coverage mode is enabled, add a counter to loop condition. - if (llvm::EnableSingleByteCoverage) - incrementProfileCounter(S.getCond()); - // As long as the condition is true, go to the loop body. llvm::BasicBlock *LoopBody = createBasicBlock("while.body"); if (EmitBoolCondBranch) { llvm::BasicBlock *ExitBlock = LoopExit.getBlock(); - if (ConditionScope.requiresCleanups()) + if (getIsCounterPair(&S).second || ConditionScope.requiresCleanups()) ExitBlock = createBasicBlock("while.exit"); llvm::MDNode *Weights = createProfileWeightsForLoop(S.getCond(), getProfileCount(S.getBody())); @@ -1088,6 +1076,7 @@ void CodeGenFunction::EmitWhileStmt(const WhileStmt &S, if (ExitBlock != LoopExit.getBlock()) { EmitBlock(ExitBlock); + incrementProfileCounter(UseSkipPath, &S); EmitBranchThroughCleanup(LoopExit); } } else if (const Attr *A = Stmt::getLikelihoodAttr(S.getBody())) { @@ -1105,11 +1094,7 @@ void CodeGenFunction::EmitWhileStmt(const WhileStmt &S, { RunCleanupsScope BodyScope(*this); EmitBlock(LoopBody); - // When single byte coverage mode is enabled, add a counter to the body. - if (llvm::EnableSingleByteCoverage) - incrementProfileCounter(S.getBody()); - else - incrementProfileCounter(&S); + incrementProfileCounter(UseExecPath, &S); EmitStmt(S.getBody()); } @@ -1129,13 +1114,10 @@ void CodeGenFunction::EmitWhileStmt(const WhileStmt &S, // The LoopHeader typically is just a branch if we skipped emitting // a branch, try to erase it. - if (!EmitBoolCondBranch) + if (!EmitBoolCondBranch) { SimplifyForwardingBlocks(LoopHeader.getBlock()); - - // When single byte coverage mode is enabled, add a counter to continuation - // block. - if (llvm::EnableSingleByteCoverage) - incrementProfileCounter(&S); + PGO.markStmtAsUsed(true, &S); + } if (CGM.shouldEmitConvergenceTokens()) ConvergenceTokenStack.pop_back(); @@ -1154,10 +1136,7 @@ void CodeGenFunction::EmitDoStmt(const DoStmt &S, // Emit the body of the loop. llvm::BasicBlock *LoopBody = createBasicBlock("do.body"); - if (llvm::EnableSingleByteCoverage) - EmitBlockWithFallThrough(LoopBody, S.getBody()); - else - EmitBlockWithFallThrough(LoopBody, &S); + EmitBlockWithFallThrough(LoopBody, &S); if (CGM.shouldEmitConvergenceTokens()) ConvergenceTokenStack.push_back(emitConvergenceLoopToken(LoopBody)); @@ -1168,9 +1147,6 @@ void CodeGenFunction::EmitDoStmt(const DoStmt &S, } EmitBlock(LoopCond.getBlock()); - // When single byte coverage mode is enabled, add a counter to loop condition. - if (llvm::EnableSingleByteCoverage) - incrementProfileCounter(S.getCond()); // C99 6.8.5.2: "The evaluation of the controlling expression takes place // after each execution of the loop body." @@ -1193,16 +1169,25 @@ void CodeGenFunction::EmitDoStmt(const DoStmt &S, SourceLocToDebugLoc(R.getEnd()), checkIfLoopMustProgress(S.getCond(), hasEmptyLoopBody(S))); + auto *LoopFalse = + (getIsCounterPair(&S).second ? createBasicBlock("do.loopfalse") + : LoopExit.getBlock()); + // As long as the condition is true, iterate the loop. if (EmitBoolCondBranch) { uint64_t BackedgeCount = getProfileCount(S.getBody()) - ParentCount; Builder.CreateCondBr( - BoolCondVal, LoopBody, LoopExit.getBlock(), + BoolCondVal, LoopBody, LoopFalse, createProfileWeightsForLoop(S.getCond(), BackedgeCount)); } LoopStack.pop(); + if (LoopFalse != LoopExit.getBlock()) { + EmitBlock(LoopFalse); + incrementProfileCounter(UseSkipPath, &S, /*UseBoth=*/true); + } + // Emit the exit block. EmitBlock(LoopExit.getBlock()); @@ -1211,11 +1196,6 @@ void CodeGenFunction::EmitDoStmt(const DoStmt &S, if (!EmitBoolCondBranch) SimplifyForwardingBlocks(LoopCond.getBlock()); - // When single byte coverage mode is enabled, add a counter to continuation - // block. - if (llvm::EnableSingleByteCoverage) - incrementProfileCounter(&S); - if (CGM.shouldEmitConvergenceTokens()) ConvergenceTokenStack.pop_back(); } @@ -1275,15 +1255,10 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S, BreakContinueStack.back().ContinueBlock = Continue; } - // When single byte coverage mode is enabled, add a counter to loop - // condition. - if (llvm::EnableSingleByteCoverage) - incrementProfileCounter(S.getCond()); - llvm::BasicBlock *ExitBlock = LoopExit.getBlock(); // If there are any cleanups between here and the loop-exit scope, // create a block to stage a loop exit along. - if (ForScope.requiresCleanups()) + if (getIsCounterPair(&S).second || ForScope.requiresCleanups()) ExitBlock = createBasicBlock("for.cond.cleanup"); // As long as the condition is true, iterate the loop. @@ -1302,6 +1277,7 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S, if (ExitBlock != LoopExit.getBlock()) { EmitBlock(ExitBlock); + incrementProfileCounter(UseSkipPath, &S); EmitBranchThroughCleanup(LoopExit); } @@ -1309,13 +1285,11 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S, } else { // Treat it as a non-zero constant. Don't even create a new block for the // body, just fall into it. + PGO.markStmtAsUsed(true, &S); } - // When single byte coverage mode is enabled, add a counter to the body. - if (llvm::EnableSingleByteCoverage) - incrementProfileCounter(S.getBody()); - else - incrementProfileCounter(&S); + incrementProfileCounter(UseExecPath, &S); + { // Create a separate cleanup scope for the body, in case it is not // a compound statement. @@ -1327,8 +1301,6 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S, if (S.getInc()) { EmitBlock(Continue.getBlock()); EmitStmt(S.getInc()); - if (llvm::EnableSingleByteCoverage) - incrementProfileCounter(S.getInc()); } BreakContinueStack.pop_back(); @@ -1345,11 +1317,6 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S, // Emit the fall-through block. EmitBlock(LoopExit.getBlock(), true); - // When single byte coverage mode is enabled, add a counter to continuation - // block. - if (llvm::EnableSingleByteCoverage) - incrementProfileCounter(&S); - if (CGM.shouldEmitConvergenceTokens()) ConvergenceTokenStack.pop_back(); } @@ -1385,7 +1352,7 @@ CodeGenFunction::EmitCXXForRangeStmt(const CXXForRangeStmt &S, // If there are any cleanups between here and the loop-exit scope, // create a block to stage a loop exit along. llvm::BasicBlock *ExitBlock = LoopExit.getBlock(); - if (ForScope.requiresCleanups()) + if (getIsCounterPair(&S).second || ForScope.requiresCleanups()) ExitBlock = createBasicBlock("for.cond.cleanup"); // The loop body, consisting of the specified body and the loop variable. @@ -1403,14 +1370,12 @@ CodeGenFunction::EmitCXXForRangeStmt(const CXXForRangeStmt &S, if (ExitBlock != LoopExit.getBlock()) { EmitBlock(ExitBlock); + incrementProfileCounter(UseSkipPath, &S); EmitBranchThroughCleanup(LoopExit); } EmitBlock(ForBody); - if (llvm::EnableSingleByteCoverage) - incrementProfileCounter(S.getBody()); - else - incrementProfileCounter(&S); + incrementProfileCounter(UseExecPath, &S); // Create a block for the increment. In case of a 'continue', we jump there. JumpDest Continue = getJumpDestInCurrentScope("for.inc"); @@ -1441,11 +1406,6 @@ CodeGenFunction::EmitCXXForRangeStmt(const CXXForRangeStmt &S, // Emit the fall-through block. EmitBlock(LoopExit.getBlock(), true); - // When single byte coverage mode is enabled, add a counter to continuation - // block. - if (llvm::EnableSingleByteCoverage) - incrementProfileCounter(&S); - if (CGM.shouldEmitConvergenceTokens()) ConvergenceTokenStack.pop_back(); } @@ -2286,6 +2246,18 @@ void CodeGenFunction::EmitSwitchStmt(const SwitchStmt &S) { ConditionScope.ForceCleanup(); + // Close the last case (or DefaultBlock). + EmitBranch(SwitchExit.getBlock()); + + // Insert a False Counter if SwitchStmt doesn't have DefaultStmt. + if (getIsCounterPair(S.getCond()).second) { + auto *ImplicitDefaultBlock = createBasicBlock("sw.false"); + EmitBlock(ImplicitDefaultBlock); + incrementProfileCounter(UseSkipPath, S.getCond()); + Builder.CreateBr(SwitchInsn->getDefaultDest()); + SwitchInsn->setDefaultDest(ImplicitDefaultBlock); + } + // Emit continuation. EmitBlock(SwitchExit.getBlock(), true); incrementProfileCounter(&S); diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 27ec68bd2a872d..435d6a8b6271aa 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -52,10 +52,6 @@ using namespace clang; using namespace CodeGen; -namespace llvm { -extern cl::opt EnableSingleByteCoverage; -} // namespace llvm - /// shouldEmitLifetimeMarkers - Decide whether we need emit the life-time /// markers. static bool shouldEmitLifetimeMarkers(const CodeGenOptions &CGOpts, @@ -1368,10 +1364,7 @@ void CodeGenFunction::EmitFunctionBody(const Stmt *Body) { void CodeGenFunction::EmitBlockWithFallThrough(llvm::BasicBlock *BB, const Stmt *S) { llvm::BasicBlock *SkipCountBB = nullptr; - // Do not skip over the instrumentation when single byte coverage mode is - // enabled. - if (HaveInsertPoint() && CGM.getCodeGenOpts().hasProfileClangInstr() && - !llvm::EnableSingleByteCoverage) { + if (HaveInsertPoint() && CGM.getCodeGenOpts().hasProfileClangInstr()) { // When instrumenting for profiling, the fallthrough to certain // statements needs to skip over the instrumentation code so that we // get an accurate count. @@ -1380,7 +1373,7 @@ void CodeGenFunction::EmitBlockWithFallThrough(llvm::BasicBlock *BB, } EmitBlock(BB); uint64_t CurrentCount = getCurrentProfileCount(); - incrementProfileCounter(S); + incrementProfileCounter(UseExecPath, S); setCurrentProfileCount(getCurrentProfileCount() + CurrentCount); if (SkipCountBB) EmitBlock(SkipCountBB); @@ -1776,6 +1769,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; @@ -1784,6 +1778,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: // @@ -1797,8 +1795,9 @@ void CodeGenFunction::EmitBranchToCounterBlock( // goto TrueBlock; if (LOp == BO_LAnd) { + SkipNextBlock = FalseBlock; ThenBlock = CounterIncrBlock; - ElseBlock = FalseBlock; + ElseBlock = (SkipIncrBlock ? SkipIncrBlock : SkipNextBlock); NextBlock = TrueBlock; } @@ -1815,7 +1814,8 @@ void CodeGenFunction::EmitBranchToCounterBlock( // goto FalseBlock; else if (LOp == BO_LOr) { - ThenBlock = TrueBlock; + SkipNextBlock = TrueBlock; + ThenBlock = (SkipIncrBlock ? SkipIncrBlock : SkipNextBlock); ElseBlock = CounterIncrBlock; NextBlock = FalseBlock; } else { @@ -1825,11 +1825,17 @@ void CodeGenFunction::EmitBranchToCounterBlock( // Emit Branch based on condition. EmitBranchOnBoolExpr(Cond, ThenBlock, ElseBlock, TrueCount, LH); + if (SkipIncrBlock) { + EmitBlock(SkipIncrBlock); + incrementProfileCounter(UseSkipPath, 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(UseExecPath, CntrStmt); // Go to the next block. EmitBranch(NextBlock); @@ -1848,6 +1854,8 @@ void CodeGenFunction::EmitBranchOnBoolExpr( Cond = Cond->IgnoreParens(); if (const BinaryOperator *CondBOp = dyn_cast(Cond)) { + auto HasSkip = getIsCounterPair(CondBOp); + // Handle X && Y in a condition. if (CondBOp->getOpcode() == BO_LAnd) { MCDCLogOpStack.push_back(CondBOp); @@ -1879,6 +1887,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()); @@ -1889,12 +1899,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(UseSkipPath, CondBOp); + EmitBranch(FalseBlock); + } EmitBlock(LHSTrue); } - incrementProfileCounter(CondBOp); + incrementProfileCounter(UseExecPath, CondBOp); setCurrentProfileCount(getProfileCount(CondBOp->getRHS())); // Any temporaries created here are conditional. @@ -1934,6 +1949,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 @@ -1948,12 +1965,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(UseSkipPath, CondBOp); + EmitBranch(TrueBlock); + } EmitBlock(LHSFalse); } - incrementProfileCounter(CondBOp); + incrementProfileCounter(UseExecPath, CondBOp); setCurrentProfileCount(getProfileCount(CondBOp->getRHS())); // Any temporaries created here are conditional. @@ -2011,7 +2033,7 @@ void CodeGenFunction::EmitBranchOnBoolExpr( cond.begin(*this); EmitBlock(LHSBlock); - incrementProfileCounter(CondOp); + incrementProfileCounter(UseExecPath, CondOp); { ApplyDebugLocation DL(*this, Cond); EmitBranchOnBoolExpr(CondOp->getLHS(), TrueBlock, FalseBlock, @@ -2021,6 +2043,7 @@ void CodeGenFunction::EmitBranchOnBoolExpr( cond.begin(*this); EmitBlock(RHSBlock); + incrementProfileCounter(UseSkipPath, CondOp); EmitBranchOnBoolExpr(CondOp->getRHS(), TrueBlock, FalseBlock, TrueCount - LHSScaledTrueCount, LH, CondOp); cond.end(*this); diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index e2dc0b1e381684..cdeff1e261d42b 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -1627,14 +1627,31 @@ class CodeGenFunction : public CodeGenTypeCache { } void markStmtMaybeUsed(const Stmt *S) { PGO.markStmtMaybeUsed(S); } + enum CounterForIncrement { + UseExecPath = 0, + UseSkipPath, + }; + /// Increment the profiler's counter for the given statement by \p StepV. /// If \p StepV is null, the default increment is 1. void incrementProfileCounter(const Stmt *S, llvm::Value *StepV = nullptr) { + incrementProfileCounter(UseExecPath, S, false, StepV); + } + + /// Emit increment of Counter. + /// \param ExecSkip Use `Skipped` Counter if UseSkipPath is specified. + /// \param S The Stmt that Counter is associated. + /// \param UseBoth Mark both Exec/Skip as used. (for verification) + /// \param StepV The offset Value for adding to Counter. + void incrementProfileCounter(CounterForIncrement ExecSkip, const Stmt *S, + bool UseBoth = false, + llvm::Value *StepV = nullptr) { if (CGM.getCodeGenOpts().hasProfileClangInstr() && !CurFn->hasFnAttribute(llvm::Attribute::NoProfile) && !CurFn->hasFnAttribute(llvm::Attribute::SkipProfile)) { auto AL = ApplyDebugLocation::CreateArtificial(*this); - PGO.emitCounterSetOrIncrement(Builder, S, StepV); + PGO.emitCounterSetOrIncrement(Builder, S, (ExecSkip == UseSkipPath), + UseBoth, StepV); } PGO.setCurrentStmt(S); } diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp index 792373839107f0..cea38bc6a3d400 100644 --- a/clang/lib/CodeGen/CodeGenPGO.cpp +++ b/clang/lib/CodeGen/CodeGenPGO.cpp @@ -342,14 +342,6 @@ struct MapRegionCounters : public RecursiveASTVisitor { return Base::VisitBinaryOperator(S); } - bool VisitConditionalOperator(ConditionalOperator *S) { - if (llvm::EnableSingleByteCoverage && S->getTrueExpr()) - CounterMap[S->getTrueExpr()] = NextCounter++; - if (llvm::EnableSingleByteCoverage && S->getFalseExpr()) - CounterMap[S->getFalseExpr()] = NextCounter++; - return Base::VisitConditionalOperator(S); - } - /// Include \p S in the function hash. bool VisitStmt(Stmt *S) { auto Type = updateCounterMappings(S); @@ -365,18 +357,6 @@ struct MapRegionCounters : public RecursiveASTVisitor { if (Hash.getHashVersion() == PGO_HASH_V1) return Base::TraverseIfStmt(If); - // When single byte coverage mode is enabled, add a counter to then and - // else. - bool NoSingleByteCoverage = !llvm::EnableSingleByteCoverage; - for (Stmt *CS : If->children()) { - if (!CS || NoSingleByteCoverage) - continue; - if (CS == If->getThen()) - CounterMap[If->getThen()] = NextCounter++; - else if (CS == If->getElse()) - CounterMap[If->getElse()] = NextCounter++; - } - // Otherwise, keep track of which branch we're in while traversing. VisitStmt(If); @@ -393,81 +373,6 @@ struct MapRegionCounters : public RecursiveASTVisitor { return true; } - bool TraverseWhileStmt(WhileStmt *While) { - // When single byte coverage mode is enabled, add a counter to condition and - // body. - bool NoSingleByteCoverage = !llvm::EnableSingleByteCoverage; - for (Stmt *CS : While->children()) { - if (!CS || NoSingleByteCoverage) - continue; - if (CS == While->getCond()) - CounterMap[While->getCond()] = NextCounter++; - else if (CS == While->getBody()) - CounterMap[While->getBody()] = NextCounter++; - } - - Base::TraverseWhileStmt(While); - if (Hash.getHashVersion() != PGO_HASH_V1) - Hash.combine(PGOHash::EndOfScope); - return true; - } - - bool TraverseDoStmt(DoStmt *Do) { - // When single byte coverage mode is enabled, add a counter to condition and - // body. - bool NoSingleByteCoverage = !llvm::EnableSingleByteCoverage; - for (Stmt *CS : Do->children()) { - if (!CS || NoSingleByteCoverage) - continue; - if (CS == Do->getCond()) - CounterMap[Do->getCond()] = NextCounter++; - else if (CS == Do->getBody()) - CounterMap[Do->getBody()] = NextCounter++; - } - - Base::TraverseDoStmt(Do); - if (Hash.getHashVersion() != PGO_HASH_V1) - Hash.combine(PGOHash::EndOfScope); - return true; - } - - bool TraverseForStmt(ForStmt *For) { - // When single byte coverage mode is enabled, add a counter to condition, - // increment and body. - bool NoSingleByteCoverage = !llvm::EnableSingleByteCoverage; - for (Stmt *CS : For->children()) { - if (!CS || NoSingleByteCoverage) - continue; - if (CS == For->getCond()) - CounterMap[For->getCond()] = NextCounter++; - else if (CS == For->getInc()) - CounterMap[For->getInc()] = NextCounter++; - else if (CS == For->getBody()) - CounterMap[For->getBody()] = NextCounter++; - } - - Base::TraverseForStmt(For); - if (Hash.getHashVersion() != PGO_HASH_V1) - Hash.combine(PGOHash::EndOfScope); - return true; - } - - bool TraverseCXXForRangeStmt(CXXForRangeStmt *ForRange) { - // When single byte coverage mode is enabled, add a counter to body. - bool NoSingleByteCoverage = !llvm::EnableSingleByteCoverage; - for (Stmt *CS : ForRange->children()) { - if (!CS || NoSingleByteCoverage) - continue; - if (CS == ForRange->getBody()) - CounterMap[ForRange->getBody()] = NextCounter++; - } - - Base::TraverseCXXForRangeStmt(ForRange); - if (Hash.getHashVersion() != PGO_HASH_V1) - Hash.combine(PGOHash::EndOfScope); - return true; - } - // If the statement type \p N is nestable, and its nesting impacts profile // stability, define a custom traversal which tracks the end of the statement // in the hash (provided we're not using the V1 hash). @@ -479,6 +384,10 @@ struct MapRegionCounters : public RecursiveASTVisitor { return true; \ } + DEFINE_NESTABLE_TRAVERSAL(WhileStmt) + DEFINE_NESTABLE_TRAVERSAL(DoStmt) + DEFINE_NESTABLE_TRAVERSAL(ForStmt) + DEFINE_NESTABLE_TRAVERSAL(CXXForRangeStmt) DEFINE_NESTABLE_TRAVERSAL(ObjCForCollectionStmt) DEFINE_NESTABLE_TRAVERSAL(CXXTryStmt) DEFINE_NESTABLE_TRAVERSAL(CXXCatchStmt) @@ -1137,6 +1046,16 @@ void CodeGenPGO::emitCounterRegionMapping(const Decl *D) { if (CoverageMapping.empty()) return; + // Scan max(FalseCnt) and update NumRegionCounters. + unsigned MaxNumCounters = NumRegionCounters; + for (const auto [_, V] : *RegionCounterMap) { + assert((!V.Executed.hasValue() || MaxNumCounters > V.Executed) && + "TrueCnt should not be reassigned"); + if (V.Skipped.hasValue()) + MaxNumCounters = std::max(MaxNumCounters, V.Skipped + 1); + } + NumRegionCounters = MaxNumCounters; + CGM.getCoverageMapping()->addFunctionMappingRecord( FuncNameVar, FuncName, FunctionHash, CoverageMapping); } @@ -1197,11 +1116,25 @@ std::pair CodeGenPGO::getIsCounterPair(const Stmt *S) const { } void CodeGenPGO::emitCounterSetOrIncrement(CGBuilderTy &Builder, const Stmt *S, + bool UseSkipPath, bool UseBoth, llvm::Value *StepV) { - if (!RegionCounterMap || !Builder.GetInsertBlock()) + if (!RegionCounterMap) return; - unsigned Counter = (*RegionCounterMap)[S].Executed; + unsigned Counter; + auto &TheMap = (*RegionCounterMap)[S]; + if (!UseSkipPath) { + if (!TheMap.Executed.hasValue()) + return; + Counter = TheMap.Executed; + } else { + if (!TheMap.Skipped.hasValue()) + return; + Counter = TheMap.Skipped; + } + + if (!Builder.GetInsertBlock()) + return; // Make sure that pointer to global is passed in with zero addrspace // This is relevant during GPU profiling @@ -1213,10 +1146,11 @@ void CodeGenPGO::emitCounterSetOrIncrement(CGBuilderTy &Builder, const Stmt *S, NormalizedFuncNameVarPtr, Builder.getInt64(FunctionHash), Builder.getInt32(NumRegionCounters), Builder.getInt32(Counter), StepV}; - if (llvm::EnableSingleByteCoverage) + if (llvm::EnableSingleByteCoverage) { + assert(!StepV && "StepV is impossible in SingleByte"); Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::instrprof_cover), ArrayRef(Args, 4)); - else if (!StepV) + } else if (!StepV) Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::instrprof_increment), ArrayRef(Args, 4)); else diff --git a/clang/lib/CodeGen/CodeGenPGO.h b/clang/lib/CodeGen/CodeGenPGO.h index 1944b640951d5c..da386f41c0aea1 100644 --- a/clang/lib/CodeGen/CodeGenPGO.h +++ b/clang/lib/CodeGen/CodeGenPGO.h @@ -112,6 +112,7 @@ class CodeGenPGO { public: std::pair getIsCounterPair(const Stmt *S) const; void emitCounterSetOrIncrement(CGBuilderTy &Builder, const Stmt *S, + bool UseFalsePath, bool UseBoth, llvm::Value *StepV); void emitMCDCTestVectorBitmapUpdate(CGBuilderTy &Builder, const Expr *S, Address MCDCCondBitmapAddr, diff --git a/clang/lib/CodeGen/CoverageMappingGen.cpp b/clang/lib/CodeGen/CoverageMappingGen.cpp index f09157771d2b5c..c68c6c46dfd5f2 100644 --- a/clang/lib/CodeGen/CoverageMappingGen.cpp +++ b/clang/lib/CodeGen/CoverageMappingGen.cpp @@ -884,6 +884,9 @@ struct CounterCoverageMappingBuilder /// The map of statements to count values. llvm::DenseMap &CounterMap; + CounterExpressionBuilder::SubstMap MapToExpand; + unsigned NextCounterNum; + MCDC::State &MCDCState; /// A stack of currently live regions. @@ -950,31 +953,69 @@ struct CounterCoverageMappingBuilder /// /// \param S Key to the CounterMap /// \param ParentCnt The Counter representing how many times S is evaluated. - /// \param SkipCntForOld (To be removed later) Optional fake Counter - /// to override Skipped for adjustment of - /// expressions in the old behavior of - /// EnableSingleByteCoverage that is unaware of - /// Branch coverage. BranchCounterPair getBranchCounterPair(const Stmt *S, Counter ParentCnt, std::optional SkipCntForOld = std::nullopt) { - Counter ExecCnt = getRegionCounter(S); - - // The old behavior of SingleByte is unaware of Branches. - // Will be pruned after the migration of SingleByte. - if (llvm::EnableSingleByteCoverage) { - assert(SkipCntForOld && - "SingleByte must provide SkipCntForOld as a fake Skipped count."); - return {ExecCnt, *SkipCntForOld}; + auto &TheMap = CounterMap[S]; + auto ExecCnt = Counter::getCounter(TheMap.Executed); + + BranchCounterPair Counters = {ExecCnt, + Builder.subtract(ParentCnt, ExecCnt)}; + + if (!llvm::EnableSingleByteCoverage || !Counters.Skipped.isExpression()) { + assert( + !TheMap.Skipped.hasValue() && + "SkipCnt shouldn't be allocated but refer to an existing counter."); + return Counters; } - return {ExecCnt, Builder.subtract(ParentCnt, ExecCnt)}; + // Assign second if second is not assigned yet. + if (!TheMap.Skipped.hasValue()) + TheMap.Skipped = NextCounterNum++; + + // Replace an expression (ParentCnt - ExecCnt) with SkipCnt. + Counter SkipCnt = Counter::getCounter(TheMap.Skipped); + MapToExpand[SkipCnt] = Builder.subst(Counters.Skipped, MapToExpand); + Counters.Skipped = SkipCnt; + return Counters; + } + + /// Returns {TrueCnt,FalseCnt} for "implicit default". + /// FalseCnt is considered as the False count on SwitchStmt. + std::pair + getSwitchImplicitDefaultCounterPair(const Stmt *Cond, Counter ParentCount, + Counter CaseCountSum) { + if (llvm::EnableSingleByteCoverage) + // Allocate the new Counter since `subtract(Parent - Sum)` is unavailable. + return {Counter::getZero(), // Folded + Counter::getCounter(CounterMap[Cond].Skipped = NextCounterNum++)}; + + // Simplify is skipped while building the counters above: it can get + // really slow on top of switches with thousands of cases. Instead, + // trigger simplification by adding zero to the last counter. + CaseCountSum = + addCounters(CaseCountSum, Counter::getZero(), /*Simplify=*/true); + + return {CaseCountSum, Builder.subtract(ParentCount, CaseCountSum)}; } bool IsCounterEqual(Counter OutCount, Counter ParentCount) { if (OutCount == ParentCount) return true; + // Try comaparison with pre-replaced expressions. + // + // For example, getBranchCounterPair(#0) returns {#1, #0 - #1}. + // The sum of the pair should be equivalent to the Parent, #0. + // OTOH when (#0 - #1) is replaced with the new counter #2, + // The sum is (#1 + #2). If the reverse substitution #2 => (#0 - #1) + // can be applied, the sum can be transformed to (#1 + (#0 - #1)). + // To apply substitutions to both hand expressions, transform (LHS - RHS) + // and check isZero. + if (Builder.subst(Builder.subtract(OutCount, ParentCount), MapToExpand) + .isZero()) + return true; + return false; } @@ -1188,12 +1229,14 @@ struct CounterCoverageMappingBuilder /// and add it to the function's SourceRegions. /// Returns Counter that corresponds to SC. Counter createSwitchCaseRegion(const SwitchCase *SC, Counter ParentCount) { + Counter TrueCnt = getRegionCounter(SC); + Counter FalseCnt = (llvm::EnableSingleByteCoverage + ? Counter::getZero() // Folded + : subtractCounters(ParentCount, TrueCnt)); // Push region onto RegionStack but immediately pop it (which adds it to // the function's SourceRegions) because it doesn't apply to any other // source other than the SwitchCase. - Counter TrueCnt = getRegionCounter(SC); - popRegions(pushRegion(TrueCnt, getStart(SC), SC->getColonLoc(), - subtractCounters(ParentCount, TrueCnt))); + popRegions(pushRegion(TrueCnt, getStart(SC), SC->getColonLoc(), FalseCnt)); return TrueCnt; } @@ -1460,7 +1503,8 @@ struct CounterCoverageMappingBuilder llvm::DenseMap &CounterMap, MCDC::State &MCDCState, SourceManager &SM, const LangOptions &LangOpts) : CoverageMappingBuilder(CVM, SM, LangOpts), CounterMap(CounterMap), - MCDCState(MCDCState), MCDCBuilder(CVM.getCodeGenModule(), MCDCState) {} + NextCounterNum(CounterMap.size()), MCDCState(MCDCState), + MCDCBuilder(CVM.getCodeGenModule(), MCDCState) {} /// Write the mapping data to the output stream void write(llvm::raw_ostream &OS) { @@ -1580,9 +1624,8 @@ struct CounterCoverageMappingBuilder void VisitBreakStmt(const BreakStmt *S) { assert(!BreakContinueStack.empty() && "break not in a loop or switch!"); - if (!llvm::EnableSingleByteCoverage) - BreakContinueStack.back().BreakCount = addCounters( - BreakContinueStack.back().BreakCount, getRegion().getCounter()); + BreakContinueStack.back().BreakCount = addCounters( + BreakContinueStack.back().BreakCount, getRegion().getCounter()); // FIXME: a break in a switch should terminate regions for all preceding // case statements, not just the most recent one. terminateRegion(S); @@ -1590,9 +1633,8 @@ struct CounterCoverageMappingBuilder void VisitContinueStmt(const ContinueStmt *S) { assert(!BreakContinueStack.empty() && "continue stmt not in a loop!"); - if (!llvm::EnableSingleByteCoverage) - BreakContinueStack.back().ContinueCount = addCounters( - BreakContinueStack.back().ContinueCount, getRegion().getCounter()); + BreakContinueStack.back().ContinueCount = addCounters( + BreakContinueStack.back().ContinueCount, getRegion().getCounter()); terminateRegion(S); } @@ -1610,9 +1652,7 @@ struct CounterCoverageMappingBuilder extendRegion(S); Counter ParentCount = getRegion().getCounter(); - Counter BodyCount = llvm::EnableSingleByteCoverage - ? getRegionCounter(S->getBody()) - : getRegionCounter(S); + Counter BodyCount = getRegionCounter(S); // Handle the body first so that we can get the backedge count. BreakContinueStack.push_back(BreakContinue()); @@ -1625,12 +1665,9 @@ struct CounterCoverageMappingBuilder // Go back to handle the condition. Counter CondCount = - llvm::EnableSingleByteCoverage - ? getRegionCounter(S->getCond()) - : addCounters(ParentCount, BackedgeCount, BC.ContinueCount); - auto BranchCount = getBranchCounterPair(S, CondCount, getRegionCounter(S)); - assert(BranchCount.Executed.isZero() || BranchCount.Executed == BodyCount || - llvm::EnableSingleByteCoverage); + addCounters(ParentCount, BackedgeCount, BC.ContinueCount); + auto BranchCount = getBranchCounterPair(S, CondCount); + assert(BranchCount.Executed.isZero() || BranchCount.Executed == BodyCount); propagateCounts(CondCount, S->getCond()); adjustForOutOfOrderTraversal(getEnd(S)); @@ -1640,9 +1677,6 @@ struct CounterCoverageMappingBuilder if (Gap) fillGapAreaWithCount(Gap->getBegin(), Gap->getEnd(), BodyCount); - assert( - !llvm::EnableSingleByteCoverage || - (BC.BreakCount.isZero() && BranchCount.Skipped == getRegionCounter(S))); Counter OutCount = addCounters(BC.BreakCount, BranchCount.Skipped); if (!IsCounterEqual(OutCount, ParentCount)) { pushRegion(OutCount); @@ -1652,45 +1686,32 @@ struct CounterCoverageMappingBuilder } // Create Branch Region around condition. - if (!llvm::EnableSingleByteCoverage) - createBranchRegion(S->getCond(), BodyCount, BranchCount.Skipped); + createBranchRegion(S->getCond(), BodyCount, BranchCount.Skipped); } void VisitDoStmt(const DoStmt *S) { extendRegion(S); Counter ParentCount = getRegion().getCounter(); - Counter BodyCount = llvm::EnableSingleByteCoverage - ? getRegionCounter(S->getBody()) - : getRegionCounter(S); + Counter BodyCount = getRegionCounter(S); BreakContinueStack.push_back(BreakContinue()); extendRegion(S->getBody()); - Counter BackedgeCount; - if (llvm::EnableSingleByteCoverage) - propagateCounts(BodyCount, S->getBody()); - else - BackedgeCount = - propagateCounts(addCounters(ParentCount, BodyCount), S->getBody()); + Counter BackedgeCount = + propagateCounts(addCounters(ParentCount, BodyCount), S->getBody()); BreakContinue BC = BreakContinueStack.pop_back_val(); bool BodyHasTerminateStmt = HasTerminateStmt; HasTerminateStmt = false; - Counter CondCount = llvm::EnableSingleByteCoverage - ? getRegionCounter(S->getCond()) - : addCounters(BackedgeCount, BC.ContinueCount); - auto BranchCount = getBranchCounterPair(S, CondCount, getRegionCounter(S)); - assert(BranchCount.Executed.isZero() || BranchCount.Executed == BodyCount || - llvm::EnableSingleByteCoverage); + Counter CondCount = addCounters(BackedgeCount, BC.ContinueCount); + auto BranchCount = getBranchCounterPair(S, CondCount); + assert(BranchCount.Executed.isZero() || BranchCount.Executed == BodyCount); propagateCounts(CondCount, S->getCond()); - assert( - !llvm::EnableSingleByteCoverage || - (BC.BreakCount.isZero() && BranchCount.Skipped == getRegionCounter(S))); Counter OutCount = addCounters(BC.BreakCount, BranchCount.Skipped); if (!IsCounterEqual(OutCount, ParentCount)) { pushRegion(OutCount); @@ -1698,8 +1719,7 @@ struct CounterCoverageMappingBuilder } // Create Branch Region around condition. - if (!llvm::EnableSingleByteCoverage) - createBranchRegion(S->getCond(), BodyCount, BranchCount.Skipped); + createBranchRegion(S->getCond(), BodyCount, BranchCount.Skipped); if (BodyHasTerminateStmt) HasTerminateStmt = true; @@ -1711,9 +1731,7 @@ struct CounterCoverageMappingBuilder Visit(S->getInit()); Counter ParentCount = getRegion().getCounter(); - Counter BodyCount = llvm::EnableSingleByteCoverage - ? getRegionCounter(S->getBody()) - : getRegionCounter(S); + Counter BodyCount = getRegionCounter(S); // The loop increment may contain a break or continue. if (S->getInc()) @@ -1732,25 +1750,16 @@ struct CounterCoverageMappingBuilder // the count for all the continue statements. BreakContinue IncrementBC; if (const Stmt *Inc = S->getInc()) { - Counter IncCount; - if (llvm::EnableSingleByteCoverage) - IncCount = getRegionCounter(S->getInc()); - else - IncCount = addCounters(BackedgeCount, BodyBC.ContinueCount); - propagateCounts(IncCount, Inc); + propagateCounts(addCounters(BackedgeCount, BodyBC.ContinueCount), Inc); IncrementBC = BreakContinueStack.pop_back_val(); } // Go back to handle the condition. - Counter CondCount = - llvm::EnableSingleByteCoverage - ? getRegionCounter(S->getCond()) - : addCounters( - addCounters(ParentCount, BackedgeCount, BodyBC.ContinueCount), - IncrementBC.ContinueCount); - auto BranchCount = getBranchCounterPair(S, CondCount, getRegionCounter(S)); - assert(BranchCount.Executed.isZero() || BranchCount.Executed == BodyCount || - llvm::EnableSingleByteCoverage); + Counter CondCount = addCounters( + addCounters(ParentCount, BackedgeCount, BodyBC.ContinueCount), + IncrementBC.ContinueCount); + auto BranchCount = getBranchCounterPair(S, CondCount); + assert(BranchCount.Executed.isZero() || BranchCount.Executed == BodyCount); if (const Expr *Cond = S->getCond()) { propagateCounts(CondCount, Cond); @@ -1762,8 +1771,6 @@ struct CounterCoverageMappingBuilder if (Gap) fillGapAreaWithCount(Gap->getBegin(), Gap->getEnd(), BodyCount); - assert(!llvm::EnableSingleByteCoverage || - (BodyBC.BreakCount.isZero() && IncrementBC.BreakCount.isZero())); Counter OutCount = addCounters(BodyBC.BreakCount, IncrementBC.BreakCount, BranchCount.Skipped); if (!IsCounterEqual(OutCount, ParentCount)) { @@ -1774,8 +1781,7 @@ struct CounterCoverageMappingBuilder } // Create Branch Region around condition. - if (!llvm::EnableSingleByteCoverage) - createBranchRegion(S->getCond(), BodyCount, BranchCount.Skipped); + createBranchRegion(S->getCond(), BodyCount, BranchCount.Skipped); } void VisitCXXForRangeStmt(const CXXForRangeStmt *S) { @@ -1786,9 +1792,7 @@ struct CounterCoverageMappingBuilder Visit(S->getRangeStmt()); Counter ParentCount = getRegion().getCounter(); - Counter BodyCount = llvm::EnableSingleByteCoverage - ? getRegionCounter(S->getBody()) - : getRegionCounter(S); + Counter BodyCount = getRegionCounter(S); BreakContinueStack.push_back(BreakContinue()); extendRegion(S->getBody()); @@ -1805,12 +1809,8 @@ struct CounterCoverageMappingBuilder Counter LoopCount = addCounters(ParentCount, BackedgeCount, BC.ContinueCount); - auto BranchCount = getBranchCounterPair(S, LoopCount, getRegionCounter(S)); - assert(BranchCount.Executed.isZero() || BranchCount.Executed == BodyCount || - llvm::EnableSingleByteCoverage); - assert( - !llvm::EnableSingleByteCoverage || - (BC.BreakCount.isZero() && BranchCount.Skipped == getRegionCounter(S))); + auto BranchCount = getBranchCounterPair(S, LoopCount); + assert(BranchCount.Executed.isZero() || BranchCount.Executed == BodyCount); Counter OutCount = addCounters(BC.BreakCount, BranchCount.Skipped); if (!IsCounterEqual(OutCount, ParentCount)) { @@ -1821,8 +1821,7 @@ struct CounterCoverageMappingBuilder } // Create Branch Region around condition. - if (!llvm::EnableSingleByteCoverage) - createBranchRegion(S->getCond(), BodyCount, BranchCount.Skipped); + createBranchRegion(S->getCond(), BodyCount, BranchCount.Skipped); } void VisitObjCForCollectionStmt(const ObjCForCollectionStmt *S) { @@ -1884,7 +1883,7 @@ struct CounterCoverageMappingBuilder propagateCounts(Counter::getZero(), Body); BreakContinue BC = BreakContinueStack.pop_back_val(); - if (!BreakContinueStack.empty() && !llvm::EnableSingleByteCoverage) + if (!BreakContinueStack.empty()) BreakContinueStack.back().ContinueCount = addCounters( BreakContinueStack.back().ContinueCount, BC.ContinueCount); @@ -1899,11 +1898,6 @@ struct CounterCoverageMappingBuilder MostRecentLocation = getStart(S); handleFileExit(ExitLoc); - // When single byte coverage mode is enabled, do not create branch region by - // early returning. - if (llvm::EnableSingleByteCoverage) - return; - // Create a Branch Region around each Case. Subtract the case's // counter from the Parent counter to track the "False" branch count. Counter CaseCountSum; @@ -1918,15 +1912,9 @@ struct CounterCoverageMappingBuilder // the hidden branch, which will be added later by the CodeGen. This region // will be associated with the switch statement's condition. if (!HasDefaultCase) { - // Simplify is skipped while building the counters above: it can get - // really slow on top of switches with thousands of cases. Instead, - // trigger simplification by adding zero to the last counter. - CaseCountSum = - addCounters(CaseCountSum, Counter::getZero(), /*Simplify=*/true); - - // This is considered as the False count on SwitchStmt. - Counter SwitchFalse = subtractCounters(ParentCount, CaseCountSum); - createBranchRegion(S->getCond(), CaseCountSum, SwitchFalse); + auto Counters = getSwitchImplicitDefaultCounterPair( + S->getCond(), ParentCount, CaseCountSum); + createBranchRegion(S->getCond(), Counters.first, Counters.second); } } @@ -1934,9 +1922,7 @@ struct CounterCoverageMappingBuilder extendRegion(S); SourceMappingRegion &Parent = getRegion(); - Counter Count = llvm::EnableSingleByteCoverage - ? getRegionCounter(S) - : addCounters(Parent.getCounter(), getRegionCounter(S)); + Counter Count = addCounters(Parent.getCounter(), getRegionCounter(S)); // Reuse the existing region if it starts at our label. This is typical of // the first case in a switch. @@ -2055,12 +2041,7 @@ struct CounterCoverageMappingBuilder extendRegion(S->getCond()); Counter ParentCount = getRegion().getCounter(); - auto [ThenCount, ElseCount] = - (llvm::EnableSingleByteCoverage - ? BranchCounterPair{getRegionCounter(S->getThen()), - (S->getElse() ? getRegionCounter(S->getElse()) - : Counter::getZero())} - : getBranchCounterPair(S, ParentCount)); + auto [ThenCount, ElseCount] = getBranchCounterPair(S, ParentCount); // Emitting a counter for the condition makes it easier to interpret the // counter for the body when looking at the coverage. @@ -2085,26 +2066,20 @@ struct CounterCoverageMappingBuilder fillGapAreaWithCount(Gap->getBegin(), Gap->getEnd(), ElseCount); extendRegion(Else); - Counter ElseOutCount = propagateCounts(ElseCount, Else); - if (!llvm::EnableSingleByteCoverage) - OutCount = addCounters(OutCount, ElseOutCount); + OutCount = addCounters(OutCount, propagateCounts(ElseCount, Else)); if (ThenHasTerminateStmt) HasTerminateStmt = true; - } else if (!llvm::EnableSingleByteCoverage) + } else OutCount = addCounters(OutCount, ElseCount); - if (llvm::EnableSingleByteCoverage) - OutCount = getRegionCounter(S); - if (!IsCounterEqual(OutCount, ParentCount)) { pushRegion(OutCount); GapRegionCounter = OutCount; } - if (!llvm::EnableSingleByteCoverage) - // Create Branch Region around condition. - createBranchRegion(S->getCond(), ThenCount, ElseCount); + // Create Branch Region around condition. + createBranchRegion(S->getCond(), ThenCount, ElseCount); } void VisitCXXTryStmt(const CXXTryStmt *S) { @@ -2130,11 +2105,7 @@ struct CounterCoverageMappingBuilder extendRegion(E); Counter ParentCount = getRegion().getCounter(); - auto [TrueCount, FalseCount] = - (llvm::EnableSingleByteCoverage - ? BranchCounterPair{getRegionCounter(E->getTrueExpr()), - getRegionCounter(E->getFalseExpr())} - : getBranchCounterPair(E, ParentCount)); + auto [TrueCount, FalseCount] = getBranchCounterPair(E, ParentCount); Counter OutCount; if (const auto *BCO = dyn_cast(E)) { @@ -2153,11 +2124,8 @@ struct CounterCoverageMappingBuilder } extendRegion(E->getFalseExpr()); - Counter FalseOutCount = propagateCounts(FalseCount, E->getFalseExpr()); - if (llvm::EnableSingleByteCoverage) - OutCount = getRegionCounter(E); - else - OutCount = addCounters(OutCount, FalseOutCount); + OutCount = + addCounters(OutCount, propagateCounts(FalseCount, E->getFalseExpr())); if (!IsCounterEqual(OutCount, ParentCount)) { pushRegion(OutCount); @@ -2165,8 +2133,7 @@ struct CounterCoverageMappingBuilder } // Create Branch Region around condition. - if (!llvm::EnableSingleByteCoverage) - createBranchRegion(E->getCond(), TrueCount, FalseCount); + createBranchRegion(E->getCond(), TrueCount, FalseCount); } void createOrCancelDecision(const BinaryOperator *E, unsigned Since) { @@ -2265,9 +2232,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(); @@ -2326,9 +2290,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(); diff --git a/clang/test/CoverageMapping/single-byte-counters.cpp b/clang/test/CoverageMapping/single-byte-counters.cpp index f09e13038d900f..bb2f1f0895a7b9 100644 --- a/clang/test/CoverageMapping/single-byte-counters.cpp +++ b/clang/test/CoverageMapping/single-byte-counters.cpp @@ -4,49 +4,49 @@ int testIf(int x) { // CHECK-NEXT: File 0, [[@LINE]]:19 -> [[@LINE+8]]:2 = [[C00:#0]] int result = 0; if (x == 0) // CHECK-NEXT: File 0, [[@LINE]]:7 -> [[@LINE]]:13 = [[C00]] - - // CHECK-NEXT: Gap,File 0, [[@LINE-2]]:14 -> [[@LINE+1]]:5 = [[C0T:#1]] + // CHECK-NEXT: Branch,File 0, [[@LINE-1]]:7 -> [[@LINE-1]]:13 = [[C0T:#1]], [[C0F:#2]] + // CHECK-NEXT: Gap,File 0, [[@LINE-2]]:14 -> [[@LINE+1]]:5 = [[C0T]] result = -1; // CHECK-NEXT: File 0, [[@LINE]]:5 -> [[@LINE]]:16 = [[C0T]] - return result; // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE]]:16 = [[C0E:#2]] + return result; // #0 } // CHECK-NEXT: testIfElse int testIfElse(int x) { // CHECK-NEXT: File 0, [[@LINE]]:23 -> [[@LINE+9]]:2 = [[C10:#0]] int result = 0; if (x < 0) // CHECK-NEXT: File 0, [[@LINE]]:7 -> [[@LINE]]:12 = [[C10]] - - // CHECK-NEXT: Gap,File 0, [[@LINE-2]]:13 -> [[@LINE+1]]:5 = [[C1T:#1]] + // CHECK-NEXT: Branch,File 0, [[@LINE-1]]:7 -> [[@LINE-1]]:12 = [[C1T:#1]], [[C1F:#2]] + // CHECK-NEXT: Gap,File 0, [[@LINE-2]]:13 -> [[@LINE+1]]:5 = [[C1T]] result = 0; // CHECK-NEXT: File 0, [[@LINE]]:5 -> [[@LINE]]:15 = [[C1T]] - else // CHECK-NEXT: Gap,File 0, [[@LINE-1]]:16 -> [[@LINE+1]]:5 = [[C1F:#2]] + else // CHECK-NEXT: Gap,File 0, [[@LINE-1]]:16 -> [[@LINE+1]]:5 = [[C1F]] result = x * x; // CHECK-NEXT: File 0, [[@LINE]]:5 -> [[@LINE]]:19 = [[C1F]] - return result; // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE]]:16 = [[C1E:#3]] + return result; // #0 } // CHECK-NEXT: testIfElseReturn int testIfElseReturn(int x) { // CHECK-NEXT: File 0, [[@LINE]]:29 -> [[@LINE+10]]:2 = [[C20:#0]] int result = 0; if (x > 0) // CHECK-NEXT: File 0, [[@LINE]]:7 -> [[@LINE]]:12 = [[C20]] - - // CHECK-NEXT: Gap,File 0, [[@LINE-2]]:13 -> [[@LINE+1]]:5 = [[C2T:#1]] + // CHECK-NEXT: Branch,File 0, [[@LINE-1]]:7 -> [[@LINE-1]]:12 = [[C2T:#1]], [[C2F:#2]] + // CHECK-NEXT: Gap,File 0, [[@LINE-2]]:13 -> [[@LINE+1]]:5 = [[C2T]] result = x * x; // CHECK-NEXT: File 0, [[@LINE]]:5 -> [[@LINE]]:19 = [[C2T]] - else // CHECK-NEXT: Gap,File 0, [[@LINE-1]]:20 -> [[@LINE+1]]:5 = [[C2F:#2]] + else // CHECK-NEXT: Gap,File 0, [[@LINE-1]]:20 -> [[@LINE+1]]:5 = [[C2F]] return 0; // CHECK-NEXT: File 0, [[@LINE]]:5 -> [[@LINE]]:13 = [[C2F]] - // CHECK-NEXT: Gap,File 0, [[@LINE-1]]:14 -> [[@LINE+1]]:3 = [[C2E:#3]] - return result; // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE]]:16 = [[C2E:#3]] + // CHECK-NEXT: Gap,File 0, [[@LINE-1]]:14 -> [[@LINE+1]]:3 = [[C2T]] + return result; // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE]]:16 = [[C2T]] } // CHECK-NEXT: testIfBothReturn int testIfBothReturn(int x) { // CHECK-NEXT: File 0, [[@LINE]]:29 -> [[@LINE+10]]:2 = [[C20:#0]] int result = 0; if (x > 0) // CHECK-NEXT: File 0, [[@LINE]]:7 -> [[@LINE]]:12 = [[C20]] - - // CHECK-NEXT: Gap,File 0, [[@LINE-2]]:13 -> [[@LINE+1]]:5 = [[C2T:#1]] + // CHECK-NEXT: Branch,File 0, [[@LINE-1]]:7 -> [[@LINE-1]]:12 = [[C2T:#1]], [[C2F:#2]] + // CHECK-NEXT: Gap,File 0, [[@LINE-2]]:13 -> [[@LINE+1]]:5 = [[C2T]] return 42; // CHECK-NEXT: File 0, [[@LINE]]:5 -> [[@LINE]]:14 = [[C2T]] - else // CHECK-NEXT: Gap,File 0, [[@LINE-1]]:15 -> [[@LINE+1]]:5 = [[C2F:#2]] + else // CHECK-NEXT: Gap,File 0, [[@LINE-1]]:15 -> [[@LINE+1]]:5 = [[C2F]] return 0; // CHECK-NEXT: File 0, [[@LINE]]:5 -> [[@LINE]]:13 = [[C2F]] - // CHECK-NEXT: Gap,File 0, [[@LINE-1]]:14 -> [[@LINE+1]]:3 = #3 - return -1; // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE]]:12 = #3 + // CHECK-NEXT: Gap,File 0, [[@LINE-1]]:14 -> [[@LINE+1]]:3 = 0 + return -1; // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE]]:12 = 0 } // CHECK-NEXT: testSwitch @@ -55,17 +55,17 @@ int testSwitch(int x) { // CHECK-NEXT: File 0, [[@LINE]]:23 -> [[@LINE+20]]:2 = switch (x) { // CHECK-NEXT: Gap,File 0, [[@LINE-1]]:14 -> [[@LINE+13]]:15 = 0 case 1: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+3]]:10 = [[C31:#2]] - + // CHECK-NEXT: Branch,File 0, [[@LINE-1]]:3 -> [[@LINE-1]]:9 = [[C31]], 0 result = 1; break; // CHECK-NEXT: Gap,File 0, [[@LINE-1]]:11 -> [[@LINE+1]]:3 = 0 case 2: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+3]]:10 = [[C32:#3]] - + // CHECK-NEXT: Branch,File 0, [[@LINE-1]]:3 -> [[@LINE-1]]:9 = [[C32]], 0 result = 2; break; // CHECK-NEXT: Gap,File 0, [[@LINE-1]]:11 -> [[@LINE+1]]:3 = 0 default: // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE+2]]:15 = [[C3D:#4]] - + // CHECK-NEXT: Branch,File 0, [[@LINE-1]]:3 -> [[@LINE-1]]:10 = [[C3D]], 0 result = 0; } // CHECK-NEXT: Gap,File 0, [[@LINE-1]]:4 -> [[@LINE+1]]:3 = [[C3E:#1]] @@ -76,91 +76,91 @@ int testSwitch(int x) { // CHECK-NEXT: File 0, [[@LINE]]:23 -> [[@LINE+20]]:2 = int testWhile() { // CHECK-NEXT: File 0, [[@LINE]]:17 -> [[@LINE+12]]:2 = [[C40:#0]] int i = 0; int sum = 0; - while (i < 10) { // CHECK-NEXT: File 0, [[@LINE]]:10 -> [[@LINE]]:16 = [[C4C:#1]] - - // CHECK-NEXT: Gap,File 0, [[@LINE-2]]:17 -> [[@LINE-2]]:18 = [[C4T:#2]] + while (i < 10) { // CHECK-NEXT: File 0, [[@LINE]]:10 -> [[@LINE]]:16 = ([[C40]] + [[C4T:#1]]) + // CHECK-NEXT: Branch,File 0, [[@LINE-1]]:10 -> [[@LINE-1]]:16 = [[C4T]], [[C4F:#0]] + // CHECK-NEXT: Gap,File 0, [[@LINE-2]]:17 -> [[@LINE-2]]:18 = [[C4T]] // CHECK-NEXT: File 0, [[@LINE-3]]:18 -> [[@LINE+3]]:4 = [[C4T]] sum += i; i++; } - return sum; // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE]]:13 = [[C4E:#3]] + return sum; // #0 } // CHECK-NEXT: testContinueBreak -int testContinueBreak() { // CHECK-NEXT: File 0, [[@LINE]]:25 -> [[@LINE+23]]:2 = #0 +int testContinueBreak() { // CHECK-NEXT: File 0, [[@LINE]]:25 -> [[@LINE+23]]:2 = [[C50:#0]] int i = 0; int sum = 0; - while (i < 10) { // CHECK-NEXT: File 0, [[@LINE]]:10 -> [[@LINE]]:16 = #1 - - // CHECK-NEXT: Gap,File 0, [[@LINE-2]]:17 -> [[@LINE-2]]:18 = [[C5B:#2]] + while (i < 10) { // CHECK-NEXT: File 0, [[@LINE]]:10 -> [[@LINE]]:16 = (([[C50]] + [[C5T:#2]]) + [[C5F1:#5]]) + // CHECK-NEXT: Branch,File 0, [[@LINE-1]]:10 -> [[@LINE-1]]:16 = [[C5B:#1]], [[C5E:#6]] + // CHECK-NEXT: Gap,File 0, [[@LINE-2]]:17 -> [[@LINE-2]]:18 = [[C5B]] // CHECK-NEXT: File 0, [[@LINE-3]]:18 -> [[@LINE+14]]:4 = [[C5B]] if (i == 4) // CHECK-NEXT: File 0, [[@LINE]]:9 -> [[@LINE]]:15 = [[C5B]] - - // CHECK-NEXT: Gap,File 0, [[@LINE-2]]:16 -> [[@LINE+1]]:7 = [[C5T:#4]] + // CHECK-NEXT: Branch,File 0, [[@LINE-1]]:9 -> [[@LINE-1]]:15 = [[C5T]], [[C5F:#4]] + // CHECK-NEXT: Gap,File 0, [[@LINE-2]]:16 -> [[@LINE+1]]:7 = [[C5T]] continue; // CHECK-NEXT: File 0, [[@LINE]]:7 -> [[@LINE]]:15 = [[C5T]] - // CHECK-NEXT: Gap,File 0, [[@LINE-1]]:16 -> [[@LINE+2]]:5 = [[C5F:#5]] + // CHECK-NEXT: Gap,File 0, [[@LINE-1]]:16 -> [[@LINE+2]]:5 = [[C5F]] // CHECK-NEXT: File 0, [[@LINE+1]]:5 -> [[@LINE+8]]:4 = [[C5F]] if (i == 5) // CHECK-NEXT: File 0, [[@LINE]]:9 -> [[@LINE]]:15 = [[C5F]] - - // CHECK-NEXT: Gap,File 0, [[@LINE-2]]:16 -> [[@LINE+1]]:7 = [[C5T1:#6]] + // CHECK-NEXT: Branch,File 0, [[@LINE-1]]:9 -> [[@LINE-1]]:15 = [[C5T1:#3]], [[C5F1]] + // CHECK-NEXT: Gap,File 0, [[@LINE-2]]:16 -> [[@LINE+1]]:7 = [[C5T1]] break; // CHECK-NEXT: File 0, [[@LINE]]:7 -> [[@LINE]]:12 = [[C5T1]] - // CHECK-NEXT: Gap,File 0, [[@LINE-1]]:13 -> [[@LINE+1]]:5 = [[C5F1:#7]] + // CHECK-NEXT: Gap,File 0, [[@LINE-1]]:13 -> [[@LINE+1]]:5 = [[C5F1]] sum += i; // CHECK-NEXT: File 0, [[@LINE]]:5 -> [[@LINE+2]]:4 = [[C5F1]] i++; } - // CHECK-NEXT: Gap,File 0, [[@LINE-1]]:4 -> [[@LINE+1]]:3 = [[C5E:#3]] - return sum; // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE]]:13 = [[C5E]] + // #0 + return sum; // #0 } // CHECK-NEXT: testFor int testFor() { // CHECK-NEXT: File 0, [[@LINE]]:15 -> [[@LINE+13]]:2 = [[C60:#0]] int i; int sum = 0; - // CHECK-NEXT: File 0, [[@LINE+3]]:19 -> [[@LINE+3]]:25 = [[C61:#1]] - - // CHECK-NEXT: File 0, [[@LINE+1]]:27 -> [[@LINE+1]]:30 = [[C6C:#2]] + // CHECK-NEXT: File 0, [[@LINE+3]]:19 -> [[@LINE+3]]:25 = ([[C60]] + [[C6B:#1]]) + // CHECK-NEXT: Branch,File 0, [[@LINE+2]]:19 -> [[@LINE+2]]:25 = [[C6B]], [[C6E:#0]] + // CHECK-NEXT: File 0, [[@LINE+1]]:27 -> [[@LINE+1]]:30 = [[C6B]] for (int i = 0; i < 10; i++) { - // CHECK-NEXT: Gap,File 0, [[@LINE-1]]:31 -> [[@LINE-1]]:32 = [[C6B:#3]] + // CHECK-NEXT: Gap,File 0, [[@LINE-1]]:31 -> [[@LINE-1]]:32 = [[C6B]] // CHECK-NEXT: File 0, [[@LINE-2]]:32 -> [[@LINE+2]]:4 = [[C6B]] sum += i; } - return sum; // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE]]:13 = [[C6E:#4]] + return sum; // #0 } // CHECK-NEXT: testForRange int testForRange() { // CHECK-NEXT: File 0, [[@LINE]]:20 -> [[@LINE+11]]:2 = [[C70:#0]] int sum = 0; int array[] = {1, 2, 3, 4, 5}; - + // CHECK-NEXT: Branch,File 0, [[@LINE+1]]:20 -> [[@LINE+1]]:21 = [[C7B:#1]], [[C7E:#0]] for (int element : array) { - // CHECK-NEXT: Gap,File 0, [[@LINE-1]]:28 -> [[@LINE-1]]:29 = [[C7B:#1]] + // CHECK-NEXT: Gap,File 0, [[@LINE-1]]:28 -> [[@LINE-1]]:29 = [[C7B]] // CHECK-NEXT: File 0, [[@LINE-2]]:29 -> [[@LINE+2]]:4 = [[C7B]] sum += element; } - return sum; // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE]]:13 = [[C7E:#2]] + return sum; // #0 } // CHECK-NEXT: testDo int testDo() { // CHECK-NEXT: File 0, [[@LINE]]:14 -> [[@LINE+9]]:2 = [[C80:#0]] int i = 0; int sum = 0; - do { // CHECK-NEXT: File 0, [[@LINE]]:6 -> [[@LINE+3]]:4 = [[C8B:#1]] + do { // CHECK-NEXT: File 0, [[@LINE]]:6 -> [[@LINE+3]]:4 = ([[C80]] + [[C8B:#1]]) sum += i; i++; - } while (i < 5); // CHECK-NEXT: File 0, [[@LINE]]:12 -> [[@LINE]]:17 = [[C8C:#2]] - - return sum; // CHECK-NEXT: File 0, [[@LINE]]:3 -> [[@LINE]]:13 = [[C8E:#3]] + } while (i < 5); // CHECK-NEXT: File 0, [[@LINE]]:12 -> [[@LINE]]:17 = ([[C80]] + [[C8B]]) + // CHECK-NEXT: Branch,File 0, [[@LINE-1]]:12 -> [[@LINE-1]]:17 = [[C8B]], [[C8E:#0]] + return sum; // #0 } // CHECK-NEXT: testConditional int testConditional(int x) { // CHECK-NEXT: File 0, [[@LINE]]:28 -> [[@LINE+7]]:2 = [[C90:#0]] int result = (x > 0) ? 1 : -1; // CHECK-NEXT: File 0, [[@LINE]]:15 -> [[@LINE]]:22 = [[C90]] - - // CHECK-NEXT: Gap,File 0, [[@LINE-2]]:24 -> [[@LINE-2]]:25 = [[C9T:#2]] + // CHECK-NEXT: Branch,File 0, [[@LINE-1]]:15 -> [[@LINE-1]]:22 = [[C9T:#1]], [[C9F:#2]] + // CHECK-NEXT: Gap,File 0, [[@LINE-2]]:24 -> [[@LINE-2]]:25 = [[C9T]] // CHECK-NEXT: File 0, [[@LINE-3]]:25 -> [[@LINE-3]]:26 = [[C9T]] - // CHECK-NEXT: File 0, [[@LINE-4]]:29 -> [[@LINE-4]]:31 = [[C9F:#3]] - return result; // CHECK-NEXT: File 0, [[@LINE]]:2 -> [[@LINE]]:15 = [[C9E:#1]] + // CHECK-NEXT: File 0, [[@LINE-4]]:29 -> [[@LINE-4]]:31 = [[C9F]] + return result; // #0 } diff --git a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp index 6d6678e9e4afe2..83fe5f071c62aa 100644 --- a/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp +++ b/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp @@ -637,6 +637,9 @@ static unsigned getMaxCounterID(const CounterMappingContext &Ctx, unsigned MaxCounterID = 0; for (const auto &Region : Record.MappingRegions) { MaxCounterID = std::max(MaxCounterID, Ctx.getMaxCounterID(Region.Count)); + if (Region.isBranch()) + MaxCounterID = + std::max(MaxCounterID, Ctx.getMaxCounterID(Region.FalseCount)); } return MaxCounterID; } 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 ea8c6f9bc634ed..5aed1ad9ff31b9 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 @@ -4,15 +4,12 @@ big_switch # Func Hash: 13144136522122330070 # Num Counters: -27 +25 # Counter Values: 1 1 1 1 -1 -1 -1 0 1 1 @@ -28,17 +25,18 @@ big_switch 1 1 1 -1 -1 -1 -1 +0 +0 +0 +0 +0 1 boolean_operators # Func Hash: 1245693242827665 # Num Counters: -17 +26 # Counter Values: 1 1 @@ -57,25 +55,30 @@ boolean_operators 1 1 1 +0 +1 +1 +1 +1 +1 +1 +1 +0 boolop_loops # Func Hash: 12402604614320574815 # Num Counters: -23 +21 # Counter Values: 1 -0 -1 1 1 1 -0 1 1 1 1 -0 1 1 1 @@ -85,6 +88,8 @@ boolop_loops 1 1 1 +0 +1 1 1 @@ -92,13 +97,10 @@ branch-c-general.c:static_func # Func Hash: 18129 # Num Counters: -5 +2 # Counter Values: 1 1 -1 -1 -1 conditional_operator # Func Hash: @@ -107,16 +109,16 @@ conditional_operator 5 # Counter Values: 1 -1 0 1 1 +0 conditionals # Func Hash: 4904767535850050386 # Num Counters: -25 +24 # Counter Values: 1 1 @@ -124,11 +126,6 @@ conditionals 1 1 1 -0 -1 -1 -1 -1 1 1 1 @@ -137,18 +134,22 @@ conditionals 1 1 1 +0 1 +0 1 1 +0 1 1 +0 1 do_fallthrough # Func Hash: 8714614136504380050 # Num Counters: -10 +7 # Counter Values: 1 1 @@ -157,15 +158,12 @@ do_fallthrough 1 1 1 -1 -1 -1 early_exits # Func Hash: 2880354649761471549 # Num Counters: -20 +17 # Counter Values: 1 0 @@ -175,15 +173,12 @@ early_exits 1 1 1 -1 -1 -1 +0 1 1 1 0 -1 -1 +0 1 0 0 @@ -192,7 +187,7 @@ jumps # Func Hash: 15051420506203462683 # Num Counters: -38 +33 # Counter Values: 1 1 @@ -200,18 +195,15 @@ jumps 1 0 0 -0 1 0 1 1 -0 1 1 0 1 -1 -1 +0 1 1 1 @@ -220,16 +212,14 @@ jumps 1 1 0 +0 1 1 1 1 -1 -1 -1 -0 0 1 +0 1 1 @@ -245,25 +235,18 @@ simple_loops # Func Hash: 1245818015463121 # Num Counters: -11 +4 # Counter Values: 1 1 1 1 -1 -1 -1 -1 -1 -1 -1 switches # Func Hash: 43242458792028222 # Num Counters: -29 +28 # Counter Values: 1 1 @@ -274,13 +257,11 @@ switches 0 1 1 -0 -1 -1 1 1 1 1 +0 1 1 1 @@ -288,9 +269,10 @@ switches 0 1 1 -1 -1 -1 +0 +0 +0 +0 1 0 0 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 9d23dcb67ad2ac..e04e5588b568ce 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 @@ -11,52 +11,52 @@ Sections: Type: SHT_PROGBITS Flags: [ SHF_GNU_RETAIN ] AddressAlign: 0x8 - Content: D7878914FBE99B074D000000D136449C106D04004C551E9517F40F4F0101000D010715080205020F0016090018001B0D001C009D808080080D001D0104110203040215000A000F19001001858080800819010500081D01030202210006000825001000181001010001 + Content: D7878914FBE99B0760000000D136449C106D04004C551E9517F40F4F01010401050109010D010D0E010715080203020F0016200501000F0016050018001B05001C009D8080800805001D010407020A000F200901000A000F09001001858080800809010500080F010600080F00100018200D01001000181001010001 - Name: '__llvm_covfun (1)' Type: SHT_PROGBITS Flags: [ SHF_GNU_RETAIN ] AddressAlign: 0x8 - Content: 83AD05A5F1438E68EA00000052D33558163C11444C551E9517F40F4F010100260111150E02050113001A09001C001F0D002000A1808080080D00210B040D0109000E15000F009080808008150010020615010B000C21000D008E8080800821000E0010310106008C8080800831000C04063100100015290016009780808008290017020629010B000C35000D008E8080800835000E00102D0106008C808080082D000C02062D010B000C3D000D008E808080083D000E0010100201005B1D010502041D0009000A1D0009000F4D000E000F45001000918080800845001100134901050104490009000A490009000F5D000E000F55001000918080800855001100131002010001 + Content: 83AD05A5F1438E682801000052D33558163C11444C551E9517F40F4F01010101052E0111150E02030113001A2005010013001A05001C001F05002000A1808080080500210B04050109000E2009350009000E09000F009080808008090010020609010B000C200D39000B000C0D000D008E808080080D000E0010350106008C8080800835000C0406350010001520113D00100015110016009780808008110017020611010B000C201541000B000C15000D008E8080800815000E00103D0106008C808080083D000C02063D010B000C201945000B000C19000D008E8080800819000E0010100201005B050109000A050009000F2021000009000A21000E000F202551000E000F1D00100091808080081D00110013050109000A050009000F20002D0009000A2D000E000F205D31000E000F29001000918080800829001100131002010001 - Name: '__llvm_covfun (2)' Type: SHT_PROGBITS Flags: [ SHF_GNU_RETAIN ] AddressAlign: 0x8 - Content: 0449C70428C57369F80000003D5C2D0E4B13F9274C551E9517F40F4F01010028012114180210020100010101070008050009008A8080800805000A000C100101000109010313020D000A00111100120093808080081100130604110209000F190010018780808008190107000C1D000D0185808080081D010502041D0009000E21000F018780808008210107000F15010402838080800810010100011501030B021500070008290009008A8080800829000A000C10010100012D010309023100060504310109000F3D00100187808080083D0107000D41000E028780808008410207000A35010C0013390015028380808008100101000139010302023900070008490009008A8080800849000A000C1001010001 + Content: 0449C70428C57369380100003D5C2D0E4B13F9274C551E9517F40F4F010109072D01110D310D310D3123310D1923310D192E01211418021002010001010107000820052500070008050009008A8080800805000A000C100101000103010A0011200931000A00110900120093808080080900130604090209000F200D290009000F0D00100187808080080D0107000C29000D0185808080082901050204290009000E20112D0009000E11000F018780808008110107000F13010402838080800810010100011301030B02130007000820153500070008150009008A8080800815000A000C10010100011F010605041F0109000F201D390009000F1D00100187808080081D0107000D39000E028780808008390207000A39010C001320193D000C00133D001502838080800810010100013D010302023D0007000820214100070008210009008A8080800821000A000C1001010001 - Name: '__llvm_covfun (3)' Type: SHT_PROGBITS Flags: [ SHF_GNU_RETAIN ] AddressAlign: 0x8 - Content: 55947829059F255EB80100001B9C495D3463E1D04C551E9517F40F4F01010046013B0E2F02100201000105010F001409001600190D001A009B808080080D001B040400011402858080800810010100230001050104000009000A15000B008C8080800815000C000E11010402818080800810010100011D010126021D01070008210009008A8080800821000A000C1001010001250103000D25000E0283808080081001010001000103210229000A000B2D000C008D808080082D000D03043501030204350109000A39000B008C8080800839000C000E1002010001310103000D31000E0181808080084101011B024501011A024901011902490207000C4D000D0185808080084D0105000F5100100283808080081001010001510103140255000A000F5900100091808080085900110A04610103090400011006918080800869010501110001120185808080086D0105011200011301858080800871010501115D030402838080800810010100015D0103080275000F0015790017001A7D001B009C808080087D001C0604000115028580808008100101003F0001050304000009000A8501000B008C808080088501000C000E8D01010302048D010109000A9101000B008C808080089101000C000E1002010001 + Content: 55947829059F255E140200001B9C495D3463E1D04C551E9517F40F4F010102396D517553013B0E2F02100201000101010F001420055D000F0014000016001905001A009B8080800805001B040400011402858080800810010100230001050104000009000A2009590009000A09000B008C8080800809000C000E5D010402818080800810010100010D0101030D0D0107000820116100070008110009008A8080800811000A000C100101000100010E0283808080081001010001000103210219000A000B201569000A000B15000C008D8080800815000D03041901030204190109000A201D650009000A1D000B008C808080081D000C000E1002010001690103000D69000E0181808080082101011B022501011A022901011902290207000C202D6D0007000C2D000D0185808080082D0105000F6D001002838080800810010100016D0103140203000A000F203175000A000F3100100091808080083100110A043501030904200071010D000E0000100691808080083D01050111203D000005000B00011201858080800841010501122041000005000B00011301858080800845010501112045000005000B7503040283808080081001010001750103080207000F001520498101000F0015510017001A49001B009C8080800849001C0604000115028580808008100101003F0001050304000009000A204D790009000A4D000B008C808080084D000C000E5101030204510109000A20557D0009000A55000B008C8080800855000C000E1002010001 - Name: '__llvm_covfun (4)' Type: SHT_PROGBITS Flags: [ SHF_GNU_RETAIN ] AddressAlign: 0x8 - Content: 7129CA3C268292BF4D0100003E688383C9A099004C551E9517F40F4F01010035016C112502100201011C000217028A80808008090103010A05020402838080800810010100620501031C020D003F0046110048004B15004C00CD8080800815004D1704000119148F80808008210105130F21010B000C25000D008E8080800825000E001010010100152D0105100F2D010B000C31000D008E8080800831000E0010350107000C35000D0185808080083901050D0F39010B000C3D000D008E808080083D000E0010410107000F4100100185808080084501050A0F45010B000C49000D008E8080800849000E00104D0107080F000012039180808008550107021155010D000E59000F00908080800859001000125D010900115101080285808080081001010001610105020F61010B0017650018018980808008650109000F1902040383808080081001010121190203020219000700116D00120093808080086D001300151001010001 + Content: 7129CA3C268292BFBB0100003E688383C9A099004C551E9517F40F4F01010907390B25051113391125151D151D3541354141016C112502100201011C000217028A80808008090103010A2009000003000A05020402838080800810010100620501031C0203003F0046200D69003F00460F0048004B0D004C00CD808080080D004D1704000119148F80808008150105130F2015000005000B15010B000C20194D000B000C19000D008E8080800819000E001010010100151B0105020C201D000005000B1B010B000C202151000B000C21000D008E8080800821000E001000010D018580808008250105020F2025000005000B25010B000C202955000B000C29000D008E8080800829000E00100001100185808080082D01050A0F202D000005000B2D010B000C203159000B000C31000D008E8080800831000E0010200061010F001000001203918080800839010702112039000007001339010D000E203D5D000D000E3D000F0090808080083D001000123502080285808080081001010001230105020F2041000005000C23010B0017204565000B0017450018018980808008450109000F69020403838080800810010101216902030202690007001120496D0007001149001200938080800849001300151001010001 - Name: '__llvm_covfun (5)' Type: SHT_PROGBITS Flags: [ SHF_GNU_RETAIN ] AddressAlign: 0x8 - Content: 3F4D1C6E6087417B32010000D6FF56B8865A69B64C551E9517F40F4F01010031019301131F02050113001909001B001E0D001F00A0808080080D00201C04000115198C80808008190105180C19010B000C1D000D008E808080081D000E00101001010015250105150C25010B000C29000D008E8080800829000E00102D0107000C2D000D018580808008310105120C31010B000C35000D008E8080800835000E0010390107000C39000D03858080800810010101013D02050D0C3D010B000C41000D008E8080800841000E0010450107000C45000D0185808080084901050A0C49010B000C4D000D008E808080084D000E0010510107000C51000D0385808080081001010101550205050C55010B000C59000D008E8080800859000E00105D0107000C5D000D018580808008610105020C61010B000C65000D008E8080800865000E0010690107000C1003010001 + Content: 3F4D1C6E6087417B83010000D6FF56B8865A69B64C551E9517F40F4F01010301090D150D153A019301131F0203011300192005610013001909001B001E05001F00A0808080080500201C04000115198C808080080D0105180C200D00000500120D010B000C201145000B000C11000D008E8080800811000E001010010100150B0105020C201500000500120B010B000C201949000B000C19000D008E8080800819000E001000010D0185808080081D0105020C201D00000500201D010B000C20214D000B000C21000D008E8080800821000E001000010D0385808080081001010101250205020C2025000005001325010B000C202951000B000C29000D008E8080800829000E001000010D0185808080082D0105020C202D00000500212D010B000C203155000B000C31000D008E8080800831000E001000010D0385808080081001010101350205020C2035000005002735010B000C203959000B000C39000D008E8080800839000E001000010D0185808080083D0105020C203D000005000C3D010B000C20415D000B000C41000D008E8080800841000E00101004010001 - Name: '__llvm_covfun (6)' Type: SHT_PROGBITS Flags: [ SHF_GNU_RETAIN ] AddressAlign: 0x8 - Content: 59A48AA8899AA3587200000091E33C8FF36C04004C551E9517F40F4F0101001501B4011A0C02050213001A09001C001F0D002000A1808080080D002108040D0109000E1500120013100101005D0D0109000E1D00120013100101005D0D0109000E0D000900172D0012001725001B001C10010100630D0109000E0D000900173D0012001735001B001C1002010063 + Content: 59A48AA8899AA358C100000091E33C8FF36C04004C551E9517F40F4F01010101052001B4011A0C02030213001A2005010013001A05001C001F05002000A1808080080500210804050109000E2039090009000E0900120013203D0D00120013100101005D050109000E2011410009000E110012001320154500120013100101005D050109000E05000900172049210009000E2100120017204D250012001719001B001C20551D001B001C1001010063050109000E05000900172031590009000E310012001720355D0012001729001B001C202D65001B001C1002010063 - Name: '__llvm_covfun (7)' Type: SHT_PROGBITS Flags: [ SHF_GNU_RETAIN ] AddressAlign: 0x8 - Content: F5953D044B505D139E0000005FD132562FE71EAC4C551E9517F40F4F0101001D01C201150D02100201000111010A000B11000A001511000F0015090016018580808008090105000810010100010D0103070225000A001125000A001C250015001C1D001D0185808080081D01050008100101000121010304023D001100123D0011001C3D0016001C31001E002135002200231001010061390103020255000A001155000A001C550015001C49001E00214D002200231001010061 + Content: F5953D044B505D13D50000005FD132562FE71EAC4C551E9517F40F4F010107010501110111011D011D012901292201C201150D02100201000103010A000B03000A0015200935000A000B09000F0015200D39000F0015050016018580808008050105000810010100010B010A00110B000A001C203D15000A0011150015001C2041190015001C11001D018580808008110105000810010100011301110012130011001C20214500110012210016001C2025490016001C1D001E00211D0022002310010100611B010A00111B000A001C204D2D000A00112D0015001C2051310015001C29001E002129002200231001010061 - Name: '__llvm_covfun (8)' Type: SHT_PROGBITS Flags: [ SHF_GNU_RETAIN ] AddressAlign: 0x8 - Content: 20E5C369BDF15C7940000000D0D60000000000004C551E9517F40F4F0101000B01D1011D0702100201000101010B001109001300948080800809001400150D001800191001010001050103020205000B000C01001000111001010001 + Content: 20E5C369BDF15C7949000000D0D60000000000004C551E9517F40F4F0101000C01D1011D0702100201000101010B001120050D000B001105001300948080800805001400150D00180019100101000101010B000C200911000B000C11001000111001010001 - Name: '__llvm_covfun (9)' Type: SHT_PROGBITS Flags: [ SHF_GNU_RETAIN ] AddressAlign: 0x8 - Content: 7DE8E7C47096EB425200000092EAF0986287F0784C551E9517F40F4F0101000D01DA01170B02050113001909001B001E0D001F00A0808080080D002009041502080606100101024D15030B00102100110092808080082100120017250018018780808008250107010619010E0013 + Content: 7DE8E7C47096EB427100000092EAF0986287F0784C551E9517F40F4F0101050715010D0D15050905091001DA01170B020301130019200519001300190B001B001E05001F00A08080800805002009041302080606100101024D13030B0010200D11000B00100D00110092808080080D00120017110018018780808008110107010611010E0013200915000E0013 - Name: '__llvm_covfun (10)' Type: SHT_PROGBITS Flags: [ SHF_GNU_RETAIN ] @@ -66,7 +66,7 @@ Sections: Type: SHT_PROGBITS Flags: [ SHF_GNU_RETAIN ] AddressAlign: 0x8 - Content: 4CB4F49D6737EBF922000000D1460000000000004C551E9517F40F4F0101000501E7011B0302050113001909001B001E0D001F00A0808080080D00200104 + Content: 4CB4F49D6737EBF92B000000D1460000000000004C551E9517F40F4F01010101050601E7011B030203011300192005010013001905001B001E05001F00A0808080080500200104 - Name: __llvm_covmap Type: SHT_PROGBITS Flags: [ SHF_GNU_RETAIN ] @@ -106,61 +106,61 @@ Symbols: Type: STT_OBJECT Section: __llvm_covfun Binding: STB_WEAK - Size: 0x69 + Size: 0x7C Other: [ STV_HIDDEN ] - Name: __covrec_688E43F1A505AD83u Type: STT_OBJECT Section: '__llvm_covfun (1)' Binding: STB_WEAK - Size: 0x106 + Size: 0x144 Other: [ STV_HIDDEN ] - Name: __covrec_6973C52804C74904u Type: STT_OBJECT Section: '__llvm_covfun (2)' Binding: STB_WEAK - Size: 0x114 + Size: 0x154 Other: [ STV_HIDDEN ] - Name: __covrec_5E259F0529789455u Type: STT_OBJECT Section: '__llvm_covfun (3)' Binding: STB_WEAK - Size: 0x1D4 + Size: 0x230 Other: [ STV_HIDDEN ] - Name: __covrec_BF9282263CCA2971u Type: STT_OBJECT Section: '__llvm_covfun (4)' Binding: STB_WEAK - Size: 0x169 + Size: 0x1D7 Other: [ STV_HIDDEN ] - Name: __covrec_7B4187606E1C4D3Fu Type: STT_OBJECT Section: '__llvm_covfun (5)' Binding: STB_WEAK - Size: 0x14E + Size: 0x19F Other: [ STV_HIDDEN ] - Name: __covrec_58A39A89A88AA459u Type: STT_OBJECT Section: '__llvm_covfun (6)' Binding: STB_WEAK - Size: 0x8E + Size: 0xDD Other: [ STV_HIDDEN ] - Name: __covrec_135D504B043D95F5u Type: STT_OBJECT Section: '__llvm_covfun (7)' Binding: STB_WEAK - Size: 0xBA + Size: 0xF1 Other: [ STV_HIDDEN ] - Name: __covrec_795CF1BD69C3E520u Type: STT_OBJECT Section: '__llvm_covfun (8)' Binding: STB_WEAK - Size: 0x5C + Size: 0x65 Other: [ STV_HIDDEN ] - Name: __covrec_42EB9670C4E7E87Du Type: STT_OBJECT Section: '__llvm_covfun (9)' Binding: STB_WEAK - Size: 0x6E + Size: 0x8D Other: [ STV_HIDDEN ] - Name: __covrec_DB956436E78DD5FAu Type: STT_OBJECT @@ -172,6 +172,6 @@ Symbols: Type: STT_OBJECT Section: '__llvm_covfun (11)' Binding: STB_WEAK - Size: 0x3E + Size: 0x47 Other: [ STV_HIDDEN ] ... 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 9660e857092bcb..30810ada1ed95d 100644 --- a/llvm/test/tools/llvm-cov/Inputs/branch-c-general.c +++ b/llvm/test/tools/llvm-cov/Inputs/branch-c-general.c @@ -6,73 +6,73 @@ void simple_loops() { // CHECK: @LINE|{{.*}}simple_loops() int i; - for (i = 0; i < 100; ++i) { // BRCOV: Branch ([[@LINE]]:15): [True: [[#min(C,100)]], False: 1] + for (i = 0; i < 100; ++i) { // CHECK: Branch ([[@LINE]]:15): [True: [[#min(C,100)]], False: 1] } - while (i > 0) // BRCOV: Branch ([[@LINE]]:10): [True: [[#min(C,100)]], False: 1] + while (i > 0) // CHECK: Branch ([[@LINE]]:10): [True: [[#min(C,100)]], False: 1] i--; - do {} while (i++ < 75); // BRCOV: Branch ([[@LINE]]:16): [True: [[#min(C,75)]], False: 1] + do {} while (i++ < 75); // CHECK: Branch ([[@LINE]]:16): [True: [[#min(C,75)]], False: 1] } void conditionals() { // CHECK: @LINE|{{.*}}conditionals() - for (int i = 0; i < 100; ++i) {//BRCOV: Branch ([[@LINE]]:19): [True: [[#min(C,100)]], False: 1] - if (i % 2) { // BRCOV: Branch ([[@LINE]]:9): [True: [[#min(C,50)]], False: [[#min(C,50)]]] - if (i) {} // BRCOV: Branch ([[@LINE]]:11): [True: [[#min(C,50)]], False: 0] - } else if (i % 3) { // BRCOV: Branch ([[@LINE]]:16): [True: [[#min(C,33)]], False: [[#min(C,17)]]] - if (i) {} // BRCOV: Branch ([[@LINE]]:11): [True: [[#min(C,33)]], False: 0] + for (int i = 0; i < 100; ++i) {//CHECK: Branch ([[@LINE]]:19): [True: [[#min(C,100)]], False: 1] + if (i % 2) { // CHECK: Branch ([[@LINE]]:9): [True: [[#min(C,50)]], False: [[#min(C,50)]]] + if (i) {} // CHECK: Branch ([[@LINE]]:11): [True: [[#min(C,50)]], False: 0] + } else if (i % 3) { // CHECK: Branch ([[@LINE]]:16): [True: [[#min(C,33)]], False: [[#min(C,17)]]] + if (i) {} // CHECK: Branch ([[@LINE]]:11): [True: [[#min(C,33)]], False: 0] } else { - if (i) {} // BRCOV: Branch ([[@LINE]]:11): [True: [[#min(C,16)]], False: 1] + if (i) {} // CHECK: Branch ([[@LINE]]:11): [True: [[#min(C,16)]], False: 1] } - // BRCOV: Branch ([[@LINE+1]]:9): [True: [[#min(C,100)]], Folded] - if (1 && i) {} // BRCOV: Branch ([[@LINE]]:14): [True: [[#min(C,99)]], False: 1] - if (0 || i) {} // BRCOV: Branch ([[@LINE]]:9): [Folded, False: [[#min(C,100)]]] - } // BRCOV: Branch ([[@LINE-1]]:14): [True: [[#min(C,99)]], False: 1] + // CHECK: Branch ([[@LINE+1]]:9): [True: [[#min(C,100)]], Folded] + if (1 && i) {} // CHECK: Branch ([[@LINE]]:14): [True: [[#min(C,99)]], False: 1] + if (0 || i) {} // CHECK: Branch ([[@LINE]]:9): [Folded, False: [[#min(C,100)]]] + } // CHECK: Branch ([[@LINE-1]]:14): [True: [[#min(C,99)]], False: 1] } void early_exits() { // CHECK: @LINE|{{.*}}early_exits() int i = 0; - if (i) {} // BRCOV: Branch ([[@LINE]]:7): [True: 0, False: 1] + if (i) {} // CHECK: Branch ([[@LINE]]:7): [True: 0, False: 1] - while (i < 100) { // BRCOV: Branch ([[@LINE]]:10): [True: [[#min(C,51)]], False: 0] + while (i < 100) { // CHECK: Branch ([[@LINE]]:10): [True: [[#min(C,51)]], False: 0] i++; - if (i > 50) // BRCOV: Branch ([[@LINE]]:9): [True: 1, False: [[#min(C,50)]]] + if (i > 50) // CHECK: Branch ([[@LINE]]:9): [True: 1, False: [[#min(C,50)]]] break; - if (i % 2) // BRCOV: Branch ([[@LINE]]:9): [True: [[#min(C,25)]], False: [[#min(C,25)]]] + if (i % 2) // CHECK: Branch ([[@LINE]]:9): [True: [[#min(C,25)]], False: [[#min(C,25)]]] continue; } - if (i) {} // BRCOV: Branch ([[@LINE]]:7): [True: 1, False: 0] + if (i) {} // CHECK: Branch ([[@LINE]]:7): [True: 1, False: 0] do { - if (i > 75) // BRCOV: Branch ([[@LINE]]:9): [True: 1, False: [[#min(C,25)]]] + if (i > 75) // CHECK: Branch ([[@LINE]]:9): [True: 1, False: [[#min(C,25)]]] return; else i++; - } while (i < 100); // BRCOV: Branch ([[@LINE]]:12): [True: [[#min(C,25)]], False: 0] + } while (i < 100); // CHECK: Branch ([[@LINE]]:12): [True: [[#min(C,25)]], False: 0] - if (i) {} // BRCOV: Branch ([[@LINE]]:7): [True: 0, False: 0] + if (i) {} // CHECK: Branch ([[@LINE]]:7): [True: 0, False: 0] } void jumps() { // CHECK: @LINE|{{.*}}jumps() int i; - for (i = 0; i < 2; ++i) { // BRCOV: Branch ([[@LINE]]:15): [True: 1, False: 0] + for (i = 0; i < 2; ++i) { // CHECK: Branch ([[@LINE]]:15): [True: 1, False: 0] goto outofloop; // Never reached -> no weights - if (i) {} // BRCOV: Branch ([[@LINE]]:9): [True: 0, False: 0] + if (i) {} // CHECK: Branch ([[@LINE]]:9): [True: 0, False: 0] } outofloop: - if (i) {} // BRCOV: Branch ([[@LINE]]:7): [True: 0, False: 1] + if (i) {} // CHECK: Branch ([[@LINE]]:7): [True: 0, False: 1] goto loop1; - while (i) { // BRCOV: Branch ([[@LINE]]:10): [True: 0, False: 1] + while (i) { // CHECK: Branch ([[@LINE]]:10): [True: 0, False: 1] loop1: - if (i) {} // BRCOV: Branch ([[@LINE]]:9): [True: 0, False: 1] + if (i) {} // CHECK: Branch ([[@LINE]]:9): [True: 0, False: 1] } goto loop2; @@ -80,27 +80,27 @@ void jumps() { // CHECK: @LINE|{{.*}}jumps() second: third: i++; - if (i < 3) // BRCOV: Branch ([[@LINE]]:7): [True: [[#min(C,2)]], False: 1] + if (i < 3) // CHECK: Branch ([[@LINE]]:7): [True: [[#min(C,2)]], False: 1] goto loop2; - while (i < 3) { // BRCOV: Branch ([[@LINE]]:10): [True: 0, False: 1] + while (i < 3) { // CHECK: Branch ([[@LINE]]:10): [True: 0, False: 1] loop2: switch (i) { - case 0: // BRCOV: Branch ([[@LINE]]:5): [True: 1, Folded] + case 0: // CHECK: Branch ([[@LINE]]:5): [True: 1, Folded] goto first; - case 1: // BRCOV: Branch ([[@LINE]]:5): [True: 1, Folded] + case 1: // CHECK: Branch ([[@LINE]]:5): [True: 1, Folded] goto second; - case 2: // BRCOV: Branch ([[@LINE]]:5): [True: 1, Folded] + case 2: // CHECK: Branch ([[@LINE]]:5): [True: 1, Folded] goto third; } } - for (i = 0; i < 10; ++i) { // BRCOV: Branch ([[@LINE]]:15): [True: [[#min(C,10)]], False: 1] + for (i = 0; i < 10; ++i) { // CHECK: Branch ([[@LINE]]:15): [True: [[#min(C,10)]], False: 1] goto withinloop; // never reached -> no weights - if (i) {} // BRCOV: Branch ([[@LINE]]:9): [True: 0, False: 0] + if (i) {} // CHECK: Branch ([[@LINE]]:9): [True: 0, False: 0] withinloop: - if (i) {} // BRCOV: Branch ([[@LINE]]:9): [True: [[#min(C,9)]], False: 1] + if (i) {} // CHECK: Branch ([[@LINE]]:9): [True: [[#min(C,9)]], False: 1] } } @@ -110,67 +110,67 @@ void switches() { // CHECK: @LINE|{{.*}}switches() // No cases -> no weights switch (weights[0]) { - default: // BRCOV: Branch ([[@LINE]]:3): [True: 1, Folded] + default: // CHECK: Branch ([[@LINE]]:3): [True: 1, Folded] break; } - // BRCOV: Branch ([[@LINE+1]]:63): [True: [[#min(C,15)]], False: 0] + // CHECK: Branch ([[@LINE+1]]:63): [True: [[#min(C,15)]], False: 0] for (int i = 0, len = sizeof(weights) / sizeof(weights[0]); i < len; ++i) { switch (i[weights]) { - case 1: // BRCOV: Branch ([[@LINE]]:5): [True: 1, Folded] - if (i) {} // BRCOV: Branch ([[@LINE]]:11): [True: 0, False: 1] + case 1: // CHECK: Branch ([[@LINE]]:5): [True: 1, Folded] + if (i) {} // CHECK: Branch ([[@LINE]]:11): [True: 0, False: 1] // fallthrough - case 2: // BRCOV: Branch ([[@LINE]]:5): [True: [[#min(C,2)]], Folded] - if (i) {} // BRCOV: Branch ([[@LINE]]:11): [True: [[#min(C,2)]], False: 1] + case 2: // CHECK: Branch ([[@LINE]]:5): [True: [[#min(C,2)]], Folded] + if (i) {} // CHECK: Branch ([[@LINE]]:11): [True: [[#min(C,2)]], False: 1] break; - case 3: // BRCOV: Branch ([[@LINE]]:5): [True: [[#min(C,3)]], Folded] - if (i) {} // BRCOV: Branch ([[@LINE]]:11): [True: [[#min(C,3)]], False: 0] + case 3: // CHECK: Branch ([[@LINE]]:5): [True: [[#min(C,3)]], Folded] + if (i) {} // CHECK: Branch ([[@LINE]]:11): [True: [[#min(C,3)]], False: 0] continue; - case 4: // BRCOV: Branch ([[@LINE]]:5): [True: [[#min(C,4)]], Folded] - if (i) {} // BRCOV: Branch ([[@LINE]]:11): [True: [[#min(C,4)]], False: 0] + case 4: // CHECK: Branch ([[@LINE]]:5): [True: [[#min(C,4)]], Folded] + if (i) {} // CHECK: Branch ([[@LINE]]:11): [True: [[#min(C,4)]], False: 0] switch (i) { - case 6 ... 9: // BRCOV: Branch ([[@LINE]]:7): [True: [[#min(C,4)]], Folded] - if (i) {} // BRCOV: Branch ([[@LINE]]:13): [True: [[#min(C,4)]], False: 0] + case 6 ... 9: // CHECK: Branch ([[@LINE]]:7): [True: [[#min(C,4)]], Folded] + if (i) {} // CHECK: Branch ([[@LINE]]:13): [True: [[#min(C,4)]], False: 0] continue; } - default: // BRCOV: Branch ([[@LINE]]:5): [True: [[#min(C,5)]], Folded] - if (i == len - 1) // BRCOV: Branch ([[@LINE]]:11): [True: 1, False: [[#min(C,4)]]] + default: // CHECK: Branch ([[@LINE]]:5): [True: [[#min(C,5)]], Folded] + if (i == len - 1) // CHECK: Branch ([[@LINE]]:11): [True: 1, False: [[#min(C,4)]]] return; } } // Never reached -> no weights - if (weights[0]) {} // BRCOV: Branch ([[@LINE]]:7): [True: 0, False: 0] + if (weights[0]) {} // CHECK: Branch ([[@LINE]]:7): [True: 0, False: 0] } void big_switch() { // CHECK: @LINE|{{.*}}big_switch() - for (int i = 0; i < 32; ++i) {// BRCOV: Branch ([[@LINE]]:19): [True: [[#min(C,32)]], False: 1] + for (int i = 0; i < 32; ++i) {// CHECK: Branch ([[@LINE]]:19): [True: [[#min(C,32)]], False: 1] switch (1 << i) { - case (1 << 0): // BRCOV: Branch ([[@LINE]]:5): [True: 1, Folded] - if (i) {} // BRCOV: Branch ([[@LINE]]:11): [True: 0, False: 1] + case (1 << 0): // CHECK: Branch ([[@LINE]]:5): [True: 1, Folded] + if (i) {} // CHECK: Branch ([[@LINE]]:11): [True: 0, False: 1] // fallthrough - case (1 << 1): // BRCOV: Branch ([[@LINE]]:5): [True: 1, Folded] - if (i) {} // BRCOV: Branch ([[@LINE]]:11): [True: 1, False: 1] + case (1 << 1): // CHECK: Branch ([[@LINE]]:5): [True: 1, Folded] + if (i) {} // CHECK: Branch ([[@LINE]]:11): [True: 1, False: 1] break; - case (1 << 2) ... (1 << 12):// BRCOV: Branch ([[@LINE]]:5): [True: [[#min(C,11)]], Folded] - if (i) {} // BRCOV: Branch ([[@LINE]]:11): [True: [[#min(C,11)]], False: 0] + case (1 << 2) ... (1 << 12):// CHECK: Branch ([[@LINE]]:5): [True: [[#min(C,11)]], Folded] + if (i) {} // CHECK: Branch ([[@LINE]]:11): [True: [[#min(C,11)]], False: 0] break; // The branch for the large case range above appears after the case body. - case (1 << 13): // BRCOV: Branch ([[@LINE]]:5): [True: 1, Folded] - if (i) {} // BRCOV: Branch ([[@LINE]]:11): [True: 1, False: 0] + case (1 << 13): // CHECK: Branch ([[@LINE]]:5): [True: 1, Folded] + if (i) {} // CHECK: Branch ([[@LINE]]:11): [True: 1, False: 0] break; - case (1 << 14) ... (1 << 28)://BRCOV: Branch ([[@LINE]]:5): [True: [[#min(C,15)]], Folded] - if (i) {} // BRCOV: Branch ([[@LINE]]:11): [True: [[#min(C,15)]], False: 0] + case (1 << 14) ... (1 << 28)://CHECK: Branch ([[@LINE]]:5): [True: [[#min(C,15)]], Folded] + if (i) {} // CHECK: Branch ([[@LINE]]:11): [True: [[#min(C,15)]], False: 0] break; // The branch for the large case range above appears after the case body. case (1 << 29) ... ((1 << 29) + 1): - if (i) {} // BRCOV: Branch ([[@LINE]]:11): [True: 1, False: 0] + if (i) {} // CHECK: Branch ([[@LINE]]:11): [True: 1, False: 0] break; - default: // BRCOV: Branch ([[@LINE]]:5): [True: [[#min(C,2)]], Folded] - if (i) {} // BRCOV: Branch ([[@LINE]]:11): [True: [[#min(C,2)]], False: 0] + default: // CHECK: Branch ([[@LINE]]:5): [True: [[#min(C,2)]], Folded] + if (i) {} // CHECK: Branch ([[@LINE]]:11): [True: [[#min(C,2)]], False: 0] break; } } @@ -180,43 +180,43 @@ 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: [[#min(C,66)]], False: [[#min(C,34)]]] - // BRCOV: Branch ([[@LINE-1]]:18): [True: [[#min(C,33)]], False: 1] - v = i % 3 && i; // BRCOV: Branch ([[@LINE]]:9): [True: [[#min(C,66)]], False: [[#min(C,34)]]] - // BRCOV: Branch ([[@LINE-1]]:18): [True: [[#min(C,66)]], False: 0] - v = i % 3 || i % 2 || i; // BRCOV: Branch ([[@LINE]]:9): [True: [[#min(C,66)]], False: [[#min(C,34)]]] - // BRCOV: Branch ([[@LINE-1]]:18): [True: [[#min(C,17)]], False: [[#min(C,17)]]] - v = i % 2 && i % 3 && i; // BRCOV: Branch ([[@LINE-2]]:27): [True: [[#min(C,16)]], False: 1] - } // BRCOV: Branch ([[@LINE-1]]:9): [True: [[#min(C,50)]], False: [[#min(C,50)]]] - // BRCOV: Branch ([[@LINE-2]]:18): [True: [[#min(C,33)]], False: [[#min(C,17)]]] -} // BRCOV: Branch ([[@LINE-3]]:27): [True: [[#min(C,33)]], False: 0] + v = i % 3 || i; // CHECK: Branch ([[@LINE]]:9): [True: [[#min(C,66)]], False: [[#min(C,34)]]] + // CHECK: Branch ([[@LINE-1]]:18): [True: [[#min(C,33)]], False: 1] + v = i % 3 && i; // CHECK: Branch ([[@LINE]]:9): [True: [[#min(C,66)]], False: [[#min(C,34)]]] + // CHECK: Branch ([[@LINE-1]]:18): [True: [[#min(C,66)]], False: 0] + v = i % 3 || i % 2 || i; // CHECK: Branch ([[@LINE]]:9): [True: [[#min(C,66)]], False: [[#min(C,34)]]] + // CHECK: Branch ([[@LINE-1]]:18): [True: [[#min(C,17)]], False: [[#min(C,17)]]] + v = i % 2 && i % 3 && i; // CHECK: Branch ([[@LINE-2]]:27): [True: [[#min(C,16)]], False: 1] + } // CHECK: Branch ([[@LINE-1]]:9): [True: [[#min(C,50)]], False: [[#min(C,50)]]] + // CHECK: Branch ([[@LINE-2]]:18): [True: [[#min(C,33)]], False: [[#min(C,17)]]] +} // CHECK: Branch ([[@LINE-3]]:27): [True: [[#min(C,33)]], False: 0] void boolop_loops() { // CHECK: @LINE|{{.*}}boolop_loops() int i = 100; - while (i && i > 50) // BRCOV: Branch ([[@LINE]]:10): [True: [[#min(C,51)]], False: 0] - i--; // BRCOV: Branch ([[@LINE-1]]:15): [True: [[#min(C,50)]], False: 1] + while (i && i > 50) // CHECK: Branch ([[@LINE]]:10): [True: [[#min(C,51)]], False: 0] + i--; // CHECK: Branch ([[@LINE-1]]:15): [True: [[#min(C,50)]], False: 1] - while ((i % 2) || (i > 0)) // BRCOV: Branch ([[@LINE]]:10): [True: [[#min(C,25)]], False: [[#min(C,26)]]] - i--; // BRCOV: Branch ([[@LINE-1]]:21): [True: [[#min(C,25)]], False: 1] + while ((i % 2) || (i > 0)) // CHECK: Branch ([[@LINE]]:10): [True: [[#min(C,25)]], False: [[#min(C,26)]]] + i--; // CHECK: Branch ([[@LINE-1]]:21): [True: [[#min(C,25)]], False: 1] - for (i = 100; i && i > 50; --i); // BRCOV: Branch ([[@LINE]]:17): [True: [[#min(C,51)]], False: 0] - // BRCOV: Branch ([[@LINE-1]]:22): [True: [[#min(C,50)]], False: 1] - for (; (i % 2) || (i > 0); --i); // BRCOV: Branch ([[@LINE]]:10): [True: [[#min(C,25)]], False: [[#min(C,26)]]] - // BRCOV: Branch ([[@LINE-1]]:21): [True: [[#min(C,25)]], False: 1] + for (i = 100; i && i > 50; --i); // CHECK: Branch ([[@LINE]]:17): [True: [[#min(C,51)]], False: 0] + // CHECK: Branch ([[@LINE-1]]:22): [True: [[#min(C,50)]], False: 1] + for (; (i % 2) || (i > 0); --i); // CHECK: Branch ([[@LINE]]:10): [True: [[#min(C,25)]], False: [[#min(C,26)]]] + // CHECK: Branch ([[@LINE-1]]:21): [True: [[#min(C,25)]], False: 1] } void conditional_operator() { // CHECK: @LINE|{{.*}}conditional_operator() int i = 100; - int j = i < 50 ? i : 1; // BRCOV: Branch ([[@LINE]]:11): [True: 0, False: 1] + int j = i < 50 ? i : 1; // CHECK: Branch ([[@LINE]]:11): [True: 0, False: 1] - int k = i ?: 0; // BRCOV: Branch ([[@LINE]]:11): [True: 1, False: 0] + int k = i ?: 0; // CHECK: Branch ([[@LINE]]:11): [True: 1, False: 0] } void do_fallthrough() { // CHECK: @LINE|{{.*}}do_fallthrough() - for (int i = 0; i < 10; ++i) {// BRCOV: Branch ([[@LINE]]:19): [True: [[#min(C,10)]], False: 1] + for (int i = 0; i < 10; ++i) {// CHECK: Branch ([[@LINE]]:19): [True: [[#min(C,10)]], False: 1] int j = 0; do { // The number of exits out of this do-loop via the break statement @@ -224,12 +224,12 @@ void do_fallthrough() { // CHECK: @LINE|{{.*}}do_fallthrough() // fallthrough count). Make sure that does not violate any assertions. if (i < 8) break; j++; - } while (j < 2); // BRCOV: Branch ([[@LINE]]:14): [True: [[#min(C,2)]], False: [[#min(C,2)]]] + } while (j < 2); // CHECK: Branch ([[@LINE]]:14): [True: [[#min(C,2)]], False: [[#min(C,2)]]] } } static void static_func() { // CHECK: @LINE|{{.*}}static_func() - for (int i = 0; i < 10; ++i) {// BRCOV: Branch ([[@LINE]]:19): [True: [[#min(C,10)]], False: 1] + for (int i = 0; i < 10; ++i) {// CHECK: Branch ([[@LINE]]:19): [True: [[#min(C,10)]], False: 1] } } 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 f9662438de0e64..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: -67 +127 # Counter Values: 4 0 @@ -63,16 +63,76 @@ _Z4funcii 0 0 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 -4 +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 +1 main # Func Hash: 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 56f3d4955f4d93..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: F0A0ED2C305C0BB32D02000089B21C19C99E86758F2950E06FBD46E8010100600108194302100701000101010C000E01000C010E01000C020E01000C030E01000C040E25010C000E1D010C000E15010C000E0D010C000E05010C000E100101000101010C000E01000C010E01000C020E01000C030E01000C040E4D010C000E45010C000E3D010C000E35010C000E2D010C000E100101000101010C011001000C031001000C051001000C071001000C091001000D000F69010D000F65010C011065000D000F71010D000F61010C011061000D000F79010D000F5D010C01105D000D000F8101010D000F59010C011059000D000F8901010D000F55010C011055000D000F9101010D000F100101000101010C011001000C031001000C051001000C071001000C091001000D000FAD01010D000FA901010C0110A901000D000FB501010D000FA501010C0110A501000D000FBD01010D000FA101010C0110A101000D000FC501010D000F9D01010C01109D01000D000FCD01010D000F9901010C01109901000D000FD501010D000F10010100010101070008DD010009018580808008DD0101050016E1010017028580808008E101020500161001010001E50101030E02E50100070008E9010009018580808008E90101050016ED010017028580808008ED01020500161001010001F10101030902F10100070008F5010009018580808008F50101050016F9010017028580808008F901020500161001010001FD0101030402FD01000700088102000901858080800881020105001685020017028580808008850202050016 + 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: 0x249 + 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 cce61784f9c48c..ec571ee8b52bdf 100644 --- a/llvm/test/tools/llvm-cov/Inputs/branch-logical-mixed.cpp +++ b/llvm/test/tools/llvm-cov/Inputs/branch-logical-mixed.cpp @@ -13,62 +13,62 @@ void func(int a, int b) { bool b4 = a > b; bool b5 = a != b; - bool c = b0 && // BRCOV: Branch ([[@LINE]]:12): [True: [[#min(C,3)]], False: 1] - b1 && // BRCOV: Branch ([[@LINE]]:12): [True: [[#min(C,2)]], False: 1] - b2 && // BRCOV: Branch ([[@LINE]]:12): [True: [[#min(C,2)]], False: 0] - b3 && // BRCOV: Branch ([[@LINE]]:12): [True: 0, False: [[#min(C,2)]]] - 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: [[#min(C,3)]], False: 1] + b1 && // CHECK: Branch ([[@LINE]]:12): [True: [[#min(C,2)]], False: 1] + b2 && // CHECK: Branch ([[@LINE]]:12): [True: [[#min(C,2)]], False: 0] + b3 && // CHECK: Branch ([[@LINE]]:12): [True: 0, False: [[#min(C,2)]]] + 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: [[#min(C,3)]], 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: [[#min(C,3)]], 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: [[#min(C,3)]], False: 1] - b5) || // BRCOV: Branch ([[@LINE]]:13): [True: 1, False: [[#min(C,2)]]] - (b1 && // BRCOV: Branch ([[@LINE]]:13): [True: [[#min(C,2)]], False: 1] - b4) || // BRCOV: Branch ([[@LINE]]:13): [True: 0, False: [[#min(C,2)]]] - (b2 && // BRCOV: Branch ([[@LINE]]:13): [True: [[#min(C,3)]], False: 0] - b3) || // BRCOV: Branch ([[@LINE]]:13): [True: 0, False: [[#min(C,3)]]] - (b3 && // BRCOV: Branch ([[@LINE]]:13): [True: 0, False: [[#min(C,3)]]] - b2) || // BRCOV: Branch ([[@LINE]]:13): [True: 0, False: 0] - (b4 && // BRCOV: Branch ([[@LINE]]:13): [True: 1, False: [[#min(C,2)]]] - b1) || // BRCOV: Branch ([[@LINE]]:13): [True: 0, False: 1] - (b5 && // BRCOV: Branch ([[@LINE]]:13): [True: 1, False: [[#min(C,2)]]] - b0); // BRCOV: Branch ([[@LINE]]:13): [True: 0, False: 1] + bool e = (b0 && // CHECK: Branch ([[@LINE]]:13): [True: [[#min(C,3)]], False: 1] + b5) || // CHECK: Branch ([[@LINE]]:13): [True: 1, False: [[#min(C,2)]]] + (b1 && // CHECK: Branch ([[@LINE]]:13): [True: [[#min(C,2)]], False: 1] + b4) || // CHECK: Branch ([[@LINE]]:13): [True: 0, False: [[#min(C,2)]]] + (b2 && // CHECK: Branch ([[@LINE]]:13): [True: [[#min(C,3)]], False: 0] + b3) || // CHECK: Branch ([[@LINE]]:13): [True: 0, False: [[#min(C,3)]]] + (b3 && // CHECK: Branch ([[@LINE]]:13): [True: 0, False: [[#min(C,3)]]] + b2) || // CHECK: Branch ([[@LINE]]:13): [True: 0, False: 0] + (b4 && // CHECK: Branch ([[@LINE]]:13): [True: 1, False: [[#min(C,2)]]] + b1) || // CHECK: Branch ([[@LINE]]:13): [True: 0, False: 1] + (b5 && // CHECK: Branch ([[@LINE]]:13): [True: 1, False: [[#min(C,2)]]] + b0); // CHECK: Branch ([[@LINE]]:13): [True: 0, False: 1] - bool f = (b0 || // BRCOV: Branch ([[@LINE]]:13): [True: [[#min(C,3)]], False: 1] - b5) && // BRCOV: Branch ([[@LINE]]:13): [True: 1, False: 0] - (b1 || // BRCOV: Branch ([[@LINE]]:13): [True: [[#min(C,2)]], False: [[#min(C,2)]]] - b4) && // BRCOV: Branch ([[@LINE]]:13): [True: 1, False: 1] - (b2 || // BRCOV: Branch ([[@LINE]]:13): [True: [[#min(C,3)]], False: 0] - b3) && // BRCOV: Branch ([[@LINE]]:13): [True: 0, False: 0] - (b3 || // BRCOV: Branch ([[@LINE]]:13): [True: 0, False: [[#min(C,3)]]] - b2) && // BRCOV: Branch ([[@LINE]]:13): [True: [[#min(C,3)]], False: 0] - (b4 || // BRCOV: Branch ([[@LINE]]:13): [True: 1, False: [[#min(C,2)]]] - b1) && // BRCOV: Branch ([[@LINE]]:13): [True: [[#min(C,2)]], False: 0] - (b5 || // BRCOV: Branch ([[@LINE]]:13): [True: 1, False: [[#min(C,2)]]] - b0); // BRCOV: Branch ([[@LINE]]:13): [True: [[#min(C,2)]], False: 0] + bool f = (b0 || // CHECK: Branch ([[@LINE]]:13): [True: [[#min(C,3)]], False: 1] + b5) && // CHECK: Branch ([[@LINE]]:13): [True: 1, False: 0] + (b1 || // CHECK: Branch ([[@LINE]]:13): [True: [[#min(C,2)]], False: [[#min(C,2)]]] + b4) && // CHECK: Branch ([[@LINE]]:13): [True: 1, False: 1] + (b2 || // CHECK: Branch ([[@LINE]]:13): [True: [[#min(C,3)]], False: 0] + b3) && // CHECK: Branch ([[@LINE]]:13): [True: 0, False: 0] + (b3 || // CHECK: Branch ([[@LINE]]:13): [True: 0, False: [[#min(C,3)]]] + b2) && // CHECK: Branch ([[@LINE]]:13): [True: [[#min(C,3)]], False: 0] + (b4 || // CHECK: Branch ([[@LINE]]:13): [True: 1, False: [[#min(C,2)]]] + b1) && // CHECK: Branch ([[@LINE]]:13): [True: [[#min(C,2)]], False: 0] + (b5 || // CHECK: Branch ([[@LINE]]:13): [True: 1, False: [[#min(C,2)]]] + b0); // CHECK: Branch ([[@LINE]]:13): [True: [[#min(C,2)]], False: 0] - if (c) // BRCOV: Branch ([[@LINE]]:7): [True: 0, False: [[#min(C,4)]]] + if (c) // CHECK: Branch ([[@LINE]]:7): [True: 0, False: [[#min(C,4)]]] printf("case0\n"); else printf("case1\n"); - if (d) // BRCOV: Branch ([[@LINE]]:7): [True: [[#min(C,4)]], False: 0] + if (d) // CHECK: Branch ([[@LINE]]:7): [True: [[#min(C,4)]], False: 0] printf("case2\n"); else printf("case3\n"); - if (e) // BRCOV: Branch ([[@LINE]]:7): [True: 1, False: [[#min(C,3)]]] + if (e) // CHECK: Branch ([[@LINE]]:7): [True: 1, False: [[#min(C,3)]]] printf("case4\n"); else printf("case5\n"); - if (f) // BRCOV: Branch ([[@LINE]]:7): [True: [[#min(C,3)]], False: 1] + if (f) // CHECK: Branch ([[@LINE]]:7): [True: [[#min(C,3)]], False: 1] printf("case6\n"); else printf("case7\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 afb4b1038d3f8f..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,23 +25,46 @@ _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: -10 +15 # Counter Values: 3 3 2 1 0 -3 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 5c5f62b11863bd..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: B01D983FC67363959E000000039B9E2C8DB865C493E696313ECE8F5D0D01010101010101010101010101000401241A07020C010E0014140018001D1001010365011C0B1000160405080F002624001000152C0018001D3400200025013C0A1000160305070F001F44001000154C0019001E0119060F0017011D050F00170154091000150205050F001705000F00170121060F00170401070F001F01000F001F5C00100015640019001E0201050F001701000F0017010D060F0017 + 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 ad627106f32bd5..1534c22a926b06 100644 --- a/llvm/test/tools/llvm-cov/Inputs/branch-macros.cpp +++ b/llvm/test/tools/llvm-cov/Inputs/branch-macros.cpp @@ -5,7 +5,7 @@ #define COND1 (a == b) #define COND2 (a != b) #define COND3 (COND1 && COND2) -#define COND4 (COND3 ? COND2 : COND1) // BRCOV: | Branch ([[@LINE]]:15): [True: 1, False: [[#min(C,2)]]] +#define COND4 (COND3 ? COND2 : COND1) // CHECK: | Branch ([[@LINE]]:15): [True: 1, False: [[#min(C,2)]]] #define MACRO1 COND3 #define MACRO2 MACRO1 #define MACRO3 MACRO2 @@ -14,31 +14,31 @@ // CHECK: |{{ +}}[[#min(C,3)]]|bool func( bool func(int a, int b) { - bool c = COND1 && COND2; // BRCOV: | | | Branch ([[@LINE-12]]:15): [True: 1, False: [[#min(C,2)]]] - // BRCOV: | | | Branch ([[@LINE-12]]:15): [True: 0, False: 1] - bool d = COND3; // BRCOV: | | | | | Branch ([[@LINE-14]]:15): [True: 1, False: [[#min(C,2)]]] - // BRCOV: | | | | | Branch ([[@LINE-14]]:15): [True: 0, False: 1] - bool e = MACRO1; // BRCOV: | | | | | | | Branch ([[@LINE-16]]:15): [True: 1, False: [[#min(C,2)]]] - // BRCOV: | | | | | | | Branch ([[@LINE-16]]:15): [True: 0, False: 1] - bool f = MACRO2; // BRCOV: | | | | | | | | | Branch ([[@LINE-18]]:15): [True: 1, False: [[#min(C,2)]]] - // BRCOV: | | | | | | | | | Branch ([[@LINE-18]]:15): [True: 0, False: 1] - bool g = MACRO3; // BRCOV: | | | | | | | | | | | Branch ([[@LINE-20]]:15): [True: 1, False: [[#min(C,2)]]] - // BRCOV: | | | | | | | | | | | Branch ([[@LINE-20]]:15): [True: 0, False: 1] + bool c = COND1 && COND2; // CHECK: | | | Branch ([[@LINE-12]]:15): [True: 1, False: [[#min(C,2)]]] + // CHECK: | | | Branch ([[@LINE-12]]:15): [True: 0, False: 1] + bool d = COND3; // CHECK: | | | | | Branch ([[@LINE-14]]:15): [True: 1, False: [[#min(C,2)]]] + // CHECK: | | | | | Branch ([[@LINE-14]]:15): [True: 0, False: 1] + bool e = MACRO1; // CHECK: | | | | | | | Branch ([[@LINE-16]]:15): [True: 1, False: [[#min(C,2)]]] + // CHECK: | | | | | | | Branch ([[@LINE-16]]:15): [True: 0, False: 1] + bool f = MACRO2; // CHECK: | | | | | | | | | Branch ([[@LINE-18]]:15): [True: 1, False: [[#min(C,2)]]] + // CHECK: | | | | | | | | | Branch ([[@LINE-18]]:15): [True: 0, False: 1] + bool g = MACRO3; // CHECK: | | | | | | | | | | | Branch ([[@LINE-20]]:15): [True: 1, False: [[#min(C,2)]]] + // CHECK: | | | | | | | | | | | Branch ([[@LINE-20]]:15): [True: 0, False: 1] return c && d && e && f && g; - // BRCOV: | Branch ([[@LINE-1]]:10): [True: 0, False: [[#min(C,3)]]] - // 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: [[#min(C,3)]]] + // 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: [[#min(C,2)]]] - // BRCOV: | | | | | | | | | | | Branch ([[@LINE-32]]:15): [True: 0, False: 1] - // BRCOV: | | | | | | | Branch ([[@LINE-34]]:15): [True: 1, False: [[#min(C,2)]]] - // BRCOV: | | | | | | | Branch ([[@LINE-34]]:15): [True: 0, False: 1] - // BRCOV: | | | Branch ([[@LINE-33]]:15): [True: 1, False: [[#min(C,2)]]] + bool h = MACRO3 || COND4; // CHECK: | | | | | | | | | | | Branch ([[@LINE-32]]:15): [True: 1, False: [[#min(C,2)]]] + // CHECK: | | | | | | | | | | | Branch ([[@LINE-32]]:15): [True: 0, False: 1] + // CHECK: | | | | | | | Branch ([[@LINE-34]]:15): [True: 1, False: [[#min(C,2)]]] + // CHECK: | | | | | | | Branch ([[@LINE-34]]:15): [True: 0, False: 1] + // CHECK: | | | Branch ([[@LINE-33]]:15): [True: 1, False: [[#min(C,2)]]] return h; } diff --git a/llvm/test/tools/llvm-cov/Inputs/branch-templates-single.proftext b/llvm/test/tools/llvm-cov/Inputs/branch-templates-single.proftext index 829431334478f3..42cb368bd186eb 100644 --- a/llvm/test/tools/llvm-cov/Inputs/branch-templates-single.proftext +++ b/llvm/test/tools/llvm-cov/Inputs/branch-templates-single.proftext @@ -4,34 +4,31 @@ _Z4funcIbEiT_ # Func Hash: 11045778961 # Num Counters: -4 +3 # Counter Values: 1 1 0 -0 _Z4funcIfEiT_ # Func Hash: 11045778961 # Num Counters: -4 +3 # Counter Values: 1 0 1 -0 _Z4funcIiEiT_ # Func Hash: 11045778961 # Num Counters: -4 +3 # Counter Values: 1 0 1 -0 main # Func Hash: @@ -41,9 +38,9 @@ main # Counter Values: 1 1 -1 0 1 +0 1 -1 +0 diff --git a/llvm/test/tools/llvm-cov/Inputs/branch-templates-single.yaml b/llvm/test/tools/llvm-cov/Inputs/branch-templates-single.yaml index d4ede6db448e61..de145925c6bab9 100644 --- a/llvm/test/tools/llvm-cov/Inputs/branch-templates-single.yaml +++ b/llvm/test/tools/llvm-cov/Inputs/branch-templates-single.yaml @@ -11,22 +11,22 @@ Sections: Type: SHT_PROGBITS Flags: [ SHF_GNU_RETAIN ] AddressAlign: 0x8 - Content: FAD58DE7366495DB5100000058242991A444920226ED9A40DAABBC6B0101000D011D0C090201010700130500140185808080080501050016090103060209000700170D00180185808080080D01050016110103040211000700171500180185808080081501050016190103010B + Content: FAD58DE7366495DB5700000058242991A444920226ED9A40DAABBC6B0101000D011D0C0902010107001320051100070013050014018580808008050105001601010700172009150007001709001801858080800809010500160101070017200D19000700170D00180185808080080D01050016 - Name: '__llvm_covfun (1)' Type: SHT_PROGBITS Flags: [ SHF_GNU_RETAIN ] AddressAlign: 0x8 - Content: 5427717259E0E43E38000000113661920200000026ED9A40DAABBC6B01010008010D0F06020101060007050008018580808008050105000D09000E028580808008090205000D0D000E0183808080080D01030102 + Content: 5427717259E0E43E3F000000113661920200000026ED9A40DAABBC6B01010009010D0F0602010106000720050900060007050008018580808008050105000D09000E028580808008090205000D00000E0183808080080001030102 - Name: '__llvm_covfun (2)' Type: SHT_PROGBITS Flags: [ SHF_GNU_RETAIN ] AddressAlign: 0x8 - Content: 4B7E22082F0551AA38000000113661920200000026ED9A40DAABBC6B01010008010D0F06020101060007050008018580808008050105000D09000E028580808008090205000D0D000E0183808080080D01030102 + Content: 4B7E22082F0551AA3F000000113661920200000026ED9A40DAABBC6B01010009010D0F0602010106000720050900060007050008018580808008050105000D09000E028580808008090205000D00000E0183808080080001030102 - Name: '__llvm_covfun (3)' Type: SHT_PROGBITS Flags: [ SHF_GNU_RETAIN ] AddressAlign: 0x8 - Content: AC1440BC3DA3E41A38000000113661920200000026ED9A40DAABBC6B01010008010D0F06020101060007050008018580808008050105000D09000E028580808008090205000D0D000E0183808080080D01030102 + Content: AC1440BC3DA3E41A3F000000113661920200000026ED9A40DAABBC6B01010009010D0F0602010106000720050900060007050008018580808008050105000D09000E028580808008090205000D00000E0183808080080001030102 - Name: __llvm_covmap Type: SHT_PROGBITS Flags: [ SHF_GNU_RETAIN ] @@ -58,24 +58,24 @@ Symbols: Type: STT_OBJECT Section: __llvm_covfun Binding: STB_WEAK - Size: 0x6D + Size: 0x73 Other: [ STV_HIDDEN ] - Name: __covrec_3EE4E05972712754u Type: STT_OBJECT Section: '__llvm_covfun (1)' Binding: STB_WEAK - Size: 0x54 + Size: 0x5B Other: [ STV_HIDDEN ] - Name: __covrec_AA51052F08227E4Bu Type: STT_OBJECT Section: '__llvm_covfun (2)' Binding: STB_WEAK - Size: 0x54 + Size: 0x5B Other: [ STV_HIDDEN ] - Name: __covrec_1AE4A33DBC4014ACu Type: STT_OBJECT Section: '__llvm_covfun (3)' Binding: STB_WEAK - Size: 0x54 + Size: 0x5B Other: [ STV_HIDDEN ] ... diff --git a/llvm/test/tools/llvm-cov/Inputs/branch-templates.cpp b/llvm/test/tools/llvm-cov/Inputs/branch-templates.cpp index 4d932eaf5944a8..597e596ae84d5c 100644 --- a/llvm/test/tools/llvm-cov/Inputs/branch-templates.cpp +++ b/llvm/test/tools/llvm-cov/Inputs/branch-templates.cpp @@ -11,27 +11,27 @@ void unused(T x) { template int func(T x) { - if(x) // BRCOV: | Branch ([[@LINE]]:6): [True: 0, False: 1] - return 0; // BRCOV: | Branch ([[@LINE-1]]:6): [True: 1, False: 0] - else // BRCOV: | Branch ([[@LINE-2]]:6): [True: 0, False: 1] + if(x) // CHECK: | Branch ([[@LINE]]:6): [True: 0, False: 1] + return 0; // CHECK: | Branch ([[@LINE-1]]:6): [True: 1, False: 0] + else // CHECK: | Branch ([[@LINE-2]]:6): [True: 0, False: 1] return 1; int j = 1; } // CHECK-LABEL: _Z4funcIiEiT_: - // BRCOV: | | Branch ([[@LINE-8]]:6): [True: 0, False: 1] + // CHECK: | | Branch ([[@LINE-8]]:6): [True: 0, False: 1] // CHECK-LABEL: _Z4funcIbEiT_: - // BRCOV: | | Branch ([[@LINE-10]]:6): [True: 1, False: 0] + // CHECK: | | Branch ([[@LINE-10]]:6): [True: 1, False: 0] // CHECK-LABEL: _Z4funcIfEiT_: - // BRCOV: | | Branch ([[@LINE-12]]:6): [True: 0, False: 1] + // CHECK: | | Branch ([[@LINE-12]]:6): [True: 0, False: 1] int main() { - if (func(0)) // BRCOV: | Branch ([[@LINE]]:7): [True: 1, False: 0] + if (func(0)) // CHECK: | Branch ([[@LINE]]:7): [True: 1, False: 0] printf("case1\n"); - if (func(true)) // BRCOV: | Branch ([[@LINE]]:7): [True: 0, False: 1] + if (func(true)) // CHECK: | Branch ([[@LINE]]:7): [True: 0, False: 1] printf("case2\n"); - if (func(0.0)) // BRCOV: | Branch ([[@LINE]]:7): [True: 1, False: 0] + if (func(0.0)) // CHECK: | Branch ([[@LINE]]:7): [True: 1, False: 0] printf("case3\n"); (void)0; return 0; diff --git a/llvm/test/tools/llvm-cov/Inputs/showLineExecutionCounts-single.proftext b/llvm/test/tools/llvm-cov/Inputs/showLineExecutionCounts-single.proftext index 1b7b949de49625..d352a43644c742 100644 --- a/llvm/test/tools/llvm-cov/Inputs/showLineExecutionCounts-single.proftext +++ b/llvm/test/tools/llvm-cov/Inputs/showLineExecutionCounts-single.proftext @@ -4,18 +4,12 @@ main # Func Hash: 15239891155360101223 # Num Counters: -14 +8 # Counter Values: 161 0 161 161 -161 -161 -161 -161 -161 -161 0 161 0 diff --git a/llvm/test/tools/llvm-cov/Inputs/showLineExecutionCounts-single.yaml b/llvm/test/tools/llvm-cov/Inputs/showLineExecutionCounts-single.yaml index 84b184023f0822..b0fc47a198c995 100644 --- a/llvm/test/tools/llvm-cov/Inputs/showLineExecutionCounts-single.yaml +++ b/llvm/test/tools/llvm-cov/Inputs/showLineExecutionCounts-single.yaml @@ -11,7 +11,7 @@ Sections: Type: SHT_PROGBITS Flags: [ SHF_GNU_RETAIN ] AddressAlign: 0x8 - Content: FAD58DE7366495DB9A0000006733DBEA42F87ED3C60E0B951FF3509D0101001A01060C130210020100010101070008050009008A8080800805000A0204090204008A8080800809000A020410030100010D01030A02110013001A15001C001F19002000A180808008190021020410030100011D010306021D0007000D25000F0090808080082500100015290018001D2101030502210007000D31000F018980808008310109000E350109000E10010100012D0103000B + Content: FAD58DE7366495DBA40000006733DBEA42F87ED3C60E0B951FF3509D01010101091A01060C13021002010001010107000820051500070008050009008A8080800805000A0204150204008A8080800815000A02041003010001030113001A2009010013001A09001C001F09002000A18080800809002102041003010001010107000D200D190007000D0D000F0090808080080D00100015190018001D010107000D20111D0007000D11000F018980808008110109000E1D0109000E1001010001 - Name: __llvm_covmap Type: SHT_PROGBITS Flags: [ SHF_GNU_RETAIN ] @@ -40,6 +40,6 @@ Symbols: Type: STT_OBJECT Section: __llvm_covfun Binding: STB_WEAK - Size: 0xB6 + Size: 0xC0 Other: [ STV_HIDDEN ] ... diff --git a/llvm/test/tools/llvm-cov/branch-macros.test b/llvm/test/tools/llvm-cov/branch-macros.test index b16ef9d4846d87..311d6d803fd3d7 100644 --- a/llvm/test/tools/llvm-cov/branch-macros.test +++ b/llvm/test/tools/llvm-cov/branch-macros.test @@ -1,6 +1,6 @@ // 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 -D#C=999 -// RUN: llvm-cov show --binary-counters --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 -D#C=1 +// 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 -D#C=999 +// RUN: llvm-cov show --binary-counters --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 -D#C=1 // 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 diff --git a/llvm/test/tools/llvm-cov/branch-templates.test b/llvm/test/tools/llvm-cov/branch-templates.test index d5535022239f5f..6454c4ad8dd35f 100644 --- a/llvm/test/tools/llvm-cov/branch-templates.test +++ b/llvm/test/tools/llvm-cov/branch-templates.test @@ -6,6 +6,8 @@ // RUN: yaml2obj %S/Inputs/branch-templates-single.yaml -o %t.o // RUN: llvm-profdata merge %S/Inputs/branch-templates-single.proftext -o %t.profdata // RUN: llvm-cov show --show-expansions --show-branches=count %t.o -instr-profile %t.profdata -path-equivalence=.,%S/Inputs | FileCheck %S/Inputs/branch-templates.cpp +// RUN: llvm-cov report --show-branch-summary %t.o -instr-profile %t.profdata -show-functions -path-equivalence=.,%S/Inputs %S/Inputs/branch-templates.cpp | FileCheck %s -check-prefix=REPORT +// RUN: llvm-cov report --show-branch-summary %t.o -instr-profile %t.profdata -path-equivalence=.,%S/Inputs | FileCheck %s -check-prefix=REPORTFILE // REPORT: Name Regions Miss Cover Lines Miss Cover Branches Miss Cover // REPORT-NEXT: ---