Started partitioning of transfer function logic (and thus the policy behind
these operations) into GRTransferFuncs and its subclasses. Originally all
of this logic was handled by the class RValue, but in reality different
analyses will want more flexibility on how they evaluate different values.
Transfer functions migrated so far: "Cast"
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@47125 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/Analysis/GRExprEngine.cpp b/Analysis/GRExprEngine.cpp
index 16abcc4..3ff4c4b 100644
--- a/Analysis/GRExprEngine.cpp
+++ b/Analysis/GRExprEngine.cpp
@@ -18,6 +18,9 @@
#include "ValueState.h"
#include "clang/Analysis/PathSensitive/GRCoreEngine.h"
+#include "clang/Analysis/PathSensitive/GRTransferFuncs.h"
+#include "GRSimpleVals.h"
+
#include "clang/AST/Expr.h"
#include "clang/AST/ASTContext.h"
#include "clang/Analysis/Analyses/LiveVariables.h"
@@ -73,7 +76,6 @@
typedef GRIndirectGotoNodeBuilder<GRExprEngine> IndirectGotoNodeBuilder;
typedef GRSwitchNodeBuilder<GRExprEngine> SwitchNodeBuilder;
-
class NodeSet {
typedef llvm::SmallVector<NodeTy*,3> ImplTy;
ImplTy Impl;
@@ -115,6 +117,10 @@
/// ValueMgr - Object that manages the data for all created RValues.
ValueManager& ValMgr;
+ /// TF - Object that represents a bundle of transfer functions
+ /// for manipulating and creating RValues.
+ GRTransferFuncs& TF;
+
/// SymMgr - Object that manages the symbol information.
SymbolManager& SymMgr;
@@ -139,10 +145,12 @@
bool StateCleaned;
public:
- GRExprEngine(GraphTy& g) : G(g), Liveness(G.getCFG(), G.getFunctionDecl()),
+ GRExprEngine(GraphTy& g) :
+ G(g), Liveness(G.getCFG(), G.getFunctionDecl()),
Builder(NULL),
StateMgr(G.getContext(), G.getAllocator()),
ValMgr(StateMgr.getValueManager()),
+ TF(*(new GRSimpleVals())), // FIXME.
SymMgr(StateMgr.getSymbolManager()),
StmtEntryNode(NULL), CurrentStmt(NULL) {
@@ -312,6 +320,11 @@
/// VisitUnaryOperator - Transfer function logic for unary operators.
void VisitUnaryOperator(UnaryOperator* B, NodeTy* Pred, NodeSet& Dst);
+
+ inline RValue EvalCast(ValueManager& ValMgr, RValue R, Expr* CastExpr) {
+ return TF.EvalCast(ValMgr, R, CastExpr);
+ }
+
};
} // end anonymous namespace
@@ -702,7 +715,7 @@
NodeTy* N = *I1;
StateTy St = N->getState();
const RValue& V = GetValue(St, E);
- Nodify(Dst, CastE, N, SetValue(St, CastE, V.EvalCast(ValMgr, CastE)));
+ Nodify(Dst, CastE, N, SetValue(St, CastE, EvalCast(ValMgr, V, CastE)));
}
}
@@ -1511,10 +1524,13 @@
Diagnostic& Diag) {
GRCoreEngine<GRExprEngine> Engine(cfg, FD, Ctx);
+ GRExprEngine* CheckerState = &Engine.getCheckerState();
+
+ // Execute the worklist algorithm.
Engine.ExecuteWorkList();
// Look for explicit-Null dereferences and warn about them.
- GRExprEngine* CheckerState = &Engine.getCheckerState();
+
for (GRExprEngine::null_iterator I=CheckerState->null_begin(),
E=CheckerState->null_end(); I!=E; ++I) {