summaryrefslogtreecommitdiffstats
path: root/clang/lib/Analysis/CFG.cpp
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2014-08-07 16:05:51 +0000
committerManuel Klimek <klimek@google.com>2014-08-07 16:05:51 +0000
commit7c03013c8b595d0c12ef1cc01f6b77918bc637df (patch)
treeabb7cd0f65b17b7ed9f55e7b41e6c9ea9eb23d45 /clang/lib/Analysis/CFG.cpp
parenta3ddbc9d23e48d99a9392ac33f63ca1553314917 (diff)
downloadbcm5719-llvm-7c03013c8b595d0c12ef1cc01f6b77918bc637df.tar.gz
bcm5719-llvm-7c03013c8b595d0c12ef1cc01f6b77918bc637df.zip
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. llvm-svn: 215118
Diffstat (limited to 'clang/lib/Analysis/CFG.cpp')
-rw-r--r--clang/lib/Analysis/CFG.cpp19
1 files changed, 15 insertions, 4 deletions
diff --git a/clang/lib/Analysis/CFG.cpp b/clang/lib/Analysis/CFG.cpp
index b9698d550bf..96571fdbecd 100644
--- a/clang/lib/Analysis/CFG.cpp
+++ b/clang/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;
}
OpenPOWER on IntegriCloud