[analyzer] Refactor conditional expression evaluating code
Summary: Instead of digging through the ExplodedGraph, to figure out which edge brought us here, I compute the value of conditional expression by looking at the sub-expression values. To do this, I needed to change the liveness algorithm a bit -- now, the full conditional expression also depends on all atomic sub-expressions, not only the outermost ones. Reviewers: jordan_rose CC: cfe-commits Differential Revision: http://llvm-reviews.chandlerc.com/D1340 llvm-svn: 189090
This commit is contained in:
@@ -212,6 +212,8 @@ class TransferFunctions : public StmtVisitor<TransferFunctions> {
|
||||
LiveVariables::LivenessValues &val;
|
||||
LiveVariables::Observer *observer;
|
||||
const CFGBlock *currentBlock;
|
||||
|
||||
void markLogicalExprLeaves(const Expr *E);
|
||||
public:
|
||||
TransferFunctions(LiveVariablesImpl &im,
|
||||
LiveVariables::LivenessValues &Val,
|
||||
@@ -368,9 +370,25 @@ void TransferFunctions::VisitBinaryOperator(BinaryOperator *B) {
|
||||
if (observer)
|
||||
observer->observerKill(DR);
|
||||
}
|
||||
} else if (B->isLogicalOp()) {
|
||||
// Leaf expressions in the logical operator tree are live until we reach the
|
||||
// outermost logical operator. Static analyzer relies on this behaviour.
|
||||
markLogicalExprLeaves(B->getLHS()->IgnoreParens());
|
||||
markLogicalExprLeaves(B->getRHS()->IgnoreParens());
|
||||
}
|
||||
}
|
||||
|
||||
void TransferFunctions::markLogicalExprLeaves(const Expr *E) {
|
||||
const BinaryOperator *B = dyn_cast<BinaryOperator>(E);
|
||||
if (!B || !B->isLogicalOp()) {
|
||||
val.liveStmts = LV.SSetFact.add(val.liveStmts, E);
|
||||
return;
|
||||
}
|
||||
|
||||
markLogicalExprLeaves(B->getLHS()->IgnoreParens());
|
||||
markLogicalExprLeaves(B->getRHS()->IgnoreParens());
|
||||
}
|
||||
|
||||
void TransferFunctions::VisitBlockExpr(BlockExpr *BE) {
|
||||
AnalysisDeclContext::referenced_decls_iterator I, E;
|
||||
llvm::tie(I, E) =
|
||||
|
||||
Reference in New Issue
Block a user