Index: include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h =================================================================== --- include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h +++ include/clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h @@ -95,6 +95,8 @@ void HandleBranch(const Stmt *Cond, const Stmt *Term, const CFGBlock *B, ExplodedNode *Pred); + void HandleCleanupTemporaryBranch(const CXXBindTemporaryExpr *BTE, + const CFGBlock *B, ExplodedNode *Pred); /// Handle conditional logic for running static initializers. void HandleStaticInit(const DeclStmt *DS, const CFGBlock *B, Index: include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h =================================================================== --- include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h +++ include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h @@ -227,6 +227,15 @@ const CFGBlock *DstT, const CFGBlock *DstF) override; + /// Called by CoreEngine. + /// Used to generate successor nodes for temporary destructors depending + /// on whether the corresponding constructor was visited. + void processCleanupTemporaryBranch(const CXXBindTemporaryExpr *BTE, + NodeBuilderContext &BldCtx, + ExplodedNode *Pred, ExplodedNodeSet &Dst, + const CFGBlock *DstT, + const CFGBlock *DstF) override; + /// Called by CoreEngine. Used to processing branching behavior /// at static initalizers. void processStaticInitializer(const DeclStmt *DS, @@ -408,7 +417,11 @@ void VisitIncrementDecrementOperator(const UnaryOperator* U, ExplodedNode *Pred, ExplodedNodeSet &Dst); - + + void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *BTE, + ExplodedNode *Pred, ExplodedNodeSet &PreVisit, + ExplodedNodeSet &Dst); + void VisitCXXCatchStmt(const CXXCatchStmt *CS, ExplodedNode *Pred, ExplodedNodeSet &Dst); Index: include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h =================================================================== --- include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h +++ include/clang/StaticAnalyzer/Core/PathSensitive/SubEngine.h @@ -72,6 +72,16 @@ const CFGBlock *DstT, const CFGBlock *DstF) = 0; + /// Called by CoreEngine. + /// Used to generate successor nodes for temporary destructors depending + /// on whether the corresponding constructor was visited. + virtual void processCleanupTemporaryBranch(const CXXBindTemporaryExpr *BTE, + NodeBuilderContext &BldCtx, + ExplodedNode *Pred, + ExplodedNodeSet &Dst, + const CFGBlock *DstT, + const CFGBlock *DstF) = 0; + /// Called by CoreEngine. Used to processing branching behavior /// at static initalizers. virtual void processStaticInitializer(const DeclStmt *DS, Index: lib/Analysis/CFG.cpp =================================================================== --- lib/Analysis/CFG.cpp +++ lib/Analysis/CFG.cpp @@ -295,6 +295,12 @@ CFGBlock *Block; CFGBlock *Succ; + + // Used while visiting subtrees for temporary destructurs. + // Tracks the last CXXBindTemporaryExpr that we added; used when we add branch + // points and thus need to know whether a temporary constructor was executed. + CXXBindTemporaryExpr *LastBindTemporary; + JumpTarget ContinueJumpTarget; JumpTarget BreakJumpTarget; CFGBlock *SwitchTerminatedBlock; @@ -420,6 +426,15 @@ CFGBlock * VisitConditionalOperatorForTemporaryDtors(AbstractConditionalOperator *E, bool BindToTemporary); + /// Adds cleanup logic for temporaries in case of a conditional path. + /// + /// 1. Does nothing if 'E' does not construct temporary objects. + /// 2. Equivalent to VisitForTemporaryDtors if 'E' contains temporary + /// destructors, but they are already handled in a branch due to a child + /// statement of 'E'. + /// 3. Otherwise, creates a new decision node that conditionally executes the + /// temporary destructor and routes back to the current block on entry. + CFGBlock *VisitForTemporaryDtorsBranch(Stmt *E, bool BindToTemporary); // NYS == Not Yet Supported CFGBlock *NYS() { @@ -911,6 +926,7 @@ // as the exit block. Succ = createBlock(); assert(Succ == &cfg->getExit()); + LastBindTemporary = nullptr; Block = nullptr; // the EXIT block is empty. Create all other blocks lazily. if (BuildOpts.AddImplicitDtors) @@ -3518,54 +3534,13 @@ CFGBlock *CFGBuilder::VisitBinaryOperatorForTemporaryDtors(BinaryOperator *E) { if (E->isLogicalOp()) { - // Destructors for temporaries in LHS expression should be called after - // those for RHS expression. Even if this will unnecessarily create a block, - // this block will be used at least by the full expression. - autoCreateBlock(); - CFGBlock *ConfluenceBlock = VisitForTemporaryDtors(E->getLHS()); - if (badCFG) - return nullptr; - - Succ = ConfluenceBlock; - Block = nullptr; - CFGBlock *RHSBlock = VisitForTemporaryDtors(E->getRHS()); - - if (RHSBlock) { - if (badCFG) - return nullptr; - - // If RHS expression did produce destructors we need to connect created - // blocks to CFG in same manner as for binary operator itself. - CFGBlock *LHSBlock = createBlock(false); - LHSBlock->setTerminator(CFGTerminator(E, true)); - - // For binary operator LHS block is before RHS in list of predecessors - // of ConfluenceBlock. - std::reverse(ConfluenceBlock->pred_begin(), - ConfluenceBlock->pred_end()); - - // See if this is a known constant. - TryResult KnownVal = tryEvaluateBool(E->getLHS()); - if (KnownVal.isKnown() && (E->getOpcode() == BO_LOr)) - KnownVal.negate(); - - // Link LHSBlock with RHSBlock exactly the same way as for binary operator - // itself. - if (E->getOpcode() == BO_LOr) { - addSuccessor(LHSBlock, KnownVal.isTrue() ? nullptr : ConfluenceBlock); - addSuccessor(LHSBlock, KnownVal.isFalse() ? nullptr : RHSBlock); - } else { - assert (E->getOpcode() == BO_LAnd); - addSuccessor(LHSBlock, KnownVal.isFalse() ? nullptr : RHSBlock); - addSuccessor(LHSBlock, KnownVal.isTrue() ? nullptr : ConfluenceBlock); - } - - Block = LHSBlock; - return LHSBlock; - } - - Block = ConfluenceBlock; - return ConfluenceBlock; + // The left-hand-side of a conditional operator is unconditionally executed. + VisitForTemporaryDtors(E->getLHS()); + // We do not know at CFG-construction time whether the right-hand-side was + // executed, thus we add a branch node that depends on the temporary + // constructor call. + VisitForTemporaryDtorsBranch(E->getRHS(), false); + return Block; } if (E->isAssignmentOp()) { @@ -3597,13 +3572,14 @@ // anything built thus far. Control won't flow out of this block. const CXXDestructorDecl *Dtor = E->getTemporary()->getDestructor(); if (Dtor->isNoReturn()) { - Succ = B; + if (B) Succ = B; Block = createNoReturnBlock(); } else { autoCreateBlock(); } appendTemporaryDtor(Block, E); + LastBindTemporary = E; B = Block; } return B; @@ -3611,64 +3587,40 @@ CFGBlock *CFGBuilder::VisitConditionalOperatorForTemporaryDtors( AbstractConditionalOperator *E, bool BindToTemporary) { - // First add destructors for condition expression. Even if this will - // unnecessarily create a block, this block will be used at least by the full - // expression. - autoCreateBlock(); - CFGBlock *ConfluenceBlock = VisitForTemporaryDtors(E->getCond()); - if (badCFG) - return nullptr; - if (BinaryConditionalOperator *BCO - = dyn_cast(E)) { - ConfluenceBlock = VisitForTemporaryDtors(BCO->getCommon()); - if (badCFG) - return nullptr; - } - - // Try to add block with destructors for LHS expression. - CFGBlock *LHSBlock = nullptr; - Succ = ConfluenceBlock; - Block = nullptr; - LHSBlock = VisitForTemporaryDtors(E->getTrueExpr(), BindToTemporary); - if (badCFG) - return nullptr; + VisitForTemporaryDtors(E->getCond()); + VisitForTemporaryDtorsBranch(E->getTrueExpr(), BindToTemporary); + VisitForTemporaryDtorsBranch(E->getFalseExpr(), BindToTemporary); + return Block; +} - // Try to add block with destructors for RHS expression; - Succ = ConfluenceBlock; +CFGBlock *CFGBuilder::VisitForTemporaryDtorsBranch(Stmt *E, + bool BindToTemporary) { + CFGBlock *SaveBlock = Block; + CFGBlock *SaveSucc = Succ; + if (Block) Succ = Block; + // Create a new block for the temprary cleanup of 'E'. Block = nullptr; - CFGBlock *RHSBlock = VisitForTemporaryDtors(E->getFalseExpr(), - BindToTemporary); - if (badCFG) - return nullptr; - - if (!RHSBlock && !LHSBlock) { - // If neither LHS nor RHS expression had temporaries to destroy don't create - // more blocks. - Block = ConfluenceBlock; + CFGBlock *B = VisitForTemporaryDtors(E); + if (!B) { + // If there were no temporaries, we pretend nothing happened. + Block = SaveBlock; + Succ = SaveSucc; return Block; } - - Block = createBlock(false); - Block->setTerminator(CFGTerminator(E, true)); - assert(Block->getTerminator().isTemporaryDtorsBranch()); - - // See if this is a known constant. - const TryResult &KnownVal = tryEvaluateBool(E->getCond()); - - if (LHSBlock) { - addSuccessor(Block, LHSBlock, !KnownVal.isFalse()); - } else if (KnownVal.isFalse()) { - addSuccessor(Block, nullptr); - } else { - addSuccessor(Block, ConfluenceBlock); - std::reverse(ConfluenceBlock->pred_begin(), ConfluenceBlock->pred_end()); + if (!LastBindTemporary) { + // If the temporaries were already handled in a branch, we do not need to + // add yet another branch. + return Block; } - - if (!RHSBlock) - RHSBlock = ConfluenceBlock; - - addSuccessor(Block, RHSBlock, !KnownVal.isTrue()); - + // Otherwise, we know that LastBindTemporary is an unhandled guard for + // the temporary cleanup in B. + assert(Block == B); + CFGBlock *Decision = createBlock(false); + Decision->setTerminator(CFGTerminator(LastBindTemporary, true)); + LastBindTemporary = nullptr; + addSuccessor(Decision, B); + addSuccessor(Decision, Succ); + Block = Decision; return Block; } Index: lib/StaticAnalyzer/Core/CoreEngine.cpp =================================================================== --- lib/StaticAnalyzer/Core/CoreEngine.cpp +++ lib/StaticAnalyzer/Core/CoreEngine.cpp @@ -14,6 +14,7 @@ #include "clang/StaticAnalyzer/Core/PathSensitive/CoreEngine.h" #include "clang/AST/Expr.h" +#include "clang/AST/ExprCXX.h" #include "clang/AST/StmtCXX.h" #include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h" #include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h" @@ -346,6 +347,11 @@ default: llvm_unreachable("Analysis for this terminator not implemented."); + case Stmt::CXXBindTemporaryExprClass: + HandleCleanupTemporaryBranch( + cast(B->getTerminator().getStmt()), B, Pred); + return; + // Model static initializers. case Stmt::DeclStmtClass: HandleStaticInit(cast(Term), B, Pred); @@ -461,6 +467,17 @@ enqueue(Dst); } +void CoreEngine::HandleCleanupTemporaryBranch(const CXXBindTemporaryExpr *BTE, + const CFGBlock *B, + ExplodedNode *Pred) { + assert(B->succ_size() == 2); + NodeBuilderContext Ctx(*this, B, Pred); + ExplodedNodeSet Dst; + SubEng.processCleanupTemporaryBranch(BTE, Ctx, Pred, Dst, *(B->succ_begin()), + *(B->succ_begin() + 1)); + // Enqueue the new frontier onto the worklist. + enqueue(Dst); +} void CoreEngine::HandleStaticInit(const DeclStmt *DS, const CFGBlock *B, ExplodedNode *Pred) { Index: lib/StaticAnalyzer/Core/ExprEngine.cpp =================================================================== --- lib/StaticAnalyzer/Core/ExprEngine.cpp +++ lib/StaticAnalyzer/Core/ExprEngine.cpp @@ -757,6 +757,18 @@ // Handled due to fully linearised CFG. break; + case Stmt::CXXBindTemporaryExprClass: { + Bldr.takeNodes(Pred); + ExplodedNodeSet PreVisit; + getCheckerManager().runCheckersForPreStmt(PreVisit, Pred, S, *this); + ExplodedNodeSet Next; + VisitCXXBindTemporaryExpr(cast(S), Pred, PreVisit, + Next); + getCheckerManager().runCheckersForPostStmt(Dst, Next, S, *this); + Bldr.addNodes(Dst); + break; + } + // Cases not handled yet; but will handle some day. case Stmt::DesignatedInitExprClass: case Stmt::ExtVectorElementExprClass: @@ -794,7 +806,6 @@ case Stmt::SizeOfPackExprClass: case Stmt::StringLiteralClass: case Stmt::ObjCStringLiteralClass: - case Stmt::CXXBindTemporaryExprClass: case Stmt::CXXPseudoDestructorExprClass: case Stmt::SubstNonTypeTemplateParmExprClass: case Stmt::CXXNullPtrLiteralExprClass: { @@ -1389,11 +1400,8 @@ if (!BO || !BO->isLogicalOp()) return Condition; - // FIXME: This is a workaround until we handle temporary destructor branches - // correctly; currently, temporary destructor branches lead to blocks that - // only have a terminator (and no statements). These blocks violate the - // invariant this function assumes. - if (B->getTerminator().isTemporaryDtorsBranch()) return Condition; + assert(!B->getTerminator().isTemporaryDtorsBranch() && + "Temporary destructor branches handled by processBindTemporary."); // For logical operations, we still have the case where some branches // use the traditional "merge" approach and others sink the branch @@ -1422,6 +1430,8 @@ ExplodedNodeSet &Dst, const CFGBlock *DstT, const CFGBlock *DstF) { + assert((!Condition || !isa(Condition)) && + "CXXBindTemporaryExprs are handled by processBindTemporary."); const LocationContext *LCtx = Pred->getLocationContext(); PrettyStackTraceLocationContext StackCrashInfo(LCtx); currBldrCtx = &BldCtx; Index: lib/StaticAnalyzer/Core/ExprEngineCXX.cpp =================================================================== --- lib/StaticAnalyzer/Core/ExprEngineCXX.cpp +++ lib/StaticAnalyzer/Core/ExprEngineCXX.cpp @@ -22,6 +22,15 @@ using namespace clang; using namespace ento; +typedef std::pair + CXXBindTemporaryContext; + +// Keeps track of whether CXXBindTemporaryExpr nodes have been evaluated. +// The StackFrameContext assures that nested calls due to inlined recursive +// functions do not interfere. +REGISTER_TRAIT_WITH_PROGRAMSTATE(InitializedTemporariesSet, + llvm::ImmutableSet); + void ExprEngine::CreateCXXTemporaryObject(const MaterializeTemporaryExpr *ME, ExplodedNode *Pred, ExplodedNodeSet &Dst) { @@ -174,6 +183,26 @@ return MRMgr.getCXXTempObjectRegion(CE, LCtx); } +void ExprEngine::processCleanupTemporaryBranch(const CXXBindTemporaryExpr *BTE, + NodeBuilderContext &BldCtx, + ExplodedNode *Pred, + ExplodedNodeSet &Dst, + const CFGBlock *DstT, + const CFGBlock *DstF) { + BranchNodeBuilder TempDtorBuilder(Pred, Dst, BldCtx, DstT, DstF); + if (Pred->getState()->contains( + std::make_pair(BTE, Pred->getStackFrame()))) { + TempDtorBuilder.markInfeasible(false); + ProgramStateRef State = Pred->getState(); + State = State->remove( + std::make_pair(BTE, Pred->getStackFrame())); + TempDtorBuilder.generateNode(State, true, Pred); + } else { + TempDtorBuilder.markInfeasible(true); + TempDtorBuilder.generateNode(Pred->getState(), false, Pred); + } +} + void ExprEngine::VisitCXXConstructExpr(const CXXConstructExpr *CE, ExplodedNode *Pred, ExplodedNodeSet &destNodes) { @@ -479,6 +508,25 @@ Bldr.generateNode(CDE, Pred, state); } +void ExprEngine::VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *BTE, + ExplodedNode *Pred, + ExplodedNodeSet &PreVisit, + ExplodedNodeSet &Dst) { + if (!getAnalysisManager().options.includeTemporaryDtorsInCFG()) { + // In case we don't have temporary destructors in the CFG, do not mark + // the initialization - we would otherwise never clean it up. + Dst = PreVisit; + return; + } + StmtNodeBuilder StmtBldr(PreVisit, Dst, *currBldrCtx); + ProgramStateRef State = Pred->getState(); + assert(!State->contains( + std::make_pair(BTE, Pred->getStackFrame()))); + State = State->add( + std::make_pair(BTE, Pred->getStackFrame())); + StmtBldr.generateNode(BTE, Pred, State); +} + void ExprEngine::VisitCXXCatchStmt(const CXXCatchStmt *CS, ExplodedNode *Pred, ExplodedNodeSet &Dst) { Index: test/Analysis/temp-obj-dtors-cfg-output.cpp =================================================================== --- test/Analysis/temp-obj-dtors-cfg-output.cpp +++ test/Analysis/temp-obj-dtors-cfg-output.cpp @@ -324,7 +324,7 @@ // CHECK: [B3] // CHECK: 1: [B5.8] && [B4.5] // CHECK: 2: [B5.3]([B3.1]) -// CHECK: T: (Temp Dtor) [B5.8] && ... +// CHECK: T: (Temp Dtor) [B4.2] // CHECK: Preds (2): B4 B5 // CHECK: Succs (2): B2 B1 // CHECK: [B4] @@ -354,7 +354,7 @@ // CHECK: [B7] // CHECK: 1: [B9.5] && [B8.5] // CHECK: 2: bool a = A() && B(); -// CHECK: T: (Temp Dtor) [B9.5] && ... +// CHECK: T: (Temp Dtor) [B8.2] // CHECK: Preds (2): B8 B9 // CHECK: Succs (2): B6 B5 // CHECK: [B8] @@ -390,9 +390,9 @@ // CHECK: [B3] // CHECK: 1: [B5.8] || [B4.5] // CHECK: 2: [B5.3]([B3.1]) -// CHECK: T: (Temp Dtor) [B5.8] || ... +// CHECK: T: (Temp Dtor) [B4.2] // CHECK: Preds (2): B4 B5 -// CHECK: Succs (2): B1 B2 +// CHECK: Succs (2): B2 B1 // CHECK: [B4] // CHECK: 1: B() (CXXConstructExpr, class B) // CHECK: 2: [B4.1] (BindTemporary) @@ -420,9 +420,9 @@ // CHECK: [B7] // CHECK: 1: [B9.5] || [B8.5] // CHECK: 2: bool a = A() || B(); -// CHECK: T: (Temp Dtor) [B9.5] || ... +// CHECK: T: (Temp Dtor) [B8.2] // CHECK: Preds (2): B8 B9 -// CHECK: Succs (2): B5 B6 +// CHECK: Succs (2): B6 B5 // CHECK: [B8] // CHECK: 1: B() (CXXConstructExpr, class B) // CHECK: 2: [B8.1] (BindTemporary) @@ -442,11 +442,11 @@ // CHECK: Succs (2): B7 B8 // CHECK: [B0 (EXIT)] // CHECK: Preds (1): B1 -// CHECK: [B11 (ENTRY)] -// CHECK: Succs (1): B10 +// CHECK: [B12 (ENTRY)] +// CHECK: Succs (1): B11 // CHECK: [B1] // CHECK: 1: int b; -// CHECK: 2: [B7.5].~A() (Implicit destructor) +// CHECK: 2: [B8.5].~A() (Implicit destructor) // CHECK: Preds (2): B2 B3 // CHECK: Succs (1): B0 // CHECK: [B2] @@ -477,63 +477,66 @@ // CHECK: [B5] // CHECK: 1: ~A() (Temporary object destructor) // CHECK: 2: ~A() (Temporary object destructor) -// CHECK: Preds (1): B7 +// CHECK: Preds (1): B6 // CHECK: Succs (1): B4 // CHECK: [B6] +// CHECK: T: (Temp Dtor) [B9.6] +// CHECK: Preds (2): B7 B8 +// CHECK: Succs (2): B5 B4 +// CHECK: [B7] // CHECK: 1: ~A() (Temporary object destructor) // CHECK: 2: ~A() (Temporary object destructor) // CHECK: 3: ~A() (Temporary object destructor) // CHECK: 4: ~B() (Temporary object destructor) -// CHECK: Preds (1): B7 -// CHECK: Succs (1): B4 -// CHECK: [B7] -// CHECK: 1: [B10.5] ? [B8.6] : [B9.15] -// CHECK: 2: [B7.1] (ImplicitCastExpr, NoOp, const class A) -// CHECK: 3: [B7.2] -// CHECK: 4: [B7.3] (CXXConstructExpr, class A) -// CHECK: 5: A a = B() ? A() : A(B()); -// CHECK: T: (Temp Dtor) [B10.5] ? ... : ... -// CHECK: Preds (2): B8 B9 -// CHECK: Succs (2): B5 B6 +// CHECK: Preds (1): B8 +// CHECK: Succs (1): B6 // CHECK: [B8] -// CHECK: 1: A() (CXXConstructExpr, class A) -// CHECK: 2: [B8.1] (BindTemporary) -// CHECK: 3: [B8.2] (ImplicitCastExpr, NoOp, const class A) -// CHECK: 4: [B8.3] -// CHECK: 5: [B8.4] (CXXConstructExpr, class A) -// CHECK: 6: [B8.5] (BindTemporary) -// CHECK: Preds (1): B10 -// CHECK: Succs (1): B7 +// CHECK: 1: [B11.5] ? [B9.6] : [B10.15] +// CHECK: 2: [B8.1] (ImplicitCastExpr, NoOp, const class A) +// CHECK: 3: [B8.2] +// CHECK: 4: [B8.3] (CXXConstructExpr, class A) +// CHECK: 5: A a = B() ? A() : A(B()); +// CHECK: T: (Temp Dtor) [B10.15] +// CHECK: Preds (2): B9 B10 +// CHECK: Succs (2): B7 B6 // CHECK: [B9] -// CHECK: 1: B() (CXXConstructExpr, class B) +// CHECK: 1: A() (CXXConstructExpr, class A) // CHECK: 2: [B9.1] (BindTemporary) -// CHECK: 3: [B9.2].operator A -// CHECK: 4: [B9.2] -// CHECK: 5: [B9.4] (ImplicitCastExpr, UserDefinedConversion, class A) +// CHECK: 3: [B9.2] (ImplicitCastExpr, NoOp, const class A) +// CHECK: 4: [B9.3] +// CHECK: 5: [B9.4] (CXXConstructExpr, class A) // CHECK: 6: [B9.5] (BindTemporary) -// CHECK: 7: [B9.6] (ImplicitCastExpr, NoOp, const class A) -// CHECK: 8: [B9.7] -// CHECK: 9: [B9.8] (CXXConstructExpr, class A) -// CHECK: 10: [B9.9] (BindTemporary) -// CHECK: 11: A([B9.10]) (CXXFunctionalCastExpr, ConstructorConversion, class A) -// CHECK: 12: [B9.11] (ImplicitCastExpr, NoOp, const class A) -// CHECK: 13: [B9.12] -// CHECK: 14: [B9.13] (CXXConstructExpr, class A) -// CHECK: 15: [B9.14] (BindTemporary) -// CHECK: Preds (1): B10 -// CHECK: Succs (1): B7 +// CHECK: Preds (1): B11 +// CHECK: Succs (1): B8 // CHECK: [B10] // CHECK: 1: B() (CXXConstructExpr, class B) // CHECK: 2: [B10.1] (BindTemporary) -// CHECK: 3: [B10.2].operator bool +// CHECK: 3: [B10.2].operator A // CHECK: 4: [B10.2] -// CHECK: 5: [B10.4] (ImplicitCastExpr, UserDefinedConversion, _Bool) -// CHECK: T: [B10.5] ? ... : ... +// CHECK: 5: [B10.4] (ImplicitCastExpr, UserDefinedConversion, class A) +// CHECK: 6: [B10.5] (BindTemporary) +// CHECK: 7: [B10.6] (ImplicitCastExpr, NoOp, const class A) +// CHECK: 8: [B10.7] +// CHECK: 9: [B10.8] (CXXConstructExpr, class A) +// CHECK: 10: [B10.9] (BindTemporary) +// CHECK: 11: A([B10.10]) (CXXFunctionalCastExpr, ConstructorConversion, class A) +// CHECK: 12: [B10.11] (ImplicitCastExpr, NoOp, const class A) +// CHECK: 13: [B10.12] +// CHECK: 14: [B10.13] (CXXConstructExpr, class A) +// CHECK: 15: [B10.14] (BindTemporary) // CHECK: Preds (1): B11 -// CHECK: Succs (2): B8 B9 +// CHECK: Succs (1): B8 +// CHECK: [B11] +// CHECK: 1: B() (CXXConstructExpr, class B) +// CHECK: 2: [B11.1] (BindTemporary) +// CHECK: 3: [B11.2].operator bool +// CHECK: 4: [B11.2] +// CHECK: 5: [B11.4] (ImplicitCastExpr, UserDefinedConversion, _Bool) +// CHECK: T: [B11.5] ? ... : ... +// CHECK: Preds (1): B12 +// CHECK: Succs (2): B9 B10 // CHECK: [B0 (EXIT)] // CHECK: Preds (1): B1 -// CHECK: C() : b_(true) // CHECK: [B2 (ENTRY)] // CHECK: Succs (1): B1 // CHECK: [B1] @@ -543,12 +546,10 @@ // CHECK: Succs (1): B0 // CHECK: [B0 (EXIT)] // CHECK: Preds (1): B1 -// CHECK: ~C() // CHECK: [B1 (ENTRY)] // CHECK: Succs (1): B0 // CHECK: [B0 (EXIT)] // CHECK: Preds (1): B1 -// CHECK: operator bool() // CHECK: [B2 (ENTRY)] // CHECK: Succs (1): B1 // CHECK: [B1] @@ -560,7 +561,6 @@ // CHECK: Succs (1): B0 // CHECK: [B0 (EXIT)] // CHECK: Preds (1): B1 -// CHECK: D() : b_(true) // CHECK: [B2 (ENTRY)] // CHECK: Succs (1): B1 // CHECK: [B1] @@ -570,7 +570,6 @@ // CHECK: Succs (1): B0 // CHECK: [B0 (EXIT)] // CHECK: Preds (1): B1 -// CHECK: operator bool() // CHECK: [B2 (ENTRY)] // CHECK: Succs (1): B1 // CHECK: [B1] @@ -582,7 +581,6 @@ // CHECK: Succs (1): B0 // CHECK: [B0 (EXIT)] // CHECK: Preds (1): B1 -// CHECK: int test_cond_unnamed_custom_destructor() // CHECK: [B4 (ENTRY)] // CHECK: Succs (1): B3 // CHECK: [B1] @@ -607,7 +605,6 @@ // CHECK: Succs (2): B2 B1 // CHECK: [B0 (EXIT)] // CHECK: Preds (2): B1 B2 -// CHECK: int test_cond_named_custom_destructor() // CHECK: [B5 (ENTRY)] // CHECK: Succs (1): B4 // CHECK: [B1] @@ -642,7 +639,6 @@ // CHECK: Succs (2): B3 B2 // CHECK: [B0 (EXIT)] // CHECK: Preds (3): B1 B2 B3 -// CHECK: int test_cond_unnamed_auto_destructor() // CHECK: [B4 (ENTRY)] // CHECK: Succs (1): B3 // CHECK: [B1] @@ -665,7 +661,6 @@ // CHECK: Succs (2): B2 B1 // CHECK: [B0 (EXIT)] // CHECK: Preds (2): B1 B2 -// CHECK: int test_cond_named_auto_destructor() // CHECK: [B4 (ENTRY)] // CHECK: Succs (1): B3 // CHECK: [B1] @@ -693,272 +688,296 @@ // CHECK: Succs (2): B2 B1 // CHECK: [B0 (EXIT)] // CHECK: Preds (2): B1 B2 -// CHECK: [B14 (ENTRY)] -// CHECK: Succs (1): B13 +// CHECK: [B16 (ENTRY)] +// CHECK: Succs (1): B15 // CHECK: [B1] // CHECK: 1: ~B() (Temporary object destructor) // CHECK: 2: int b; -// CHECK: 3: [B10.4].~A() (Implicit destructor) +// CHECK: 3: [B12.4].~A() (Implicit destructor) // CHECK: Preds (2): B2 B3 // CHECK: Succs (1): B0 // CHECK: [B2] // CHECK: 1: ~A() (Temporary object destructor) // CHECK: 2: ~A() (Temporary object destructor) -// CHECK: Preds (1): B4 +// CHECK: Preds (1): B3 // CHECK: Succs (1): B1 // CHECK: [B3] +// CHECK: T: (Temp Dtor) [B6.6] +// CHECK: Preds (2): B4 B5 +// CHECK: Succs (2): B2 B1 +// CHECK: [B4] // CHECK: 1: ~A() (Temporary object destructor) // CHECK: 2: ~A() (Temporary object destructor) // CHECK: 3: ~A() (Temporary object destructor) // CHECK: 4: ~B() (Temporary object destructor) -// CHECK: Preds (1): B4 -// CHECK: Succs (1): B1 -// CHECK: [B4] -// CHECK: 1: [B7.8] ? [B5.6] : [B6.15] -// CHECK: 2: [B4.1] (ImplicitCastExpr, NoOp, const class A) -// CHECK: 3: [B4.2] -// CHECK: 4: [B7.3]([B4.3]) -// CHECK: T: (Temp Dtor) [B7.8] ? ... : ... -// CHECK: Preds (2): B5 B6 -// CHECK: Succs (2): B2 B3 +// CHECK: Preds (1): B5 +// CHECK: Succs (1): B3 // CHECK: [B5] -// CHECK: 1: A() (CXXConstructExpr, class A) -// CHECK: 2: [B5.1] (BindTemporary) -// CHECK: 3: [B5.2] (ImplicitCastExpr, NoOp, const class A) -// CHECK: 4: [B5.3] -// CHECK: 5: [B5.4] (CXXConstructExpr, class A) -// CHECK: 6: [B5.5] (BindTemporary) -// CHECK: Preds (1): B7 -// CHECK: Succs (1): B4 +// CHECK: 1: [B8.8] ? [B6.6] : [B7.15] +// CHECK: 2: [B5.1] (ImplicitCastExpr, NoOp, const class A) +// CHECK: 3: [B5.2] +// CHECK: 4: [B8.3]([B5.3]) +// CHECK: T: (Temp Dtor) [B7.15] +// CHECK: Preds (2): B6 B7 +// CHECK: Succs (2): B4 B3 // CHECK: [B6] -// CHECK: 1: B() (CXXConstructExpr, class B) +// CHECK: 1: A() (CXXConstructExpr, class A) // CHECK: 2: [B6.1] (BindTemporary) -// CHECK: 3: [B6.2].operator A -// CHECK: 4: [B6.2] -// CHECK: 5: [B6.4] (ImplicitCastExpr, UserDefinedConversion, class A) +// CHECK: 3: [B6.2] (ImplicitCastExpr, NoOp, const class A) +// CHECK: 4: [B6.3] +// CHECK: 5: [B6.4] (CXXConstructExpr, class A) // CHECK: 6: [B6.5] (BindTemporary) -// CHECK: 7: [B6.6] (ImplicitCastExpr, NoOp, const class A) -// CHECK: 8: [B6.7] -// CHECK: 9: [B6.8] (CXXConstructExpr, class A) -// CHECK: 10: [B6.9] (BindTemporary) -// CHECK: 11: A([B6.10]) (CXXFunctionalCastExpr, ConstructorConversion, class A) -// CHECK: 12: [B6.11] (ImplicitCastExpr, NoOp, const class A) -// CHECK: 13: [B6.12] -// CHECK: 14: [B6.13] (CXXConstructExpr, class A) -// CHECK: 15: [B6.14] (BindTemporary) -// CHECK: Preds (1): B7 -// CHECK: Succs (1): B4 +// CHECK: Preds (1): B8 +// CHECK: Succs (1): B5 // CHECK: [B7] +// CHECK: 1: B() (CXXConstructExpr, class B) +// CHECK: 2: [B7.1] (BindTemporary) +// CHECK: 3: [B7.2].operator A +// CHECK: 4: [B7.2] +// CHECK: 5: [B7.4] (ImplicitCastExpr, UserDefinedConversion, class A) +// CHECK: 6: [B7.5] (BindTemporary) +// CHECK: 7: [B7.6] (ImplicitCastExpr, NoOp, const class A) +// CHECK: 8: [B7.7] +// CHECK: 9: [B7.8] (CXXConstructExpr, class A) +// CHECK: 10: [B7.9] (BindTemporary) +// CHECK: 11: A([B7.10]) (CXXFunctionalCastExpr, ConstructorConversion, class A) +// CHECK: 12: [B7.11] (ImplicitCastExpr, NoOp, const class A) +// CHECK: 13: [B7.12] +// CHECK: 14: [B7.13] (CXXConstructExpr, class A) +// CHECK: 15: [B7.14] (BindTemporary) +// CHECK: Preds (1): B8 +// CHECK: Succs (1): B5 +// CHECK: [B8] // CHECK: 1: ~B() (Temporary object destructor) // CHECK: 2: foo -// CHECK: 3: [B7.2] (ImplicitCastExpr, FunctionToPointerDecay, void (*)(const class A &)) +// CHECK: 3: [B8.2] (ImplicitCastExpr, FunctionToPointerDecay, void (*)(const class A &)) // CHECK: 4: B() (CXXConstructExpr, class B) -// CHECK: 5: [B7.4] (BindTemporary) -// CHECK: 6: [B7.5].operator bool -// CHECK: 7: [B7.5] -// CHECK: 8: [B7.7] (ImplicitCastExpr, UserDefinedConversion, _Bool) -// CHECK: T: [B7.8] ? ... : ... -// CHECK: Preds (2): B8 B9 -// CHECK: Succs (2): B5 B6 -// CHECK: [B8] -// CHECK: 1: ~A() (Temporary object destructor) -// CHECK: Preds (1): B10 -// CHECK: Succs (1): B7 +// CHECK: 5: [B8.4] (BindTemporary) +// CHECK: 6: [B8.5].operator bool +// CHECK: 7: [B8.5] +// CHECK: 8: [B8.7] (ImplicitCastExpr, UserDefinedConversion, _Bool) +// CHECK: T: [B8.8] ? ... : ... +// CHECK: Preds (2): B9 B10 +// CHECK: Succs (2): B6 B7 // CHECK: [B9] // CHECK: 1: ~A() (Temporary object destructor) // CHECK: 2: ~A() (Temporary object destructor) -// CHECK: 3: ~B() (Temporary object destructor) // CHECK: Preds (1): B10 -// CHECK: Succs (1): B7 +// CHECK: Succs (1): B8 // CHECK: [B10] -// CHECK: 1: [B13.5] ? [B11.6] : [B12.15] -// CHECK: 2: [B10.1] (ImplicitCastExpr, NoOp, const class A) -// CHECK: 3: [B10.2] -// CHECK: 4: const A &a = B() ? A() : A(B()); -// CHECK: T: (Temp Dtor) [B13.5] ? ... : ... +// CHECK: T: (Temp Dtor) [B13.6] // CHECK: Preds (2): B11 B12 -// CHECK: Succs (2): B8 B9 +// CHECK: Succs (2): B9 B8 // CHECK: [B11] -// CHECK: 1: A() (CXXConstructExpr, class A) -// CHECK: 2: [B11.1] (BindTemporary) -// CHECK: 3: [B11.2] (ImplicitCastExpr, NoOp, const class A) -// CHECK: 4: [B11.3] -// CHECK: 5: [B11.4] (CXXConstructExpr, class A) -// CHECK: 6: [B11.5] (BindTemporary) -// CHECK: Preds (1): B13 +// CHECK: 1: ~A() (Temporary object destructor) +// CHECK: 2: ~A() (Temporary object destructor) +// CHECK: 3: ~A() (Temporary object destructor) +// CHECK: 4: ~B() (Temporary object destructor) +// CHECK: Preds (1): B12 // CHECK: Succs (1): B10 // CHECK: [B12] -// CHECK: 1: B() (CXXConstructExpr, class B) -// CHECK: 2: [B12.1] (BindTemporary) -// CHECK: 3: [B12.2].operator A -// CHECK: 4: [B12.2] -// CHECK: 5: [B12.4] (ImplicitCastExpr, UserDefinedConversion, class A) -// CHECK: 6: [B12.5] (BindTemporary) -// CHECK: 7: [B12.6] (ImplicitCastExpr, NoOp, const class A) -// CHECK: 8: [B12.7] -// CHECK: 9: [B12.8] (CXXConstructExpr, class A) -// CHECK: 10: [B12.9] (BindTemporary) -// CHECK: 11: A([B12.10]) (CXXFunctionalCastExpr, ConstructorConversion, class A) -// CHECK: 12: [B12.11] (ImplicitCastExpr, NoOp, const class A) -// CHECK: 13: [B12.12] -// CHECK: 14: [B12.13] (CXXConstructExpr, class A) -// CHECK: 15: [B12.14] (BindTemporary) -// CHECK: Preds (1): B13 -// CHECK: Succs (1): B10 +// CHECK: 1: [B15.5] ? [B13.6] : [B14.15] +// CHECK: 2: [B12.1] (ImplicitCastExpr, NoOp, const class A) +// CHECK: 3: [B12.2] +// CHECK: 4: const A &a = B() ? A() : A(B()); +// CHECK: T: (Temp Dtor) [B14.15] +// CHECK: Preds (2): B13 B14 +// CHECK: Succs (2): B11 B10 // CHECK: [B13] -// CHECK: 1: B() (CXXConstructExpr, class B) +// CHECK: 1: A() (CXXConstructExpr, class A) // CHECK: 2: [B13.1] (BindTemporary) -// CHECK: 3: [B13.2].operator bool -// CHECK: 4: [B13.2] -// CHECK: 5: [B13.4] (ImplicitCastExpr, UserDefinedConversion, _Bool) -// CHECK: T: [B13.5] ? ... : ... -// CHECK: Preds (1): B14 -// CHECK: Succs (2): B11 B12 +// CHECK: 3: [B13.2] (ImplicitCastExpr, NoOp, const class A) +// CHECK: 4: [B13.3] +// CHECK: 5: [B13.4] (CXXConstructExpr, class A) +// CHECK: 6: [B13.5] (BindTemporary) +// CHECK: Preds (1): B15 +// CHECK: Succs (1): B12 +// CHECK: [B14] +// CHECK: 1: B() (CXXConstructExpr, class B) +// CHECK: 2: [B14.1] (BindTemporary) +// CHECK: 3: [B14.2].operator A +// CHECK: 4: [B14.2] +// CHECK: 5: [B14.4] (ImplicitCastExpr, UserDefinedConversion, class A) +// CHECK: 6: [B14.5] (BindTemporary) +// CHECK: 7: [B14.6] (ImplicitCastExpr, NoOp, const class A) +// CHECK: 8: [B14.7] +// CHECK: 9: [B14.8] (CXXConstructExpr, class A) +// CHECK: 10: [B14.9] (BindTemporary) +// CHECK: 11: A([B14.10]) (CXXFunctionalCastExpr, ConstructorConversion, class A) +// CHECK: 12: [B14.11] (ImplicitCastExpr, NoOp, const class A) +// CHECK: 13: [B14.12] +// CHECK: 14: [B14.13] (CXXConstructExpr, class A) +// CHECK: 15: [B14.14] (BindTemporary) +// CHECK: Preds (1): B15 +// CHECK: Succs (1): B12 +// CHECK: [B15] +// CHECK: 1: B() (CXXConstructExpr, class B) +// CHECK: 2: [B15.1] (BindTemporary) +// CHECK: 3: [B15.2].operator bool +// CHECK: 4: [B15.2] +// CHECK: 5: [B15.4] (ImplicitCastExpr, UserDefinedConversion, _Bool) +// CHECK: T: [B15.5] ? ... : ... +// CHECK: Preds (1): B16 +// CHECK: Succs (2): B13 B14 // CHECK: [B0 (EXIT)] // CHECK: Preds (1): B1 -// CHECK: [B8 (ENTRY)] -// CHECK: Succs (1): B7 +// CHECK: [B9 (ENTRY)] +// CHECK: Succs (1): B8 // CHECK: [B1] -// CHECK: 1: ~A() (Temporary object destructor) -// CHECK: 2: int b; -// CHECK: 3: [B4.5].~A() (Implicit destructor) +// CHECK: 1: int b; +// CHECK: 2: [B5.5].~A() (Implicit destructor) // CHECK: Preds (2): B2 B3 // CHECK: Succs (1): B0 // CHECK: [B2] // CHECK: 1: ~A() (Temporary object destructor) -// CHECK: Preds (1): B4 +// CHECK: Preds (1): B3 // CHECK: Succs (1): B1 // CHECK: [B3] +// CHECK: T: (Temp Dtor) [B6.4] +// CHECK: Preds (2): B4 B5 +// CHECK: Succs (2): B2 B1 +// CHECK: [B4] // CHECK: 1: ~A() (Temporary object destructor) // CHECK: 2: ~A() (Temporary object destructor) -// CHECK: Preds (1): B4 -// CHECK: Succs (1): B1 -// CHECK: [B4] -// CHECK: 1: [B7.2] ?: [B6.6] -// CHECK: 2: [B4.1] (ImplicitCastExpr, NoOp, const class A) -// CHECK: 3: [B4.2] -// CHECK: 4: [B4.3] (CXXConstructExpr, class A) -// CHECK: 5: A a = A() ?: A(); -// CHECK: T: (Temp Dtor) [B7.5] ? ... : ... -// CHECK: Preds (2): B5 B6 -// CHECK: Succs (2): B2 B3 +// CHECK: Preds (1): B5 +// CHECK: Succs (1): B3 // CHECK: [B5] -// CHECK: 1: [B7.2] (ImplicitCastExpr, NoOp, const class A) -// CHECK: 2: [B5.1] -// CHECK: 3: [B5.2] (CXXConstructExpr, class A) -// CHECK: 4: [B5.3] (BindTemporary) -// CHECK: Preds (1): B7 -// CHECK: Succs (1): B4 +// CHECK: 1: [B8.2] ?: [B7.6] +// CHECK: 2: [B5.1] (ImplicitCastExpr, NoOp, const class A) +// CHECK: 3: [B5.2] +// CHECK: 4: [B5.3] (CXXConstructExpr, class A) +// CHECK: 5: A a = A() ?: A(); +// CHECK: T: (Temp Dtor) [B7.6] +// CHECK: Preds (2): B6 B7 +// CHECK: Succs (2): B4 B3 // CHECK: [B6] -// CHECK: 1: A() (CXXConstructExpr, class A) -// CHECK: 2: [B6.1] (BindTemporary) -// CHECK: 3: [B6.2] (ImplicitCastExpr, NoOp, const class A) -// CHECK: 4: [B6.3] -// CHECK: 5: [B6.4] (CXXConstructExpr, class A) -// CHECK: 6: [B6.5] (BindTemporary) -// CHECK: Preds (1): B7 -// CHECK: Succs (1): B4 +// CHECK: 1: [B8.2] (ImplicitCastExpr, NoOp, const class A) +// CHECK: 2: [B6.1] +// CHECK: 3: [B6.2] (CXXConstructExpr, class A) +// CHECK: 4: [B6.3] (BindTemporary) +// CHECK: Preds (1): B8 +// CHECK: Succs (1): B5 // CHECK: [B7] // CHECK: 1: A() (CXXConstructExpr, class A) // CHECK: 2: [B7.1] (BindTemporary) -// CHECK: 3: [B7.2].operator bool -// CHECK: 4: [B7.2] -// CHECK: 5: [B7.4] (ImplicitCastExpr, UserDefinedConversion, _Bool) -// CHECK: T: [B7.5] ? ... : ... +// CHECK: 3: [B7.2] (ImplicitCastExpr, NoOp, const class A) +// CHECK: 4: [B7.3] +// CHECK: 5: [B7.4] (CXXConstructExpr, class A) +// CHECK: 6: [B7.5] (BindTemporary) // CHECK: Preds (1): B8 -// CHECK: Succs (2): B5 B6 +// CHECK: Succs (1): B5 +// CHECK: [B8] +// CHECK: 1: A() (CXXConstructExpr, class A) +// CHECK: 2: [B8.1] (BindTemporary) +// CHECK: 3: [B8.2].operator bool +// CHECK: 4: [B8.2] +// CHECK: 5: [B8.4] (ImplicitCastExpr, UserDefinedConversion, _Bool) +// CHECK: T: [B8.5] ? ... : ... +// CHECK: Preds (1): B9 +// CHECK: Succs (2): B6 B7 // CHECK: [B0 (EXIT)] // CHECK: Preds (1): B1 -// CHECK: [B13 (ENTRY)] -// CHECK: Succs (1): B12 +// CHECK: [B16 (ENTRY)] +// CHECK: Succs (1): B15 // CHECK: [B1] -// CHECK: 1: ~A() (Temporary object destructor) -// CHECK: 2: int b; -// CHECK: 3: [B9.4].~A() (Implicit destructor) +// CHECK: 1: int b; +// CHECK: 2: [B12.4].~A() (Implicit destructor) // CHECK: Preds (2): B2 B3 // CHECK: Succs (1): B0 // CHECK: [B2] // CHECK: 1: ~A() (Temporary object destructor) -// CHECK: Preds (1): B4 +// CHECK: Preds (1): B3 // CHECK: Succs (1): B1 // CHECK: [B3] +// CHECK: T: (Temp Dtor) [B6.4] +// CHECK: Preds (2): B4 B5 +// CHECK: Succs (2): B2 B1 +// CHECK: [B4] // CHECK: 1: ~A() (Temporary object destructor) // CHECK: 2: ~A() (Temporary object destructor) -// CHECK: Preds (1): B4 -// CHECK: Succs (1): B1 -// CHECK: [B4] -// CHECK: 1: [B7.5] ?: [B6.6] -// CHECK: 2: [B4.1] (ImplicitCastExpr, NoOp, const class A) -// CHECK: 3: [B4.2] -// CHECK: 4: [B7.3]([B4.3]) -// CHECK: T: (Temp Dtor) [B7.8] ? ... : ... -// CHECK: Preds (2): B5 B6 -// CHECK: Succs (2): B2 B3 +// CHECK: Preds (1): B5 +// CHECK: Succs (1): B3 // CHECK: [B5] -// CHECK: 1: [B7.5] (ImplicitCastExpr, NoOp, const class A) -// CHECK: 2: [B5.1] -// CHECK: 3: [B5.2] (CXXConstructExpr, class A) -// CHECK: 4: [B5.3] (BindTemporary) -// CHECK: Preds (1): B7 -// CHECK: Succs (1): B4 +// CHECK: 1: [B8.4] ?: [B7.6] +// CHECK: 2: [B5.1] (ImplicitCastExpr, NoOp, const class A) +// CHECK: 3: [B5.2] +// CHECK: 4: [B8.2]([B5.3]) +// CHECK: T: (Temp Dtor) [B7.6] +// CHECK: Preds (2): B6 B7 +// CHECK: Succs (2): B4 B3 // CHECK: [B6] -// CHECK: 1: A() (CXXConstructExpr, class A) -// CHECK: 2: [B6.1] (BindTemporary) -// CHECK: 3: [B6.2] (ImplicitCastExpr, NoOp, const class A) -// CHECK: 4: [B6.3] -// CHECK: 5: [B6.4] (CXXConstructExpr, class A) -// CHECK: 6: [B6.5] (BindTemporary) -// CHECK: Preds (1): B7 -// CHECK: Succs (1): B4 +// CHECK: 1: [B8.4] (ImplicitCastExpr, NoOp, const class A) +// CHECK: 2: [B6.1] +// CHECK: 3: [B6.2] (CXXConstructExpr, class A) +// CHECK: 4: [B6.3] (BindTemporary) +// CHECK: Preds (1): B8 +// CHECK: Succs (1): B5 // CHECK: [B7] -// CHECK: 1: ~A() (Temporary object destructor) -// CHECK: 2: foo -// CHECK: 3: [B7.2] (ImplicitCastExpr, FunctionToPointerDecay, void (*)(const class A &)) -// CHECK: 4: A() (CXXConstructExpr, class A) -// CHECK: 5: [B7.4] (BindTemporary) -// CHECK: 6: [B7.5].operator bool -// CHECK: 7: [B7.5] -// CHECK: 8: [B7.7] (ImplicitCastExpr, UserDefinedConversion, _Bool) -// CHECK: T: [B7.8] ? ... : ... -// CHECK: Preds (2): B9 B8 -// CHECK: Succs (2): B5 B6 +// CHECK: 1: A() (CXXConstructExpr, class A) +// CHECK: 2: [B7.1] (BindTemporary) +// CHECK: 3: [B7.2] (ImplicitCastExpr, NoOp, const class A) +// CHECK: 4: [B7.3] +// CHECK: 5: [B7.4] (CXXConstructExpr, class A) +// CHECK: 6: [B7.5] (BindTemporary) +// CHECK: Preds (1): B8 +// CHECK: Succs (1): B5 // CHECK: [B8] -// CHECK: 1: ~A() (Temporary object destructor) -// CHECK: Preds (1): B9 -// CHECK: Succs (1): B7 +// CHECK: 1: foo +// CHECK: 2: [B8.1] (ImplicitCastExpr, FunctionToPointerDecay, void (*)(const class A &)) +// CHECK: 3: A() (CXXConstructExpr, class A) +// CHECK: 4: [B8.3] (BindTemporary) +// CHECK: 5: [B8.4].operator bool +// CHECK: 6: [B8.4] +// CHECK: 7: [B8.6] (ImplicitCastExpr, UserDefinedConversion, _Bool) +// CHECK: T: [B8.7] ? ... : ... +// CHECK: Preds (2): B9 B10 +// CHECK: Succs (2): B6 B7 // CHECK: [B9] -// CHECK: 1: [B12.2] ?: [B11.6] -// CHECK: 2: [B9.1] (ImplicitCastExpr, NoOp, const class A) -// CHECK: 3: [B9.2] -// CHECK: 4: const A &a = A() ?: A(); -// CHECK: T: (Temp Dtor) [B12.5] ? ... : ... -// CHECK: Preds (2): B10 B11 -// CHECK: Succs (2): B7 B8 +// CHECK: 1: ~A() (Temporary object destructor) +// CHECK: Preds (1): B10 +// CHECK: Succs (1): B8 // CHECK: [B10] -// CHECK: 1: [B12.2] (ImplicitCastExpr, NoOp, const class A) -// CHECK: 2: [B10.1] -// CHECK: 3: [B10.2] (CXXConstructExpr, class A) -// CHECK: 4: [B10.3] (BindTemporary) -// CHECK: Preds (1): B12 -// CHECK: Succs (1): B9 +// CHECK: T: (Temp Dtor) [B13.4] +// CHECK: Preds (2): B11 B12 +// CHECK: Succs (2): B9 B8 // CHECK: [B11] -// CHECK: 1: A() (CXXConstructExpr, class A) -// CHECK: 2: [B11.1] (BindTemporary) -// CHECK: 3: [B11.2] (ImplicitCastExpr, NoOp, const class A) -// CHECK: 4: [B11.3] -// CHECK: 5: [B11.4] (CXXConstructExpr, class A) -// CHECK: 6: [B11.5] (BindTemporary) +// CHECK: 1: ~A() (Temporary object destructor) +// CHECK: 2: ~A() (Temporary object destructor) // CHECK: Preds (1): B12 -// CHECK: Succs (1): B9 +// CHECK: Succs (1): B10 // CHECK: [B12] +// CHECK: 1: [B15.2] ?: [B14.6] +// CHECK: 2: [B12.1] (ImplicitCastExpr, NoOp, const class A) +// CHECK: 3: [B12.2] +// CHECK: 4: const A &a = A() ?: A(); +// CHECK: T: (Temp Dtor) [B14.6] +// CHECK: Preds (2): B13 B14 +// CHECK: Succs (2): B11 B10 +// CHECK: [B13] +// CHECK: 1: [B15.2] (ImplicitCastExpr, NoOp, const class A) +// CHECK: 2: [B13.1] +// CHECK: 3: [B13.2] (CXXConstructExpr, class A) +// CHECK: 4: [B13.3] (BindTemporary) +// CHECK: Preds (1): B15 +// CHECK: Succs (1): B12 +// CHECK: [B14] // CHECK: 1: A() (CXXConstructExpr, class A) -// CHECK: 2: [B12.1] (BindTemporary) -// CHECK: 3: [B12.2].operator bool -// CHECK: 4: [B12.2] -// CHECK: 5: [B12.4] (ImplicitCastExpr, UserDefinedConversion, _Bool) -// CHECK: T: [B12.5] ? ... : ... -// CHECK: Preds (1): B13 -// CHECK: Succs (2): B10 B11 +// CHECK: 2: [B14.1] (BindTemporary) +// CHECK: 3: [B14.2] (ImplicitCastExpr, NoOp, const class A) +// CHECK: 4: [B14.3] +// CHECK: 5: [B14.4] (CXXConstructExpr, class A) +// CHECK: 6: [B14.5] (BindTemporary) +// CHECK: Preds (1): B15 +// CHECK: Succs (1): B12 +// CHECK: [B15] +// CHECK: 1: A() (CXXConstructExpr, class A) +// CHECK: 2: [B15.1] (BindTemporary) +// CHECK: 3: [B15.2].operator bool +// CHECK: 4: [B15.2] +// CHECK: 5: [B15.4] (ImplicitCastExpr, UserDefinedConversion, _Bool) +// CHECK: T: [B15.5] ? ... : ... +// CHECK: Preds (1): B16 +// CHECK: Succs (2): B13 B14 // CHECK: [B0 (EXIT)] // CHECK: Preds (1): B1 // CHECK: [B2 (ENTRY)] @@ -1089,6 +1108,7 @@ // CHECK: Succs (1): B2 // CHECK: [B1] // CHECK: 1: int b; +// CHECK: Preds (1): B2(Unreachable) // CHECK: Succs (1): B0 // CHECK: [B2 (NORETURN)] // CHECK: 1: int a; @@ -1105,6 +1125,7 @@ // CHECK: Succs (1): B2 // CHECK: [B1] // CHECK: 1: int b; +// CHECK: Preds (1): B2(Unreachable) // CHECK: Succs (1): B0 // CHECK: [B2 (NORETURN)] // CHECK: 1: int a; @@ -1117,7 +1138,6 @@ // CHECK: Succs (1): B0 // CHECK: [B0 (EXIT)] // CHECK: Preds (2): B1 B2 -// CHECK: int testConsistencyNestedSimple(bool value) // CHECK: [B9 (ENTRY)] // CHECK: Succs (1): B8 // CHECK: [B1] @@ -1132,7 +1152,7 @@ // CHECK: Succs (1): B0 // CHECK: [B3] // CHECK: T: if [B5.1] -// CHECK: Preds (1): B5 +// CHECK: Preds (2): B4(Unreachable) B5 // CHECK: Succs (2): B2 B1 // CHECK: [B4 (NORETURN)] // CHECK: 1: ~NoReturn() (Temporary object destructor) @@ -1140,9 +1160,9 @@ // CHECK: Succs (1): B0 // CHECK: [B5] // CHECK: 1: [B7.3] || [B6.7] -// CHECK: T: (Temp Dtor) [B7.3] || ... +// CHECK: T: (Temp Dtor) [B6.4] // CHECK: Preds (2): B6 B7 -// CHECK: Succs (2): B3 B4 +// CHECK: Succs (2): B4 B3 // CHECK: [B6] // CHECK: 1: check // CHECK: 2: [B6.1] (ImplicitCastExpr, FunctionToPointerDecay, _Bool (*)(const class NoReturn &)) @@ -1168,7 +1188,6 @@ // CHECK: Succs (2): B7 B1 // CHECK: [B0 (EXIT)] // CHECK: Preds (3): B1 B2 B4 -// CHECK: int testConsistencyNestedComplex(bool value) // CHECK: [B10 (ENTRY)] // CHECK: Succs (1): B9 // CHECK: [B1] @@ -1183,7 +1202,7 @@ // CHECK: Succs (1): B0 // CHECK: [B3] // CHECK: T: if [B5.1] -// CHECK: Preds (1): B5 +// CHECK: Preds (2): B4(Unreachable) B5 // CHECK: Succs (2): B2 B1 // CHECK: [B4 (NORETURN)] // CHECK: 1: ~NoReturn() (Temporary object destructor) @@ -1191,9 +1210,9 @@ // CHECK: Succs (1): B0 // CHECK: [B5] // CHECK: 1: [B8.3] || [B7.3] || [B6.7] -// CHECK: T: (Temp Dtor) [B8.3] || [B7.3] || ... +// CHECK: T: (Temp Dtor) [B6.4] // CHECK: Preds (3): B6 B7 B8 -// CHECK: Succs (2): B3 B4 +// CHECK: Succs (2): B4 B3 // CHECK: [B6] // CHECK: 1: check // CHECK: 2: [B6.1] (ImplicitCastExpr, FunctionToPointerDecay, _Bool (*)(const class NoReturn &)) @@ -1226,7 +1245,6 @@ // CHECK: Succs (2): B8 B1 // CHECK: [B0 (EXIT)] // CHECK: Preds (3): B1 B2 B4 -// CHECK: int testConsistencyNestedNormalReturn(bool value) // CHECK: [B10 (ENTRY)] // CHECK: Succs (1): B9 // CHECK: [B1] @@ -1241,7 +1259,7 @@ // CHECK: Succs (1): B0 // CHECK: [B3] // CHECK: T: if [B5.1] -// CHECK: Preds (1): B5 +// CHECK: Preds (2): B4(Unreachable) B5 // CHECK: Succs (2): B2 B1 // CHECK: [B4 (NORETURN)] // CHECK: 1: ~NoReturn() (Temporary object destructor) @@ -1249,9 +1267,9 @@ // CHECK: Succs (1): B0 // CHECK: [B5] // CHECK: 1: [B8.3] || [B7.2] || [B6.7] -// CHECK: T: (Temp Dtor) [B8.3] || [B7.2] || ... +// CHECK: T: (Temp Dtor) [B6.4] // CHECK: Preds (3): B6 B7 B8 -// CHECK: Succs (2): B3 B4 +// CHECK: Succs (2): B4 B3 // CHECK: [B6] // CHECK: 1: check // CHECK: 2: [B6.1] (ImplicitCastExpr, FunctionToPointerDecay, _Bool (*)(const class NoReturn &)) @@ -1283,3 +1301,4 @@ // CHECK: Succs (2): B8 B1 // CHECK: [B0 (EXIT)] // CHECK: Preds (3): B1 B2 B4 + Index: test/Analysis/temporaries.cpp =================================================================== --- test/Analysis/temporaries.cpp +++ test/Analysis/temporaries.cpp @@ -3,6 +3,7 @@ // RUN: %clang_cc1 -analyze -analyzer-checker=core,debug.ExprInspection -DTEMPORARY_DTORS -verify -w -analyzer-config cfg-temporary-dtors=true %s extern bool clang_analyzer_eval(bool); +extern bool clang_analyzer_warnIfReached(); struct Trivial { Trivial(int x) : value(x) {} @@ -111,13 +112,13 @@ } namespace destructors { - void testPR16664andPR18159Crash() { - struct Dtor { - ~Dtor(); - }; - extern bool coin(); - extern bool check(const Dtor &); + struct Dtor { + ~Dtor(); + }; + extern bool coin(); + extern bool check(const Dtor &); + void testPR16664andPR18159Crash() { // Regression test: we used to assert here when tmp dtors are enabled. // PR16664 and PR18159 if (coin() && (coin() || coin() || check(Dtor()))) { @@ -193,8 +194,7 @@ (i == 4 || i == 4 || compute(i == 5 && (i == 4 || check(NoReturnDtor()))))) || i != 4) { - // FIXME: This shouldn't cause a warning. - clang_analyzer_eval(true); // expected-warning{{TRUE}} + clang_analyzer_eval(true); // no warning, unreachable code } } @@ -211,8 +211,7 @@ void testConsistencyNestedComplex(bool value) { if (value) { if (!value || !value || check(NoReturnDtor())) { - // FIXME: This shouldn't cause a warning. - clang_analyzer_eval(true); // expected-warning{{TRUE}} + clang_analyzer_eval(true); // no warning, unreachable code } } } @@ -225,6 +224,79 @@ } } } + // PR16664 and PR18159 + void testConsistencyNestedComplexMidBranch(bool value) { + if (value) { + if (!value || !value || check(NoReturnDtor()) || value) { + clang_analyzer_eval(true); // no warning, unreachable code + } + } + } + + // PR16664 and PR18159 + void testConsistencyNestedComplexNestedBranch(bool value) { + if (value) { + if (!value || (!value || check(NoReturnDtor()) || value)) { + clang_analyzer_eval(true); // no warning, unreachable code + } + } + } + + // PR16664 and PR18159 + void testConsistencyNestedVariableModification(bool value) { + bool other = true; + if (value) { + if (!other || !value || (other = false) || check(NoReturnDtor()) || + !other) { + clang_analyzer_eval(true); // no warning, unreachable code + } + } + } + + void testTernaryNoReturnTrueBranch(bool value) { + if (value) { + bool b = value && value ? check(NoReturnDtor()) : true; + clang_analyzer_eval(true); // no warning, unreachable code + } + } + void testTernaryNoReturnFalseBranch(bool value) { + if (value) { + bool b = !value && !value ? true : check(NoReturnDtor()); + clang_analyzer_eval(true); // no warning, unreachable code + } + } + void testTernaryIgnoreNoreturnBranch(bool value) { + if (value) { + bool b = !value && !value ? check(NoReturnDtor()) : true; + clang_analyzer_eval(true); // expected-warning{{TRUE}} + } + } + + void testLoop() { + for (int i = 0; i < 10; ++i) { + if (i < 3 && (i >= 2 || check(NoReturnDtor()))) { + clang_analyzer_eval(true); // no warning, unreachable code + } + } + } + + bool testRecursiveFrames(bool isInner) { + if (isInner || check(NoReturnDtor()) || testRecursiveFrames(true)) { + clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} + } + } + void testRecursiveFramesStart() { testRecursiveFrames(false); } + + void testMultipleTemporaries(bool value) { + if (value) { + // FIXME: Find a way to verify construction order. + // ~Dtor should run before ~NoReturnDtor() because construction order is + // guaranteed by comma operator. + if (!value || check((NoReturnDtor(), Dtor())) || value) { + clang_analyzer_eval(true); // no warning, unreachable code + } + } + } void testBinaryOperatorShortcut(bool value) { if (value) { @@ -234,6 +306,32 @@ } } + void testIfAtEndOfLoop() { + int y = 0; + while (true) { + if (y > 0) { + clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} + } + ++y; + // Test that the CFG gets hooked up correctly when temporary destructors + // are handled after a statically known branch condition. + if (true) (void)0; else (void)check(NoReturnDtor()); + } + } + + void testTernaryAtEndOfLoop() { + int y = 0; + while (true) { + if (y > 0) { + clang_analyzer_warnIfReached(); // expected-warning{{REACHABLE}} + } + ++y; + // Test that the CFG gets hooked up correctly when temporary destructors + // are handled after a statically known branch condition. + true ? (void)0 : (void)check(NoReturnDtor()); + } + } + #endif // TEMPORARY_DTORS }