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