blob: 1b2545a3fd3a3bf683be0c712b513331ce38cecc [file] [log] [blame]
Ted Kremenekd27f8162008-01-15 23:55:06 +00001//===-- GRConstants.cpp - Simple, Path-Sens. Constant Prop. ------*- C++ -*-==//
2//
Ted Kremenekab2b8c52008-01-23 19:59:44 +00003// The LLValM 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
18#include "clang/Analysis/PathSensitive/GREngine.h"
19#include "clang/AST/Expr.h"
Ted Kremenek874d63f2008-01-24 02:02:54 +000020#include "clang/AST/ASTContext.h"
Ted Kremenekd27f8162008-01-15 23:55:06 +000021#include "clang/Analysis/Analyses/LiveVariables.h"
Ted Kremenekd27f8162008-01-15 23:55:06 +000022
23#include "llvm/Support/Casting.h"
24#include "llvm/Support/DataTypes.h"
25#include "llvm/ADT/APSInt.h"
26#include "llvm/ADT/FoldingSet.h"
27#include "llvm/ADT/ImmutableMap.h"
Ted Kremenek3c6c6722008-01-16 17:56:25 +000028#include "llvm/ADT/SmallVector.h"
Ted Kremenekab2b8c52008-01-23 19:59:44 +000029#include "llvm/Support/Allocator.h"
Ted Kremenekd27f8162008-01-15 23:55:06 +000030#include "llvm/Support/Compiler.h"
Ted Kremenekab2b8c52008-01-23 19:59:44 +000031#include "llvm/Support/Streams.h"
32
Ted Kremenek5ee4ff82008-01-25 22:55:56 +000033#include <functional>
34
Ted Kremenekaa66a322008-01-16 21:46:15 +000035#ifndef NDEBUG
36#include "llvm/Support/GraphWriter.h"
37#include <sstream>
38#endif
39
Ted Kremenekd27f8162008-01-15 23:55:06 +000040using namespace clang;
Ted Kremenekd27f8162008-01-15 23:55:06 +000041using llvm::dyn_cast;
42using llvm::cast;
Ted Kremenek5ee4ff82008-01-25 22:55:56 +000043using llvm::APSInt;
Ted Kremenekd27f8162008-01-15 23:55:06 +000044
45//===----------------------------------------------------------------------===//
Ted Kremenekab2b8c52008-01-23 19:59:44 +000046/// ValueKey - A variant smart pointer that wraps either a ValueDecl* or a
Ted Kremenekd27f8162008-01-15 23:55:06 +000047/// Stmt*. Use cast<> or dyn_cast<> to get actual pointer type
48//===----------------------------------------------------------------------===//
49namespace {
Ted Kremenekbd03f1d2008-01-28 22:09:13 +000050
51typedef uintptr_t SymbolID;
Ted Kremenekab2b8c52008-01-23 19:59:44 +000052
53class VISIBILITY_HIDDEN ValueKey {
Ted Kremenekbd03f1d2008-01-28 22:09:13 +000054 uintptr_t Raw;
Ted Kremenekcc1c3652008-01-25 23:43:12 +000055 void operator=(const ValueKey& RHS); // Do not implement.
Ted Kremenekbd03f1d2008-01-28 22:09:13 +000056
Ted Kremenekd27f8162008-01-15 23:55:06 +000057public:
Ted Kremenekbd03f1d2008-01-28 22:09:13 +000058 enum Kind { IsSubExpr=0x0, IsBlkExpr=0x1, IsDecl=0x2, // L-Value Bindings.
59 IsSymbol=0x3, // Symbol Bindings.
60 Flags=0x3 };
61
62 inline Kind getKind() const {
63 return (Kind) (Raw & Flags);
64 }
65
66 inline void* getPtr() const {
67 assert (getKind() != IsSymbol);
68 return reinterpret_cast<void*>(Raw & ~Flags);
69 }
70
71 inline SymbolID getSymbolID() const {
72 assert (getKind() == IsSymbol);
73 return Raw >> 2;
74 }
Ted Kremenekd27f8162008-01-15 23:55:06 +000075
Ted Kremenekab2b8c52008-01-23 19:59:44 +000076 ValueKey(const ValueDecl* VD)
Ted Kremenekbd03f1d2008-01-28 22:09:13 +000077 : Raw(reinterpret_cast<uintptr_t>(VD) | IsDecl) {
78 assert(VD && "ValueDecl cannot be NULL.");
79 }
Ted Kremenekab2b8c52008-01-23 19:59:44 +000080
Ted Kremenek5c1b9962008-01-24 19:43:37 +000081 ValueKey(Stmt* S, bool isBlkExpr = false)
Ted Kremenekcc1c3652008-01-25 23:43:12 +000082 : Raw(reinterpret_cast<uintptr_t>(S) | (isBlkExpr ? IsBlkExpr : IsSubExpr)){
Ted Kremenekbd03f1d2008-01-28 22:09:13 +000083 assert(S && "Tracked statement cannot be NULL.");
Ted Kremenekcc1c3652008-01-25 23:43:12 +000084 }
Ted Kremenekd27f8162008-01-15 23:55:06 +000085
Ted Kremenekbd03f1d2008-01-28 22:09:13 +000086 ValueKey(SymbolID V)
87 : Raw((V << 2) | IsSymbol) {}
88
89 bool isSymbol() const { return getKind() == IsSymbol; }
Ted Kremenek565256e2008-01-24 22:44:24 +000090 bool isSubExpr() const { return getKind() == IsSubExpr; }
Ted Kremenekbd03f1d2008-01-28 22:09:13 +000091 bool isDecl() const { return getKind() == IsDecl; }
Ted Kremenekd27f8162008-01-15 23:55:06 +000092
93 inline void Profile(llvm::FoldingSetNodeID& ID) const {
Ted Kremenekbd03f1d2008-01-28 22:09:13 +000094 ID.AddInteger(isSymbol() ? 1 : 0);
95
96 if (isSymbol())
97 ID.AddInteger((uint64_t) getSymbolID());
98 else
99 ID.AddPointer(getPtr());
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000100 }
101
102 inline bool operator==(const ValueKey& X) const {
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000103 return isSymbol() ? getSymbolID() == X.getSymbolID()
104 : getPtr() == X.getPtr();
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000105 }
106
107 inline bool operator!=(const ValueKey& X) const {
108 return !operator==(X);
109 }
110
111 inline bool operator<(const ValueKey& X) const {
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000112 if (isSymbol())
113 return X.isSymbol() ? getSymbolID() < X.getSymbolID() : false;
Ted Kremenek5c1b9962008-01-24 19:43:37 +0000114
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000115 return getPtr() < X.getPtr();
Ted Kremenekb3d2dca2008-01-16 23:33:44 +0000116 }
Ted Kremenekd27f8162008-01-15 23:55:06 +0000117};
118} // end anonymous namespace
119
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000120// Machinery to get cast<> and dyn_cast<> working with ValueKey.
Ted Kremenekd27f8162008-01-15 23:55:06 +0000121namespace llvm {
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000122 template<> inline bool isa<ValueDecl,ValueKey>(const ValueKey& V) {
123 return V.getKind() == ValueKey::IsDecl;
Ted Kremenekd27f8162008-01-15 23:55:06 +0000124 }
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000125 template<> inline bool isa<Stmt,ValueKey>(const ValueKey& V) {
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000126 return ((unsigned) V.getKind()) < ValueKey::IsDecl;
Ted Kremenekd27f8162008-01-15 23:55:06 +0000127 }
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000128 template<> struct VISIBILITY_HIDDEN cast_retty_impl<ValueDecl,ValueKey> {
Ted Kremenekaa66a322008-01-16 21:46:15 +0000129 typedef const ValueDecl* ret_type;
Ted Kremenekd27f8162008-01-15 23:55:06 +0000130 };
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000131 template<> struct VISIBILITY_HIDDEN cast_retty_impl<Stmt,ValueKey> {
Ted Kremenekd27f8162008-01-15 23:55:06 +0000132 typedef const Stmt* ret_type;
133 };
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000134 template<> struct VISIBILITY_HIDDEN simplify_type<ValueKey> {
Ted Kremenekd27f8162008-01-15 23:55:06 +0000135 typedef void* SimpleType;
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000136 static inline SimpleType getSimplifiedValue(const ValueKey &V) {
Ted Kremenekd27f8162008-01-15 23:55:06 +0000137 return V.getPtr();
138 }
139 };
140} // end llvm namespace
141
142//===----------------------------------------------------------------------===//
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000143// ValueManager.
Ted Kremenekd27f8162008-01-15 23:55:06 +0000144//===----------------------------------------------------------------------===//
145
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000146namespace {
147
Ted Kremenek5ee4ff82008-01-25 22:55:56 +0000148typedef llvm::ImmutableSet<APSInt > APSIntSetTy;
149
150
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000151class VISIBILITY_HIDDEN ValueManager {
Ted Kremenek874d63f2008-01-24 02:02:54 +0000152 ASTContext* Ctx;
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000153
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000154 typedef llvm::FoldingSet<llvm::FoldingSetNodeWrapper<APSInt> > APSIntSetTy;
155 APSIntSetTy APSIntSet;
156
157 llvm::BumpPtrAllocator BPAlloc;
158
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000159public:
160 ValueManager() {}
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000161 ~ValueManager();
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000162
Ted Kremenek874d63f2008-01-24 02:02:54 +0000163 void setContext(ASTContext* ctx) { Ctx = ctx; }
164 ASTContext* getContext() const { return Ctx; }
165
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000166 APSInt& getValue(const APSInt& X);
167
Ted Kremenekd27f8162008-01-15 23:55:06 +0000168};
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000169} // end anonymous namespace
170
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000171ValueManager::~ValueManager() {
172 // Note that the dstor for the contents of APSIntSet will never be called,
173 // so we iterate over the set and invoke the dstor for each APSInt. This
174 // frees an aux. memory allocated to represent very large constants.
175 for (APSIntSetTy::iterator I=APSIntSet.begin(), E=APSIntSet.end(); I!=E; ++I)
176 I->getValue().~APSInt();
177}
Ted Kremenek5ee4ff82008-01-25 22:55:56 +0000178
Ted Kremenek5ee4ff82008-01-25 22:55:56 +0000179
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000180
181APSInt& ValueManager::getValue(const APSInt& X) {
182 llvm::FoldingSetNodeID ID;
183 void* InsertPos;
184 typedef llvm::FoldingSetNodeWrapper<APSInt> FoldNodeTy;
Ted Kremenekcc1c3652008-01-25 23:43:12 +0000185
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000186 X.Profile(ID);
187 FoldNodeTy* P = APSIntSet.FindNodeOrInsertPos(ID, InsertPos);
Ted Kremenek5ee4ff82008-01-25 22:55:56 +0000188
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000189 if (!P) {
190 P = (FoldNodeTy*) BPAlloc.Allocate<FoldNodeTy>();
191 new (P) FoldNodeTy(X);
192 APSIntSet.InsertNode(P, InsertPos);
193 }
194
195 return *P;
Ted Kremenek5ee4ff82008-01-25 22:55:56 +0000196}
197
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000198//===----------------------------------------------------------------------===//
199// Expression Values.
200//===----------------------------------------------------------------------===//
Ted Kremenekf13794e2008-01-24 23:19:54 +0000201
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000202namespace {
203
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000204class VISIBILITY_HIDDEN RValue {
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000205public:
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000206 enum BaseKind { InvalidKind=0x0, LValueKind=0x1, NonLValueKind=0x2,
207 SymbolKind=0x3, BaseFlags = 0x3 };
Ted Kremenekf13794e2008-01-24 23:19:54 +0000208
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000209private:
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000210 uintptr_t Data;
Ted Kremenekf13794e2008-01-24 23:19:54 +0000211 unsigned Kind;
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000212
213protected:
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000214 RValue(const void* d, bool isLValue, unsigned ValKind)
215 : Data(reinterpret_cast<uintptr_t>(const_cast<void*>(d))),
216 Kind((isLValue ? LValueKind : NonLValueKind) | (ValKind << 2)) {}
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000217
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000218 explicit RValue()
219 : Data(0), Kind(InvalidKind) {}
Ted Kremenekf13794e2008-01-24 23:19:54 +0000220
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000221 explicit RValue(unsigned SymID)
222 : Data(SymID), Kind(SymbolKind) {}
223
224 void* getRawPtr() const {
225 assert (getBaseKind() != InvalidKind && getBaseKind() != SymbolKind);
226 return reinterpret_cast<void*>(Data);
227 }
228
229 uintptr_t getRawData() const {
230 return Data;
231 }
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000232
233public:
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000234 ~RValue() {};
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000235
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000236 RValue Cast(ValueManager& ValMgr, Expr* CastExpr) const;
Ted Kremenek874d63f2008-01-24 02:02:54 +0000237
Ted Kremenekf13794e2008-01-24 23:19:54 +0000238 unsigned getRawKind() const { return Kind; }
239 BaseKind getBaseKind() const { return (BaseKind) (Kind & 0x3); }
240 unsigned getSubKind() const { return (Kind & ~0x3) >> 2; }
241
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000242 void Profile(llvm::FoldingSetNodeID& ID) const {
Ted Kremenekf13794e2008-01-24 23:19:54 +0000243 ID.AddInteger((unsigned) getRawKind());
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000244 ID.AddPointer(reinterpret_cast<void*>(Data));
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000245 }
246
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000247 bool operator==(const RValue& RHS) const {
Ted Kremenekf13794e2008-01-24 23:19:54 +0000248 return getRawKind() == RHS.getRawKind() && Data == RHS.Data;
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000249 }
250
Ted Kremenekf13794e2008-01-24 23:19:54 +0000251 inline bool isValid() const { return getRawKind() != InvalidKind; }
252 inline bool isInvalid() const { return getRawKind() == InvalidKind; }
253
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000254 void print(std::ostream& OS) const;
255 void print() const { print(*llvm::cerr.stream()); }
256
257 // Implement isa<T> support.
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000258 static inline bool classof(const RValue*) { return true; }
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000259};
260
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000261class VISIBILITY_HIDDEN InvalidValue : public RValue {
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000262public:
Ted Kremenekf13794e2008-01-24 23:19:54 +0000263 InvalidValue() {}
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000264
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000265 static inline bool classof(const RValue* V) {
Ted Kremenekf13794e2008-01-24 23:19:54 +0000266 return V->getBaseKind() == InvalidKind;
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000267 }
268};
269
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000270class VISIBILITY_HIDDEN SymbolValue : public RValue {
271public:
272 SymbolValue(unsigned SymID) : RValue(SymID) {}
273
274 unsigned getID() const {
275 return (unsigned) getRawData();
276 }
277
278 static inline bool classof(const RValue* V) {
279 return V->getBaseKind() == SymbolKind;
280 }
281};
282
283class VISIBILITY_HIDDEN LValue : public RValue {
Ted Kremenekf13794e2008-01-24 23:19:54 +0000284protected:
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000285 LValue(unsigned SubKind, void* D) : RValue(D, true, SubKind) {}
Ted Kremenekf13794e2008-01-24 23:19:54 +0000286
287public:
288 // Implement isa<T> support.
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000289 static inline bool classof(const RValue* V) {
Ted Kremenekf13794e2008-01-24 23:19:54 +0000290 return V->getBaseKind() == LValueKind;
291 }
292};
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000293
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000294class VISIBILITY_HIDDEN NonLValue : public RValue {
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000295protected:
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000296 NonLValue(unsigned SubKind, const void* d) : RValue(d, false, SubKind) {}
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000297
298public:
Ted Kremenekf13794e2008-01-24 23:19:54 +0000299 void print(std::ostream& Out) const;
300
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000301 NonLValue Add(ValueManager& ValMgr, const NonLValue& RHS) const;
302 NonLValue Sub(ValueManager& ValMgr, const NonLValue& RHS) const;
303 NonLValue Mul(ValueManager& ValMgr, const NonLValue& RHS) const;
304 NonLValue Div(ValueManager& ValMgr, const NonLValue& RHS) const;
305 NonLValue Rem(ValueManager& ValMgr, const NonLValue& RHS) const;
306 NonLValue UnaryMinus(ValueManager& ValMgr, UnaryOperator* U) const;
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000307
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000308 static NonLValue GetValue(ValueManager& ValMgr, const APSInt& V);
309 static NonLValue GetValue(ValueManager& ValMgr, IntegerLiteral* I);
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000310
311 // Implement isa<T> support.
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000312 static inline bool classof(const RValue* V) {
313 return V->getBaseKind() == NonLValueKind;
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000314 }
315};
Ted Kremenekf13794e2008-01-24 23:19:54 +0000316
317} // end anonymous namespace
318
319//===----------------------------------------------------------------------===//
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000320// LValues.
Ted Kremenekf13794e2008-01-24 23:19:54 +0000321//===----------------------------------------------------------------------===//
322
323namespace {
324
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000325enum { LValueDeclKind, NumLValueKind };
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000326
327class VISIBILITY_HIDDEN LValueDecl : public LValue {
328public:
Ted Kremenek9de04c42008-01-24 20:55:43 +0000329 LValueDecl(const ValueDecl* vd)
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000330 : LValue(LValueDeclKind,const_cast<ValueDecl*>(vd)) {}
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000331
332 ValueDecl* getDecl() const {
333 return static_cast<ValueDecl*>(getRawPtr());
334 }
335
336 // Implement isa<T> support.
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000337 static inline bool classof(const RValue* V) {
Ted Kremenekf13794e2008-01-24 23:19:54 +0000338 return V->getSubKind() == LValueDeclKind;
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000339 }
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000340};
341
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000342} // end anonymous namespace
343
344//===----------------------------------------------------------------------===//
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000345// Non-LValues.
346//===----------------------------------------------------------------------===//
347
348namespace {
349
350enum { ConcreteIntKind, ConstrainedIntegerKind, NumNonLValueKind };
351
352class VISIBILITY_HIDDEN ConcreteInt : public NonLValue {
353public:
354 ConcreteInt(const APSInt& V) : NonLValue(ConcreteIntKind, &V) {}
355
356 const APSInt& getValue() const {
357 return *static_cast<APSInt*>(getRawPtr());
358 }
359
360 ConcreteInt Add(ValueManager& ValMgr, const ConcreteInt& V) const {
361 return ValMgr.getValue(getValue() + V.getValue());
362 }
363
364 ConcreteInt Sub(ValueManager& ValMgr, const ConcreteInt& V) const {
365 return ValMgr.getValue(getValue() - V.getValue());
366 }
367
368 ConcreteInt Mul(ValueManager& ValMgr, const ConcreteInt& V) const {
369 return ValMgr.getValue(getValue() * V.getValue());
370 }
371
372 ConcreteInt Div(ValueManager& ValMgr, const ConcreteInt& V) const {
373 return ValMgr.getValue(getValue() / V.getValue());
374 }
375
376 ConcreteInt Rem(ValueManager& ValMgr, const ConcreteInt& V) const {
377 return ValMgr.getValue(getValue() % V.getValue());
378 }
379
380 ConcreteInt Cast(ValueManager& ValMgr, Expr* CastExpr) const {
381 assert (CastExpr->getType()->isIntegerType());
382
383 APSInt X(getValue());
384 X.extOrTrunc(ValMgr.getContext()->getTypeSize(CastExpr->getType(),
385 CastExpr->getLocStart()));
386 return ValMgr.getValue(X);
387 }
388
389 ConcreteInt UnaryMinus(ValueManager& ValMgr, UnaryOperator* U) const {
390 assert (U->getType() == U->getSubExpr()->getType());
391 assert (U->getType()->isIntegerType());
392 return ValMgr.getValue(-getValue());
393 }
394
395 // Implement isa<T> support.
396 static inline bool classof(const RValue* V) {
397 return V->getSubKind() == ConcreteIntKind;
398 }
399};
400
401} // end anonymous namespace
402
403//===----------------------------------------------------------------------===//
404// Transfer function dispatch.
405//===----------------------------------------------------------------------===//
406
407RValue RValue::Cast(ValueManager& ValMgr, Expr* CastExpr) const {
408 switch (getSubKind()) {
409 case ConcreteIntKind:
410 return cast<ConcreteInt>(this)->Cast(ValMgr, CastExpr);
411 default:
412 return InvalidValue();
413 }
414}
415
416NonLValue NonLValue::UnaryMinus(ValueManager& ValMgr, UnaryOperator* U) const {
417 switch (getSubKind()) {
418 case ConcreteIntKind:
419 return cast<ConcreteInt>(this)->UnaryMinus(ValMgr, U);
420 default:
421 return cast<NonLValue>(InvalidValue());
422 }
423}
424
425#define RVALUE_DISPATCH_CASE(k1,k2,Op)\
426case (k1##Kind*NumNonLValueKind+k2##Kind):\
427 return cast<k1>(*this).Op(ValMgr,cast<k2>(RHS));
428
429#define RVALUE_DISPATCH(Op)\
430switch (getSubKind()*NumNonLValueKind+RHS.getSubKind()){\
431 RVALUE_DISPATCH_CASE(ConcreteInt,ConcreteInt,Op)\
432 default:\
433 assert (!isValid() || !RHS.isValid() && "Missing case.");\
434 break;\
435}\
436return cast<NonLValue>(InvalidValue());
437
438NonLValue NonLValue::Add(ValueManager& ValMgr, const NonLValue& RHS) const {
439 RVALUE_DISPATCH(Add)
440}
441
442NonLValue NonLValue::Sub(ValueManager& ValMgr, const NonLValue& RHS) const {
443 RVALUE_DISPATCH(Sub)
444}
445
446NonLValue NonLValue::Mul(ValueManager& ValMgr, const NonLValue& RHS) const {
447 RVALUE_DISPATCH(Mul)
448}
449
450NonLValue NonLValue::Div(ValueManager& ValMgr, const NonLValue& RHS) const {
451 RVALUE_DISPATCH(Div)
452}
453
454NonLValue NonLValue::Rem(ValueManager& ValMgr, const NonLValue& RHS) const {
455 RVALUE_DISPATCH(Rem)
456}
457
458
459#undef RVALUE_DISPATCH_CASE
460#undef RVALUE_DISPATCH
461
462//===----------------------------------------------------------------------===//
463// Utility methods for constructing RValues.
464//===----------------------------------------------------------------------===//
465
466NonLValue NonLValue::GetValue(ValueManager& ValMgr, const APSInt& V) {
467 return ConcreteInt(ValMgr.getValue(V));
468}
469
470NonLValue NonLValue::GetValue(ValueManager& ValMgr, IntegerLiteral* I) {
471 return ConcreteInt(ValMgr.getValue(APSInt(I->getValue(),
472 I->getType()->isUnsignedIntegerType())));
473}
474
475//===----------------------------------------------------------------------===//
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000476// Pretty-Printing.
477//===----------------------------------------------------------------------===//
478
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000479void RValue::print(std::ostream& Out) const {
Ted Kremenekf13794e2008-01-24 23:19:54 +0000480 switch (getBaseKind()) {
481 case InvalidKind:
482 Out << "Invalid";
483 break;
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000484
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000485 case NonLValueKind:
486 cast<NonLValue>(this)->print(Out);
Ted Kremenekf13794e2008-01-24 23:19:54 +0000487 break;
488
489 case LValueKind:
490 assert (false && "FIXME: LValue printing not implemented.");
491 break;
492
493 default:
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000494 assert (false && "Invalid RValue.");
Ted Kremenekf13794e2008-01-24 23:19:54 +0000495 }
496}
497
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000498void NonLValue::print(std::ostream& Out) const {
Ted Kremenekf13794e2008-01-24 23:19:54 +0000499 switch (getSubKind()) {
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000500 case ConcreteIntKind:
501 Out << cast<ConcreteInt>(this)->getValue().toString();
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000502 break;
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000503
504 default:
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000505 assert (false && "Pretty-printed not implemented for this NonLValue.");
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000506 break;
507 }
508}
509
510//===----------------------------------------------------------------------===//
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000511// ValueMapTy - A ImmutableMap type Stmt*/Decl*/Symbols to RValues.
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000512//===----------------------------------------------------------------------===//
513
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000514typedef llvm::ImmutableMap<ValueKey,RValue> ValueMapTy;
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000515
516namespace clang {
517 template<>
518 struct VISIBILITY_HIDDEN GRTrait<ValueMapTy> {
519 static inline void* toPtr(ValueMapTy M) {
520 return reinterpret_cast<void*>(M.getRoot());
521 }
522 static inline ValueMapTy toState(void* P) {
523 return ValueMapTy(static_cast<ValueMapTy::TreeTy*>(P));
524 }
525 };
Ted Kremenekd27f8162008-01-15 23:55:06 +0000526}
527
528//===----------------------------------------------------------------------===//
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000529// The Checker.
Ted Kremenekd27f8162008-01-15 23:55:06 +0000530//===----------------------------------------------------------------------===//
531
532namespace {
Ted Kremenekd27f8162008-01-15 23:55:06 +0000533
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000534class VISIBILITY_HIDDEN GRConstants {
Ted Kremenekd27f8162008-01-15 23:55:06 +0000535
536public:
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000537 typedef ValueMapTy StateTy;
Ted Kremenekd27f8162008-01-15 23:55:06 +0000538 typedef GRNodeBuilder<GRConstants> NodeBuilder;
539 typedef ExplodedNode<StateTy> NodeTy;
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000540
541 class NodeSet {
542 typedef llvm::SmallVector<NodeTy*,3> ImplTy;
543 ImplTy Impl;
544 public:
545
546 NodeSet() {}
547 NodeSet(NodeTy* N) { assert (N && !N->isInfeasible()); Impl.push_back(N); }
548
549 void Add(NodeTy* N) { if (N && !N->isInfeasible()) Impl.push_back(N); }
550
551 typedef ImplTy::iterator iterator;
552 typedef ImplTy::const_iterator const_iterator;
553
554 unsigned size() const { return Impl.size(); }
Ted Kremenek9de04c42008-01-24 20:55:43 +0000555 bool empty() const { return Impl.empty(); }
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000556
557 iterator begin() { return Impl.begin(); }
558 iterator end() { return Impl.end(); }
559
560 const_iterator begin() const { return Impl.begin(); }
561 const_iterator end() const { return Impl.end(); }
562 };
Ted Kremenekd27f8162008-01-15 23:55:06 +0000563
564protected:
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000565 /// Liveness - live-variables information the ValueDecl* and block-level
566 /// Expr* in the CFG. Used to prune out dead state.
Ted Kremenekd27f8162008-01-15 23:55:06 +0000567 LiveVariables* Liveness;
568
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000569 /// Builder - The current GRNodeBuilder which is used when building the nodes
570 /// for a given statement.
Ted Kremenekd27f8162008-01-15 23:55:06 +0000571 NodeBuilder* Builder;
572
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000573 /// StateMgr - Object that manages the data for all created states.
574 ValueMapTy::Factory StateMgr;
Ted Kremenekd27f8162008-01-15 23:55:06 +0000575
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000576 /// ValueMgr - Object that manages the data for all created RValues.
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000577 ValueManager ValMgr;
578
579 /// cfg - the current CFG.
Ted Kremenekd27f8162008-01-15 23:55:06 +0000580 CFG* cfg;
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000581
582 /// StmtEntryNode - The immediate predecessor node.
583 NodeTy* StmtEntryNode;
584
585 /// CurrentStmt - The current block-level statement.
586 Stmt* CurrentStmt;
587
588 bool StateCleaned;
Ted Kremenekd27f8162008-01-15 23:55:06 +0000589
Ted Kremenek7b8009a2008-01-24 02:28:56 +0000590 ASTContext* getContext() const { return ValMgr.getContext(); }
591
Ted Kremenekd27f8162008-01-15 23:55:06 +0000592public:
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000593 GRConstants() : Liveness(NULL), Builder(NULL), cfg(NULL),
594 StmtEntryNode(NULL), CurrentStmt(NULL) {}
Ted Kremenekd27f8162008-01-15 23:55:06 +0000595
596 ~GRConstants() { delete Liveness; }
597
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000598 /// getCFG - Returns the CFG associated with this analysis.
Ted Kremenekd27f8162008-01-15 23:55:06 +0000599 CFG& getCFG() { assert (cfg); return *cfg; }
600
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000601 /// Initialize - Initialize the checker's state based on the specified
602 /// CFG. This results in liveness information being computed for
603 /// each block-level statement in the CFG.
Ted Kremenek874d63f2008-01-24 02:02:54 +0000604 void Initialize(CFG& c, ASTContext& ctx) {
605 cfg = &c;
606 ValMgr.setContext(&ctx);
Ted Kremenekd27f8162008-01-15 23:55:06 +0000607 Liveness = new LiveVariables(c);
608 Liveness->runOnCFG(c);
Ted Kremenek79649df2008-01-17 18:25:22 +0000609 Liveness->runOnAllBlocks(c, NULL, true);
Ted Kremenekd27f8162008-01-15 23:55:06 +0000610 }
611
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000612 /// getInitialState - Return the initial state used for the root vertex
613 /// in the ExplodedGraph.
Ted Kremenekd27f8162008-01-15 23:55:06 +0000614 StateTy getInitialState() {
Ted Kremenekcb448ca2008-01-16 00:53:15 +0000615 return StateMgr.GetEmptyMap();
Ted Kremenekd27f8162008-01-15 23:55:06 +0000616 }
Ted Kremenekd27f8162008-01-15 23:55:06 +0000617
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000618 /// ProcessStmt - Called by GREngine. Used to generate new successor
619 /// nodes by processing the 'effects' of a block-level statement.
620 void ProcessStmt(Stmt* S, NodeBuilder& builder);
621
622 /// RemoveDeadBindings - Return a new state that is the same as 'M' except
623 /// that all subexpression mappings are removed and that any
624 /// block-level expressions that are not live at 'S' also have their
625 /// mappings removed.
626 StateTy RemoveDeadBindings(Stmt* S, StateTy M);
627
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000628 StateTy SetValue(StateTy St, Stmt* S, const RValue& V);
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000629
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000630 StateTy SetValue(StateTy St, const Stmt* S, const RValue& V) {
Ted Kremenek9de04c42008-01-24 20:55:43 +0000631 return SetValue(St, const_cast<Stmt*>(S), V);
632 }
633
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000634 StateTy SetValue(StateTy St, const LValue& LV, const RValue& V);
Ted Kremenek1ccd31c2008-01-16 19:42:59 +0000635
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000636 RValue GetValue(const StateTy& St, Stmt* S);
637 inline RValue GetValue(const StateTy& St, const Stmt* S) {
Ted Kremenek9de04c42008-01-24 20:55:43 +0000638 return GetValue(St, const_cast<Stmt*>(S));
639 }
640
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000641 RValue GetValue(const StateTy& St, const LValue& LV);
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000642 LValue GetLValue(const StateTy& St, Stmt* S);
Ted Kremenekd27f8162008-01-15 23:55:06 +0000643
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000644 void Nodify(NodeSet& Dst, Stmt* S, NodeTy* Pred, StateTy St);
Ted Kremenekd27f8162008-01-15 23:55:06 +0000645
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000646 /// Visit - Transfer function logic for all statements. Dispatches to
647 /// other functions that handle specific kinds of statements.
648 void Visit(Stmt* S, NodeTy* Pred, NodeSet& Dst);
Ted Kremenek874d63f2008-01-24 02:02:54 +0000649
650 /// VisitCast - Transfer function logic for all casts (implicit and explicit).
651 void VisitCast(Expr* CastE, Expr* E, NodeTy* Pred, NodeSet& Dst);
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000652
Ted Kremenek7b8009a2008-01-24 02:28:56 +0000653 /// VisitUnaryOperator - Transfer function logic for unary operators.
654 void VisitUnaryOperator(UnaryOperator* B, NodeTy* Pred, NodeSet& Dst);
655
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000656 /// VisitBinaryOperator - Transfer function logic for binary operators.
Ted Kremenek9de04c42008-01-24 20:55:43 +0000657 void VisitBinaryOperator(BinaryOperator* B, NodeTy* Pred, NodeSet& Dst);
658
659 /// VisitDeclStmt - Transfer function logic for DeclStmts.
660 void VisitDeclStmt(DeclStmt* DS, NodeTy* Pred, NodeSet& Dst);
Ted Kremenekd27f8162008-01-15 23:55:06 +0000661};
662} // end anonymous namespace
663
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000664
Ted Kremenekd27f8162008-01-15 23:55:06 +0000665void GRConstants::ProcessStmt(Stmt* S, NodeBuilder& builder) {
666 Builder = &builder;
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000667
668 StmtEntryNode = builder.getLastNode();
669 CurrentStmt = S;
670 NodeSet Dst;
671 StateCleaned = false;
672
673 Visit(S, StmtEntryNode, Dst);
674
675 // If no nodes were generated, generate a new node that has all the
676 // dead mappings removed.
677 if (Dst.size() == 1 && *Dst.begin() == StmtEntryNode) {
678 StateTy St = RemoveDeadBindings(S, StmtEntryNode->getState());
679 builder.generateNode(S, St, StmtEntryNode);
680 }
Ted Kremenekf84469b2008-01-18 00:41:32 +0000681
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000682 CurrentStmt = NULL;
683 StmtEntryNode = NULL;
684 Builder = NULL;
Ted Kremenekd27f8162008-01-15 23:55:06 +0000685}
686
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000687
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000688RValue GRConstants::GetValue(const StateTy& St, const LValue& LV) {
Ted Kremenekf13794e2008-01-24 23:19:54 +0000689 switch (LV.getSubKind()) {
690 case LValueDeclKind: {
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000691 StateTy::TreeTy* T = St.SlimFind(cast<LValueDecl>(LV).getDecl());
692 return T ? T->getValue().second : InvalidValue();
693 }
694 default:
695 assert (false && "Invalid LValue.");
Ted Kremenekca3e8572008-01-16 22:28:08 +0000696 break;
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000697 }
698
699 return InvalidValue();
700}
701
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000702RValue GRConstants::GetValue(const StateTy& St, Stmt* S) {
Ted Kremenek671c9e82008-01-24 00:50:08 +0000703 for (;;) {
704 switch (S->getStmtClass()) {
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000705
706 // ParenExprs are no-ops.
707
Ted Kremenek671c9e82008-01-24 00:50:08 +0000708 case Stmt::ParenExprClass:
709 S = cast<ParenExpr>(S)->getSubExpr();
710 continue;
711
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000712 // DeclRefExprs can either evaluate to an LValue or a Non-LValue
713 // (assuming an implicit "load") depending on the context. In this
714 // context we assume that we are retrieving the value contained
715 // within the referenced variables.
716
Ted Kremenek671c9e82008-01-24 00:50:08 +0000717 case Stmt::DeclRefExprClass:
718 return GetValue(St, LValueDecl(cast<DeclRefExpr>(S)->getDecl()));
Ted Kremenekca3e8572008-01-16 22:28:08 +0000719
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000720 // Integer literals evaluate to an RValue. Simply retrieve the
721 // RValue for the literal.
722
Ted Kremenek671c9e82008-01-24 00:50:08 +0000723 case Stmt::IntegerLiteralClass:
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000724 return NonLValue::GetValue(ValMgr, cast<IntegerLiteral>(S));
725
726 // Casts where the source and target type are the same
727 // are no-ops. We blast through these to get the descendant
728 // subexpression that has a value.
729
Ted Kremenek874d63f2008-01-24 02:02:54 +0000730 case Stmt::ImplicitCastExprClass: {
731 ImplicitCastExpr* C = cast<ImplicitCastExpr>(S);
732 if (C->getType() == C->getSubExpr()->getType()) {
733 S = C->getSubExpr();
734 continue;
735 }
736 break;
737 }
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000738
Ted Kremenek874d63f2008-01-24 02:02:54 +0000739 case Stmt::CastExprClass: {
740 CastExpr* C = cast<CastExpr>(S);
741 if (C->getType() == C->getSubExpr()->getType()) {
742 S = C->getSubExpr();
743 continue;
744 }
745 break;
746 }
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000747
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000748 // Handle all other Stmt* using a lookup.
749
Ted Kremenek671c9e82008-01-24 00:50:08 +0000750 default:
751 break;
752 };
753
754 break;
755 }
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000756
Ted Kremenek5c1b9962008-01-24 19:43:37 +0000757 StateTy::TreeTy* T = St.SlimFind(S);
Ted Kremenek874d63f2008-01-24 02:02:54 +0000758
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000759 return T ? T->getValue().second : InvalidValue();
760}
761
762LValue GRConstants::GetLValue(const StateTy& St, Stmt* S) {
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000763 while (ParenExpr* P = dyn_cast<ParenExpr>(S))
764 S = P->getSubExpr();
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000765
766 if (DeclRefExpr* DR = dyn_cast<DeclRefExpr>(S))
767 return LValueDecl(DR->getDecl());
768
769 return cast<LValue>(GetValue(St, S));
770}
771
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000772
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000773GRConstants::StateTy GRConstants::SetValue(StateTy St, Stmt* S,
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000774 const RValue& V) {
Ted Kremenekcc1c3652008-01-25 23:43:12 +0000775 assert (S);
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000776
777 if (!StateCleaned) {
778 St = RemoveDeadBindings(CurrentStmt, St);
779 StateCleaned = true;
780 }
781
Ted Kremenek9ff731d2008-01-24 22:27:20 +0000782 bool isBlkExpr = false;
783
784 if (S == CurrentStmt) {
785 isBlkExpr = getCFG().isBlkExpr(S);
786
787 if (!isBlkExpr)
788 return St;
789 }
Ted Kremenekdaadf452008-01-24 19:28:01 +0000790
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000791 return V.isValid() ? StateMgr.Add(St, ValueKey(S,isBlkExpr), V)
792 : St;
793}
794
795GRConstants::StateTy GRConstants::SetValue(StateTy St, const LValue& LV,
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000796 const RValue& V) {
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000797 if (!LV.isValid())
798 return St;
799
800 if (!StateCleaned) {
801 St = RemoveDeadBindings(CurrentStmt, St);
802 StateCleaned = true;
Ted Kremenekca3e8572008-01-16 22:28:08 +0000803 }
Ted Kremenek0525a4f2008-01-16 19:47:19 +0000804
Ted Kremenekf13794e2008-01-24 23:19:54 +0000805 switch (LV.getSubKind()) {
806 case LValueDeclKind:
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000807 return V.isValid() ? StateMgr.Add(St, cast<LValueDecl>(LV).getDecl(), V)
808 : StateMgr.Remove(St, cast<LValueDecl>(LV).getDecl());
809
810 default:
811 assert ("SetValue for given LValue type not yet implemented.");
812 return St;
813 }
Ted Kremenekd27f8162008-01-15 23:55:06 +0000814}
815
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000816GRConstants::StateTy GRConstants::RemoveDeadBindings(Stmt* Loc, StateTy M) {
Ted Kremenekf84469b2008-01-18 00:41:32 +0000817 // Note: in the code below, we can assign a new map to M since the
818 // iterators are iterating over the tree of the *original* map.
Ted Kremenekf84469b2008-01-18 00:41:32 +0000819 StateTy::iterator I = M.begin(), E = M.end();
820
Ted Kremenek5c1b9962008-01-24 19:43:37 +0000821 // Remove old bindings for subexpressions and "dead" block-level expressions.
822 for (; I!=E && !I.getKey().isDecl(); ++I) {
823 if (I.getKey().isSubExpr() || !Liveness->isLive(Loc,cast<Stmt>(I.getKey())))
824 M = StateMgr.Remove(M, I.getKey());
825 }
Ted Kremenekf84469b2008-01-18 00:41:32 +0000826
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000827 // Remove bindings for "dead" decls.
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000828 for (; I!=E && I.getKey().isDecl(); ++I)
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000829 if (VarDecl* V = dyn_cast<VarDecl>(cast<ValueDecl>(I.getKey())))
830 if (!Liveness->isLive(Loc, V))
831 M = StateMgr.Remove(M, I.getKey());
Ted Kremenek565256e2008-01-24 22:44:24 +0000832
Ted Kremeneke00fe3f2008-01-17 00:52:48 +0000833 return M;
Ted Kremeneke00fe3f2008-01-17 00:52:48 +0000834}
835
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000836void GRConstants::Nodify(NodeSet& Dst, Stmt* S, GRConstants::NodeTy* Pred,
837 GRConstants::StateTy St) {
838
839 // If the state hasn't changed, don't generate a new node.
840 if (St == Pred->getState())
841 return;
Ted Kremenekcb448ca2008-01-16 00:53:15 +0000842
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000843 Dst.Add(Builder->generateNode(S, St, Pred));
Ted Kremenekcb448ca2008-01-16 00:53:15 +0000844}
Ted Kremenekd27f8162008-01-15 23:55:06 +0000845
Ted Kremenek874d63f2008-01-24 02:02:54 +0000846void GRConstants::VisitCast(Expr* CastE, Expr* E, GRConstants::NodeTy* Pred,
847 GRConstants::NodeSet& Dst) {
848
849 QualType T = CastE->getType();
850
851 // Check for redundant casts.
852 if (E->getType() == T) {
853 Dst.Add(Pred);
854 return;
855 }
856
857 NodeSet S1;
858 Visit(E, Pred, S1);
859
860 for (NodeSet::iterator I1=S1.begin(), E1=S1.end(); I1 != E1; ++I1) {
861 NodeTy* N = *I1;
862 StateTy St = N->getState();
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000863 const RValue& V = GetValue(St, E);
864 Nodify(Dst, CastE, N, SetValue(St, CastE, V.Cast(ValMgr, CastE)));
Ted Kremenek874d63f2008-01-24 02:02:54 +0000865 }
Ted Kremenek9de04c42008-01-24 20:55:43 +0000866}
867
868void GRConstants::VisitDeclStmt(DeclStmt* DS, GRConstants::NodeTy* Pred,
869 GRConstants::NodeSet& Dst) {
870
871 StateTy St = Pred->getState();
872
873 for (const ScopedDecl* D = DS->getDecl(); D; D = D->getNextDeclarator())
874 if (const VarDecl* VD = dyn_cast<VarDecl>(D))
875 St = SetValue(St, LValueDecl(VD), GetValue(St, VD->getInit()));
876
877 Nodify(Dst, DS, Pred, St);
878
879 if (Dst.empty())
880 Dst.Add(Pred);
881}
Ted Kremenek874d63f2008-01-24 02:02:54 +0000882
Ted Kremenek7b8009a2008-01-24 02:28:56 +0000883void GRConstants::VisitUnaryOperator(UnaryOperator* U,
884 GRConstants::NodeTy* Pred,
885 GRConstants::NodeSet& Dst) {
886 NodeSet S1;
887 Visit(U->getSubExpr(), Pred, S1);
888
889 for (NodeSet::iterator I1=S1.begin(), E1=S1.end(); I1 != E1; ++I1) {
890 NodeTy* N1 = *I1;
891 StateTy St = N1->getState();
892
893 switch (U->getOpcode()) {
894 case UnaryOperator::PostInc: {
895 const LValue& L1 = GetLValue(St, U->getSubExpr());
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000896 NonLValue R1 = cast<NonLValue>(GetValue(St, L1));
Ted Kremenek7b8009a2008-01-24 02:28:56 +0000897
898 QualType T = U->getType();
Ted Kremeneke0cf9c82008-01-24 19:00:57 +0000899 unsigned bits = getContext()->getTypeSize(T, U->getLocStart());
Ted Kremenek5ee4ff82008-01-25 22:55:56 +0000900 APSInt One(llvm::APInt(bits, 1), T->isUnsignedIntegerType());
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000901 NonLValue R2 = NonLValue::GetValue(ValMgr, One);
Ted Kremeneke0cf9c82008-01-24 19:00:57 +0000902
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000903 NonLValue Result = R1.Add(ValMgr, R2);
Ted Kremenek7b8009a2008-01-24 02:28:56 +0000904 Nodify(Dst, U, N1, SetValue(SetValue(St, U, R1), L1, Result));
905 break;
906 }
907
908 case UnaryOperator::PostDec: {
909 const LValue& L1 = GetLValue(St, U->getSubExpr());
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000910 NonLValue R1 = cast<NonLValue>(GetValue(St, L1));
Ted Kremenek7b8009a2008-01-24 02:28:56 +0000911
912 QualType T = U->getType();
Ted Kremeneke0cf9c82008-01-24 19:00:57 +0000913 unsigned bits = getContext()->getTypeSize(T, U->getLocStart());
Ted Kremenek5ee4ff82008-01-25 22:55:56 +0000914 APSInt One(llvm::APInt(bits, 1), T->isUnsignedIntegerType());
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000915 NonLValue R2 = NonLValue::GetValue(ValMgr, One);
Ted Kremenek7b8009a2008-01-24 02:28:56 +0000916
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000917 NonLValue Result = R1.Sub(ValMgr, R2);
Ted Kremenek7b8009a2008-01-24 02:28:56 +0000918 Nodify(Dst, U, N1, SetValue(SetValue(St, U, R1), L1, Result));
919 break;
920 }
921
922 case UnaryOperator::PreInc: {
923 const LValue& L1 = GetLValue(St, U->getSubExpr());
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000924 NonLValue R1 = cast<NonLValue>(GetValue(St, L1));
Ted Kremenek7b8009a2008-01-24 02:28:56 +0000925
926 QualType T = U->getType();
Ted Kremeneke0cf9c82008-01-24 19:00:57 +0000927 unsigned bits = getContext()->getTypeSize(T, U->getLocStart());
Ted Kremenek5ee4ff82008-01-25 22:55:56 +0000928 APSInt One(llvm::APInt(bits, 1), T->isUnsignedIntegerType());
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000929 NonLValue R2 = NonLValue::GetValue(ValMgr, One);
Ted Kremenek7b8009a2008-01-24 02:28:56 +0000930
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000931 NonLValue Result = R1.Add(ValMgr, R2);
Ted Kremenek7b8009a2008-01-24 02:28:56 +0000932 Nodify(Dst, U, N1, SetValue(SetValue(St, U, Result), L1, Result));
933 break;
934 }
935
936 case UnaryOperator::PreDec: {
937 const LValue& L1 = GetLValue(St, U->getSubExpr());
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000938 NonLValue R1 = cast<NonLValue>(GetValue(St, L1));
Ted Kremenek7b8009a2008-01-24 02:28:56 +0000939
940 QualType T = U->getType();
Ted Kremeneke0cf9c82008-01-24 19:00:57 +0000941 unsigned bits = getContext()->getTypeSize(T, U->getLocStart());
Ted Kremenek5ee4ff82008-01-25 22:55:56 +0000942 APSInt One(llvm::APInt(bits, 1), T->isUnsignedIntegerType());
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000943 NonLValue R2 = NonLValue::GetValue(ValMgr, One);
Ted Kremenek7b8009a2008-01-24 02:28:56 +0000944
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000945 NonLValue Result = R1.Sub(ValMgr, R2);
Ted Kremenek7b8009a2008-01-24 02:28:56 +0000946 Nodify(Dst, U, N1, SetValue(SetValue(St, U, Result), L1, Result));
947 break;
948 }
949
Ted Kremenekdacbb4f2008-01-24 08:20:02 +0000950 case UnaryOperator::Minus: {
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000951 const NonLValue& R1 = cast<NonLValue>(GetValue(St, U->getSubExpr()));
952 Nodify(Dst, U, N1, SetValue(St, U, R1.UnaryMinus(ValMgr, U)));
Ted Kremenekdacbb4f2008-01-24 08:20:02 +0000953 break;
954 }
955
Ted Kremenek7b8009a2008-01-24 02:28:56 +0000956 default: ;
957 assert (false && "Not implemented.");
958 }
959 }
960}
961
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000962void GRConstants::VisitBinaryOperator(BinaryOperator* B,
963 GRConstants::NodeTy* Pred,
964 GRConstants::NodeSet& Dst) {
965 NodeSet S1;
966 Visit(B->getLHS(), Pred, S1);
Ted Kremenekcb448ca2008-01-16 00:53:15 +0000967
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000968 for (NodeSet::iterator I1=S1.begin(), E1=S1.end(); I1 != E1; ++I1) {
969 NodeTy* N1 = *I1;
Ted Kremeneke00fe3f2008-01-17 00:52:48 +0000970
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000971 // When getting the value for the LHS, check if we are in an assignment.
972 // In such cases, we want to (initially) treat the LHS as an LValue,
973 // so we use GetLValue instead of GetValue so that DeclRefExpr's are
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000974 // evaluated to LValueDecl's instead of to an NonLValue.
975 const RValue& V1 =
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000976 B->isAssignmentOp() ? GetLValue(N1->getState(), B->getLHS())
977 : GetValue(N1->getState(), B->getLHS());
Ted Kremenekcb448ca2008-01-16 00:53:15 +0000978
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000979 NodeSet S2;
980 Visit(B->getRHS(), N1, S2);
981
982 for (NodeSet::iterator I2=S2.begin(), E2=S2.end(); I2 != E2; ++I2) {
983 NodeTy* N2 = *I2;
984 StateTy St = N2->getState();
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000985 const RValue& V2 = GetValue(St, B->getRHS());
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000986
987 switch (B->getOpcode()) {
988 case BinaryOperator::Add: {
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000989 const NonLValue& R1 = cast<NonLValue>(V1);
990 const NonLValue& R2 = cast<NonLValue>(V2);
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000991
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000992 Nodify(Dst, B, N2, SetValue(St, B, R1.Add(ValMgr, R2)));
Ted Kremenekab2b8c52008-01-23 19:59:44 +0000993 break;
994 }
995
996 case BinaryOperator::Sub: {
Ted Kremenekbd03f1d2008-01-28 22:09:13 +0000997 const NonLValue& R1 = cast<NonLValue>(V1);
998 const NonLValue& R2 = cast<NonLValue>(V2);
999 Nodify(Dst, B, N2, SetValue(St, B, R1.Sub(ValMgr, R2)));
Ted Kremenekab2b8c52008-01-23 19:59:44 +00001000 break;
1001 }
1002
Ted Kremenek2eafd0e2008-01-23 23:42:27 +00001003 case BinaryOperator::Mul: {
Ted Kremenekbd03f1d2008-01-28 22:09:13 +00001004 const NonLValue& R1 = cast<NonLValue>(V1);
1005 const NonLValue& R2 = cast<NonLValue>(V2);
1006 Nodify(Dst, B, N2, SetValue(St, B, R1.Mul(ValMgr, R2)));
Ted Kremenek2eafd0e2008-01-23 23:42:27 +00001007 break;
1008 }
1009
Ted Kremenek5ee4ff82008-01-25 22:55:56 +00001010 case BinaryOperator::Div: {
Ted Kremenekbd03f1d2008-01-28 22:09:13 +00001011 const NonLValue& R1 = cast<NonLValue>(V1);
1012 const NonLValue& R2 = cast<NonLValue>(V2);
1013 Nodify(Dst, B, N2, SetValue(St, B, R1.Div(ValMgr, R2)));
Ted Kremenek5ee4ff82008-01-25 22:55:56 +00001014 break;
1015 }
1016
Ted Kremenekab2b8c52008-01-23 19:59:44 +00001017 case BinaryOperator::Assign: {
1018 const LValue& L1 = cast<LValue>(V1);
Ted Kremenekbd03f1d2008-01-28 22:09:13 +00001019 const NonLValue& R2 = cast<NonLValue>(V2);
Ted Kremenekab2b8c52008-01-23 19:59:44 +00001020 Nodify(Dst, B, N2, SetValue(SetValue(St, B, R2), L1, R2));
1021 break;
1022 }
Ted Kremenekb4ae33f2008-01-23 23:38:00 +00001023
1024 case BinaryOperator::AddAssign: {
1025 const LValue& L1 = cast<LValue>(V1);
Ted Kremenekbd03f1d2008-01-28 22:09:13 +00001026 NonLValue R1 = cast<NonLValue>(GetValue(N1->getState(), L1));
1027 NonLValue Result = R1.Add(ValMgr, cast<NonLValue>(V2));
Ted Kremenekb4ae33f2008-01-23 23:38:00 +00001028 Nodify(Dst, B, N2, SetValue(SetValue(St, B, Result), L1, Result));
1029 break;
1030 }
1031
1032 case BinaryOperator::SubAssign: {
1033 const LValue& L1 = cast<LValue>(V1);
Ted Kremenekbd03f1d2008-01-28 22:09:13 +00001034 NonLValue R1 = cast<NonLValue>(GetValue(N1->getState(), L1));
1035 NonLValue Result = R1.Sub(ValMgr, cast<NonLValue>(V2));
Ted Kremenekb4ae33f2008-01-23 23:38:00 +00001036 Nodify(Dst, B, N2, SetValue(SetValue(St, B, Result), L1, Result));
1037 break;
1038 }
Ted Kremenek2eafd0e2008-01-23 23:42:27 +00001039
1040 case BinaryOperator::MulAssign: {
1041 const LValue& L1 = cast<LValue>(V1);
Ted Kremenekbd03f1d2008-01-28 22:09:13 +00001042 NonLValue R1 = cast<NonLValue>(GetValue(N1->getState(), L1));
1043 NonLValue Result = R1.Mul(ValMgr, cast<NonLValue>(V2));
Ted Kremenek2eafd0e2008-01-23 23:42:27 +00001044 Nodify(Dst, B, N2, SetValue(SetValue(St, B, Result), L1, Result));
1045 break;
1046 }
Ted Kremenek5c1e2622008-01-25 23:45:34 +00001047
1048 case BinaryOperator::DivAssign: {
1049 const LValue& L1 = cast<LValue>(V1);
Ted Kremenekbd03f1d2008-01-28 22:09:13 +00001050 NonLValue R1 = cast<NonLValue>(GetValue(N1->getState(), L1));
1051 NonLValue Result = R1.Div(ValMgr, cast<NonLValue>(V2));
Ted Kremenek5c1e2622008-01-25 23:45:34 +00001052 Nodify(Dst, B, N2, SetValue(SetValue(St, B, Result), L1, Result));
1053 break;
1054 }
Ted Kremenekab2b8c52008-01-23 19:59:44 +00001055
1056 default:
1057 Dst.Add(N2);
1058 break;
1059 }
Ted Kremenekcb448ca2008-01-16 00:53:15 +00001060 }
Ted Kremenekd27f8162008-01-15 23:55:06 +00001061 }
Ted Kremenekd27f8162008-01-15 23:55:06 +00001062}
Ted Kremenekee985462008-01-16 18:18:48 +00001063
Ted Kremenek1ccd31c2008-01-16 19:42:59 +00001064
Ted Kremenekab2b8c52008-01-23 19:59:44 +00001065void GRConstants::Visit(Stmt* S, GRConstants::NodeTy* Pred,
1066 GRConstants::NodeSet& Dst) {
1067
1068 // FIXME: add metadata to the CFG so that we can disable
1069 // this check when we KNOW that there is no block-level subexpression.
1070 // The motivation is that this check requires a hashtable lookup.
1071
1072 if (S != CurrentStmt && getCFG().isBlkExpr(S)) {
1073 Dst.Add(Pred);
1074 return;
1075 }
1076
1077 switch (S->getStmtClass()) {
1078 case Stmt::BinaryOperatorClass:
Ted Kremenekb4ae33f2008-01-23 23:38:00 +00001079 case Stmt::CompoundAssignOperatorClass:
Ted Kremenekab2b8c52008-01-23 19:59:44 +00001080 VisitBinaryOperator(cast<BinaryOperator>(S), Pred, Dst);
1081 break;
1082
Ted Kremenek7b8009a2008-01-24 02:28:56 +00001083 case Stmt::UnaryOperatorClass:
1084 VisitUnaryOperator(cast<UnaryOperator>(S), Pred, Dst);
1085 break;
1086
Ted Kremenekab2b8c52008-01-23 19:59:44 +00001087 case Stmt::ParenExprClass:
1088 Visit(cast<ParenExpr>(S)->getSubExpr(), Pred, Dst);
1089 break;
1090
Ted Kremenek874d63f2008-01-24 02:02:54 +00001091 case Stmt::ImplicitCastExprClass: {
1092 ImplicitCastExpr* C = cast<ImplicitCastExpr>(S);
1093 VisitCast(C, C->getSubExpr(), Pred, Dst);
1094 break;
1095 }
1096
1097 case Stmt::CastExprClass: {
1098 CastExpr* C = cast<CastExpr>(S);
1099 VisitCast(C, C->getSubExpr(), Pred, Dst);
1100 break;
1101 }
1102
Ted Kremenek9de04c42008-01-24 20:55:43 +00001103 case Stmt::DeclStmtClass:
1104 VisitDeclStmt(cast<DeclStmt>(S), Pred, Dst);
1105 break;
1106
Ted Kremenekab2b8c52008-01-23 19:59:44 +00001107 default:
1108 Dst.Add(Pred); // No-op. Simply propagate the current state unchanged.
1109 break;
Ted Kremenek79649df2008-01-17 18:25:22 +00001110 }
Ted Kremenek1ccd31c2008-01-16 19:42:59 +00001111}
1112
Ted Kremenekee985462008-01-16 18:18:48 +00001113//===----------------------------------------------------------------------===//
1114// Driver.
1115//===----------------------------------------------------------------------===//
1116
Ted Kremenekaa66a322008-01-16 21:46:15 +00001117#ifndef NDEBUG
1118namespace llvm {
1119template<>
1120struct VISIBILITY_HIDDEN DOTGraphTraits<GRConstants::NodeTy*> :
1121 public DefaultDOTGraphTraits {
Ted Kremenek9ff731d2008-01-24 22:27:20 +00001122
1123 static void PrintKindLabel(std::ostream& Out, ValueKey::Kind kind) {
Ted Kremenek803c9ed2008-01-23 22:30:44 +00001124 switch (kind) {
Ted Kremenek565256e2008-01-24 22:44:24 +00001125 case ValueKey::IsSubExpr: Out << "Sub-Expressions:\\l"; break;
Ted Kremenek803c9ed2008-01-23 22:30:44 +00001126 case ValueKey::IsDecl: Out << "Variables:\\l"; break;
1127 case ValueKey::IsBlkExpr: Out << "Block-level Expressions:\\l"; break;
1128 default: assert (false && "Unknown ValueKey type.");
1129 }
1130 }
1131
Ted Kremenek9ff731d2008-01-24 22:27:20 +00001132 static void PrintKind(std::ostream& Out, GRConstants::StateTy M,
1133 ValueKey::Kind kind, bool isFirstGroup = false) {
1134 bool isFirst = true;
1135
1136 for (GRConstants::StateTy::iterator I=M.begin(), E=M.end();I!=E;++I) {
1137 if (I.getKey().getKind() != kind)
1138 continue;
1139
1140 if (isFirst) {
1141 if (!isFirstGroup) Out << "\\l\\l";
1142 PrintKindLabel(Out, kind);
1143 isFirst = false;
1144 }
1145 else
1146 Out << "\\l";
1147
1148 Out << ' ';
1149
1150 if (ValueDecl* V = dyn_cast<ValueDecl>(I.getKey()))
1151 Out << V->getName();
1152 else {
1153 Stmt* E = cast<Stmt>(I.getKey());
1154 Out << " (" << (void*) E << ") ";
1155 E->printPretty(Out);
1156 }
1157
1158 Out << " : ";
1159 I.getData().print(Out);
1160 }
1161 }
1162
Ted Kremenekaa66a322008-01-16 21:46:15 +00001163 static std::string getNodeLabel(const GRConstants::NodeTy* N, void*) {
1164 std::ostringstream Out;
Ted Kremenek803c9ed2008-01-23 22:30:44 +00001165
1166 // Program Location.
Ted Kremenekaa66a322008-01-16 21:46:15 +00001167 ProgramPoint Loc = N->getLocation();
1168
1169 switch (Loc.getKind()) {
1170 case ProgramPoint::BlockEntranceKind:
1171 Out << "Block Entrance: B"
1172 << cast<BlockEntrance>(Loc).getBlock()->getBlockID();
1173 break;
1174
1175 case ProgramPoint::BlockExitKind:
1176 assert (false);
1177 break;
1178
1179 case ProgramPoint::PostStmtKind: {
1180 const PostStmt& L = cast<PostStmt>(Loc);
Ted Kremenek9ff731d2008-01-24 22:27:20 +00001181 Out << L.getStmt()->getStmtClassName() << ':'
1182 << (void*) L.getStmt() << ' ';
1183
Ted Kremenekaa66a322008-01-16 21:46:15 +00001184 L.getStmt()->printPretty(Out);
1185 break;
1186 }
1187
1188 default: {
1189 const BlockEdge& E = cast<BlockEdge>(Loc);
1190 Out << "Edge: (B" << E.getSrc()->getBlockID() << ", B"
1191 << E.getDst()->getBlockID() << ')';
1192 }
1193 }
1194
Ted Kremenek803c9ed2008-01-23 22:30:44 +00001195 Out << "\\|";
Ted Kremenekaa66a322008-01-16 21:46:15 +00001196
Ted Kremenek9ff731d2008-01-24 22:27:20 +00001197 PrintKind(Out, N->getState(), ValueKey::IsDecl, true);
1198 PrintKind(Out, N->getState(), ValueKey::IsBlkExpr);
Ted Kremenek565256e2008-01-24 22:44:24 +00001199 PrintKind(Out, N->getState(), ValueKey::IsSubExpr);
Ted Kremenek803c9ed2008-01-23 22:30:44 +00001200
Ted Kremenek803c9ed2008-01-23 22:30:44 +00001201 Out << "\\l";
Ted Kremenekaa66a322008-01-16 21:46:15 +00001202 return Out.str();
1203 }
1204};
1205} // end llvm namespace
1206#endif
1207
Ted Kremenekee985462008-01-16 18:18:48 +00001208namespace clang {
Ted Kremenek874d63f2008-01-24 02:02:54 +00001209void RunGRConstants(CFG& cfg, ASTContext& Ctx) {
1210 GREngine<GRConstants> Engine(cfg, Ctx);
Ted Kremenekee985462008-01-16 18:18:48 +00001211 Engine.ExecuteWorkList();
Ted Kremenekaa66a322008-01-16 21:46:15 +00001212#ifndef NDEBUG
1213 llvm::ViewGraph(*Engine.getGraph().roots_begin(),"GRConstants");
1214#endif
Ted Kremenekee985462008-01-16 18:18:48 +00001215}
Ted Kremenekab2b8c52008-01-23 19:59:44 +00001216} // end clang namespace