From c8f9454fb468fdef89e0056322ef6e18fc7cd1c2 Mon Sep 17 00:00:00 2001 From: Manuel Klimek Date: Thu, 7 Aug 2014 16:05:51 +0000 Subject: Model temporary destructors from logical operators with known values. If the truth value of a LHS is known, we can build the knowledge whether a temporary destructor is executed or not into the CFG. This is needed by the return type analysis. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@215118 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Analysis/CFG.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'lib/Analysis') diff --git a/lib/Analysis/CFG.cpp b/lib/Analysis/CFG.cpp index b9698d550b..96571fdbec 100644 --- a/lib/Analysis/CFG.cpp +++ b/lib/Analysis/CFG.cpp @@ -3631,12 +3631,23 @@ CFGBlock *CFGBuilder::VisitBinaryOperatorForTemporaryDtors( BinaryOperator *E, TempDtorContext &Context) { if (E->isLogicalOp()) { VisitForTemporaryDtors(E->getLHS(), false, Context); - // 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. + TryResult LHSVal = tryEvaluateBool(E->getLHS()); + bool RHSNotExecuted = (E->getOpcode() == BO_LAnd && LHSVal.isFalse()) || + (E->getOpcode() == BO_LOr && LHSVal.isTrue()); + if (RHSNotExecuted) { + return Block; + } + TempDtorContext RHSContext(/*IsConditional=*/true); VisitForTemporaryDtors(E->getRHS(), false, RHSContext); - InsertTempDtorDecisionBlock(RHSContext); + + // If the LHS is known, and the RHS is not executed, we returned above. + // Thus, once we arrive here, and the LHS is known, we also know that the + // RHS was executed and can execute the RHS unconditionally (that is, we + // don't insert a decision block). + if (!LHSVal.isKnown()) + InsertTempDtorDecisionBlock(RHSContext); + return Block; } -- cgit v1.2.3