blob: c1200917d953c846f4e5d12a327356badb6da5b3 [file] [log] [blame]
Ted Kremenekd27f8162008-01-15 23:55:06 +00001//===-- GRConstants.cpp - Simple, Path-Sens. Constant Prop. ------*- C++ -*-==//
Ted Kremenek64924852008-01-31 02:35:41 +00002//
Ted Kremenek4af84312008-01-31 06:49:09 +00003// The LLVM Compiler Infrastructure
Ted Kremenekd27f8162008-01-15 23:55:06 +00004//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// Constant Propagation via Graph Reachability
11//
12// This files defines a simple analysis that performs path-sensitive
13// constant propagation within a function. An example use of this analysis
14// is to perform simple checks for NULL dereferences.
15//
16//===----------------------------------------------------------------------===//
17
Ted Kremeneka90ccfe2008-01-31 19:34:24 +000018#include "RValues.h"
19#include "ValueState.h"
20
Ted Kremenekd27f8162008-01-15 23:55:06 +000021#include "clang/Analysis/PathSensitive/GREngine.h"
22#include "clang/AST/Expr.h"
Ted Kremenek874d63f2008-01-24 02:02:54 +000023#include "clang/AST/ASTContext.h"
Ted Kremenekd27f8162008-01-15 23:55:06 +000024#include "clang/Analysis/Analyses/LiveVariables.h"
Ted Kremenekd27f8162008-01-15 23:55:06 +000025
26#include "llvm/Support/Casting.h"
27#include "llvm/Support/DataTypes.h"
28#include "llvm/ADT/APSInt.h"
29#include "llvm/ADT/FoldingSet.h"
30#include "llvm/ADT/ImmutableMap.h"
Ted Kremenek3c6c6722008-01-16 17:56:25 +000031#include "llvm/ADT/SmallVector.h"
Ted Kremenekb38911f2008-01-30 23:03:39 +000032#include "llvm/ADT/SmallPtrSet.h"
Ted Kremenekab2b8c52008-01-23 19:59:44 +000033#include "llvm/Support/Allocator.h"
Ted Kremenekd27f8162008-01-15 23:55:06 +000034#include "llvm/Support/Compiler.h"
Ted Kremenekab2b8c52008-01-23 19:59:44 +000035#include "llvm/Support/Streams.h"
36
Ted Kremenek5ee4ff82008-01-25 22:55:56 +000037#include <functional>
38
Ted Kremenekaa66a322008-01-16 21:46:15 +000039#ifndef NDEBUG
40#include "llvm/Support/GraphWriter.h"
41#include <sstream>
42#endif
43
Ted Kremenekd27f8162008-01-15 23:55:06 +000044using namespace clang;
Ted Kremenekd27f8162008-01-15 23:55:06 +000045using llvm::dyn_cast;
46using llvm::cast;
Ted Kremenek5ee4ff82008-01-25 22:55:56 +000047using llvm::APSInt;
Ted Kremenekd27f8162008-01-15 23:55:06 +000048
49//===----------------------------------------------------------------------===//
Ted Kremenekbd03f1d2008-01-28 22:09:13 +000050// The Checker.
Ted Kremenekb38911f2008-01-30 23:03:39 +000051//
52// FIXME: This checker logic should be eventually broken into two components.
53// The first is the "meta"-level checking logic; the code that
54// does the Stmt visitation, fetching values from the map, etc.
55// The second part does the actual state manipulation. This way we
56// get more of a separate of concerns of these two pieces, with the
57// latter potentially being refactored back into the main checking
58// logic.
Ted Kremenekd27f8162008-01-15 23:55:06 +000059//===----------------------------------------------------------------------===//
60
61namespace {
Ted Kremenekd27f8162008-01-15 23:55:06 +000062
Ted Kremenekab2b8c52008-01-23 19:59:44 +000063class VISIBILITY_HIDDEN GRConstants {
Ted Kremenekd27f8162008-01-15 23:55:06 +000064
65public:
Ted Kremeneke070a1d2008-02-04 21:59:01 +000066 typedef ValueStateManager::StateTy StateTy;
Ted Kremenek7d7fe6d2008-01-29 22:56:11 +000067 typedef GRStmtNodeBuilder<GRConstants> StmtNodeBuilder;
68 typedef GRBranchNodeBuilder<GRConstants> BranchNodeBuilder;
Ted Kremenekcb48b9c2008-01-29 00:33:40 +000069 typedef ExplodedGraph<GRConstants> GraphTy;
70 typedef GraphTy::NodeTy NodeTy;
Ted Kremenekab2b8c52008-01-23 19:59:44 +000071
72 class NodeSet {
73 typedef llvm::SmallVector<NodeTy*,3> ImplTy;
74 ImplTy Impl;
75 public:
76
77 NodeSet() {}
Ted Kremenekb38911f2008-01-30 23:03:39 +000078 NodeSet(NodeTy* N) { assert (N && !N->isSink()); Impl.push_back(N); }
Ted Kremenekab2b8c52008-01-23 19:59:44 +000079
Ted Kremenekb38911f2008-01-30 23:03:39 +000080 void Add(NodeTy* N) { if (N && !N->isSink()) Impl.push_back(N); }
Ted Kremenekab2b8c52008-01-23 19:59:44 +000081
82 typedef ImplTy::iterator iterator;
83 typedef ImplTy::const_iterator const_iterator;
84
85 unsigned size() const { return Impl.size(); }
Ted Kremenek9de04c42008-01-24 20:55:43 +000086 bool empty() const { return Impl.empty(); }
Ted Kremenekab2b8c52008-01-23 19:59:44 +000087
88 iterator begin() { return Impl.begin(); }
89 iterator end() { return Impl.end(); }
90
91 const_iterator begin() const { return Impl.begin(); }
92 const_iterator end() const { return Impl.end(); }
93 };
Ted Kremenekd27f8162008-01-15 23:55:06 +000094
95protected:
Ted Kremenekcb48b9c2008-01-29 00:33:40 +000096 /// G - the simulation graph.
97 GraphTy& G;
98
Ted Kremenekab2b8c52008-01-23 19:59:44 +000099 /// Liveness - live-variables information the ValueDecl* and block-level
100 /// Expr* in the CFG. Used to prune out dead state.
Ted Kremenekbffaa832008-01-29 05:13:23 +0000101 LiveVariables Liveness;
Ted Kremenekd27f8162008-01-15 23:55:06 +0000102
Ted Kremenekf4b7a692008-01-29 22:11:49 +0000103 /// Builder - The current GRStmtNodeBuilder which is used when building the nodes
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000104 /// for a given statement.
Ted Kremenek7d7fe6d2008-01-29 22:56:11 +0000105 StmtNodeBuilder* Builder;
106
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000107 /// StateMgr - Object that manages the data for all created states.
Ted Kremeneke070a1d2008-02-04 21:59:01 +0000108 ValueStateManager StateMgr;
Ted Kremenekd27f8162008-01-15 23:55:06 +0000109
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000110 /// ValueMgr - Object that manages the data for all created RValues.
Ted Kremeneke070a1d2008-02-04 21:59:01 +0000111 ValueManager& ValMgr;
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000112
Ted Kremenek68fd2572008-01-29 17:27:31 +0000113 /// SymMgr - Object that manages the symbol information.
Ted Kremeneke070a1d2008-02-04 21:59:01 +0000114 SymbolManager& SymMgr;
Ted Kremenek68fd2572008-01-29 17:27:31 +0000115
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000116 /// StmtEntryNode - The immediate predecessor node.
117 NodeTy* StmtEntryNode;
118
119 /// CurrentStmt - The current block-level statement.
120 Stmt* CurrentStmt;
121
Ted Kremenekb38911f2008-01-30 23:03:39 +0000122 /// UninitBranches - Nodes in the ExplodedGraph that result from
123 /// taking a branch based on an uninitialized value.
124 typedef llvm::SmallPtrSet<NodeTy*,5> UninitBranchesTy;
125 UninitBranchesTy UninitBranches;
126
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000127 bool StateCleaned;
Ted Kremenekd27f8162008-01-15 23:55:06 +0000128
Ted Kremenekcb48b9c2008-01-29 00:33:40 +0000129 ASTContext& getContext() const { return G.getContext(); }
Ted Kremenek7b8009a2008-01-24 02:28:56 +0000130
Ted Kremenekd27f8162008-01-15 23:55:06 +0000131public:
Ted Kremenekbffaa832008-01-29 05:13:23 +0000132 GRConstants(GraphTy& g) : G(g), Liveness(G.getCFG(), G.getFunctionDecl()),
Ted Kremeneke070a1d2008-02-04 21:59:01 +0000133 Builder(NULL),
134 StateMgr(G.getContext()),
135 ValMgr(StateMgr.getValueManager()),
136 SymMgr(StateMgr.getSymbolManager()),
137 StmtEntryNode(NULL), CurrentStmt(NULL) {
Ted Kremenekd27f8162008-01-15 23:55:06 +0000138
Ted Kremenekcb48b9c2008-01-29 00:33:40 +0000139 // Compute liveness information.
Ted Kremenekbffaa832008-01-29 05:13:23 +0000140 Liveness.runOnCFG(G.getCFG());
141 Liveness.runOnAllBlocks(G.getCFG(), NULL, true);
Ted Kremenekd27f8162008-01-15 23:55:06 +0000142 }
Ted Kremenekcb48b9c2008-01-29 00:33:40 +0000143
144 /// getCFG - Returns the CFG associated with this analysis.
145 CFG& getCFG() { return G.getCFG(); }
Ted Kremenekd27f8162008-01-15 23:55:06 +0000146
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000147 /// getInitialState - Return the initial state used for the root vertex
148 /// in the ExplodedGraph.
Ted Kremenekd27f8162008-01-15 23:55:06 +0000149 StateTy getInitialState() {
Ted Kremeneke070a1d2008-02-04 21:59:01 +0000150 StateTy St = StateMgr.getInitialState();
Ted Kremenekff6e3c52008-01-29 00:43:03 +0000151
152 // Iterate the parameters.
153 FunctionDecl& F = G.getFunctionDecl();
154
155 for (FunctionDecl::param_iterator I=F.param_begin(), E=F.param_end();
Ted Kremenek4150abf2008-01-31 00:09:56 +0000156 I!=E; ++I)
157 St = SetValue(St, LValueDecl(*I), RValue::GetSymbolValue(SymMgr, *I));
Ted Kremenekff6e3c52008-01-29 00:43:03 +0000158
Ted Kremenekcb48b9c2008-01-29 00:33:40 +0000159 return St;
Ted Kremenekd27f8162008-01-15 23:55:06 +0000160 }
Ted Kremenek3b4f6702008-01-30 23:24:39 +0000161
162 bool isUninitControlFlow(const NodeTy* N) const {
163 return N->isSink() && UninitBranches.count(const_cast<NodeTy*>(N)) != 0;
164 }
Ted Kremenekd27f8162008-01-15 23:55:06 +0000165
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000166 /// ProcessStmt - Called by GREngine. Used to generate new successor
167 /// nodes by processing the 'effects' of a block-level statement.
Ted Kremenek7d7fe6d2008-01-29 22:56:11 +0000168 void ProcessStmt(Stmt* S, StmtNodeBuilder& builder);
169
170 /// ProcessBranch - Called by GREngine. Used to generate successor
171 /// nodes by processing the 'effects' of a branch condition.
Ted Kremenek71c29bd2008-01-29 23:32:35 +0000172 void ProcessBranch(Stmt* Condition, Stmt* Term, BranchNodeBuilder& builder);
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000173
174 /// RemoveDeadBindings - Return a new state that is the same as 'M' except
175 /// that all subexpression mappings are removed and that any
176 /// block-level expressions that are not live at 'S' also have their
177 /// mappings removed.
178 StateTy RemoveDeadBindings(Stmt* S, StateTy M);
179
Ted Kremeneke070a1d2008-02-04 21:59:01 +0000180 StateTy SetValue(StateTy St, Stmt* S, const RValue& V);
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000181
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000182 StateTy SetValue(StateTy St, const Stmt* S, const RValue& V) {
Ted Kremenek9de04c42008-01-24 20:55:43 +0000183 return SetValue(St, const_cast<Stmt*>(S), V);
184 }
185
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000186 StateTy SetValue(StateTy St, const LValue& LV, const RValue& V);
Ted Kremenek1ccd31c2008-01-16 19:42:59 +0000187
Ted Kremeneke070a1d2008-02-04 21:59:01 +0000188 inline RValue GetValue(const StateTy& St, Stmt* S) {
189 return StateMgr.GetValue(St, S);
190 }
191
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000192 inline RValue GetValue(const StateTy& St, const Stmt* S) {
Ted Kremenek9de04c42008-01-24 20:55:43 +0000193 return GetValue(St, const_cast<Stmt*>(S));
194 }
195
Ted Kremeneke070a1d2008-02-04 21:59:01 +0000196 inline RValue GetValue(const StateTy& St, const LValue& LV) {
197 return StateMgr.GetValue(St, LV);
198 }
199
200 inline LValue GetLValue(const StateTy& St, Stmt* S) {
201 return StateMgr.GetLValue(St, S);
202 }
Ted Kremenekb38911f2008-01-30 23:03:39 +0000203
204 /// Assume - Create new state by assuming that a given expression
205 /// is true or false.
206 inline StateTy Assume(StateTy St, RValue Cond, bool Assumption,
207 bool& isFeasible) {
208 if (isa<LValue>(Cond))
209 return Assume(St, cast<LValue>(Cond), Assumption, isFeasible);
210 else
211 return Assume(St, cast<NonLValue>(Cond), Assumption, isFeasible);
212 }
213
214 StateTy Assume(StateTy St, LValue Cond, bool Assumption, bool& isFeasible);
215 StateTy Assume(StateTy St, NonLValue Cond, bool Assumption, bool& isFeasible);
Ted Kremenekd27f8162008-01-15 23:55:06 +0000216
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000217 void Nodify(NodeSet& Dst, Stmt* S, NodeTy* Pred, StateTy St);
Ted Kremenekd27f8162008-01-15 23:55:06 +0000218
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000219 /// Visit - Transfer function logic for all statements. Dispatches to
220 /// other functions that handle specific kinds of statements.
221 void Visit(Stmt* S, NodeTy* Pred, NodeSet& Dst);
Ted Kremenek874d63f2008-01-24 02:02:54 +0000222
223 /// VisitCast - Transfer function logic for all casts (implicit and explicit).
224 void VisitCast(Expr* CastE, Expr* E, NodeTy* Pred, NodeSet& Dst);
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000225
Ted Kremenek7b8009a2008-01-24 02:28:56 +0000226 /// VisitUnaryOperator - Transfer function logic for unary operators.
227 void VisitUnaryOperator(UnaryOperator* B, NodeTy* Pred, NodeSet& Dst);
228
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000229 /// VisitBinaryOperator - Transfer function logic for binary operators.
Ted Kremenek9de04c42008-01-24 20:55:43 +0000230 void VisitBinaryOperator(BinaryOperator* B, NodeTy* Pred, NodeSet& Dst);
231
232 /// VisitDeclStmt - Transfer function logic for DeclStmts.
233 void VisitDeclStmt(DeclStmt* DS, NodeTy* Pred, NodeSet& Dst);
Ted Kremenekd27f8162008-01-15 23:55:06 +0000234};
235} // end anonymous namespace
236
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000237
Ted Kremeneke070a1d2008-02-04 21:59:01 +0000238GRConstants::StateTy
239GRConstants::SetValue(StateTy St, Stmt* S, const RValue& V) {
240
241 if (!StateCleaned) {
242 St = RemoveDeadBindings(CurrentStmt, St);
243 StateCleaned = true;
244 }
245
246 bool isBlkExpr = false;
247
248 if (S == CurrentStmt) {
249 isBlkExpr = getCFG().isBlkExpr(S);
250
251 if (!isBlkExpr)
252 return St;
253 }
254
255 return StateMgr.SetValue(St, S, isBlkExpr, V);
256}
257
258GRConstants::StateTy
259GRConstants::SetValue(StateTy St, const LValue& LV, const RValue& V) {
260
261 if (!LV.isValid())
262 return St;
263
264 if (!StateCleaned) {
265 St = RemoveDeadBindings(CurrentStmt, St);
266 StateCleaned = true;
267 }
268
269 return StateMgr.SetValue(St, LV, V);
270}
271
Ted Kremenek71c29bd2008-01-29 23:32:35 +0000272void GRConstants::ProcessBranch(Stmt* Condition, Stmt* Term,
273 BranchNodeBuilder& builder) {
Ted Kremenekb38911f2008-01-30 23:03:39 +0000274
275 StateTy PrevState = builder.getState();
Ted Kremenek71c29bd2008-01-29 23:32:35 +0000276
Ted Kremenekb38911f2008-01-30 23:03:39 +0000277 // Remove old bindings for subexpressions.
278 for (StateTy::iterator I=PrevState.begin(), E=PrevState.end(); I!=E; ++I)
279 if (I.getKey().isSubExpr())
280 PrevState = StateMgr.Remove(PrevState, I.getKey());
Ted Kremenek71c29bd2008-01-29 23:32:35 +0000281
Ted Kremenekb38911f2008-01-30 23:03:39 +0000282 RValue V = GetValue(PrevState, Condition);
283
284 switch (V.getBaseKind()) {
285 default:
286 break;
287
288 case RValue::InvalidKind:
289 builder.generateNode(PrevState, true);
290 builder.generateNode(PrevState, false);
291 return;
292
293 case RValue::UninitializedKind: {
294 NodeTy* N = builder.generateNode(PrevState, true);
295
296 if (N) {
297 N->markAsSink();
298 UninitBranches.insert(N);
299 }
300
301 builder.markInfeasible(false);
302 return;
303 }
304 }
305
306 // Process the true branch.
307 bool isFeasible = true;
308 StateTy St = Assume(PrevState, V, true, isFeasible);
309
310 if (isFeasible) builder.generateNode(St, true);
311 else {
312 builder.markInfeasible(true);
313 isFeasible = true;
314 }
315
316 // Process the false branch.
317 St = Assume(PrevState, V, false, isFeasible);
318
319 if (isFeasible) builder.generateNode(St, false);
320 else builder.markInfeasible(false);
321
Ted Kremenek71c29bd2008-01-29 23:32:35 +0000322}
323
Ted Kremenek7d7fe6d2008-01-29 22:56:11 +0000324void GRConstants::ProcessStmt(Stmt* S, StmtNodeBuilder& builder) {
Ted Kremenekd27f8162008-01-15 23:55:06 +0000325 Builder = &builder;
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000326
327 StmtEntryNode = builder.getLastNode();
328 CurrentStmt = S;
329 NodeSet Dst;
330 StateCleaned = false;
331
332 Visit(S, StmtEntryNode, Dst);
333
334 // If no nodes were generated, generate a new node that has all the
335 // dead mappings removed.
336 if (Dst.size() == 1 && *Dst.begin() == StmtEntryNode) {
337 StateTy St = RemoveDeadBindings(S, StmtEntryNode->getState());
338 builder.generateNode(S, St, StmtEntryNode);
339 }
Ted Kremenekf84469b2008-01-18 00:41:32 +0000340
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000341 CurrentStmt = NULL;
342 StmtEntryNode = NULL;
343 Builder = NULL;
Ted Kremenekd27f8162008-01-15 23:55:06 +0000344}
345
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000346GRConstants::StateTy GRConstants::RemoveDeadBindings(Stmt* Loc, StateTy M) {
Ted Kremenekf84469b2008-01-18 00:41:32 +0000347 // Note: in the code below, we can assign a new map to M since the
348 // iterators are iterating over the tree of the *original* map.
Ted Kremenekf84469b2008-01-18 00:41:32 +0000349 StateTy::iterator I = M.begin(), E = M.end();
350
Ted Kremenekf84469b2008-01-18 00:41:32 +0000351
Ted Kremenek65cac132008-01-29 05:25:31 +0000352 for (; I!=E && !I.getKey().isSymbol(); ++I) {
353 // Remove old bindings for subexpressions and "dead"
354 // block-level expressions.
355 if (I.getKey().isSubExpr() ||
356 I.getKey().isBlkExpr() && !Liveness.isLive(Loc,cast<Stmt>(I.getKey()))){
357 M = StateMgr.Remove(M, I.getKey());
358 }
359 else if (I.getKey().isDecl()) { // Remove bindings for "dead" decls.
360 if (VarDecl* V = dyn_cast<VarDecl>(cast<ValueDecl>(I.getKey())))
361 if (!Liveness.isLive(Loc, V))
362 M = StateMgr.Remove(M, I.getKey());
363 }
364 }
Ted Kremenek565256e2008-01-24 22:44:24 +0000365
Ted Kremeneke00fe3f2008-01-17 00:52:48 +0000366 return M;
Ted Kremeneke00fe3f2008-01-17 00:52:48 +0000367}
368
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000369void GRConstants::Nodify(NodeSet& Dst, Stmt* S, GRConstants::NodeTy* Pred,
370 GRConstants::StateTy St) {
371
372 // If the state hasn't changed, don't generate a new node.
373 if (St == Pred->getState())
374 return;
Ted Kremenekcb448ca2008-01-16 00:53:15 +0000375
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000376 Dst.Add(Builder->generateNode(S, St, Pred));
Ted Kremenekcb448ca2008-01-16 00:53:15 +0000377}
Ted Kremenekd27f8162008-01-15 23:55:06 +0000378
Ted Kremenek874d63f2008-01-24 02:02:54 +0000379void GRConstants::VisitCast(Expr* CastE, Expr* E, GRConstants::NodeTy* Pred,
380 GRConstants::NodeSet& Dst) {
381
382 QualType T = CastE->getType();
383
384 // Check for redundant casts.
385 if (E->getType() == T) {
386 Dst.Add(Pred);
387 return;
388 }
389
390 NodeSet S1;
391 Visit(E, Pred, S1);
392
393 for (NodeSet::iterator I1=S1.begin(), E1=S1.end(); I1 != E1; ++I1) {
394 NodeTy* N = *I1;
395 StateTy St = N->getState();
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000396 const RValue& V = GetValue(St, E);
397 Nodify(Dst, CastE, N, SetValue(St, CastE, V.Cast(ValMgr, CastE)));
Ted Kremenek874d63f2008-01-24 02:02:54 +0000398 }
Ted Kremenek9de04c42008-01-24 20:55:43 +0000399}
400
401void GRConstants::VisitDeclStmt(DeclStmt* DS, GRConstants::NodeTy* Pred,
402 GRConstants::NodeSet& Dst) {
403
404 StateTy St = Pred->getState();
405
406 for (const ScopedDecl* D = DS->getDecl(); D; D = D->getNextDeclarator())
Ted Kremenek403c1812008-01-28 22:51:57 +0000407 if (const VarDecl* VD = dyn_cast<VarDecl>(D)) {
408 const Expr* E = VD->getInit();
409 St = SetValue(St, LValueDecl(VD),
410 E ? GetValue(St, E) : UninitializedValue());
411 }
Ted Kremenek9de04c42008-01-24 20:55:43 +0000412
413 Nodify(Dst, DS, Pred, St);
414
415 if (Dst.empty())
416 Dst.Add(Pred);
417}
Ted Kremenek874d63f2008-01-24 02:02:54 +0000418
Ted Kremenek7b8009a2008-01-24 02:28:56 +0000419void GRConstants::VisitUnaryOperator(UnaryOperator* U,
420 GRConstants::NodeTy* Pred,
421 GRConstants::NodeSet& Dst) {
422 NodeSet S1;
423 Visit(U->getSubExpr(), Pred, S1);
424
425 for (NodeSet::iterator I1=S1.begin(), E1=S1.end(); I1 != E1; ++I1) {
426 NodeTy* N1 = *I1;
427 StateTy St = N1->getState();
428
429 switch (U->getOpcode()) {
430 case UnaryOperator::PostInc: {
431 const LValue& L1 = GetLValue(St, U->getSubExpr());
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000432 NonLValue R1 = cast<NonLValue>(GetValue(St, L1));
Ted Kremenek687af802008-01-29 19:43:15 +0000433 NonLValue R2 = NonLValue::GetValue(ValMgr, 1U, U->getType(),
434 U->getLocStart());
Ted Kremeneke0cf9c82008-01-24 19:00:57 +0000435
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000436 NonLValue Result = R1.Add(ValMgr, R2);
Ted Kremenek7b8009a2008-01-24 02:28:56 +0000437 Nodify(Dst, U, N1, SetValue(SetValue(St, U, R1), L1, Result));
438 break;
439 }
440
441 case UnaryOperator::PostDec: {
442 const LValue& L1 = GetLValue(St, U->getSubExpr());
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000443 NonLValue R1 = cast<NonLValue>(GetValue(St, L1));
Ted Kremenek687af802008-01-29 19:43:15 +0000444 NonLValue R2 = NonLValue::GetValue(ValMgr, 1U, U->getType(),
445 U->getLocStart());
Ted Kremenek7b8009a2008-01-24 02:28:56 +0000446
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000447 NonLValue Result = R1.Sub(ValMgr, R2);
Ted Kremenek7b8009a2008-01-24 02:28:56 +0000448 Nodify(Dst, U, N1, SetValue(SetValue(St, U, R1), L1, Result));
449 break;
450 }
451
452 case UnaryOperator::PreInc: {
453 const LValue& L1 = GetLValue(St, U->getSubExpr());
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000454 NonLValue R1 = cast<NonLValue>(GetValue(St, L1));
Ted Kremenek687af802008-01-29 19:43:15 +0000455 NonLValue R2 = NonLValue::GetValue(ValMgr, 1U, U->getType(),
456 U->getLocStart());
Ted Kremenek7b8009a2008-01-24 02:28:56 +0000457
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000458 NonLValue Result = R1.Add(ValMgr, R2);
Ted Kremenek7b8009a2008-01-24 02:28:56 +0000459 Nodify(Dst, U, N1, SetValue(SetValue(St, U, Result), L1, Result));
460 break;
461 }
462
463 case UnaryOperator::PreDec: {
464 const LValue& L1 = GetLValue(St, U->getSubExpr());
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000465 NonLValue R1 = cast<NonLValue>(GetValue(St, L1));
Ted Kremenek687af802008-01-29 19:43:15 +0000466 NonLValue R2 = NonLValue::GetValue(ValMgr, 1U, U->getType(),
467 U->getLocStart());
Ted Kremenek7b8009a2008-01-24 02:28:56 +0000468
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000469 NonLValue Result = R1.Sub(ValMgr, R2);
Ted Kremenek7b8009a2008-01-24 02:28:56 +0000470 Nodify(Dst, U, N1, SetValue(SetValue(St, U, Result), L1, Result));
471 break;
472 }
473
Ted Kremenekdacbb4f2008-01-24 08:20:02 +0000474 case UnaryOperator::Minus: {
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000475 const NonLValue& R1 = cast<NonLValue>(GetValue(St, U->getSubExpr()));
476 Nodify(Dst, U, N1, SetValue(St, U, R1.UnaryMinus(ValMgr, U)));
Ted Kremenekdacbb4f2008-01-24 08:20:02 +0000477 break;
478 }
479
Ted Kremenekc5d3b4c2008-02-04 16:58:30 +0000480 case UnaryOperator::Not: {
481 const NonLValue& R1 = cast<NonLValue>(GetValue(St, U->getSubExpr()));
482 Nodify(Dst, U, N1, SetValue(St, U, R1.BitwiseComplement(ValMgr)));
483 break;
484 }
485
Ted Kremenek64924852008-01-31 02:35:41 +0000486 case UnaryOperator::AddrOf: {
487 const LValue& L1 = GetLValue(St, U->getSubExpr());
488 Nodify(Dst, U, N1, SetValue(St, U, L1));
489 break;
490 }
491
492 case UnaryOperator::Deref: {
493 const LValue& L1 = GetLValue(St, U->getSubExpr());
494 Nodify(Dst, U, N1, SetValue(St, U, GetValue(St, L1)));
495 break;
496 }
497
Ted Kremenek7b8009a2008-01-24 02:28:56 +0000498 default: ;
499 assert (false && "Not implemented.");
500 }
501 }
502}
503
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000504void GRConstants::VisitBinaryOperator(BinaryOperator* B,
505 GRConstants::NodeTy* Pred,
506 GRConstants::NodeSet& Dst) {
507 NodeSet S1;
508 Visit(B->getLHS(), Pred, S1);
Ted Kremenekcb448ca2008-01-16 00:53:15 +0000509
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000510 for (NodeSet::iterator I1=S1.begin(), E1=S1.end(); I1 != E1; ++I1) {
511 NodeTy* N1 = *I1;
Ted Kremeneke00fe3f2008-01-17 00:52:48 +0000512
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000513 // When getting the value for the LHS, check if we are in an assignment.
514 // In such cases, we want to (initially) treat the LHS as an LValue,
515 // so we use GetLValue instead of GetValue so that DeclRefExpr's are
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000516 // evaluated to LValueDecl's instead of to an NonLValue.
517 const RValue& V1 =
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000518 B->isAssignmentOp() ? GetLValue(N1->getState(), B->getLHS())
519 : GetValue(N1->getState(), B->getLHS());
Ted Kremenekcb448ca2008-01-16 00:53:15 +0000520
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000521 NodeSet S2;
522 Visit(B->getRHS(), N1, S2);
523
524 for (NodeSet::iterator I2=S2.begin(), E2=S2.end(); I2 != E2; ++I2) {
525 NodeTy* N2 = *I2;
526 StateTy St = N2->getState();
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000527 const RValue& V2 = GetValue(St, B->getRHS());
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000528
529 switch (B->getOpcode()) {
Ted Kremenek687af802008-01-29 19:43:15 +0000530 default:
531 Dst.Add(N2);
532 break;
533
534 // Arithmetic opreators.
535
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000536 case BinaryOperator::Add: {
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000537 const NonLValue& R1 = cast<NonLValue>(V1);
538 const NonLValue& R2 = cast<NonLValue>(V2);
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000539
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000540 Nodify(Dst, B, N2, SetValue(St, B, R1.Add(ValMgr, R2)));
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000541 break;
542 }
543
544 case BinaryOperator::Sub: {
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000545 const NonLValue& R1 = cast<NonLValue>(V1);
546 const NonLValue& R2 = cast<NonLValue>(V2);
547 Nodify(Dst, B, N2, SetValue(St, B, R1.Sub(ValMgr, R2)));
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000548 break;
549 }
550
Ted Kremenek2eafd0e2008-01-23 23:42:27 +0000551 case BinaryOperator::Mul: {
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000552 const NonLValue& R1 = cast<NonLValue>(V1);
553 const NonLValue& R2 = cast<NonLValue>(V2);
554 Nodify(Dst, B, N2, SetValue(St, B, R1.Mul(ValMgr, R2)));
Ted Kremenek2eafd0e2008-01-23 23:42:27 +0000555 break;
556 }
557
Ted Kremenek5ee4ff82008-01-25 22:55:56 +0000558 case BinaryOperator::Div: {
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000559 const NonLValue& R1 = cast<NonLValue>(V1);
560 const NonLValue& R2 = cast<NonLValue>(V2);
561 Nodify(Dst, B, N2, SetValue(St, B, R1.Div(ValMgr, R2)));
Ted Kremenek5ee4ff82008-01-25 22:55:56 +0000562 break;
563 }
564
Ted Kremenekcce207d2008-01-28 22:26:15 +0000565 case BinaryOperator::Rem: {
566 const NonLValue& R1 = cast<NonLValue>(V1);
567 const NonLValue& R2 = cast<NonLValue>(V2);
568 Nodify(Dst, B, N2, SetValue(St, B, R1.Rem(ValMgr, R2)));
569 break;
570 }
571
Ted Kremenek687af802008-01-29 19:43:15 +0000572 // Assignment operators.
573
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000574 case BinaryOperator::Assign: {
575 const LValue& L1 = cast<LValue>(V1);
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000576 const NonLValue& R2 = cast<NonLValue>(V2);
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000577 Nodify(Dst, B, N2, SetValue(SetValue(St, B, R2), L1, R2));
578 break;
579 }
Ted Kremenekb4ae33f2008-01-23 23:38:00 +0000580
581 case BinaryOperator::AddAssign: {
582 const LValue& L1 = cast<LValue>(V1);
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000583 NonLValue R1 = cast<NonLValue>(GetValue(N1->getState(), L1));
584 NonLValue Result = R1.Add(ValMgr, cast<NonLValue>(V2));
Ted Kremenekb4ae33f2008-01-23 23:38:00 +0000585 Nodify(Dst, B, N2, SetValue(SetValue(St, B, Result), L1, Result));
586 break;
587 }
588
589 case BinaryOperator::SubAssign: {
590 const LValue& L1 = cast<LValue>(V1);
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000591 NonLValue R1 = cast<NonLValue>(GetValue(N1->getState(), L1));
592 NonLValue Result = R1.Sub(ValMgr, cast<NonLValue>(V2));
Ted Kremenekb4ae33f2008-01-23 23:38:00 +0000593 Nodify(Dst, B, N2, SetValue(SetValue(St, B, Result), L1, Result));
594 break;
595 }
Ted Kremenek2eafd0e2008-01-23 23:42:27 +0000596
597 case BinaryOperator::MulAssign: {
598 const LValue& L1 = cast<LValue>(V1);
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000599 NonLValue R1 = cast<NonLValue>(GetValue(N1->getState(), L1));
600 NonLValue Result = R1.Mul(ValMgr, cast<NonLValue>(V2));
Ted Kremenek2eafd0e2008-01-23 23:42:27 +0000601 Nodify(Dst, B, N2, SetValue(SetValue(St, B, Result), L1, Result));
602 break;
603 }
Ted Kremenek5c1e2622008-01-25 23:45:34 +0000604
605 case BinaryOperator::DivAssign: {
606 const LValue& L1 = cast<LValue>(V1);
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000607 NonLValue R1 = cast<NonLValue>(GetValue(N1->getState(), L1));
608 NonLValue Result = R1.Div(ValMgr, cast<NonLValue>(V2));
Ted Kremenek5c1e2622008-01-25 23:45:34 +0000609 Nodify(Dst, B, N2, SetValue(SetValue(St, B, Result), L1, Result));
610 break;
611 }
Ted Kremenek10099a62008-01-28 22:28:54 +0000612
613 case BinaryOperator::RemAssign: {
614 const LValue& L1 = cast<LValue>(V1);
615 NonLValue R1 = cast<NonLValue>(GetValue(N1->getState(), L1));
616 NonLValue Result = R1.Rem(ValMgr, cast<NonLValue>(V2));
617 Nodify(Dst, B, N2, SetValue(SetValue(St, B, Result), L1, Result));
618 break;
619 }
Ted Kremenek687af802008-01-29 19:43:15 +0000620
621 // Equality operators.
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000622
Ted Kremenek687af802008-01-29 19:43:15 +0000623 case BinaryOperator::EQ:
624 // FIXME: should we allow XX.EQ() to return a set of values,
625 // allowing state bifurcation? In such cases, they will also
626 // modify the state (meaning that a new state will be returned
627 // as well).
628 assert (B->getType() == getContext().IntTy);
629
630 if (isa<LValue>(V1)) {
631 const LValue& L1 = cast<LValue>(V1);
632 const LValue& L2 = cast<LValue>(V2);
633 St = SetValue(St, B, L1.EQ(ValMgr, L2));
634 }
635 else {
636 const NonLValue& R1 = cast<NonLValue>(V1);
637 const NonLValue& R2 = cast<NonLValue>(V2);
638 St = SetValue(St, B, R1.EQ(ValMgr, R2));
639 }
640
641 Nodify(Dst, B, N2, St);
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000642 break;
643 }
Ted Kremenekcb448ca2008-01-16 00:53:15 +0000644 }
Ted Kremenekd27f8162008-01-15 23:55:06 +0000645 }
Ted Kremenekd27f8162008-01-15 23:55:06 +0000646}
Ted Kremenekee985462008-01-16 18:18:48 +0000647
Ted Kremenek1ccd31c2008-01-16 19:42:59 +0000648
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000649void GRConstants::Visit(Stmt* S, GRConstants::NodeTy* Pred,
650 GRConstants::NodeSet& Dst) {
651
652 // FIXME: add metadata to the CFG so that we can disable
653 // this check when we KNOW that there is no block-level subexpression.
654 // The motivation is that this check requires a hashtable lookup.
655
656 if (S != CurrentStmt && getCFG().isBlkExpr(S)) {
657 Dst.Add(Pred);
658 return;
659 }
660
661 switch (S->getStmtClass()) {
662 case Stmt::BinaryOperatorClass:
Ted Kremenekb4ae33f2008-01-23 23:38:00 +0000663 case Stmt::CompoundAssignOperatorClass:
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000664 VisitBinaryOperator(cast<BinaryOperator>(S), Pred, Dst);
665 break;
666
Ted Kremenek7b8009a2008-01-24 02:28:56 +0000667 case Stmt::UnaryOperatorClass:
668 VisitUnaryOperator(cast<UnaryOperator>(S), Pred, Dst);
669 break;
670
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000671 case Stmt::ParenExprClass:
672 Visit(cast<ParenExpr>(S)->getSubExpr(), Pred, Dst);
673 break;
674
Ted Kremenek874d63f2008-01-24 02:02:54 +0000675 case Stmt::ImplicitCastExprClass: {
676 ImplicitCastExpr* C = cast<ImplicitCastExpr>(S);
677 VisitCast(C, C->getSubExpr(), Pred, Dst);
678 break;
679 }
680
681 case Stmt::CastExprClass: {
682 CastExpr* C = cast<CastExpr>(S);
683 VisitCast(C, C->getSubExpr(), Pred, Dst);
684 break;
685 }
686
Ted Kremenek9de04c42008-01-24 20:55:43 +0000687 case Stmt::DeclStmtClass:
688 VisitDeclStmt(cast<DeclStmt>(S), Pred, Dst);
689 break;
690
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000691 default:
692 Dst.Add(Pred); // No-op. Simply propagate the current state unchanged.
693 break;
Ted Kremenek79649df2008-01-17 18:25:22 +0000694 }
Ted Kremenek1ccd31c2008-01-16 19:42:59 +0000695}
696
Ted Kremenekee985462008-01-16 18:18:48 +0000697//===----------------------------------------------------------------------===//
Ted Kremenekb38911f2008-01-30 23:03:39 +0000698// "Assume" logic.
699//===----------------------------------------------------------------------===//
700
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000701GRConstants::StateTy GRConstants::Assume(StateTy St, LValue Cond, bool Assumption,
702 bool& isFeasible) {
Ted Kremeneka6e4d212008-02-01 06:36:40 +0000703
704 switch (Cond.getSubKind()) {
705 default:
706 assert (false && "'Assume' not implemented for this NonLValue.");
707 return St;
708
709 case LValueDeclKind:
710 isFeasible = Assumption;
711 return St;
712
713 case ConcreteIntLValueKind: {
714 bool b = cast<ConcreteIntLValue>(Cond).getValue() != 0;
715 isFeasible = b ? Assumption : !Assumption;
716 return St;
717 }
718 }
Ted Kremenekb38911f2008-01-30 23:03:39 +0000719}
720
Ted Kremeneka90ccfe2008-01-31 19:34:24 +0000721GRConstants::StateTy GRConstants::Assume(StateTy St, NonLValue Cond, bool Assumption,
722 bool& isFeasible) {
Ted Kremenekb38911f2008-01-30 23:03:39 +0000723
724 switch (Cond.getSubKind()) {
725 default:
726 assert (false && "'Assume' not implemented for this NonLValue.");
727 return St;
728
729 case ConcreteIntKind: {
730 bool b = cast<ConcreteInt>(Cond).getValue() != 0;
731 isFeasible = b ? Assumption : !Assumption;
732 return St;
733 }
734 }
735}
736
737
738//===----------------------------------------------------------------------===//
Ted Kremenekee985462008-01-16 18:18:48 +0000739// Driver.
740//===----------------------------------------------------------------------===//
741
Ted Kremenekaa66a322008-01-16 21:46:15 +0000742#ifndef NDEBUG
Ted Kremenek3b4f6702008-01-30 23:24:39 +0000743static GRConstants* GraphPrintCheckerState;
744
Ted Kremenekaa66a322008-01-16 21:46:15 +0000745namespace llvm {
746template<>
747struct VISIBILITY_HIDDEN DOTGraphTraits<GRConstants::NodeTy*> :
748 public DefaultDOTGraphTraits {
Ted Kremenek9ff731d2008-01-24 22:27:20 +0000749
750 static void PrintKindLabel(std::ostream& Out, ValueKey::Kind kind) {
Ted Kremenek803c9ed2008-01-23 22:30:44 +0000751 switch (kind) {
Ted Kremenek565256e2008-01-24 22:44:24 +0000752 case ValueKey::IsSubExpr: Out << "Sub-Expressions:\\l"; break;
Ted Kremenek803c9ed2008-01-23 22:30:44 +0000753 case ValueKey::IsDecl: Out << "Variables:\\l"; break;
754 case ValueKey::IsBlkExpr: Out << "Block-level Expressions:\\l"; break;
755 default: assert (false && "Unknown ValueKey type.");
756 }
757 }
758
Ted Kremenek9ff731d2008-01-24 22:27:20 +0000759 static void PrintKind(std::ostream& Out, GRConstants::StateTy M,
760 ValueKey::Kind kind, bool isFirstGroup = false) {
761 bool isFirst = true;
762
763 for (GRConstants::StateTy::iterator I=M.begin(), E=M.end();I!=E;++I) {
764 if (I.getKey().getKind() != kind)
765 continue;
766
767 if (isFirst) {
768 if (!isFirstGroup) Out << "\\l\\l";
769 PrintKindLabel(Out, kind);
770 isFirst = false;
771 }
772 else
773 Out << "\\l";
774
775 Out << ' ';
776
777 if (ValueDecl* V = dyn_cast<ValueDecl>(I.getKey()))
778 Out << V->getName();
779 else {
780 Stmt* E = cast<Stmt>(I.getKey());
781 Out << " (" << (void*) E << ") ";
782 E->printPretty(Out);
783 }
784
785 Out << " : ";
786 I.getData().print(Out);
787 }
788 }
789
Ted Kremenekaa66a322008-01-16 21:46:15 +0000790 static std::string getNodeLabel(const GRConstants::NodeTy* N, void*) {
791 std::ostringstream Out;
Ted Kremenek803c9ed2008-01-23 22:30:44 +0000792
793 // Program Location.
Ted Kremenekaa66a322008-01-16 21:46:15 +0000794 ProgramPoint Loc = N->getLocation();
795
796 switch (Loc.getKind()) {
797 case ProgramPoint::BlockEntranceKind:
798 Out << "Block Entrance: B"
799 << cast<BlockEntrance>(Loc).getBlock()->getBlockID();
800 break;
801
802 case ProgramPoint::BlockExitKind:
803 assert (false);
804 break;
805
806 case ProgramPoint::PostStmtKind: {
807 const PostStmt& L = cast<PostStmt>(Loc);
Ted Kremenek9ff731d2008-01-24 22:27:20 +0000808 Out << L.getStmt()->getStmtClassName() << ':'
809 << (void*) L.getStmt() << ' ';
810
Ted Kremenekaa66a322008-01-16 21:46:15 +0000811 L.getStmt()->printPretty(Out);
812 break;
813 }
814
815 default: {
816 const BlockEdge& E = cast<BlockEdge>(Loc);
817 Out << "Edge: (B" << E.getSrc()->getBlockID() << ", B"
818 << E.getDst()->getBlockID() << ')';
Ted Kremenekb38911f2008-01-30 23:03:39 +0000819
820 if (Stmt* T = E.getSrc()->getTerminator()) {
821 Out << "\\|Terminator: ";
822 E.getSrc()->printTerminator(Out);
823
824 if (isa<SwitchStmt>(T)) {
825 // FIXME
826 }
827 else {
828 Out << "\\lCondition: ";
829 if (*E.getSrc()->succ_begin() == E.getDst())
830 Out << "true";
831 else
832 Out << "false";
833 }
834
835 Out << "\\l";
836 }
Ted Kremenek3b4f6702008-01-30 23:24:39 +0000837
838 if (GraphPrintCheckerState->isUninitControlFlow(N)) {
839 Out << "\\|Control-flow based on\\lUninitialized value.\\l";
840 }
Ted Kremenekaa66a322008-01-16 21:46:15 +0000841 }
842 }
843
Ted Kremenek64924852008-01-31 02:35:41 +0000844 Out << "\\|StateID: " << (void*) N->getState().getRoot() << "\\|";
Ted Kremenekaa66a322008-01-16 21:46:15 +0000845
Ted Kremenek9ff731d2008-01-24 22:27:20 +0000846 PrintKind(Out, N->getState(), ValueKey::IsDecl, true);
847 PrintKind(Out, N->getState(), ValueKey::IsBlkExpr);
Ted Kremenek565256e2008-01-24 22:44:24 +0000848 PrintKind(Out, N->getState(), ValueKey::IsSubExpr);
Ted Kremenek803c9ed2008-01-23 22:30:44 +0000849
Ted Kremenek803c9ed2008-01-23 22:30:44 +0000850 Out << "\\l";
Ted Kremenekaa66a322008-01-16 21:46:15 +0000851 return Out.str();
852 }
853};
854} // end llvm namespace
855#endif
856
Ted Kremenekee985462008-01-16 18:18:48 +0000857namespace clang {
Ted Kremenekcb48b9c2008-01-29 00:33:40 +0000858void RunGRConstants(CFG& cfg, FunctionDecl& FD, ASTContext& Ctx) {
859 GREngine<GRConstants> Engine(cfg, FD, Ctx);
Ted Kremenekee985462008-01-16 18:18:48 +0000860 Engine.ExecuteWorkList();
Ted Kremenekaa66a322008-01-16 21:46:15 +0000861#ifndef NDEBUG
Ted Kremenek3b4f6702008-01-30 23:24:39 +0000862 GraphPrintCheckerState = &Engine.getCheckerState();
Ted Kremenekaa66a322008-01-16 21:46:15 +0000863 llvm::ViewGraph(*Engine.getGraph().roots_begin(),"GRConstants");
Ted Kremenek3b4f6702008-01-30 23:24:39 +0000864 GraphPrintCheckerState = NULL;
Ted Kremenekaa66a322008-01-16 21:46:15 +0000865#endif
Ted Kremenekee985462008-01-16 18:18:48 +0000866}
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000867} // end clang namespace