Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 1 | //===-- GRConstants.cpp - Simple, Path-Sens. Constant Prop. ------*- C++ -*-==// |
| 2 | // |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 3 | // The LLValM Compiler Infrastructure |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 4 | // |
| 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 Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 20 | #include "clang/AST/ASTContext.h" |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 21 | #include "clang/Analysis/Analyses/LiveVariables.h" |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 22 | |
| 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 Kremenek | 3c6c672 | 2008-01-16 17:56:25 +0000 | [diff] [blame] | 28 | #include "llvm/ADT/SmallVector.h" |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 29 | #include "llvm/Support/Allocator.h" |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 30 | #include "llvm/Support/Compiler.h" |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 31 | #include "llvm/Support/Streams.h" |
| 32 | |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 33 | #include <functional> |
| 34 | |
Ted Kremenek | aa66a32 | 2008-01-16 21:46:15 +0000 | [diff] [blame] | 35 | #ifndef NDEBUG |
| 36 | #include "llvm/Support/GraphWriter.h" |
| 37 | #include <sstream> |
| 38 | #endif |
| 39 | |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 40 | using namespace clang; |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 41 | using llvm::dyn_cast; |
| 42 | using llvm::cast; |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 43 | using llvm::APSInt; |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 44 | |
| 45 | //===----------------------------------------------------------------------===// |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 46 | /// ValueKey - A variant smart pointer that wraps either a ValueDecl* or a |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 47 | /// Stmt*. Use cast<> or dyn_cast<> to get actual pointer type |
| 48 | //===----------------------------------------------------------------------===// |
| 49 | namespace { |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 50 | |
| 51 | class VISIBILITY_HIDDEN ValueKey { |
Ted Kremenek | 0525a4f | 2008-01-16 19:47:19 +0000 | [diff] [blame] | 52 | uintptr_t Raw; |
Ted Kremenek | cc1c365 | 2008-01-25 23:43:12 +0000 | [diff] [blame^] | 53 | |
| 54 | void operator=(const ValueKey& RHS); // Do not implement. |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 55 | public: |
Ted Kremenek | 565256e | 2008-01-24 22:44:24 +0000 | [diff] [blame] | 56 | enum Kind { IsSubExpr=0x0, IsBlkExpr=0x1, IsDecl=0x2, Flags=0x3 }; |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 57 | inline void* getPtr() const { return reinterpret_cast<void*>(Raw & ~Flags); } |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 58 | inline Kind getKind() const { return (Kind) (Raw & Flags); } |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 59 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 60 | ValueKey(const ValueDecl* VD) |
Ted Kremenek | cc1c365 | 2008-01-25 23:43:12 +0000 | [diff] [blame^] | 61 | : Raw(reinterpret_cast<uintptr_t>(VD) | IsDecl) { assert(VD); } |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 62 | |
Ted Kremenek | 5c1b996 | 2008-01-24 19:43:37 +0000 | [diff] [blame] | 63 | ValueKey(Stmt* S, bool isBlkExpr = false) |
Ted Kremenek | cc1c365 | 2008-01-25 23:43:12 +0000 | [diff] [blame^] | 64 | : Raw(reinterpret_cast<uintptr_t>(S) | (isBlkExpr ? IsBlkExpr : IsSubExpr)){ |
| 65 | assert(S); |
| 66 | } |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 67 | |
Ted Kremenek | 565256e | 2008-01-24 22:44:24 +0000 | [diff] [blame] | 68 | bool isSubExpr() const { return getKind() == IsSubExpr; } |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 69 | bool isDecl() const { return getKind() == IsDecl; } |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 70 | |
| 71 | inline void Profile(llvm::FoldingSetNodeID& ID) const { |
Ted Kremenek | 9849185 | 2008-01-16 05:51:13 +0000 | [diff] [blame] | 72 | ID.AddPointer(getPtr()); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | inline bool operator==(const ValueKey& X) const { |
Ted Kremenek | 5c1b996 | 2008-01-24 19:43:37 +0000 | [diff] [blame] | 76 | return getPtr() == X.getPtr(); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | inline bool operator!=(const ValueKey& X) const { |
| 80 | return !operator==(X); |
| 81 | } |
| 82 | |
| 83 | inline bool operator<(const ValueKey& X) const { |
| 84 | Kind k = getKind(), Xk = X.getKind(); |
Ted Kremenek | 5c1b996 | 2008-01-24 19:43:37 +0000 | [diff] [blame] | 85 | |
| 86 | if (k == IsDecl) { |
| 87 | if (Xk != IsDecl) |
| 88 | return false; |
| 89 | } |
| 90 | else { |
| 91 | if (Xk == IsDecl) |
| 92 | return true; |
| 93 | } |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 94 | |
Ted Kremenek | 5c1b996 | 2008-01-24 19:43:37 +0000 | [diff] [blame] | 95 | return getPtr() < X.getPtr(); |
Ted Kremenek | b3d2dca | 2008-01-16 23:33:44 +0000 | [diff] [blame] | 96 | } |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 97 | }; |
| 98 | } // end anonymous namespace |
| 99 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 100 | // Machinery to get cast<> and dyn_cast<> working with ValueKey. |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 101 | namespace llvm { |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 102 | template<> inline bool isa<ValueDecl,ValueKey>(const ValueKey& V) { |
| 103 | return V.getKind() == ValueKey::IsDecl; |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 104 | } |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 105 | template<> inline bool isa<Stmt,ValueKey>(const ValueKey& V) { |
| 106 | return ((unsigned) V.getKind()) != ValueKey::IsDecl; |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 107 | } |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 108 | template<> struct VISIBILITY_HIDDEN cast_retty_impl<ValueDecl,ValueKey> { |
Ted Kremenek | aa66a32 | 2008-01-16 21:46:15 +0000 | [diff] [blame] | 109 | typedef const ValueDecl* ret_type; |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 110 | }; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 111 | template<> struct VISIBILITY_HIDDEN cast_retty_impl<Stmt,ValueKey> { |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 112 | typedef const Stmt* ret_type; |
| 113 | }; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 114 | template<> struct VISIBILITY_HIDDEN simplify_type<ValueKey> { |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 115 | typedef void* SimpleType; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 116 | static inline SimpleType getSimplifiedValue(const ValueKey &V) { |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 117 | return V.getPtr(); |
| 118 | } |
| 119 | }; |
| 120 | } // end llvm namespace |
| 121 | |
| 122 | //===----------------------------------------------------------------------===// |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 123 | // ValueManager. |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 124 | //===----------------------------------------------------------------------===// |
| 125 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 126 | namespace { |
| 127 | |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 128 | typedef llvm::ImmutableSet<APSInt > APSIntSetTy; |
| 129 | |
| 130 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 131 | class VISIBILITY_HIDDEN ValueManager { |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 132 | APSIntSetTy::Factory APSIntSetFactory; |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 133 | ASTContext* Ctx; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 134 | |
| 135 | public: |
| 136 | ValueManager() {} |
| 137 | ~ValueManager() {} |
| 138 | |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 139 | void setContext(ASTContext* ctx) { Ctx = ctx; } |
| 140 | ASTContext* getContext() const { return Ctx; } |
| 141 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 142 | APSIntSetTy GetEmptyAPSIntSet() { |
| 143 | return APSIntSetFactory.GetEmptySet(); |
| 144 | } |
| 145 | |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 146 | APSIntSetTy AddToSet(const APSIntSetTy& Set, const APSInt& Val) { |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 147 | return APSIntSetFactory.Add(Set, Val); |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 148 | } |
| 149 | }; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 150 | } // end anonymous namespace |
| 151 | |
Ted Kremenek | cc1c365 | 2008-01-25 23:43:12 +0000 | [diff] [blame^] | 152 | template <template <typename T> class OpTy> |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 153 | static inline APSIntSetTy APSIntSetOp(ValueManager& ValMgr, |
Ted Kremenek | cc1c365 | 2008-01-25 23:43:12 +0000 | [diff] [blame^] | 154 | APSIntSetTy S1, APSIntSetTy S2) { |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 155 | |
| 156 | APSIntSetTy M = ValMgr.GetEmptyAPSIntSet(); |
| 157 | |
Ted Kremenek | cc1c365 | 2008-01-25 23:43:12 +0000 | [diff] [blame^] | 158 | OpTy<APSInt> Op; |
| 159 | |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 160 | for (APSIntSetTy::iterator I1=S1.begin(), E1=S2.end(); I1!=E1; ++I1) |
| 161 | for (APSIntSetTy::iterator I2=S2.begin(), E2=S2.end(); I2!=E2; ++I2) |
Ted Kremenek | cc1c365 | 2008-01-25 23:43:12 +0000 | [diff] [blame^] | 162 | M = ValMgr.AddToSet(M, Op(*I1, *I2)); |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 163 | |
| 164 | return M; |
| 165 | } |
| 166 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 167 | //===----------------------------------------------------------------------===// |
| 168 | // Expression Values. |
| 169 | //===----------------------------------------------------------------------===// |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 170 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 171 | namespace { |
| 172 | |
| 173 | class VISIBILITY_HIDDEN ExprValue { |
| 174 | public: |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 175 | enum BaseKind { LValueKind=0x1, RValueKind=0x2, InvalidKind=0x0 }; |
| 176 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 177 | private: |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 178 | void* Data; |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 179 | unsigned Kind; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 180 | |
| 181 | protected: |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 182 | ExprValue(void* d, bool isRValue, unsigned ValKind) |
| 183 | : Data(d), |
| 184 | Kind((isRValue ? RValueKind : LValueKind) | (ValKind << 2)) {} |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 185 | |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 186 | ExprValue() : Data(NULL), Kind(0) {} |
| 187 | |
| 188 | void* getRawPtr() const { return Data; } |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 189 | |
| 190 | public: |
| 191 | ~ExprValue() {}; |
| 192 | |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 193 | ExprValue EvalCast(ValueManager& ValMgr, Expr* CastExpr) const; |
| 194 | |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 195 | unsigned getRawKind() const { return Kind; } |
| 196 | BaseKind getBaseKind() const { return (BaseKind) (Kind & 0x3); } |
| 197 | unsigned getSubKind() const { return (Kind & ~0x3) >> 2; } |
| 198 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 199 | void Profile(llvm::FoldingSetNodeID& ID) const { |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 200 | ID.AddInteger((unsigned) getRawKind()); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 201 | ID.AddPointer(Data); |
| 202 | } |
| 203 | |
| 204 | bool operator==(const ExprValue& RHS) const { |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 205 | return getRawKind() == RHS.getRawKind() && Data == RHS.Data; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 206 | } |
| 207 | |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 208 | inline bool isValid() const { return getRawKind() != InvalidKind; } |
| 209 | inline bool isInvalid() const { return getRawKind() == InvalidKind; } |
| 210 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 211 | |
| 212 | void print(std::ostream& OS) const; |
| 213 | void print() const { print(*llvm::cerr.stream()); } |
| 214 | |
| 215 | // Implement isa<T> support. |
| 216 | static inline bool classof(const ExprValue*) { return true; } |
| 217 | }; |
| 218 | |
| 219 | class VISIBILITY_HIDDEN InvalidValue : public ExprValue { |
| 220 | public: |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 221 | InvalidValue() {} |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 222 | |
| 223 | static inline bool classof(const ExprValue* V) { |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 224 | return V->getBaseKind() == InvalidKind; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 225 | } |
| 226 | }; |
| 227 | |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 228 | class VISIBILITY_HIDDEN LValue : public ExprValue { |
| 229 | protected: |
| 230 | LValue(unsigned SubKind, void* D) : ExprValue(D, false, SubKind) {} |
| 231 | |
| 232 | public: |
| 233 | // Implement isa<T> support. |
| 234 | static inline bool classof(const ExprValue* V) { |
| 235 | return V->getBaseKind() == LValueKind; |
| 236 | } |
| 237 | }; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 238 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 239 | class VISIBILITY_HIDDEN RValue : public ExprValue { |
| 240 | protected: |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 241 | RValue(unsigned SubKind, void* d) : ExprValue(d, true, SubKind) {} |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 242 | |
| 243 | public: |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 244 | void print(std::ostream& Out) const; |
| 245 | |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 246 | RValue EvalAdd(ValueManager& ValMgr, const RValue& RHS) const; |
| 247 | RValue EvalSub(ValueManager& ValMgr, const RValue& RHS) const; |
| 248 | RValue EvalMul(ValueManager& ValMgr, const RValue& RHS) const; |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 249 | RValue EvalDiv(ValueManager& ValMgr, const RValue& RHS) const; |
Ted Kremenek | dacbb4f | 2008-01-24 08:20:02 +0000 | [diff] [blame] | 250 | RValue EvalMinus(ValueManager& ValMgr, UnaryOperator* U) const; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 251 | |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 252 | static RValue GetRValue(ValueManager& ValMgr, const APSInt& V); |
Ted Kremenek | dacbb4f | 2008-01-24 08:20:02 +0000 | [diff] [blame] | 253 | static RValue GetRValue(ValueManager& ValMgr, IntegerLiteral* I); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 254 | |
| 255 | // Implement isa<T> support. |
| 256 | static inline bool classof(const ExprValue* V) { |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 257 | return V->getBaseKind() == RValueKind; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 258 | } |
| 259 | }; |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 260 | |
| 261 | } // end anonymous namespace |
| 262 | |
| 263 | //===----------------------------------------------------------------------===// |
| 264 | // "R-Values": Interface. |
| 265 | //===----------------------------------------------------------------------===// |
| 266 | |
| 267 | namespace { |
| 268 | |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 269 | enum { RValEqualityORSetKind, |
| 270 | RValInequalityANDSetKind, |
| 271 | NumRValueKind }; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 272 | |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 273 | class VISIBILITY_HIDDEN RValEqualityORSet : public RValue { |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 274 | public: |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 275 | RValEqualityORSet(const APSIntSetTy& S) |
| 276 | : RValue(RValEqualityORSetKind, S.getRoot()) {} |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 277 | |
| 278 | APSIntSetTy GetValues() const { |
| 279 | return APSIntSetTy(reinterpret_cast<APSIntSetTy::TreeTy*>(getRawPtr())); |
| 280 | } |
| 281 | |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 282 | RValEqualityORSet |
| 283 | EvalAdd(ValueManager& ValMgr, const RValEqualityORSet& V) const { |
Ted Kremenek | cc1c365 | 2008-01-25 23:43:12 +0000 | [diff] [blame^] | 284 | return APSIntSetOp<std::plus>(ValMgr, GetValues(), V.GetValues()); |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 285 | } |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 286 | |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 287 | RValEqualityORSet |
| 288 | EvalSub(ValueManager& ValMgr, const RValEqualityORSet& V) const { |
Ted Kremenek | cc1c365 | 2008-01-25 23:43:12 +0000 | [diff] [blame^] | 289 | return APSIntSetOp<std::minus>(ValMgr, GetValues(), V.GetValues()); |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 290 | } |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 291 | |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 292 | RValEqualityORSet |
| 293 | EvalMul(ValueManager& ValMgr, const RValEqualityORSet& V) const { |
Ted Kremenek | cc1c365 | 2008-01-25 23:43:12 +0000 | [diff] [blame^] | 294 | return APSIntSetOp<std::multiplies>(ValMgr, GetValues(), V.GetValues()); |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | RValEqualityORSet |
| 298 | EvalDiv(ValueManager& ValMgr, const RValEqualityORSet& V) const { |
Ted Kremenek | cc1c365 | 2008-01-25 23:43:12 +0000 | [diff] [blame^] | 299 | return APSIntSetOp<std::divides>(ValMgr, GetValues(), V.GetValues()); |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 300 | } |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 301 | |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 302 | RValEqualityORSet |
Ted Kremenek | 2cd65c8 | 2008-01-25 22:06:07 +0000 | [diff] [blame] | 303 | EvalCast(ValueManager& ValMgr, Expr* CastExpr) const; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 304 | |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 305 | RValEqualityORSet |
Ted Kremenek | 2cd65c8 | 2008-01-25 22:06:07 +0000 | [diff] [blame] | 306 | EvalMinus(ValueManager& ValMgr, UnaryOperator* U) const; |
Ted Kremenek | dacbb4f | 2008-01-24 08:20:02 +0000 | [diff] [blame] | 307 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 308 | // Implement isa<T> support. |
| 309 | static inline bool classof(const ExprValue* V) { |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 310 | return V->getSubKind() == RValEqualityORSetKind; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 311 | } |
| 312 | }; |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 313 | |
| 314 | class VISIBILITY_HIDDEN RValInequalityANDSet : public RValue { |
| 315 | public: |
| 316 | RValInequalityANDSet(const APSIntSetTy& S) |
| 317 | : RValue(RValInequalityANDSetKind, S.getRoot()) {} |
| 318 | |
| 319 | APSIntSetTy GetValues() const { |
| 320 | return APSIntSetTy(reinterpret_cast<APSIntSetTy::TreeTy*>(getRawPtr())); |
| 321 | } |
| 322 | |
| 323 | RValInequalityANDSet |
| 324 | EvalAdd(ValueManager& ValMgr, const RValInequalityANDSet& V) const; |
| 325 | |
| 326 | RValInequalityANDSet |
| 327 | EvalSub(ValueManager& ValMgr, const RValInequalityANDSet& V) const; |
| 328 | |
| 329 | RValInequalityANDSet |
| 330 | EvalMul(ValueManager& ValMgr, const RValInequalityANDSet& V) const; |
| 331 | |
| 332 | RValInequalityANDSet |
| 333 | EvalDiv(ValueManager& ValMgr, const RValInequalityANDSet& V) const; |
| 334 | |
| 335 | RValInequalityANDSet |
| 336 | EvalCast(ValueManager& ValMgr, Expr* CastExpr) const; |
| 337 | |
| 338 | RValInequalityANDSet |
| 339 | EvalMinus(ValueManager& ValMgr, UnaryOperator* U) const; |
| 340 | |
| 341 | // Implement isa<T> support. |
| 342 | static inline bool classof(const ExprValue* V) { |
| 343 | return V->getSubKind() == RValInequalityANDSetKind; |
| 344 | } |
| 345 | }; |
| 346 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 347 | } // end anonymous namespace |
| 348 | |
| 349 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 350 | // Transfer functions: Casts. |
| 351 | //===----------------------------------------------------------------------===// |
| 352 | |
| 353 | ExprValue ExprValue::EvalCast(ValueManager& ValMgr, Expr* CastExpr) const { |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 354 | switch (getSubKind()) { |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 355 | case RValEqualityORSetKind: |
| 356 | return cast<RValEqualityORSet>(this)->EvalCast(ValMgr, CastExpr); |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 357 | default: |
| 358 | return InvalidValue(); |
| 359 | } |
| 360 | } |
| 361 | |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 362 | RValEqualityORSet |
| 363 | RValEqualityORSet::EvalCast(ValueManager& ValMgr, Expr* CastExpr) const { |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 364 | QualType T = CastExpr->getType(); |
| 365 | assert (T->isIntegerType()); |
| 366 | |
| 367 | APSIntSetTy S1 = GetValues(); |
| 368 | APSIntSetTy S2 = ValMgr.GetEmptyAPSIntSet(); |
| 369 | |
| 370 | for (APSIntSetTy::iterator I=S1.begin(), E=S1.end(); I!=E; ++I) { |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 371 | APSInt X = *I; |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 372 | X.setIsSigned(T->isSignedIntegerType()); |
| 373 | X.extOrTrunc(ValMgr.getContext()->getTypeSize(T,CastExpr->getLocStart())); |
| 374 | S2 = ValMgr.AddToSet(S2, X); |
| 375 | } |
| 376 | |
| 377 | return S2; |
| 378 | } |
| 379 | |
| 380 | //===----------------------------------------------------------------------===// |
Ted Kremenek | dacbb4f | 2008-01-24 08:20:02 +0000 | [diff] [blame] | 381 | // Transfer functions: Unary Operations over R-Values. |
| 382 | //===----------------------------------------------------------------------===// |
| 383 | |
| 384 | RValue RValue::EvalMinus(ValueManager& ValMgr, UnaryOperator* U) const { |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 385 | switch (getSubKind()) { |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 386 | case RValEqualityORSetKind: |
| 387 | return cast<RValEqualityORSet>(this)->EvalMinus(ValMgr, U); |
Ted Kremenek | dacbb4f | 2008-01-24 08:20:02 +0000 | [diff] [blame] | 388 | default: |
| 389 | return cast<RValue>(InvalidValue()); |
| 390 | } |
| 391 | } |
| 392 | |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 393 | RValEqualityORSet |
| 394 | RValEqualityORSet::EvalMinus(ValueManager& ValMgr, UnaryOperator* U) const{ |
Ted Kremenek | dacbb4f | 2008-01-24 08:20:02 +0000 | [diff] [blame] | 395 | |
| 396 | assert (U->getType() == U->getSubExpr()->getType()); |
| 397 | assert (U->getType()->isIntegerType()); |
| 398 | |
| 399 | APSIntSetTy S1 = GetValues(); |
| 400 | APSIntSetTy S2 = ValMgr.GetEmptyAPSIntSet(); |
| 401 | |
| 402 | for (APSIntSetTy::iterator I=S1.begin(), E=S1.end(); I!=E; ++I) { |
| 403 | assert ((*I).isSigned()); |
| 404 | |
| 405 | // FIXME: Shouldn't operator- on APSInt return an APSInt with the proper |
| 406 | // sign? |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 407 | APSInt X(-(*I)); |
Ted Kremenek | dacbb4f | 2008-01-24 08:20:02 +0000 | [diff] [blame] | 408 | X.setIsSigned(true); |
| 409 | |
| 410 | S2 = ValMgr.AddToSet(S2, X); |
| 411 | } |
| 412 | |
| 413 | return S2; |
| 414 | } |
| 415 | |
Ted Kremenek | dacbb4f | 2008-01-24 08:20:02 +0000 | [diff] [blame] | 416 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 417 | // Transfer functions: Binary Operations over R-Values. |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 418 | //===----------------------------------------------------------------------===// |
| 419 | |
| 420 | #define RVALUE_DISPATCH_CASE(k1,k2,Op)\ |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 421 | case (k1##Kind*NumRValueKind+k2##Kind):\ |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 422 | return cast<k1>(*this).Eval##Op(ValMgr,cast<k2>(RHS)); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 423 | |
| 424 | #define RVALUE_DISPATCH(Op)\ |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 425 | switch (getSubKind()*NumRValueKind+RHS.getSubKind()){\ |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 426 | RVALUE_DISPATCH_CASE(RValEqualityORSet,RValEqualityORSet,Op)\ |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 427 | default:\ |
| 428 | assert (!isValid() || !RHS.isValid() && "Missing case.");\ |
| 429 | break;\ |
| 430 | }\ |
| 431 | return cast<RValue>(InvalidValue()); |
| 432 | |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 433 | RValue RValue::EvalAdd(ValueManager& ValMgr, const RValue& RHS) const { |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 434 | RVALUE_DISPATCH(Add) |
| 435 | } |
| 436 | |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 437 | RValue RValue::EvalSub(ValueManager& ValMgr, const RValue& RHS) const { |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 438 | RVALUE_DISPATCH(Sub) |
| 439 | } |
| 440 | |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 441 | RValue RValue::EvalMul(ValueManager& ValMgr, const RValue& RHS) const { |
Ted Kremenek | 2eafd0e | 2008-01-23 23:42:27 +0000 | [diff] [blame] | 442 | RVALUE_DISPATCH(Mul) |
| 443 | } |
| 444 | |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 445 | RValue RValue::EvalDiv(ValueManager& ValMgr, const RValue& RHS) const { |
| 446 | RVALUE_DISPATCH(Div) |
| 447 | } |
| 448 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 449 | #undef RVALUE_DISPATCH_CASE |
| 450 | #undef RVALUE_DISPATCH |
| 451 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 452 | |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 453 | RValue RValue::GetRValue(ValueManager& ValMgr, const APSInt& V) { |
| 454 | return RValEqualityORSet(ValMgr.AddToSet(ValMgr.GetEmptyAPSIntSet(), V)); |
Ted Kremenek | dacbb4f | 2008-01-24 08:20:02 +0000 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | RValue RValue::GetRValue(ValueManager& ValMgr, IntegerLiteral* I) { |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 458 | return GetRValue(ValMgr, |
| 459 | APSInt(I->getValue(),I->getType()->isUnsignedIntegerType())); |
Ted Kremenek | dacbb4f | 2008-01-24 08:20:02 +0000 | [diff] [blame] | 460 | } |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 461 | |
| 462 | //===----------------------------------------------------------------------===// |
| 463 | // "L-Values". |
| 464 | //===----------------------------------------------------------------------===// |
| 465 | |
| 466 | namespace { |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 467 | |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 468 | enum { LValueDeclKind, MaxLValueKind }; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 469 | |
| 470 | class VISIBILITY_HIDDEN LValueDecl : public LValue { |
| 471 | public: |
Ted Kremenek | 9de04c4 | 2008-01-24 20:55:43 +0000 | [diff] [blame] | 472 | LValueDecl(const ValueDecl* vd) |
| 473 | : LValue(LValueDeclKind,const_cast<ValueDecl*>(vd)) {} |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 474 | |
| 475 | ValueDecl* getDecl() const { |
| 476 | return static_cast<ValueDecl*>(getRawPtr()); |
| 477 | } |
| 478 | |
| 479 | // Implement isa<T> support. |
| 480 | static inline bool classof(const ExprValue* V) { |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 481 | return V->getSubKind() == LValueDeclKind; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 482 | } |
| 483 | }; |
| 484 | } // end anonymous namespace |
| 485 | |
| 486 | //===----------------------------------------------------------------------===// |
| 487 | // Pretty-Printing. |
| 488 | //===----------------------------------------------------------------------===// |
| 489 | |
| 490 | void ExprValue::print(std::ostream& Out) const { |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 491 | switch (getBaseKind()) { |
| 492 | case InvalidKind: |
| 493 | Out << "Invalid"; |
| 494 | break; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 495 | |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 496 | case RValueKind: |
| 497 | cast<RValue>(this)->print(Out); |
| 498 | break; |
| 499 | |
| 500 | case LValueKind: |
| 501 | assert (false && "FIXME: LValue printing not implemented."); |
| 502 | break; |
| 503 | |
| 504 | default: |
| 505 | assert (false && "Invalid ExprValue."); |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | void RValue::print(std::ostream& Out) const { |
| 510 | switch (getSubKind()) { |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 511 | case RValEqualityORSetKind: { |
| 512 | APSIntSetTy S = cast<RValEqualityORSet>(this)->GetValues(); |
Ted Kremenek | 803c9ed | 2008-01-23 22:30:44 +0000 | [diff] [blame] | 513 | bool first = true; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 514 | |
Ted Kremenek | 803c9ed | 2008-01-23 22:30:44 +0000 | [diff] [blame] | 515 | for (APSIntSetTy::iterator I=S.begin(), E=S.end(); I!=E; ++I) { |
| 516 | if (first) first = false; |
| 517 | else Out << " | "; |
| 518 | |
| 519 | Out << (*I).toString(); |
| 520 | } |
| 521 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 522 | break; |
| 523 | } |
| 524 | |
| 525 | default: |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 526 | assert (false && "Pretty-printed not implemented for this RValue."); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 527 | break; |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | //===----------------------------------------------------------------------===// |
| 532 | // ValueMapTy - A ImmutableMap type Stmt*/Decl* to ExprValues. |
| 533 | //===----------------------------------------------------------------------===// |
| 534 | |
| 535 | typedef llvm::ImmutableMap<ValueKey,ExprValue> ValueMapTy; |
| 536 | |
| 537 | namespace clang { |
| 538 | template<> |
| 539 | struct VISIBILITY_HIDDEN GRTrait<ValueMapTy> { |
| 540 | static inline void* toPtr(ValueMapTy M) { |
| 541 | return reinterpret_cast<void*>(M.getRoot()); |
| 542 | } |
| 543 | static inline ValueMapTy toState(void* P) { |
| 544 | return ValueMapTy(static_cast<ValueMapTy::TreeTy*>(P)); |
| 545 | } |
| 546 | }; |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | //===----------------------------------------------------------------------===// |
| 550 | // The Checker! |
| 551 | //===----------------------------------------------------------------------===// |
| 552 | |
| 553 | namespace { |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 554 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 555 | class VISIBILITY_HIDDEN GRConstants { |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 556 | |
| 557 | public: |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 558 | typedef ValueMapTy StateTy; |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 559 | typedef GRNodeBuilder<GRConstants> NodeBuilder; |
| 560 | typedef ExplodedNode<StateTy> NodeTy; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 561 | |
| 562 | class NodeSet { |
| 563 | typedef llvm::SmallVector<NodeTy*,3> ImplTy; |
| 564 | ImplTy Impl; |
| 565 | public: |
| 566 | |
| 567 | NodeSet() {} |
| 568 | NodeSet(NodeTy* N) { assert (N && !N->isInfeasible()); Impl.push_back(N); } |
| 569 | |
| 570 | void Add(NodeTy* N) { if (N && !N->isInfeasible()) Impl.push_back(N); } |
| 571 | |
| 572 | typedef ImplTy::iterator iterator; |
| 573 | typedef ImplTy::const_iterator const_iterator; |
| 574 | |
| 575 | unsigned size() const { return Impl.size(); } |
Ted Kremenek | 9de04c4 | 2008-01-24 20:55:43 +0000 | [diff] [blame] | 576 | bool empty() const { return Impl.empty(); } |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 577 | |
| 578 | iterator begin() { return Impl.begin(); } |
| 579 | iterator end() { return Impl.end(); } |
| 580 | |
| 581 | const_iterator begin() const { return Impl.begin(); } |
| 582 | const_iterator end() const { return Impl.end(); } |
| 583 | }; |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 584 | |
| 585 | protected: |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 586 | /// Liveness - live-variables information the ValueDecl* and block-level |
| 587 | /// Expr* in the CFG. Used to prune out dead state. |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 588 | LiveVariables* Liveness; |
| 589 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 590 | /// Builder - The current GRNodeBuilder which is used when building the nodes |
| 591 | /// for a given statement. |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 592 | NodeBuilder* Builder; |
| 593 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 594 | /// StateMgr - Object that manages the data for all created states. |
| 595 | ValueMapTy::Factory StateMgr; |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 596 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 597 | /// ValueMgr - Object that manages the data for all created ExprValues. |
| 598 | ValueManager ValMgr; |
| 599 | |
| 600 | /// cfg - the current CFG. |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 601 | CFG* cfg; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 602 | |
| 603 | /// StmtEntryNode - The immediate predecessor node. |
| 604 | NodeTy* StmtEntryNode; |
| 605 | |
| 606 | /// CurrentStmt - The current block-level statement. |
| 607 | Stmt* CurrentStmt; |
| 608 | |
| 609 | bool StateCleaned; |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 610 | |
Ted Kremenek | 7b8009a | 2008-01-24 02:28:56 +0000 | [diff] [blame] | 611 | ASTContext* getContext() const { return ValMgr.getContext(); } |
| 612 | |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 613 | public: |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 614 | GRConstants() : Liveness(NULL), Builder(NULL), cfg(NULL), |
| 615 | StmtEntryNode(NULL), CurrentStmt(NULL) {} |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 616 | |
| 617 | ~GRConstants() { delete Liveness; } |
| 618 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 619 | /// getCFG - Returns the CFG associated with this analysis. |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 620 | CFG& getCFG() { assert (cfg); return *cfg; } |
| 621 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 622 | /// Initialize - Initialize the checker's state based on the specified |
| 623 | /// CFG. This results in liveness information being computed for |
| 624 | /// each block-level statement in the CFG. |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 625 | void Initialize(CFG& c, ASTContext& ctx) { |
| 626 | cfg = &c; |
| 627 | ValMgr.setContext(&ctx); |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 628 | Liveness = new LiveVariables(c); |
| 629 | Liveness->runOnCFG(c); |
Ted Kremenek | 79649df | 2008-01-17 18:25:22 +0000 | [diff] [blame] | 630 | Liveness->runOnAllBlocks(c, NULL, true); |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 631 | } |
| 632 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 633 | /// getInitialState - Return the initial state used for the root vertex |
| 634 | /// in the ExplodedGraph. |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 635 | StateTy getInitialState() { |
Ted Kremenek | cb448ca | 2008-01-16 00:53:15 +0000 | [diff] [blame] | 636 | return StateMgr.GetEmptyMap(); |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 637 | } |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 638 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 639 | /// ProcessStmt - Called by GREngine. Used to generate new successor |
| 640 | /// nodes by processing the 'effects' of a block-level statement. |
| 641 | void ProcessStmt(Stmt* S, NodeBuilder& builder); |
| 642 | |
| 643 | /// RemoveDeadBindings - Return a new state that is the same as 'M' except |
| 644 | /// that all subexpression mappings are removed and that any |
| 645 | /// block-level expressions that are not live at 'S' also have their |
| 646 | /// mappings removed. |
| 647 | StateTy RemoveDeadBindings(Stmt* S, StateTy M); |
| 648 | |
Ted Kremenek | 9de04c4 | 2008-01-24 20:55:43 +0000 | [diff] [blame] | 649 | StateTy SetValue(StateTy St, Stmt* S, const ExprValue& V); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 650 | |
Ted Kremenek | 9de04c4 | 2008-01-24 20:55:43 +0000 | [diff] [blame] | 651 | StateTy SetValue(StateTy St, const Stmt* S, const ExprValue& V) { |
| 652 | return SetValue(St, const_cast<Stmt*>(S), V); |
| 653 | } |
| 654 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 655 | StateTy SetValue(StateTy St, const LValue& LV, const ExprValue& V); |
Ted Kremenek | 1ccd31c | 2008-01-16 19:42:59 +0000 | [diff] [blame] | 656 | |
Ted Kremenek | 9de04c4 | 2008-01-24 20:55:43 +0000 | [diff] [blame] | 657 | ExprValue GetValue(const StateTy& St, Stmt* S); |
| 658 | inline ExprValue GetValue(const StateTy& St, const Stmt* S) { |
| 659 | return GetValue(St, const_cast<Stmt*>(S)); |
| 660 | } |
| 661 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 662 | ExprValue GetValue(const StateTy& St, const LValue& LV); |
| 663 | LValue GetLValue(const StateTy& St, Stmt* S); |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 664 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 665 | void Nodify(NodeSet& Dst, Stmt* S, NodeTy* Pred, StateTy St); |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 666 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 667 | /// Visit - Transfer function logic for all statements. Dispatches to |
| 668 | /// other functions that handle specific kinds of statements. |
| 669 | void Visit(Stmt* S, NodeTy* Pred, NodeSet& Dst); |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 670 | |
| 671 | /// VisitCast - Transfer function logic for all casts (implicit and explicit). |
| 672 | void VisitCast(Expr* CastE, Expr* E, NodeTy* Pred, NodeSet& Dst); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 673 | |
Ted Kremenek | 7b8009a | 2008-01-24 02:28:56 +0000 | [diff] [blame] | 674 | /// VisitUnaryOperator - Transfer function logic for unary operators. |
| 675 | void VisitUnaryOperator(UnaryOperator* B, NodeTy* Pred, NodeSet& Dst); |
| 676 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 677 | /// VisitBinaryOperator - Transfer function logic for binary operators. |
Ted Kremenek | 9de04c4 | 2008-01-24 20:55:43 +0000 | [diff] [blame] | 678 | void VisitBinaryOperator(BinaryOperator* B, NodeTy* Pred, NodeSet& Dst); |
| 679 | |
| 680 | /// VisitDeclStmt - Transfer function logic for DeclStmts. |
| 681 | void VisitDeclStmt(DeclStmt* DS, NodeTy* Pred, NodeSet& Dst); |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 682 | }; |
| 683 | } // end anonymous namespace |
| 684 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 685 | |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 686 | void GRConstants::ProcessStmt(Stmt* S, NodeBuilder& builder) { |
| 687 | Builder = &builder; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 688 | |
| 689 | StmtEntryNode = builder.getLastNode(); |
| 690 | CurrentStmt = S; |
| 691 | NodeSet Dst; |
| 692 | StateCleaned = false; |
| 693 | |
| 694 | Visit(S, StmtEntryNode, Dst); |
| 695 | |
| 696 | // If no nodes were generated, generate a new node that has all the |
| 697 | // dead mappings removed. |
| 698 | if (Dst.size() == 1 && *Dst.begin() == StmtEntryNode) { |
| 699 | StateTy St = RemoveDeadBindings(S, StmtEntryNode->getState()); |
| 700 | builder.generateNode(S, St, StmtEntryNode); |
| 701 | } |
Ted Kremenek | f84469b | 2008-01-18 00:41:32 +0000 | [diff] [blame] | 702 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 703 | CurrentStmt = NULL; |
| 704 | StmtEntryNode = NULL; |
| 705 | Builder = NULL; |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 706 | } |
| 707 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 708 | |
| 709 | ExprValue GRConstants::GetValue(const StateTy& St, const LValue& LV) { |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 710 | switch (LV.getSubKind()) { |
| 711 | case LValueDeclKind: { |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 712 | StateTy::TreeTy* T = St.SlimFind(cast<LValueDecl>(LV).getDecl()); |
| 713 | return T ? T->getValue().second : InvalidValue(); |
| 714 | } |
| 715 | default: |
| 716 | assert (false && "Invalid LValue."); |
Ted Kremenek | ca3e857 | 2008-01-16 22:28:08 +0000 | [diff] [blame] | 717 | break; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | return InvalidValue(); |
| 721 | } |
| 722 | |
| 723 | ExprValue GRConstants::GetValue(const StateTy& St, Stmt* S) { |
Ted Kremenek | 671c9e8 | 2008-01-24 00:50:08 +0000 | [diff] [blame] | 724 | for (;;) { |
| 725 | switch (S->getStmtClass()) { |
| 726 | case Stmt::ParenExprClass: |
| 727 | S = cast<ParenExpr>(S)->getSubExpr(); |
| 728 | continue; |
| 729 | |
| 730 | case Stmt::DeclRefExprClass: |
| 731 | return GetValue(St, LValueDecl(cast<DeclRefExpr>(S)->getDecl())); |
Ted Kremenek | ca3e857 | 2008-01-16 22:28:08 +0000 | [diff] [blame] | 732 | |
Ted Kremenek | 671c9e8 | 2008-01-24 00:50:08 +0000 | [diff] [blame] | 733 | case Stmt::IntegerLiteralClass: |
Ted Kremenek | dacbb4f | 2008-01-24 08:20:02 +0000 | [diff] [blame] | 734 | return RValue::GetRValue(ValMgr, cast<IntegerLiteral>(S)); |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 735 | |
| 736 | case Stmt::ImplicitCastExprClass: { |
| 737 | ImplicitCastExpr* C = cast<ImplicitCastExpr>(S); |
| 738 | if (C->getType() == C->getSubExpr()->getType()) { |
| 739 | S = C->getSubExpr(); |
| 740 | continue; |
| 741 | } |
| 742 | break; |
| 743 | } |
| 744 | |
| 745 | case Stmt::CastExprClass: { |
| 746 | CastExpr* C = cast<CastExpr>(S); |
| 747 | if (C->getType() == C->getSubExpr()->getType()) { |
| 748 | S = C->getSubExpr(); |
| 749 | continue; |
| 750 | } |
| 751 | break; |
| 752 | } |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 753 | |
Ted Kremenek | 671c9e8 | 2008-01-24 00:50:08 +0000 | [diff] [blame] | 754 | default: |
| 755 | break; |
| 756 | }; |
| 757 | |
| 758 | break; |
| 759 | } |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 760 | |
Ted Kremenek | 5c1b996 | 2008-01-24 19:43:37 +0000 | [diff] [blame] | 761 | StateTy::TreeTy* T = St.SlimFind(S); |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 762 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 763 | return T ? T->getValue().second : InvalidValue(); |
| 764 | } |
| 765 | |
| 766 | LValue GRConstants::GetLValue(const StateTy& St, Stmt* S) { |
| 767 | if (Expr* E = dyn_cast<Expr>(S)) |
| 768 | S = E->IgnoreParens(); |
| 769 | |
| 770 | if (DeclRefExpr* DR = dyn_cast<DeclRefExpr>(S)) |
| 771 | return LValueDecl(DR->getDecl()); |
| 772 | |
| 773 | return cast<LValue>(GetValue(St, S)); |
| 774 | } |
| 775 | |
| 776 | GRConstants::StateTy GRConstants::SetValue(StateTy St, Stmt* S, |
Ted Kremenek | daadf45 | 2008-01-24 19:28:01 +0000 | [diff] [blame] | 777 | const ExprValue& V) { |
Ted Kremenek | cc1c365 | 2008-01-25 23:43:12 +0000 | [diff] [blame^] | 778 | assert (S); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 779 | |
| 780 | if (!StateCleaned) { |
| 781 | St = RemoveDeadBindings(CurrentStmt, St); |
| 782 | StateCleaned = true; |
| 783 | } |
| 784 | |
Ted Kremenek | 9ff731d | 2008-01-24 22:27:20 +0000 | [diff] [blame] | 785 | bool isBlkExpr = false; |
| 786 | |
| 787 | if (S == CurrentStmt) { |
| 788 | isBlkExpr = getCFG().isBlkExpr(S); |
| 789 | |
| 790 | if (!isBlkExpr) |
| 791 | return St; |
| 792 | } |
Ted Kremenek | daadf45 | 2008-01-24 19:28:01 +0000 | [diff] [blame] | 793 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 794 | return V.isValid() ? StateMgr.Add(St, ValueKey(S,isBlkExpr), V) |
| 795 | : St; |
| 796 | } |
| 797 | |
| 798 | GRConstants::StateTy GRConstants::SetValue(StateTy St, const LValue& LV, |
| 799 | const ExprValue& V) { |
| 800 | if (!LV.isValid()) |
| 801 | return St; |
| 802 | |
| 803 | if (!StateCleaned) { |
| 804 | St = RemoveDeadBindings(CurrentStmt, St); |
| 805 | StateCleaned = true; |
Ted Kremenek | ca3e857 | 2008-01-16 22:28:08 +0000 | [diff] [blame] | 806 | } |
Ted Kremenek | 0525a4f | 2008-01-16 19:47:19 +0000 | [diff] [blame] | 807 | |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 808 | switch (LV.getSubKind()) { |
| 809 | case LValueDeclKind: |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 810 | return V.isValid() ? StateMgr.Add(St, cast<LValueDecl>(LV).getDecl(), V) |
| 811 | : StateMgr.Remove(St, cast<LValueDecl>(LV).getDecl()); |
| 812 | |
| 813 | default: |
| 814 | assert ("SetValue for given LValue type not yet implemented."); |
| 815 | return St; |
| 816 | } |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 817 | } |
| 818 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 819 | GRConstants::StateTy GRConstants::RemoveDeadBindings(Stmt* Loc, StateTy M) { |
Ted Kremenek | f84469b | 2008-01-18 00:41:32 +0000 | [diff] [blame] | 820 | // Note: in the code below, we can assign a new map to M since the |
| 821 | // iterators are iterating over the tree of the *original* map. |
Ted Kremenek | f84469b | 2008-01-18 00:41:32 +0000 | [diff] [blame] | 822 | StateTy::iterator I = M.begin(), E = M.end(); |
| 823 | |
Ted Kremenek | 5c1b996 | 2008-01-24 19:43:37 +0000 | [diff] [blame] | 824 | // Remove old bindings for subexpressions and "dead" block-level expressions. |
| 825 | for (; I!=E && !I.getKey().isDecl(); ++I) { |
| 826 | if (I.getKey().isSubExpr() || !Liveness->isLive(Loc,cast<Stmt>(I.getKey()))) |
| 827 | M = StateMgr.Remove(M, I.getKey()); |
| 828 | } |
Ted Kremenek | f84469b | 2008-01-18 00:41:32 +0000 | [diff] [blame] | 829 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 830 | // Remove bindings for "dead" decls. |
Ted Kremenek | 5c1b996 | 2008-01-24 19:43:37 +0000 | [diff] [blame] | 831 | for (; I!=E ; ++I) { |
| 832 | assert (I.getKey().isDecl()); |
| 833 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 834 | if (VarDecl* V = dyn_cast<VarDecl>(cast<ValueDecl>(I.getKey()))) |
| 835 | if (!Liveness->isLive(Loc, V)) |
| 836 | M = StateMgr.Remove(M, I.getKey()); |
Ted Kremenek | 5c1b996 | 2008-01-24 19:43:37 +0000 | [diff] [blame] | 837 | } |
Ted Kremenek | 565256e | 2008-01-24 22:44:24 +0000 | [diff] [blame] | 838 | |
Ted Kremenek | e00fe3f | 2008-01-17 00:52:48 +0000 | [diff] [blame] | 839 | return M; |
Ted Kremenek | e00fe3f | 2008-01-17 00:52:48 +0000 | [diff] [blame] | 840 | } |
| 841 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 842 | void GRConstants::Nodify(NodeSet& Dst, Stmt* S, GRConstants::NodeTy* Pred, |
| 843 | GRConstants::StateTy St) { |
| 844 | |
| 845 | // If the state hasn't changed, don't generate a new node. |
| 846 | if (St == Pred->getState()) |
| 847 | return; |
Ted Kremenek | cb448ca | 2008-01-16 00:53:15 +0000 | [diff] [blame] | 848 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 849 | Dst.Add(Builder->generateNode(S, St, Pred)); |
Ted Kremenek | cb448ca | 2008-01-16 00:53:15 +0000 | [diff] [blame] | 850 | } |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 851 | |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 852 | void GRConstants::VisitCast(Expr* CastE, Expr* E, GRConstants::NodeTy* Pred, |
| 853 | GRConstants::NodeSet& Dst) { |
| 854 | |
| 855 | QualType T = CastE->getType(); |
| 856 | |
| 857 | // Check for redundant casts. |
| 858 | if (E->getType() == T) { |
| 859 | Dst.Add(Pred); |
| 860 | return; |
| 861 | } |
| 862 | |
| 863 | NodeSet S1; |
| 864 | Visit(E, Pred, S1); |
| 865 | |
| 866 | for (NodeSet::iterator I1=S1.begin(), E1=S1.end(); I1 != E1; ++I1) { |
| 867 | NodeTy* N = *I1; |
| 868 | StateTy St = N->getState(); |
| 869 | const ExprValue& V = GetValue(St, E); |
| 870 | Nodify(Dst, CastE, N, SetValue(St, CastE, V.EvalCast(ValMgr, CastE))); |
| 871 | } |
Ted Kremenek | 9de04c4 | 2008-01-24 20:55:43 +0000 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | void GRConstants::VisitDeclStmt(DeclStmt* DS, GRConstants::NodeTy* Pred, |
| 875 | GRConstants::NodeSet& Dst) { |
| 876 | |
| 877 | StateTy St = Pred->getState(); |
| 878 | |
| 879 | for (const ScopedDecl* D = DS->getDecl(); D; D = D->getNextDeclarator()) |
| 880 | if (const VarDecl* VD = dyn_cast<VarDecl>(D)) |
| 881 | St = SetValue(St, LValueDecl(VD), GetValue(St, VD->getInit())); |
| 882 | |
| 883 | Nodify(Dst, DS, Pred, St); |
| 884 | |
| 885 | if (Dst.empty()) |
| 886 | Dst.Add(Pred); |
| 887 | } |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 888 | |
Ted Kremenek | 7b8009a | 2008-01-24 02:28:56 +0000 | [diff] [blame] | 889 | void GRConstants::VisitUnaryOperator(UnaryOperator* U, |
| 890 | GRConstants::NodeTy* Pred, |
| 891 | GRConstants::NodeSet& Dst) { |
| 892 | NodeSet S1; |
| 893 | Visit(U->getSubExpr(), Pred, S1); |
| 894 | |
| 895 | for (NodeSet::iterator I1=S1.begin(), E1=S1.end(); I1 != E1; ++I1) { |
| 896 | NodeTy* N1 = *I1; |
| 897 | StateTy St = N1->getState(); |
| 898 | |
| 899 | switch (U->getOpcode()) { |
| 900 | case UnaryOperator::PostInc: { |
| 901 | const LValue& L1 = GetLValue(St, U->getSubExpr()); |
| 902 | RValue R1 = cast<RValue>(GetValue(St, L1)); |
| 903 | |
| 904 | QualType T = U->getType(); |
Ted Kremenek | e0cf9c8 | 2008-01-24 19:00:57 +0000 | [diff] [blame] | 905 | unsigned bits = getContext()->getTypeSize(T, U->getLocStart()); |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 906 | APSInt One(llvm::APInt(bits, 1), T->isUnsignedIntegerType()); |
Ted Kremenek | e0cf9c8 | 2008-01-24 19:00:57 +0000 | [diff] [blame] | 907 | RValue R2 = RValue::GetRValue(ValMgr, One); |
| 908 | |
Ted Kremenek | 7b8009a | 2008-01-24 02:28:56 +0000 | [diff] [blame] | 909 | RValue Result = R1.EvalAdd(ValMgr, R2); |
| 910 | Nodify(Dst, U, N1, SetValue(SetValue(St, U, R1), L1, Result)); |
| 911 | break; |
| 912 | } |
| 913 | |
| 914 | case UnaryOperator::PostDec: { |
| 915 | const LValue& L1 = GetLValue(St, U->getSubExpr()); |
| 916 | RValue R1 = cast<RValue>(GetValue(St, L1)); |
| 917 | |
| 918 | QualType T = U->getType(); |
Ted Kremenek | e0cf9c8 | 2008-01-24 19:00:57 +0000 | [diff] [blame] | 919 | unsigned bits = getContext()->getTypeSize(T, U->getLocStart()); |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 920 | APSInt One(llvm::APInt(bits, 1), T->isUnsignedIntegerType()); |
Ted Kremenek | e0cf9c8 | 2008-01-24 19:00:57 +0000 | [diff] [blame] | 921 | RValue R2 = RValue::GetRValue(ValMgr, One); |
Ted Kremenek | 7b8009a | 2008-01-24 02:28:56 +0000 | [diff] [blame] | 922 | |
| 923 | RValue Result = R1.EvalSub(ValMgr, R2); |
| 924 | Nodify(Dst, U, N1, SetValue(SetValue(St, U, R1), L1, Result)); |
| 925 | break; |
| 926 | } |
| 927 | |
| 928 | case UnaryOperator::PreInc: { |
| 929 | const LValue& L1 = GetLValue(St, U->getSubExpr()); |
| 930 | RValue R1 = cast<RValue>(GetValue(St, L1)); |
| 931 | |
| 932 | QualType T = U->getType(); |
Ted Kremenek | e0cf9c8 | 2008-01-24 19:00:57 +0000 | [diff] [blame] | 933 | unsigned bits = getContext()->getTypeSize(T, U->getLocStart()); |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 934 | APSInt One(llvm::APInt(bits, 1), T->isUnsignedIntegerType()); |
Ted Kremenek | 7b8009a | 2008-01-24 02:28:56 +0000 | [diff] [blame] | 935 | RValue R2 = RValue::GetRValue(ValMgr, One); |
| 936 | |
| 937 | RValue Result = R1.EvalAdd(ValMgr, R2); |
| 938 | Nodify(Dst, U, N1, SetValue(SetValue(St, U, Result), L1, Result)); |
| 939 | break; |
| 940 | } |
| 941 | |
| 942 | case UnaryOperator::PreDec: { |
| 943 | const LValue& L1 = GetLValue(St, U->getSubExpr()); |
| 944 | RValue R1 = cast<RValue>(GetValue(St, L1)); |
| 945 | |
| 946 | QualType T = U->getType(); |
Ted Kremenek | e0cf9c8 | 2008-01-24 19:00:57 +0000 | [diff] [blame] | 947 | unsigned bits = getContext()->getTypeSize(T, U->getLocStart()); |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 948 | APSInt One(llvm::APInt(bits, 1), T->isUnsignedIntegerType()); |
Ted Kremenek | e0cf9c8 | 2008-01-24 19:00:57 +0000 | [diff] [blame] | 949 | RValue R2 = RValue::GetRValue(ValMgr, One); |
Ted Kremenek | 7b8009a | 2008-01-24 02:28:56 +0000 | [diff] [blame] | 950 | |
| 951 | RValue Result = R1.EvalSub(ValMgr, R2); |
| 952 | Nodify(Dst, U, N1, SetValue(SetValue(St, U, Result), L1, Result)); |
| 953 | break; |
| 954 | } |
| 955 | |
Ted Kremenek | dacbb4f | 2008-01-24 08:20:02 +0000 | [diff] [blame] | 956 | case UnaryOperator::Minus: { |
| 957 | const RValue& R1 = cast<RValue>(GetValue(St, U->getSubExpr())); |
| 958 | Nodify(Dst, U, N1, SetValue(St, U, R1.EvalMinus(ValMgr, U))); |
| 959 | break; |
| 960 | } |
| 961 | |
Ted Kremenek | 7b8009a | 2008-01-24 02:28:56 +0000 | [diff] [blame] | 962 | default: ; |
| 963 | assert (false && "Not implemented."); |
| 964 | } |
| 965 | } |
| 966 | } |
| 967 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 968 | void GRConstants::VisitBinaryOperator(BinaryOperator* B, |
| 969 | GRConstants::NodeTy* Pred, |
| 970 | GRConstants::NodeSet& Dst) { |
| 971 | NodeSet S1; |
| 972 | Visit(B->getLHS(), Pred, S1); |
Ted Kremenek | cb448ca | 2008-01-16 00:53:15 +0000 | [diff] [blame] | 973 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 974 | for (NodeSet::iterator I1=S1.begin(), E1=S1.end(); I1 != E1; ++I1) { |
| 975 | NodeTy* N1 = *I1; |
Ted Kremenek | e00fe3f | 2008-01-17 00:52:48 +0000 | [diff] [blame] | 976 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 977 | // When getting the value for the LHS, check if we are in an assignment. |
| 978 | // In such cases, we want to (initially) treat the LHS as an LValue, |
| 979 | // so we use GetLValue instead of GetValue so that DeclRefExpr's are |
| 980 | // evaluated to LValueDecl's instead of to an RValue. |
| 981 | const ExprValue& V1 = |
| 982 | B->isAssignmentOp() ? GetLValue(N1->getState(), B->getLHS()) |
| 983 | : GetValue(N1->getState(), B->getLHS()); |
Ted Kremenek | cb448ca | 2008-01-16 00:53:15 +0000 | [diff] [blame] | 984 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 985 | NodeSet S2; |
| 986 | Visit(B->getRHS(), N1, S2); |
| 987 | |
| 988 | for (NodeSet::iterator I2=S2.begin(), E2=S2.end(); I2 != E2; ++I2) { |
| 989 | NodeTy* N2 = *I2; |
| 990 | StateTy St = N2->getState(); |
| 991 | const ExprValue& V2 = GetValue(St, B->getRHS()); |
| 992 | |
| 993 | switch (B->getOpcode()) { |
| 994 | case BinaryOperator::Add: { |
| 995 | const RValue& R1 = cast<RValue>(V1); |
| 996 | const RValue& R2 = cast<RValue>(V2); |
| 997 | |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 998 | Nodify(Dst, B, N2, SetValue(St, B, R1.EvalAdd(ValMgr, R2))); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 999 | break; |
| 1000 | } |
| 1001 | |
| 1002 | case BinaryOperator::Sub: { |
| 1003 | const RValue& R1 = cast<RValue>(V1); |
| 1004 | const RValue& R2 = cast<RValue>(V2); |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 1005 | Nodify(Dst, B, N2, SetValue(St, B, R1.EvalSub(ValMgr, R2))); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 1006 | break; |
| 1007 | } |
| 1008 | |
Ted Kremenek | 2eafd0e | 2008-01-23 23:42:27 +0000 | [diff] [blame] | 1009 | case BinaryOperator::Mul: { |
| 1010 | const RValue& R1 = cast<RValue>(V1); |
| 1011 | const RValue& R2 = cast<RValue>(V2); |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 1012 | Nodify(Dst, B, N2, SetValue(St, B, R1.EvalMul(ValMgr, R2))); |
Ted Kremenek | 2eafd0e | 2008-01-23 23:42:27 +0000 | [diff] [blame] | 1013 | break; |
| 1014 | } |
| 1015 | |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 1016 | case BinaryOperator::Div: { |
| 1017 | const RValue& R1 = cast<RValue>(V1); |
| 1018 | const RValue& R2 = cast<RValue>(V2); |
| 1019 | Nodify(Dst, B, N2, SetValue(St, B, R1.EvalDiv(ValMgr, R2))); |
| 1020 | break; |
| 1021 | } |
| 1022 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 1023 | case BinaryOperator::Assign: { |
| 1024 | const LValue& L1 = cast<LValue>(V1); |
| 1025 | const RValue& R2 = cast<RValue>(V2); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 1026 | Nodify(Dst, B, N2, SetValue(SetValue(St, B, R2), L1, R2)); |
| 1027 | break; |
| 1028 | } |
Ted Kremenek | b4ae33f | 2008-01-23 23:38:00 +0000 | [diff] [blame] | 1029 | |
| 1030 | case BinaryOperator::AddAssign: { |
| 1031 | const LValue& L1 = cast<LValue>(V1); |
| 1032 | RValue R1 = cast<RValue>(GetValue(N1->getState(), L1)); |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 1033 | RValue Result = R1.EvalAdd(ValMgr, cast<RValue>(V2)); |
Ted Kremenek | b4ae33f | 2008-01-23 23:38:00 +0000 | [diff] [blame] | 1034 | Nodify(Dst, B, N2, SetValue(SetValue(St, B, Result), L1, Result)); |
| 1035 | break; |
| 1036 | } |
| 1037 | |
| 1038 | case BinaryOperator::SubAssign: { |
| 1039 | const LValue& L1 = cast<LValue>(V1); |
| 1040 | RValue R1 = cast<RValue>(GetValue(N1->getState(), L1)); |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 1041 | RValue Result = R1.EvalSub(ValMgr, cast<RValue>(V2)); |
Ted Kremenek | b4ae33f | 2008-01-23 23:38:00 +0000 | [diff] [blame] | 1042 | Nodify(Dst, B, N2, SetValue(SetValue(St, B, Result), L1, Result)); |
| 1043 | break; |
| 1044 | } |
Ted Kremenek | 2eafd0e | 2008-01-23 23:42:27 +0000 | [diff] [blame] | 1045 | |
| 1046 | case BinaryOperator::MulAssign: { |
| 1047 | const LValue& L1 = cast<LValue>(V1); |
| 1048 | RValue R1 = cast<RValue>(GetValue(N1->getState(), L1)); |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 1049 | RValue Result = R1.EvalMul(ValMgr, cast<RValue>(V2)); |
Ted Kremenek | 2eafd0e | 2008-01-23 23:42:27 +0000 | [diff] [blame] | 1050 | Nodify(Dst, B, N2, SetValue(SetValue(St, B, Result), L1, Result)); |
| 1051 | break; |
| 1052 | } |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 1053 | |
| 1054 | default: |
| 1055 | Dst.Add(N2); |
| 1056 | break; |
| 1057 | } |
Ted Kremenek | cb448ca | 2008-01-16 00:53:15 +0000 | [diff] [blame] | 1058 | } |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 1059 | } |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 1060 | } |
Ted Kremenek | ee98546 | 2008-01-16 18:18:48 +0000 | [diff] [blame] | 1061 | |
Ted Kremenek | 1ccd31c | 2008-01-16 19:42:59 +0000 | [diff] [blame] | 1062 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 1063 | void GRConstants::Visit(Stmt* S, GRConstants::NodeTy* Pred, |
| 1064 | GRConstants::NodeSet& Dst) { |
| 1065 | |
| 1066 | // FIXME: add metadata to the CFG so that we can disable |
| 1067 | // this check when we KNOW that there is no block-level subexpression. |
| 1068 | // The motivation is that this check requires a hashtable lookup. |
| 1069 | |
| 1070 | if (S != CurrentStmt && getCFG().isBlkExpr(S)) { |
| 1071 | Dst.Add(Pred); |
| 1072 | return; |
| 1073 | } |
| 1074 | |
| 1075 | switch (S->getStmtClass()) { |
| 1076 | case Stmt::BinaryOperatorClass: |
Ted Kremenek | b4ae33f | 2008-01-23 23:38:00 +0000 | [diff] [blame] | 1077 | case Stmt::CompoundAssignOperatorClass: |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 1078 | VisitBinaryOperator(cast<BinaryOperator>(S), Pred, Dst); |
| 1079 | break; |
| 1080 | |
Ted Kremenek | 7b8009a | 2008-01-24 02:28:56 +0000 | [diff] [blame] | 1081 | case Stmt::UnaryOperatorClass: |
| 1082 | VisitUnaryOperator(cast<UnaryOperator>(S), Pred, Dst); |
| 1083 | break; |
| 1084 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 1085 | case Stmt::ParenExprClass: |
| 1086 | Visit(cast<ParenExpr>(S)->getSubExpr(), Pred, Dst); |
| 1087 | break; |
| 1088 | |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 1089 | case Stmt::ImplicitCastExprClass: { |
| 1090 | ImplicitCastExpr* C = cast<ImplicitCastExpr>(S); |
| 1091 | VisitCast(C, C->getSubExpr(), Pred, Dst); |
| 1092 | break; |
| 1093 | } |
| 1094 | |
| 1095 | case Stmt::CastExprClass: { |
| 1096 | CastExpr* C = cast<CastExpr>(S); |
| 1097 | VisitCast(C, C->getSubExpr(), Pred, Dst); |
| 1098 | break; |
| 1099 | } |
| 1100 | |
Ted Kremenek | 9de04c4 | 2008-01-24 20:55:43 +0000 | [diff] [blame] | 1101 | case Stmt::DeclStmtClass: |
| 1102 | VisitDeclStmt(cast<DeclStmt>(S), Pred, Dst); |
| 1103 | break; |
| 1104 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 1105 | default: |
| 1106 | Dst.Add(Pred); // No-op. Simply propagate the current state unchanged. |
| 1107 | break; |
Ted Kremenek | 79649df | 2008-01-17 18:25:22 +0000 | [diff] [blame] | 1108 | } |
Ted Kremenek | 1ccd31c | 2008-01-16 19:42:59 +0000 | [diff] [blame] | 1109 | } |
| 1110 | |
Ted Kremenek | ee98546 | 2008-01-16 18:18:48 +0000 | [diff] [blame] | 1111 | //===----------------------------------------------------------------------===// |
| 1112 | // Driver. |
| 1113 | //===----------------------------------------------------------------------===// |
| 1114 | |
Ted Kremenek | aa66a32 | 2008-01-16 21:46:15 +0000 | [diff] [blame] | 1115 | #ifndef NDEBUG |
| 1116 | namespace llvm { |
| 1117 | template<> |
| 1118 | struct VISIBILITY_HIDDEN DOTGraphTraits<GRConstants::NodeTy*> : |
| 1119 | public DefaultDOTGraphTraits { |
Ted Kremenek | 9ff731d | 2008-01-24 22:27:20 +0000 | [diff] [blame] | 1120 | |
| 1121 | static void PrintKindLabel(std::ostream& Out, ValueKey::Kind kind) { |
Ted Kremenek | 803c9ed | 2008-01-23 22:30:44 +0000 | [diff] [blame] | 1122 | switch (kind) { |
Ted Kremenek | 565256e | 2008-01-24 22:44:24 +0000 | [diff] [blame] | 1123 | case ValueKey::IsSubExpr: Out << "Sub-Expressions:\\l"; break; |
Ted Kremenek | 803c9ed | 2008-01-23 22:30:44 +0000 | [diff] [blame] | 1124 | case ValueKey::IsDecl: Out << "Variables:\\l"; break; |
| 1125 | case ValueKey::IsBlkExpr: Out << "Block-level Expressions:\\l"; break; |
| 1126 | default: assert (false && "Unknown ValueKey type."); |
| 1127 | } |
| 1128 | } |
| 1129 | |
Ted Kremenek | 9ff731d | 2008-01-24 22:27:20 +0000 | [diff] [blame] | 1130 | static void PrintKind(std::ostream& Out, GRConstants::StateTy M, |
| 1131 | ValueKey::Kind kind, bool isFirstGroup = false) { |
| 1132 | bool isFirst = true; |
| 1133 | |
| 1134 | for (GRConstants::StateTy::iterator I=M.begin(), E=M.end();I!=E;++I) { |
| 1135 | if (I.getKey().getKind() != kind) |
| 1136 | continue; |
| 1137 | |
| 1138 | if (isFirst) { |
| 1139 | if (!isFirstGroup) Out << "\\l\\l"; |
| 1140 | PrintKindLabel(Out, kind); |
| 1141 | isFirst = false; |
| 1142 | } |
| 1143 | else |
| 1144 | Out << "\\l"; |
| 1145 | |
| 1146 | Out << ' '; |
| 1147 | |
| 1148 | if (ValueDecl* V = dyn_cast<ValueDecl>(I.getKey())) |
| 1149 | Out << V->getName(); |
| 1150 | else { |
| 1151 | Stmt* E = cast<Stmt>(I.getKey()); |
| 1152 | Out << " (" << (void*) E << ") "; |
| 1153 | E->printPretty(Out); |
| 1154 | } |
| 1155 | |
| 1156 | Out << " : "; |
| 1157 | I.getData().print(Out); |
| 1158 | } |
| 1159 | } |
| 1160 | |
Ted Kremenek | aa66a32 | 2008-01-16 21:46:15 +0000 | [diff] [blame] | 1161 | static std::string getNodeLabel(const GRConstants::NodeTy* N, void*) { |
| 1162 | std::ostringstream Out; |
Ted Kremenek | 803c9ed | 2008-01-23 22:30:44 +0000 | [diff] [blame] | 1163 | |
| 1164 | // Program Location. |
Ted Kremenek | aa66a32 | 2008-01-16 21:46:15 +0000 | [diff] [blame] | 1165 | ProgramPoint Loc = N->getLocation(); |
| 1166 | |
| 1167 | switch (Loc.getKind()) { |
| 1168 | case ProgramPoint::BlockEntranceKind: |
| 1169 | Out << "Block Entrance: B" |
| 1170 | << cast<BlockEntrance>(Loc).getBlock()->getBlockID(); |
| 1171 | break; |
| 1172 | |
| 1173 | case ProgramPoint::BlockExitKind: |
| 1174 | assert (false); |
| 1175 | break; |
| 1176 | |
| 1177 | case ProgramPoint::PostStmtKind: { |
| 1178 | const PostStmt& L = cast<PostStmt>(Loc); |
Ted Kremenek | 9ff731d | 2008-01-24 22:27:20 +0000 | [diff] [blame] | 1179 | Out << L.getStmt()->getStmtClassName() << ':' |
| 1180 | << (void*) L.getStmt() << ' '; |
| 1181 | |
Ted Kremenek | aa66a32 | 2008-01-16 21:46:15 +0000 | [diff] [blame] | 1182 | L.getStmt()->printPretty(Out); |
| 1183 | break; |
| 1184 | } |
| 1185 | |
| 1186 | default: { |
| 1187 | const BlockEdge& E = cast<BlockEdge>(Loc); |
| 1188 | Out << "Edge: (B" << E.getSrc()->getBlockID() << ", B" |
| 1189 | << E.getDst()->getBlockID() << ')'; |
| 1190 | } |
| 1191 | } |
| 1192 | |
Ted Kremenek | 803c9ed | 2008-01-23 22:30:44 +0000 | [diff] [blame] | 1193 | Out << "\\|"; |
Ted Kremenek | aa66a32 | 2008-01-16 21:46:15 +0000 | [diff] [blame] | 1194 | |
Ted Kremenek | 9ff731d | 2008-01-24 22:27:20 +0000 | [diff] [blame] | 1195 | PrintKind(Out, N->getState(), ValueKey::IsDecl, true); |
| 1196 | PrintKind(Out, N->getState(), ValueKey::IsBlkExpr); |
Ted Kremenek | 565256e | 2008-01-24 22:44:24 +0000 | [diff] [blame] | 1197 | PrintKind(Out, N->getState(), ValueKey::IsSubExpr); |
Ted Kremenek | 803c9ed | 2008-01-23 22:30:44 +0000 | [diff] [blame] | 1198 | |
Ted Kremenek | 803c9ed | 2008-01-23 22:30:44 +0000 | [diff] [blame] | 1199 | Out << "\\l"; |
Ted Kremenek | aa66a32 | 2008-01-16 21:46:15 +0000 | [diff] [blame] | 1200 | return Out.str(); |
| 1201 | } |
| 1202 | }; |
| 1203 | } // end llvm namespace |
| 1204 | #endif |
| 1205 | |
Ted Kremenek | ee98546 | 2008-01-16 18:18:48 +0000 | [diff] [blame] | 1206 | namespace clang { |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 1207 | void RunGRConstants(CFG& cfg, ASTContext& Ctx) { |
| 1208 | GREngine<GRConstants> Engine(cfg, Ctx); |
Ted Kremenek | ee98546 | 2008-01-16 18:18:48 +0000 | [diff] [blame] | 1209 | Engine.ExecuteWorkList(); |
Ted Kremenek | aa66a32 | 2008-01-16 21:46:15 +0000 | [diff] [blame] | 1210 | #ifndef NDEBUG |
| 1211 | llvm::ViewGraph(*Engine.getGraph().roots_begin(),"GRConstants"); |
| 1212 | #endif |
Ted Kremenek | ee98546 | 2008-01-16 18:18:48 +0000 | [diff] [blame] | 1213 | } |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 1214 | } // end clang namespace |