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 | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 50 | |
Ted Kremenek | 68fd257 | 2008-01-29 17:27:31 +0000 | [diff] [blame] | 51 | class SymbolID { |
| 52 | unsigned Data; |
| 53 | public: |
| 54 | SymbolID() : Data(~0) {} |
| 55 | SymbolID(unsigned x) : Data(x) {} |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 56 | |
Ted Kremenek | 68fd257 | 2008-01-29 17:27:31 +0000 | [diff] [blame] | 57 | bool isInitialized() const { return Data != (unsigned) ~0; } |
| 58 | operator unsigned() const { assert (isInitialized()); return Data; } |
| 59 | }; |
| 60 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 61 | class VISIBILITY_HIDDEN ValueKey { |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 62 | uintptr_t Raw; |
Ted Kremenek | cc1c365 | 2008-01-25 23:43:12 +0000 | [diff] [blame] | 63 | void operator=(const ValueKey& RHS); // Do not implement. |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 64 | |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 65 | public: |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 66 | enum Kind { IsSubExpr=0x0, IsBlkExpr=0x1, IsDecl=0x2, // L-Value Bindings. |
| 67 | IsSymbol=0x3, // Symbol Bindings. |
| 68 | Flags=0x3 }; |
| 69 | |
| 70 | inline Kind getKind() const { |
| 71 | return (Kind) (Raw & Flags); |
| 72 | } |
| 73 | |
| 74 | inline void* getPtr() const { |
| 75 | assert (getKind() != IsSymbol); |
| 76 | return reinterpret_cast<void*>(Raw & ~Flags); |
| 77 | } |
| 78 | |
| 79 | inline SymbolID getSymbolID() const { |
| 80 | assert (getKind() == IsSymbol); |
Ted Kremenek | 68fd257 | 2008-01-29 17:27:31 +0000 | [diff] [blame] | 81 | return Raw >> 2; |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 82 | } |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 83 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 84 | ValueKey(const ValueDecl* VD) |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 85 | : Raw(reinterpret_cast<uintptr_t>(VD) | IsDecl) { |
| 86 | assert(VD && "ValueDecl cannot be NULL."); |
| 87 | } |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 88 | |
Ted Kremenek | 5c1b996 | 2008-01-24 19:43:37 +0000 | [diff] [blame] | 89 | ValueKey(Stmt* S, bool isBlkExpr = false) |
Ted Kremenek | cc1c365 | 2008-01-25 23:43:12 +0000 | [diff] [blame] | 90 | : Raw(reinterpret_cast<uintptr_t>(S) | (isBlkExpr ? IsBlkExpr : IsSubExpr)){ |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 91 | assert(S && "Tracked statement cannot be NULL."); |
Ted Kremenek | cc1c365 | 2008-01-25 23:43:12 +0000 | [diff] [blame] | 92 | } |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 93 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 94 | ValueKey(SymbolID V) |
| 95 | : Raw((V << 2) | IsSymbol) {} |
| 96 | |
| 97 | bool isSymbol() const { return getKind() == IsSymbol; } |
Ted Kremenek | 565256e | 2008-01-24 22:44:24 +0000 | [diff] [blame] | 98 | bool isSubExpr() const { return getKind() == IsSubExpr; } |
Ted Kremenek | 65cac13 | 2008-01-29 05:25:31 +0000 | [diff] [blame] | 99 | bool isBlkExpr() const { return getKind() == IsBlkExpr; } |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 100 | bool isDecl() const { return getKind() == IsDecl; } |
Ted Kremenek | 65cac13 | 2008-01-29 05:25:31 +0000 | [diff] [blame] | 101 | bool isStmt() const { return getKind() <= IsBlkExpr; } |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 102 | |
| 103 | inline void Profile(llvm::FoldingSetNodeID& ID) const { |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 104 | ID.AddInteger(isSymbol() ? 1 : 0); |
| 105 | |
| 106 | if (isSymbol()) |
Ted Kremenek | f264562 | 2008-01-28 22:25:21 +0000 | [diff] [blame] | 107 | ID.AddInteger(getSymbolID()); |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 108 | else |
| 109 | ID.AddPointer(getPtr()); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | inline bool operator==(const ValueKey& X) const { |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 113 | return isSymbol() ? getSymbolID() == X.getSymbolID() |
| 114 | : getPtr() == X.getPtr(); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | inline bool operator!=(const ValueKey& X) const { |
| 118 | return !operator==(X); |
| 119 | } |
| 120 | |
| 121 | inline bool operator<(const ValueKey& X) const { |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 122 | if (isSymbol()) |
| 123 | return X.isSymbol() ? getSymbolID() < X.getSymbolID() : false; |
Ted Kremenek | 5c1b996 | 2008-01-24 19:43:37 +0000 | [diff] [blame] | 124 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 125 | return getPtr() < X.getPtr(); |
Ted Kremenek | b3d2dca | 2008-01-16 23:33:44 +0000 | [diff] [blame] | 126 | } |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 127 | }; |
| 128 | } // end anonymous namespace |
| 129 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 130 | // Machinery to get cast<> and dyn_cast<> working with ValueKey. |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 131 | namespace llvm { |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 132 | template<> inline bool isa<ValueDecl,ValueKey>(const ValueKey& V) { |
| 133 | return V.getKind() == ValueKey::IsDecl; |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 134 | } |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 135 | template<> inline bool isa<Stmt,ValueKey>(const ValueKey& V) { |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 136 | return ((unsigned) V.getKind()) < ValueKey::IsDecl; |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 137 | } |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 138 | template<> struct VISIBILITY_HIDDEN cast_retty_impl<ValueDecl,ValueKey> { |
Ted Kremenek | aa66a32 | 2008-01-16 21:46:15 +0000 | [diff] [blame] | 139 | typedef const ValueDecl* ret_type; |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 140 | }; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 141 | template<> struct VISIBILITY_HIDDEN cast_retty_impl<Stmt,ValueKey> { |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 142 | typedef const Stmt* ret_type; |
| 143 | }; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 144 | template<> struct VISIBILITY_HIDDEN simplify_type<ValueKey> { |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 145 | typedef void* SimpleType; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 146 | static inline SimpleType getSimplifiedValue(const ValueKey &V) { |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 147 | return V.getPtr(); |
| 148 | } |
| 149 | }; |
| 150 | } // end llvm namespace |
| 151 | |
Ted Kremenek | 68fd257 | 2008-01-29 17:27:31 +0000 | [diff] [blame] | 152 | |
| 153 | //===----------------------------------------------------------------------===// |
| 154 | // SymbolManager. |
| 155 | //===----------------------------------------------------------------------===// |
| 156 | |
| 157 | namespace { |
| 158 | class VISIBILITY_HIDDEN SymbolData { |
| 159 | uintptr_t Data; |
| 160 | public: |
| 161 | enum Kind { ParmKind = 0x0, Mask = 0x3 }; |
| 162 | |
| 163 | SymbolData(ParmVarDecl* D) |
| 164 | : Data(reinterpret_cast<uintptr_t>(D) | ParmKind) {} |
| 165 | |
| 166 | inline Kind getKind() const { return (Kind) (Data & Mask); } |
| 167 | inline void* getPtr() const { return reinterpret_cast<void*>(Data & ~Mask); } |
| 168 | inline bool operator==(const SymbolData& R) const { return Data == R.Data; } |
| 169 | }; |
| 170 | } |
| 171 | |
| 172 | // Machinery to get cast<> and dyn_cast<> working with SymbolData. |
| 173 | namespace llvm { |
| 174 | template<> inline bool isa<ParmVarDecl,SymbolData>(const SymbolData& V) { |
| 175 | return V.getKind() == SymbolData::ParmKind; |
| 176 | } |
| 177 | template<> struct VISIBILITY_HIDDEN cast_retty_impl<ParmVarDecl,SymbolData> { |
| 178 | typedef const ParmVarDecl* ret_type; |
| 179 | }; |
| 180 | template<> struct VISIBILITY_HIDDEN simplify_type<SymbolData> { |
| 181 | typedef void* SimpleType; |
| 182 | static inline SimpleType getSimplifiedValue(const SymbolData &V) { |
| 183 | return V.getPtr(); |
| 184 | } |
| 185 | }; |
| 186 | } // end llvm namespace |
| 187 | |
| 188 | namespace { |
| 189 | class VISIBILITY_HIDDEN SymbolManager { |
| 190 | std::vector<SymbolData> SymbolToData; |
| 191 | |
| 192 | typedef llvm::DenseMap<void*,SymbolID> MapTy; |
| 193 | MapTy DataToSymbol; |
| 194 | |
| 195 | public: |
| 196 | SymbolData getSymbolData(SymbolID id) const { |
| 197 | assert (id < SymbolToData.size()); |
| 198 | return SymbolToData[id]; |
| 199 | } |
| 200 | |
| 201 | SymbolID getSymbol(ParmVarDecl* D); |
| 202 | }; |
| 203 | } // end anonymous namespace |
| 204 | |
| 205 | SymbolID SymbolManager::getSymbol(ParmVarDecl* D) { |
| 206 | SymbolID& X = DataToSymbol[D]; |
| 207 | |
| 208 | if (!X.isInitialized()) { |
| 209 | X = SymbolToData.size(); |
| 210 | SymbolToData.push_back(D); |
| 211 | } |
| 212 | |
| 213 | return X; |
| 214 | } |
| 215 | |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 216 | //===----------------------------------------------------------------------===// |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 217 | // ValueManager. |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 218 | //===----------------------------------------------------------------------===// |
| 219 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 220 | namespace { |
| 221 | |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 222 | typedef llvm::ImmutableSet<APSInt > APSIntSetTy; |
| 223 | |
| 224 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 225 | class VISIBILITY_HIDDEN ValueManager { |
Ted Kremenek | cb48b9c | 2008-01-29 00:33:40 +0000 | [diff] [blame] | 226 | ASTContext& Ctx; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 227 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 228 | typedef llvm::FoldingSet<llvm::FoldingSetNodeWrapper<APSInt> > APSIntSetTy; |
| 229 | APSIntSetTy APSIntSet; |
| 230 | |
| 231 | llvm::BumpPtrAllocator BPAlloc; |
| 232 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 233 | public: |
Ted Kremenek | cb48b9c | 2008-01-29 00:33:40 +0000 | [diff] [blame] | 234 | ValueManager(ASTContext& ctx) : Ctx(ctx) {} |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 235 | ~ValueManager(); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 236 | |
Ted Kremenek | cb48b9c | 2008-01-29 00:33:40 +0000 | [diff] [blame] | 237 | ASTContext& getContext() const { return Ctx; } |
Ted Kremenek | 687af80 | 2008-01-29 19:43:15 +0000 | [diff] [blame] | 238 | APSInt& getValue(const APSInt& X); |
| 239 | APSInt& getValue(uint64_t X, unsigned BitWidth, bool isUnsigned); |
| 240 | APSInt& getValue(uint64_t X, QualType T, |
| 241 | SourceLocation Loc = SourceLocation()); |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 242 | }; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 243 | } // end anonymous namespace |
| 244 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 245 | ValueManager::~ValueManager() { |
| 246 | // Note that the dstor for the contents of APSIntSet will never be called, |
| 247 | // so we iterate over the set and invoke the dstor for each APSInt. This |
| 248 | // frees an aux. memory allocated to represent very large constants. |
| 249 | for (APSIntSetTy::iterator I=APSIntSet.begin(), E=APSIntSet.end(); I!=E; ++I) |
| 250 | I->getValue().~APSInt(); |
| 251 | } |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 252 | |
| 253 | APSInt& ValueManager::getValue(const APSInt& X) { |
| 254 | llvm::FoldingSetNodeID ID; |
| 255 | void* InsertPos; |
| 256 | typedef llvm::FoldingSetNodeWrapper<APSInt> FoldNodeTy; |
Ted Kremenek | cc1c365 | 2008-01-25 23:43:12 +0000 | [diff] [blame] | 257 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 258 | X.Profile(ID); |
| 259 | FoldNodeTy* P = APSIntSet.FindNodeOrInsertPos(ID, InsertPos); |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 260 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 261 | if (!P) { |
| 262 | P = (FoldNodeTy*) BPAlloc.Allocate<FoldNodeTy>(); |
| 263 | new (P) FoldNodeTy(X); |
| 264 | APSIntSet.InsertNode(P, InsertPos); |
| 265 | } |
| 266 | |
| 267 | return *P; |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 268 | } |
| 269 | |
Ted Kremenek | 687af80 | 2008-01-29 19:43:15 +0000 | [diff] [blame] | 270 | APSInt& ValueManager::getValue(uint64_t X, unsigned BitWidth, bool isUnsigned) { |
| 271 | APSInt V(BitWidth, isUnsigned); |
| 272 | V = X; |
| 273 | return getValue(V); |
| 274 | } |
| 275 | |
| 276 | APSInt& ValueManager::getValue(uint64_t X, QualType T, SourceLocation Loc) { |
| 277 | unsigned bits = Ctx.getTypeSize(T, Loc); |
| 278 | APSInt V(bits, T->isUnsignedIntegerType()); |
| 279 | V = X; |
| 280 | return getValue(V); |
| 281 | } |
| 282 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 283 | //===----------------------------------------------------------------------===// |
| 284 | // Expression Values. |
| 285 | //===----------------------------------------------------------------------===// |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 286 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 287 | namespace { |
| 288 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 289 | class VISIBILITY_HIDDEN RValue { |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 290 | public: |
Ted Kremenek | 403c181 | 2008-01-28 22:51:57 +0000 | [diff] [blame] | 291 | enum BaseKind { LValueKind=0x0, NonLValueKind=0x1, |
Ted Kremenek | 6753fe3 | 2008-01-30 18:54:06 +0000 | [diff] [blame^] | 292 | UninitializedKind=0x2, InvalidKind=0x3 }; |
| 293 | |
| 294 | enum { BaseBits = 2, BaseMask = 0x3 }; |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 295 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 296 | private: |
Ted Kremenek | f264562 | 2008-01-28 22:25:21 +0000 | [diff] [blame] | 297 | void* Data; |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 298 | unsigned Kind; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 299 | |
| 300 | protected: |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 301 | RValue(const void* d, bool isLValue, unsigned ValKind) |
Ted Kremenek | f264562 | 2008-01-28 22:25:21 +0000 | [diff] [blame] | 302 | : Data(const_cast<void*>(d)), |
Ted Kremenek | 6753fe3 | 2008-01-30 18:54:06 +0000 | [diff] [blame^] | 303 | Kind((isLValue ? LValueKind : NonLValueKind) | (ValKind << BaseBits)) {} |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 304 | |
Ted Kremenek | 403c181 | 2008-01-28 22:51:57 +0000 | [diff] [blame] | 305 | explicit RValue(BaseKind k) |
| 306 | : Data(0), Kind(k) {} |
Ted Kremenek | f264562 | 2008-01-28 22:25:21 +0000 | [diff] [blame] | 307 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 308 | void* getRawPtr() const { |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 309 | return reinterpret_cast<void*>(Data); |
| 310 | } |
| 311 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 312 | public: |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 313 | ~RValue() {}; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 314 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 315 | RValue Cast(ValueManager& ValMgr, Expr* CastExpr) const; |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 316 | |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 317 | unsigned getRawKind() const { return Kind; } |
Ted Kremenek | 6753fe3 | 2008-01-30 18:54:06 +0000 | [diff] [blame^] | 318 | BaseKind getBaseKind() const { return (BaseKind) (Kind & BaseMask); } |
| 319 | unsigned getSubKind() const { return (Kind & ~BaseMask) >> BaseBits; } |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 320 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 321 | void Profile(llvm::FoldingSetNodeID& ID) const { |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 322 | ID.AddInteger((unsigned) getRawKind()); |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 323 | ID.AddPointer(reinterpret_cast<void*>(Data)); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 324 | } |
| 325 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 326 | bool operator==(const RValue& RHS) const { |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 327 | return getRawKind() == RHS.getRawKind() && Data == RHS.Data; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 328 | } |
| 329 | |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 330 | inline bool isValid() const { return getRawKind() != InvalidKind; } |
| 331 | inline bool isInvalid() const { return getRawKind() == InvalidKind; } |
| 332 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 333 | void print(std::ostream& OS) const; |
| 334 | void print() const { print(*llvm::cerr.stream()); } |
| 335 | |
| 336 | // Implement isa<T> support. |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 337 | static inline bool classof(const RValue*) { return true; } |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 338 | }; |
| 339 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 340 | class VISIBILITY_HIDDEN InvalidValue : public RValue { |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 341 | public: |
Ted Kremenek | 403c181 | 2008-01-28 22:51:57 +0000 | [diff] [blame] | 342 | InvalidValue() : RValue(InvalidKind) {} |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 343 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 344 | static inline bool classof(const RValue* V) { |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 345 | return V->getBaseKind() == InvalidKind; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 346 | } |
| 347 | }; |
Ted Kremenek | 403c181 | 2008-01-28 22:51:57 +0000 | [diff] [blame] | 348 | |
| 349 | class VISIBILITY_HIDDEN UninitializedValue : public RValue { |
| 350 | public: |
| 351 | UninitializedValue() : RValue(UninitializedKind) {} |
| 352 | |
| 353 | static inline bool classof(const RValue* V) { |
| 354 | return V->getBaseKind() == UninitializedKind; |
| 355 | } |
| 356 | }; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 357 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 358 | class VISIBILITY_HIDDEN NonLValue : public RValue { |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 359 | protected: |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 360 | NonLValue(unsigned SubKind, const void* d) : RValue(d, false, SubKind) {} |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 361 | |
| 362 | public: |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 363 | void print(std::ostream& Out) const; |
| 364 | |
Ted Kremenek | 687af80 | 2008-01-29 19:43:15 +0000 | [diff] [blame] | 365 | // Arithmetic operators. |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 366 | NonLValue Add(ValueManager& ValMgr, const NonLValue& RHS) const; |
| 367 | NonLValue Sub(ValueManager& ValMgr, const NonLValue& RHS) const; |
| 368 | NonLValue Mul(ValueManager& ValMgr, const NonLValue& RHS) const; |
| 369 | NonLValue Div(ValueManager& ValMgr, const NonLValue& RHS) const; |
| 370 | NonLValue Rem(ValueManager& ValMgr, const NonLValue& RHS) const; |
| 371 | NonLValue UnaryMinus(ValueManager& ValMgr, UnaryOperator* U) const; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 372 | |
Ted Kremenek | 687af80 | 2008-01-29 19:43:15 +0000 | [diff] [blame] | 373 | // Equality operators. |
| 374 | NonLValue EQ(ValueManager& ValMgr, const NonLValue& RHS) const; |
| 375 | NonLValue NE(ValueManager& ValMgr, const NonLValue& RHS) const; |
Ted Kremenek | 68fd257 | 2008-01-29 17:27:31 +0000 | [diff] [blame] | 376 | |
Ted Kremenek | 687af80 | 2008-01-29 19:43:15 +0000 | [diff] [blame] | 377 | // Utility methods to create NonLValues. |
| 378 | static NonLValue GetValue(ValueManager& ValMgr, uint64_t X, QualType T, |
| 379 | SourceLocation Loc = SourceLocation()); |
| 380 | |
| 381 | static NonLValue GetValue(ValueManager& ValMgr, IntegerLiteral* I); |
Ted Kremenek | 68fd257 | 2008-01-29 17:27:31 +0000 | [diff] [blame] | 382 | static NonLValue GetSymbolValue(SymbolManager& SymMgr, ParmVarDecl *D); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 383 | |
Ted Kremenek | 687af80 | 2008-01-29 19:43:15 +0000 | [diff] [blame] | 384 | static inline NonLValue GetIntTruthValue(ValueManager& ValMgr, bool X) { |
| 385 | return GetValue(ValMgr, X ? 1U : 0U, ValMgr.getContext().IntTy); |
| 386 | } |
| 387 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 388 | // Implement isa<T> support. |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 389 | static inline bool classof(const RValue* V) { |
Ted Kremenek | 403c181 | 2008-01-28 22:51:57 +0000 | [diff] [blame] | 390 | return V->getBaseKind() >= NonLValueKind; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 391 | } |
| 392 | }; |
Ted Kremenek | 687af80 | 2008-01-29 19:43:15 +0000 | [diff] [blame] | 393 | |
| 394 | class VISIBILITY_HIDDEN LValue : public RValue { |
| 395 | protected: |
| 396 | LValue(unsigned SubKind, void* D) : RValue(D, true, SubKind) {} |
| 397 | |
| 398 | public: |
| 399 | |
| 400 | // Equality operators. |
| 401 | NonLValue EQ(ValueManager& ValMgr, const LValue& RHS) const; |
| 402 | NonLValue NE(ValueManager& ValMgr, const LValue& RHS) const; |
| 403 | |
| 404 | // Implement isa<T> support. |
| 405 | static inline bool classof(const RValue* V) { |
| 406 | return V->getBaseKind() == LValueKind; |
| 407 | } |
| 408 | }; |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 409 | |
| 410 | } // end anonymous namespace |
| 411 | |
| 412 | //===----------------------------------------------------------------------===// |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 413 | // LValues. |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 414 | //===----------------------------------------------------------------------===// |
| 415 | |
| 416 | namespace { |
| 417 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 418 | enum { LValueDeclKind, NumLValueKind }; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 419 | |
| 420 | class VISIBILITY_HIDDEN LValueDecl : public LValue { |
| 421 | public: |
Ted Kremenek | 9de04c4 | 2008-01-24 20:55:43 +0000 | [diff] [blame] | 422 | LValueDecl(const ValueDecl* vd) |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 423 | : LValue(LValueDeclKind,const_cast<ValueDecl*>(vd)) {} |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 424 | |
| 425 | ValueDecl* getDecl() const { |
| 426 | return static_cast<ValueDecl*>(getRawPtr()); |
| 427 | } |
| 428 | |
Ted Kremenek | 687af80 | 2008-01-29 19:43:15 +0000 | [diff] [blame] | 429 | inline bool operator==(const LValueDecl& R) const { |
| 430 | return getDecl() == R.getDecl(); |
| 431 | } |
| 432 | |
| 433 | inline bool operator!=(const LValueDecl& R) const { |
| 434 | return getDecl() != R.getDecl(); |
| 435 | } |
| 436 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 437 | // Implement isa<T> support. |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 438 | static inline bool classof(const RValue* V) { |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 439 | return V->getSubKind() == LValueDeclKind; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 440 | } |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 441 | }; |
| 442 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 443 | } // end anonymous namespace |
| 444 | |
| 445 | //===----------------------------------------------------------------------===// |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 446 | // Non-LValues. |
| 447 | //===----------------------------------------------------------------------===// |
| 448 | |
| 449 | namespace { |
| 450 | |
Ted Kremenek | f264562 | 2008-01-28 22:25:21 +0000 | [diff] [blame] | 451 | enum { SymbolicNonLValueKind, ConcreteIntKind, ConstrainedIntegerKind, |
| 452 | NumNonLValueKind }; |
| 453 | |
| 454 | class VISIBILITY_HIDDEN SymbolicNonLValue : public NonLValue { |
| 455 | public: |
| 456 | SymbolicNonLValue(unsigned SymID) |
| 457 | : NonLValue(SymbolicNonLValueKind, |
| 458 | reinterpret_cast<void*>((uintptr_t) SymID)) {} |
| 459 | |
| 460 | SymbolID getSymbolID() const { |
| 461 | return (SymbolID) reinterpret_cast<uintptr_t>(getRawPtr()); |
| 462 | } |
| 463 | |
| 464 | static inline bool classof(const RValue* V) { |
| 465 | return V->getSubKind() == SymbolicNonLValueKind; |
| 466 | } |
| 467 | }; |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 468 | |
| 469 | class VISIBILITY_HIDDEN ConcreteInt : public NonLValue { |
| 470 | public: |
| 471 | ConcreteInt(const APSInt& V) : NonLValue(ConcreteIntKind, &V) {} |
| 472 | |
| 473 | const APSInt& getValue() const { |
| 474 | return *static_cast<APSInt*>(getRawPtr()); |
| 475 | } |
| 476 | |
Ted Kremenek | 687af80 | 2008-01-29 19:43:15 +0000 | [diff] [blame] | 477 | // Arithmetic operators. |
| 478 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 479 | ConcreteInt Add(ValueManager& ValMgr, const ConcreteInt& V) const { |
| 480 | return ValMgr.getValue(getValue() + V.getValue()); |
| 481 | } |
Ted Kremenek | 687af80 | 2008-01-29 19:43:15 +0000 | [diff] [blame] | 482 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 483 | ConcreteInt Sub(ValueManager& ValMgr, const ConcreteInt& V) const { |
| 484 | return ValMgr.getValue(getValue() - V.getValue()); |
| 485 | } |
| 486 | |
| 487 | ConcreteInt Mul(ValueManager& ValMgr, const ConcreteInt& V) const { |
| 488 | return ValMgr.getValue(getValue() * V.getValue()); |
| 489 | } |
| 490 | |
| 491 | ConcreteInt Div(ValueManager& ValMgr, const ConcreteInt& V) const { |
| 492 | return ValMgr.getValue(getValue() / V.getValue()); |
| 493 | } |
| 494 | |
| 495 | ConcreteInt Rem(ValueManager& ValMgr, const ConcreteInt& V) const { |
| 496 | return ValMgr.getValue(getValue() % V.getValue()); |
| 497 | } |
| 498 | |
Ted Kremenek | 687af80 | 2008-01-29 19:43:15 +0000 | [diff] [blame] | 499 | ConcreteInt UnaryMinus(ValueManager& ValMgr, UnaryOperator* U) const { |
| 500 | assert (U->getType() == U->getSubExpr()->getType()); |
| 501 | assert (U->getType()->isIntegerType()); |
| 502 | return ValMgr.getValue(-getValue()); |
| 503 | } |
| 504 | |
| 505 | // Casting. |
| 506 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 507 | ConcreteInt Cast(ValueManager& ValMgr, Expr* CastExpr) const { |
| 508 | assert (CastExpr->getType()->isIntegerType()); |
| 509 | |
| 510 | APSInt X(getValue()); |
Ted Kremenek | cb48b9c | 2008-01-29 00:33:40 +0000 | [diff] [blame] | 511 | X.extOrTrunc(ValMgr.getContext().getTypeSize(CastExpr->getType(), |
| 512 | CastExpr->getLocStart())); |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 513 | return ValMgr.getValue(X); |
| 514 | } |
| 515 | |
Ted Kremenek | 687af80 | 2008-01-29 19:43:15 +0000 | [diff] [blame] | 516 | // Equality operators. |
| 517 | |
| 518 | ConcreteInt EQ(ValueManager& ValMgr, const ConcreteInt& V) const { |
| 519 | const APSInt& Val = getValue(); |
| 520 | return ValMgr.getValue(Val == V.getValue() ? 1U : 0U, |
| 521 | Val.getBitWidth(), Val.isUnsigned()); |
| 522 | } |
| 523 | |
| 524 | ConcreteInt NE(ValueManager& ValMgr, const ConcreteInt& V) const { |
| 525 | const APSInt& Val = getValue(); |
| 526 | return ValMgr.getValue(Val != V.getValue() ? 1U : 0U, |
| 527 | Val.getBitWidth(), Val.isUnsigned()); |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 528 | } |
| 529 | |
| 530 | // Implement isa<T> support. |
| 531 | static inline bool classof(const RValue* V) { |
| 532 | return V->getSubKind() == ConcreteIntKind; |
| 533 | } |
| 534 | }; |
| 535 | |
| 536 | } // end anonymous namespace |
| 537 | |
| 538 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 687af80 | 2008-01-29 19:43:15 +0000 | [diff] [blame] | 539 | // Transfer function dispatch for Non-LValues. |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 540 | //===----------------------------------------------------------------------===// |
| 541 | |
| 542 | RValue RValue::Cast(ValueManager& ValMgr, Expr* CastExpr) const { |
| 543 | switch (getSubKind()) { |
| 544 | case ConcreteIntKind: |
| 545 | return cast<ConcreteInt>(this)->Cast(ValMgr, CastExpr); |
| 546 | default: |
| 547 | return InvalidValue(); |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | NonLValue NonLValue::UnaryMinus(ValueManager& ValMgr, UnaryOperator* U) const { |
| 552 | switch (getSubKind()) { |
| 553 | case ConcreteIntKind: |
| 554 | return cast<ConcreteInt>(this)->UnaryMinus(ValMgr, U); |
| 555 | default: |
| 556 | return cast<NonLValue>(InvalidValue()); |
| 557 | } |
| 558 | } |
| 559 | |
Ted Kremenek | 687af80 | 2008-01-29 19:43:15 +0000 | [diff] [blame] | 560 | #define NONLVALUE_DISPATCH_CASE(k1,k2,Op)\ |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 561 | case (k1##Kind*NumNonLValueKind+k2##Kind):\ |
| 562 | return cast<k1>(*this).Op(ValMgr,cast<k2>(RHS)); |
| 563 | |
Ted Kremenek | 687af80 | 2008-01-29 19:43:15 +0000 | [diff] [blame] | 564 | #define NONLVALUE_DISPATCH(Op)\ |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 565 | switch (getSubKind()*NumNonLValueKind+RHS.getSubKind()){\ |
Ted Kremenek | 687af80 | 2008-01-29 19:43:15 +0000 | [diff] [blame] | 566 | NONLVALUE_DISPATCH_CASE(ConcreteInt,ConcreteInt,Op)\ |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 567 | default:\ |
Ted Kremenek | 403c181 | 2008-01-28 22:51:57 +0000 | [diff] [blame] | 568 | if (getBaseKind() == UninitializedKind ||\ |
| 569 | RHS.getBaseKind() == UninitializedKind)\ |
| 570 | return cast<NonLValue>(UninitializedValue());\ |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 571 | assert (!isValid() || !RHS.isValid() && "Missing case.");\ |
| 572 | break;\ |
| 573 | }\ |
| 574 | return cast<NonLValue>(InvalidValue()); |
| 575 | |
| 576 | NonLValue NonLValue::Add(ValueManager& ValMgr, const NonLValue& RHS) const { |
Ted Kremenek | 687af80 | 2008-01-29 19:43:15 +0000 | [diff] [blame] | 577 | NONLVALUE_DISPATCH(Add) |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | NonLValue NonLValue::Sub(ValueManager& ValMgr, const NonLValue& RHS) const { |
Ted Kremenek | 687af80 | 2008-01-29 19:43:15 +0000 | [diff] [blame] | 581 | NONLVALUE_DISPATCH(Sub) |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 582 | } |
| 583 | |
| 584 | NonLValue NonLValue::Mul(ValueManager& ValMgr, const NonLValue& RHS) const { |
Ted Kremenek | 687af80 | 2008-01-29 19:43:15 +0000 | [diff] [blame] | 585 | NONLVALUE_DISPATCH(Mul) |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 586 | } |
| 587 | |
| 588 | NonLValue NonLValue::Div(ValueManager& ValMgr, const NonLValue& RHS) const { |
Ted Kremenek | 687af80 | 2008-01-29 19:43:15 +0000 | [diff] [blame] | 589 | NONLVALUE_DISPATCH(Div) |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | NonLValue NonLValue::Rem(ValueManager& ValMgr, const NonLValue& RHS) const { |
Ted Kremenek | 687af80 | 2008-01-29 19:43:15 +0000 | [diff] [blame] | 593 | NONLVALUE_DISPATCH(Rem) |
| 594 | } |
| 595 | |
| 596 | NonLValue NonLValue::EQ(ValueManager& ValMgr, const NonLValue& RHS) const { |
| 597 | NONLVALUE_DISPATCH(EQ) |
| 598 | } |
| 599 | |
| 600 | NonLValue NonLValue::NE(ValueManager& ValMgr, const NonLValue& RHS) const { |
| 601 | NONLVALUE_DISPATCH(NE) |
| 602 | } |
| 603 | |
| 604 | #undef NONLVALUE_DISPATCH_CASE |
| 605 | #undef NONLVALUE_DISPATCH |
| 606 | |
| 607 | //===----------------------------------------------------------------------===// |
| 608 | // Transfer function dispatch for LValues. |
| 609 | //===----------------------------------------------------------------------===// |
| 610 | |
| 611 | |
| 612 | NonLValue LValue::EQ(ValueManager& ValMgr, const LValue& RHS) const { |
| 613 | if (getSubKind() != RHS.getSubKind()) |
| 614 | return NonLValue::GetIntTruthValue(ValMgr, false); |
| 615 | |
| 616 | switch (getSubKind()) { |
| 617 | default: |
| 618 | assert(false && "EQ not implemented for this LValue."); |
| 619 | return cast<NonLValue>(InvalidValue()); |
| 620 | |
| 621 | case LValueDeclKind: { |
| 622 | bool b = cast<LValueDecl>(*this) == cast<LValueDecl>(RHS); |
| 623 | return NonLValue::GetIntTruthValue(ValMgr, b); |
| 624 | } |
| 625 | } |
| 626 | } |
| 627 | |
| 628 | NonLValue LValue::NE(ValueManager& ValMgr, const LValue& RHS) const { |
| 629 | if (getSubKind() != RHS.getSubKind()) |
Ted Kremenek | 0370167 | 2008-01-29 21:27:49 +0000 | [diff] [blame] | 630 | return NonLValue::GetIntTruthValue(ValMgr, true); |
Ted Kremenek | 687af80 | 2008-01-29 19:43:15 +0000 | [diff] [blame] | 631 | |
| 632 | switch (getSubKind()) { |
| 633 | default: |
| 634 | assert(false && "EQ not implemented for this LValue."); |
| 635 | return cast<NonLValue>(InvalidValue()); |
| 636 | |
| 637 | case LValueDeclKind: { |
| 638 | bool b = cast<LValueDecl>(*this) != cast<LValueDecl>(RHS); |
| 639 | return NonLValue::GetIntTruthValue(ValMgr, b); |
| 640 | } |
| 641 | } |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 642 | } |
| 643 | |
| 644 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 645 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 687af80 | 2008-01-29 19:43:15 +0000 | [diff] [blame] | 646 | // Utility methods for constructing Non-LValues. |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 647 | //===----------------------------------------------------------------------===// |
| 648 | |
Ted Kremenek | 687af80 | 2008-01-29 19:43:15 +0000 | [diff] [blame] | 649 | NonLValue NonLValue::GetValue(ValueManager& ValMgr, uint64_t X, QualType T, |
| 650 | SourceLocation Loc) { |
| 651 | |
| 652 | return ConcreteInt(ValMgr.getValue(X, T, Loc)); |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 653 | } |
| 654 | |
| 655 | NonLValue NonLValue::GetValue(ValueManager& ValMgr, IntegerLiteral* I) { |
| 656 | return ConcreteInt(ValMgr.getValue(APSInt(I->getValue(), |
| 657 | I->getType()->isUnsignedIntegerType()))); |
| 658 | } |
| 659 | |
Ted Kremenek | 68fd257 | 2008-01-29 17:27:31 +0000 | [diff] [blame] | 660 | NonLValue NonLValue::GetSymbolValue(SymbolManager& SymMgr, ParmVarDecl* D) { |
| 661 | return SymbolicNonLValue(SymMgr.getSymbol(D)); |
| 662 | } |
| 663 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 664 | //===----------------------------------------------------------------------===// |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 665 | // Pretty-Printing. |
| 666 | //===----------------------------------------------------------------------===// |
| 667 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 668 | void RValue::print(std::ostream& Out) const { |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 669 | switch (getBaseKind()) { |
| 670 | case InvalidKind: |
| 671 | Out << "Invalid"; |
| 672 | break; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 673 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 674 | case NonLValueKind: |
| 675 | cast<NonLValue>(this)->print(Out); |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 676 | break; |
Ted Kremenek | 68fd257 | 2008-01-29 17:27:31 +0000 | [diff] [blame] | 677 | |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 678 | case LValueKind: |
| 679 | assert (false && "FIXME: LValue printing not implemented."); |
| 680 | break; |
| 681 | |
Ted Kremenek | 403c181 | 2008-01-28 22:51:57 +0000 | [diff] [blame] | 682 | case UninitializedKind: |
| 683 | Out << "Uninitialized"; |
| 684 | break; |
| 685 | |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 686 | default: |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 687 | assert (false && "Invalid RValue."); |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 688 | } |
| 689 | } |
| 690 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 691 | void NonLValue::print(std::ostream& Out) const { |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 692 | switch (getSubKind()) { |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 693 | case ConcreteIntKind: |
| 694 | Out << cast<ConcreteInt>(this)->getValue().toString(); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 695 | break; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 696 | |
Ted Kremenek | 68fd257 | 2008-01-29 17:27:31 +0000 | [diff] [blame] | 697 | case SymbolicNonLValueKind: |
Ted Kremenek | 6753fe3 | 2008-01-30 18:54:06 +0000 | [diff] [blame^] | 698 | Out << '$' << cast<SymbolicNonLValue>(this)->getSymbolID(); |
Ted Kremenek | 68fd257 | 2008-01-29 17:27:31 +0000 | [diff] [blame] | 699 | break; |
| 700 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 701 | default: |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 702 | assert (false && "Pretty-printed not implemented for this NonLValue."); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 703 | break; |
| 704 | } |
| 705 | } |
| 706 | |
| 707 | //===----------------------------------------------------------------------===// |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 708 | // ValueMapTy - A ImmutableMap type Stmt*/Decl*/Symbols to RValues. |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 709 | //===----------------------------------------------------------------------===// |
| 710 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 711 | typedef llvm::ImmutableMap<ValueKey,RValue> ValueMapTy; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 712 | |
| 713 | namespace clang { |
| 714 | template<> |
| 715 | struct VISIBILITY_HIDDEN GRTrait<ValueMapTy> { |
| 716 | static inline void* toPtr(ValueMapTy M) { |
| 717 | return reinterpret_cast<void*>(M.getRoot()); |
| 718 | } |
| 719 | static inline ValueMapTy toState(void* P) { |
| 720 | return ValueMapTy(static_cast<ValueMapTy::TreeTy*>(P)); |
| 721 | } |
| 722 | }; |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | //===----------------------------------------------------------------------===// |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 726 | // The Checker. |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 727 | //===----------------------------------------------------------------------===// |
| 728 | |
| 729 | namespace { |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 730 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 731 | class VISIBILITY_HIDDEN GRConstants { |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 732 | |
| 733 | public: |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 734 | typedef ValueMapTy StateTy; |
Ted Kremenek | 7d7fe6d | 2008-01-29 22:56:11 +0000 | [diff] [blame] | 735 | typedef GRStmtNodeBuilder<GRConstants> StmtNodeBuilder; |
| 736 | typedef GRBranchNodeBuilder<GRConstants> BranchNodeBuilder; |
Ted Kremenek | cb48b9c | 2008-01-29 00:33:40 +0000 | [diff] [blame] | 737 | typedef ExplodedGraph<GRConstants> GraphTy; |
| 738 | typedef GraphTy::NodeTy NodeTy; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 739 | |
| 740 | class NodeSet { |
| 741 | typedef llvm::SmallVector<NodeTy*,3> ImplTy; |
| 742 | ImplTy Impl; |
| 743 | public: |
| 744 | |
| 745 | NodeSet() {} |
| 746 | NodeSet(NodeTy* N) { assert (N && !N->isInfeasible()); Impl.push_back(N); } |
| 747 | |
| 748 | void Add(NodeTy* N) { if (N && !N->isInfeasible()) Impl.push_back(N); } |
| 749 | |
| 750 | typedef ImplTy::iterator iterator; |
| 751 | typedef ImplTy::const_iterator const_iterator; |
| 752 | |
| 753 | unsigned size() const { return Impl.size(); } |
Ted Kremenek | 9de04c4 | 2008-01-24 20:55:43 +0000 | [diff] [blame] | 754 | bool empty() const { return Impl.empty(); } |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 755 | |
| 756 | iterator begin() { return Impl.begin(); } |
| 757 | iterator end() { return Impl.end(); } |
| 758 | |
| 759 | const_iterator begin() const { return Impl.begin(); } |
| 760 | const_iterator end() const { return Impl.end(); } |
| 761 | }; |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 762 | |
| 763 | protected: |
Ted Kremenek | cb48b9c | 2008-01-29 00:33:40 +0000 | [diff] [blame] | 764 | /// G - the simulation graph. |
| 765 | GraphTy& G; |
| 766 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 767 | /// Liveness - live-variables information the ValueDecl* and block-level |
| 768 | /// Expr* in the CFG. Used to prune out dead state. |
Ted Kremenek | bffaa83 | 2008-01-29 05:13:23 +0000 | [diff] [blame] | 769 | LiveVariables Liveness; |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 770 | |
Ted Kremenek | f4b7a69 | 2008-01-29 22:11:49 +0000 | [diff] [blame] | 771 | /// Builder - The current GRStmtNodeBuilder which is used when building the nodes |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 772 | /// for a given statement. |
Ted Kremenek | 7d7fe6d | 2008-01-29 22:56:11 +0000 | [diff] [blame] | 773 | StmtNodeBuilder* Builder; |
| 774 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 775 | /// StateMgr - Object that manages the data for all created states. |
| 776 | ValueMapTy::Factory StateMgr; |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 777 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 778 | /// ValueMgr - Object that manages the data for all created RValues. |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 779 | ValueManager ValMgr; |
| 780 | |
Ted Kremenek | 68fd257 | 2008-01-29 17:27:31 +0000 | [diff] [blame] | 781 | /// SymMgr - Object that manages the symbol information. |
| 782 | SymbolManager SymMgr; |
| 783 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 784 | /// StmtEntryNode - The immediate predecessor node. |
| 785 | NodeTy* StmtEntryNode; |
| 786 | |
| 787 | /// CurrentStmt - The current block-level statement. |
| 788 | Stmt* CurrentStmt; |
| 789 | |
| 790 | bool StateCleaned; |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 791 | |
Ted Kremenek | cb48b9c | 2008-01-29 00:33:40 +0000 | [diff] [blame] | 792 | ASTContext& getContext() const { return G.getContext(); } |
Ted Kremenek | 7b8009a | 2008-01-24 02:28:56 +0000 | [diff] [blame] | 793 | |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 794 | public: |
Ted Kremenek | bffaa83 | 2008-01-29 05:13:23 +0000 | [diff] [blame] | 795 | GRConstants(GraphTy& g) : G(g), Liveness(G.getCFG(), G.getFunctionDecl()), |
| 796 | Builder(NULL), ValMgr(G.getContext()), StmtEntryNode(NULL), |
| 797 | CurrentStmt(NULL) { |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 798 | |
Ted Kremenek | cb48b9c | 2008-01-29 00:33:40 +0000 | [diff] [blame] | 799 | // Compute liveness information. |
Ted Kremenek | bffaa83 | 2008-01-29 05:13:23 +0000 | [diff] [blame] | 800 | Liveness.runOnCFG(G.getCFG()); |
| 801 | Liveness.runOnAllBlocks(G.getCFG(), NULL, true); |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 802 | } |
Ted Kremenek | cb48b9c | 2008-01-29 00:33:40 +0000 | [diff] [blame] | 803 | |
| 804 | /// getCFG - Returns the CFG associated with this analysis. |
| 805 | CFG& getCFG() { return G.getCFG(); } |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 806 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 807 | /// getInitialState - Return the initial state used for the root vertex |
| 808 | /// in the ExplodedGraph. |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 809 | StateTy getInitialState() { |
Ted Kremenek | cb48b9c | 2008-01-29 00:33:40 +0000 | [diff] [blame] | 810 | StateTy St = StateMgr.GetEmptyMap(); |
Ted Kremenek | ff6e3c5 | 2008-01-29 00:43:03 +0000 | [diff] [blame] | 811 | |
| 812 | // Iterate the parameters. |
| 813 | FunctionDecl& F = G.getFunctionDecl(); |
| 814 | |
| 815 | for (FunctionDecl::param_iterator I=F.param_begin(), E=F.param_end(); |
| 816 | I!=E; ++I) { |
| 817 | |
| 818 | // For now we only support symbolic values for non-pointer types. |
| 819 | if ((*I)->getType()->isPointerType() || |
| 820 | (*I)->getType()->isReferenceType()) |
| 821 | continue; |
| 822 | |
| 823 | // FIXME: Set these values to a symbol, not Uninitialized. |
Ted Kremenek | 68fd257 | 2008-01-29 17:27:31 +0000 | [diff] [blame] | 824 | St = SetValue(St, LValueDecl(*I), NonLValue::GetSymbolValue(SymMgr, *I)); |
Ted Kremenek | ff6e3c5 | 2008-01-29 00:43:03 +0000 | [diff] [blame] | 825 | } |
| 826 | |
Ted Kremenek | cb48b9c | 2008-01-29 00:33:40 +0000 | [diff] [blame] | 827 | return St; |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 828 | } |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 829 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 830 | /// ProcessStmt - Called by GREngine. Used to generate new successor |
| 831 | /// nodes by processing the 'effects' of a block-level statement. |
Ted Kremenek | 7d7fe6d | 2008-01-29 22:56:11 +0000 | [diff] [blame] | 832 | void ProcessStmt(Stmt* S, StmtNodeBuilder& builder); |
| 833 | |
| 834 | /// ProcessBranch - Called by GREngine. Used to generate successor |
| 835 | /// nodes by processing the 'effects' of a branch condition. |
Ted Kremenek | 71c29bd | 2008-01-29 23:32:35 +0000 | [diff] [blame] | 836 | void ProcessBranch(Stmt* Condition, Stmt* Term, BranchNodeBuilder& builder); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 837 | |
| 838 | /// RemoveDeadBindings - Return a new state that is the same as 'M' except |
| 839 | /// that all subexpression mappings are removed and that any |
| 840 | /// block-level expressions that are not live at 'S' also have their |
| 841 | /// mappings removed. |
| 842 | StateTy RemoveDeadBindings(Stmt* S, StateTy M); |
| 843 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 844 | StateTy SetValue(StateTy St, Stmt* S, const RValue& V); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 845 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 846 | StateTy SetValue(StateTy St, const Stmt* S, const RValue& V) { |
Ted Kremenek | 9de04c4 | 2008-01-24 20:55:43 +0000 | [diff] [blame] | 847 | return SetValue(St, const_cast<Stmt*>(S), V); |
| 848 | } |
| 849 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 850 | StateTy SetValue(StateTy St, const LValue& LV, const RValue& V); |
Ted Kremenek | 1ccd31c | 2008-01-16 19:42:59 +0000 | [diff] [blame] | 851 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 852 | RValue GetValue(const StateTy& St, Stmt* S); |
| 853 | inline RValue GetValue(const StateTy& St, const Stmt* S) { |
Ted Kremenek | 9de04c4 | 2008-01-24 20:55:43 +0000 | [diff] [blame] | 854 | return GetValue(St, const_cast<Stmt*>(S)); |
| 855 | } |
| 856 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 857 | RValue GetValue(const StateTy& St, const LValue& LV); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 858 | LValue GetLValue(const StateTy& St, Stmt* S); |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 859 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 860 | void Nodify(NodeSet& Dst, Stmt* S, NodeTy* Pred, StateTy St); |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 861 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 862 | /// Visit - Transfer function logic for all statements. Dispatches to |
| 863 | /// other functions that handle specific kinds of statements. |
| 864 | void Visit(Stmt* S, NodeTy* Pred, NodeSet& Dst); |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 865 | |
| 866 | /// VisitCast - Transfer function logic for all casts (implicit and explicit). |
| 867 | void VisitCast(Expr* CastE, Expr* E, NodeTy* Pred, NodeSet& Dst); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 868 | |
Ted Kremenek | 7b8009a | 2008-01-24 02:28:56 +0000 | [diff] [blame] | 869 | /// VisitUnaryOperator - Transfer function logic for unary operators. |
| 870 | void VisitUnaryOperator(UnaryOperator* B, NodeTy* Pred, NodeSet& Dst); |
| 871 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 872 | /// VisitBinaryOperator - Transfer function logic for binary operators. |
Ted Kremenek | 9de04c4 | 2008-01-24 20:55:43 +0000 | [diff] [blame] | 873 | void VisitBinaryOperator(BinaryOperator* B, NodeTy* Pred, NodeSet& Dst); |
| 874 | |
| 875 | /// VisitDeclStmt - Transfer function logic for DeclStmts. |
| 876 | void VisitDeclStmt(DeclStmt* DS, NodeTy* Pred, NodeSet& Dst); |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 877 | }; |
| 878 | } // end anonymous namespace |
| 879 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 880 | |
Ted Kremenek | 71c29bd | 2008-01-29 23:32:35 +0000 | [diff] [blame] | 881 | void GRConstants::ProcessBranch(Stmt* Condition, Stmt* Term, |
| 882 | BranchNodeBuilder& builder) { |
| 883 | |
| 884 | |
| 885 | } |
| 886 | |
Ted Kremenek | 7d7fe6d | 2008-01-29 22:56:11 +0000 | [diff] [blame] | 887 | void GRConstants::ProcessStmt(Stmt* S, StmtNodeBuilder& builder) { |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 888 | Builder = &builder; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 889 | |
| 890 | StmtEntryNode = builder.getLastNode(); |
| 891 | CurrentStmt = S; |
| 892 | NodeSet Dst; |
| 893 | StateCleaned = false; |
| 894 | |
| 895 | Visit(S, StmtEntryNode, Dst); |
| 896 | |
| 897 | // If no nodes were generated, generate a new node that has all the |
| 898 | // dead mappings removed. |
| 899 | if (Dst.size() == 1 && *Dst.begin() == StmtEntryNode) { |
| 900 | StateTy St = RemoveDeadBindings(S, StmtEntryNode->getState()); |
| 901 | builder.generateNode(S, St, StmtEntryNode); |
| 902 | } |
Ted Kremenek | f84469b | 2008-01-18 00:41:32 +0000 | [diff] [blame] | 903 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 904 | CurrentStmt = NULL; |
| 905 | StmtEntryNode = NULL; |
| 906 | Builder = NULL; |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 907 | } |
| 908 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 909 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 910 | RValue GRConstants::GetValue(const StateTy& St, const LValue& LV) { |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 911 | switch (LV.getSubKind()) { |
| 912 | case LValueDeclKind: { |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 913 | StateTy::TreeTy* T = St.SlimFind(cast<LValueDecl>(LV).getDecl()); |
| 914 | return T ? T->getValue().second : InvalidValue(); |
| 915 | } |
| 916 | default: |
| 917 | assert (false && "Invalid LValue."); |
Ted Kremenek | ca3e857 | 2008-01-16 22:28:08 +0000 | [diff] [blame] | 918 | break; |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 919 | } |
| 920 | |
| 921 | return InvalidValue(); |
| 922 | } |
| 923 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 924 | RValue GRConstants::GetValue(const StateTy& St, Stmt* S) { |
Ted Kremenek | 671c9e8 | 2008-01-24 00:50:08 +0000 | [diff] [blame] | 925 | for (;;) { |
| 926 | switch (S->getStmtClass()) { |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 927 | |
| 928 | // ParenExprs are no-ops. |
| 929 | |
Ted Kremenek | 671c9e8 | 2008-01-24 00:50:08 +0000 | [diff] [blame] | 930 | case Stmt::ParenExprClass: |
| 931 | S = cast<ParenExpr>(S)->getSubExpr(); |
| 932 | continue; |
| 933 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 934 | // DeclRefExprs can either evaluate to an LValue or a Non-LValue |
| 935 | // (assuming an implicit "load") depending on the context. In this |
| 936 | // context we assume that we are retrieving the value contained |
| 937 | // within the referenced variables. |
| 938 | |
Ted Kremenek | 671c9e8 | 2008-01-24 00:50:08 +0000 | [diff] [blame] | 939 | case Stmt::DeclRefExprClass: |
| 940 | return GetValue(St, LValueDecl(cast<DeclRefExpr>(S)->getDecl())); |
Ted Kremenek | ca3e857 | 2008-01-16 22:28:08 +0000 | [diff] [blame] | 941 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 942 | // Integer literals evaluate to an RValue. Simply retrieve the |
| 943 | // RValue for the literal. |
| 944 | |
Ted Kremenek | 671c9e8 | 2008-01-24 00:50:08 +0000 | [diff] [blame] | 945 | case Stmt::IntegerLiteralClass: |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 946 | return NonLValue::GetValue(ValMgr, cast<IntegerLiteral>(S)); |
| 947 | |
| 948 | // Casts where the source and target type are the same |
| 949 | // are no-ops. We blast through these to get the descendant |
| 950 | // subexpression that has a value. |
| 951 | |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 952 | case Stmt::ImplicitCastExprClass: { |
| 953 | ImplicitCastExpr* C = cast<ImplicitCastExpr>(S); |
| 954 | if (C->getType() == C->getSubExpr()->getType()) { |
| 955 | S = C->getSubExpr(); |
| 956 | continue; |
| 957 | } |
| 958 | break; |
| 959 | } |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 960 | |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 961 | case Stmt::CastExprClass: { |
| 962 | CastExpr* C = cast<CastExpr>(S); |
| 963 | if (C->getType() == C->getSubExpr()->getType()) { |
| 964 | S = C->getSubExpr(); |
| 965 | continue; |
| 966 | } |
| 967 | break; |
| 968 | } |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 969 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 970 | // Handle all other Stmt* using a lookup. |
| 971 | |
Ted Kremenek | 671c9e8 | 2008-01-24 00:50:08 +0000 | [diff] [blame] | 972 | default: |
| 973 | break; |
| 974 | }; |
| 975 | |
| 976 | break; |
| 977 | } |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 978 | |
Ted Kremenek | 5c1b996 | 2008-01-24 19:43:37 +0000 | [diff] [blame] | 979 | StateTy::TreeTy* T = St.SlimFind(S); |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 980 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 981 | return T ? T->getValue().second : InvalidValue(); |
| 982 | } |
| 983 | |
| 984 | LValue GRConstants::GetLValue(const StateTy& St, Stmt* S) { |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 985 | while (ParenExpr* P = dyn_cast<ParenExpr>(S)) |
| 986 | S = P->getSubExpr(); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 987 | |
| 988 | if (DeclRefExpr* DR = dyn_cast<DeclRefExpr>(S)) |
| 989 | return LValueDecl(DR->getDecl()); |
| 990 | |
| 991 | return cast<LValue>(GetValue(St, S)); |
| 992 | } |
| 993 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 994 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 995 | GRConstants::StateTy GRConstants::SetValue(StateTy St, Stmt* S, |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 996 | const RValue& V) { |
Ted Kremenek | cc1c365 | 2008-01-25 23:43:12 +0000 | [diff] [blame] | 997 | assert (S); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 998 | |
| 999 | if (!StateCleaned) { |
| 1000 | St = RemoveDeadBindings(CurrentStmt, St); |
| 1001 | StateCleaned = true; |
| 1002 | } |
| 1003 | |
Ted Kremenek | 9ff731d | 2008-01-24 22:27:20 +0000 | [diff] [blame] | 1004 | bool isBlkExpr = false; |
| 1005 | |
| 1006 | if (S == CurrentStmt) { |
| 1007 | isBlkExpr = getCFG().isBlkExpr(S); |
| 1008 | |
| 1009 | if (!isBlkExpr) |
| 1010 | return St; |
| 1011 | } |
Ted Kremenek | daadf45 | 2008-01-24 19:28:01 +0000 | [diff] [blame] | 1012 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 1013 | return V.isValid() ? StateMgr.Add(St, ValueKey(S,isBlkExpr), V) |
| 1014 | : St; |
| 1015 | } |
| 1016 | |
| 1017 | GRConstants::StateTy GRConstants::SetValue(StateTy St, const LValue& LV, |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 1018 | const RValue& V) { |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 1019 | if (!LV.isValid()) |
| 1020 | return St; |
| 1021 | |
| 1022 | if (!StateCleaned) { |
| 1023 | St = RemoveDeadBindings(CurrentStmt, St); |
| 1024 | StateCleaned = true; |
Ted Kremenek | ca3e857 | 2008-01-16 22:28:08 +0000 | [diff] [blame] | 1025 | } |
Ted Kremenek | 0525a4f | 2008-01-16 19:47:19 +0000 | [diff] [blame] | 1026 | |
Ted Kremenek | f13794e | 2008-01-24 23:19:54 +0000 | [diff] [blame] | 1027 | switch (LV.getSubKind()) { |
| 1028 | case LValueDeclKind: |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 1029 | return V.isValid() ? StateMgr.Add(St, cast<LValueDecl>(LV).getDecl(), V) |
| 1030 | : StateMgr.Remove(St, cast<LValueDecl>(LV).getDecl()); |
| 1031 | |
| 1032 | default: |
| 1033 | assert ("SetValue for given LValue type not yet implemented."); |
| 1034 | return St; |
| 1035 | } |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 1036 | } |
| 1037 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 1038 | GRConstants::StateTy GRConstants::RemoveDeadBindings(Stmt* Loc, StateTy M) { |
Ted Kremenek | f84469b | 2008-01-18 00:41:32 +0000 | [diff] [blame] | 1039 | // Note: in the code below, we can assign a new map to M since the |
| 1040 | // iterators are iterating over the tree of the *original* map. |
Ted Kremenek | f84469b | 2008-01-18 00:41:32 +0000 | [diff] [blame] | 1041 | StateTy::iterator I = M.begin(), E = M.end(); |
| 1042 | |
Ted Kremenek | f84469b | 2008-01-18 00:41:32 +0000 | [diff] [blame] | 1043 | |
Ted Kremenek | 65cac13 | 2008-01-29 05:25:31 +0000 | [diff] [blame] | 1044 | for (; I!=E && !I.getKey().isSymbol(); ++I) { |
| 1045 | // Remove old bindings for subexpressions and "dead" |
| 1046 | // block-level expressions. |
| 1047 | if (I.getKey().isSubExpr() || |
| 1048 | I.getKey().isBlkExpr() && !Liveness.isLive(Loc,cast<Stmt>(I.getKey()))){ |
| 1049 | M = StateMgr.Remove(M, I.getKey()); |
| 1050 | } |
| 1051 | else if (I.getKey().isDecl()) { // Remove bindings for "dead" decls. |
| 1052 | if (VarDecl* V = dyn_cast<VarDecl>(cast<ValueDecl>(I.getKey()))) |
| 1053 | if (!Liveness.isLive(Loc, V)) |
| 1054 | M = StateMgr.Remove(M, I.getKey()); |
| 1055 | } |
| 1056 | } |
Ted Kremenek | 565256e | 2008-01-24 22:44:24 +0000 | [diff] [blame] | 1057 | |
Ted Kremenek | e00fe3f | 2008-01-17 00:52:48 +0000 | [diff] [blame] | 1058 | return M; |
Ted Kremenek | e00fe3f | 2008-01-17 00:52:48 +0000 | [diff] [blame] | 1059 | } |
| 1060 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 1061 | void GRConstants::Nodify(NodeSet& Dst, Stmt* S, GRConstants::NodeTy* Pred, |
| 1062 | GRConstants::StateTy St) { |
| 1063 | |
| 1064 | // If the state hasn't changed, don't generate a new node. |
| 1065 | if (St == Pred->getState()) |
| 1066 | return; |
Ted Kremenek | cb448ca | 2008-01-16 00:53:15 +0000 | [diff] [blame] | 1067 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 1068 | Dst.Add(Builder->generateNode(S, St, Pred)); |
Ted Kremenek | cb448ca | 2008-01-16 00:53:15 +0000 | [diff] [blame] | 1069 | } |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 1070 | |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 1071 | void GRConstants::VisitCast(Expr* CastE, Expr* E, GRConstants::NodeTy* Pred, |
| 1072 | GRConstants::NodeSet& Dst) { |
| 1073 | |
| 1074 | QualType T = CastE->getType(); |
| 1075 | |
| 1076 | // Check for redundant casts. |
| 1077 | if (E->getType() == T) { |
| 1078 | Dst.Add(Pred); |
| 1079 | return; |
| 1080 | } |
| 1081 | |
| 1082 | NodeSet S1; |
| 1083 | Visit(E, Pred, S1); |
| 1084 | |
| 1085 | for (NodeSet::iterator I1=S1.begin(), E1=S1.end(); I1 != E1; ++I1) { |
| 1086 | NodeTy* N = *I1; |
| 1087 | StateTy St = N->getState(); |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 1088 | const RValue& V = GetValue(St, E); |
| 1089 | Nodify(Dst, CastE, N, SetValue(St, CastE, V.Cast(ValMgr, CastE))); |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 1090 | } |
Ted Kremenek | 9de04c4 | 2008-01-24 20:55:43 +0000 | [diff] [blame] | 1091 | } |
| 1092 | |
| 1093 | void GRConstants::VisitDeclStmt(DeclStmt* DS, GRConstants::NodeTy* Pred, |
| 1094 | GRConstants::NodeSet& Dst) { |
| 1095 | |
| 1096 | StateTy St = Pred->getState(); |
| 1097 | |
| 1098 | for (const ScopedDecl* D = DS->getDecl(); D; D = D->getNextDeclarator()) |
Ted Kremenek | 403c181 | 2008-01-28 22:51:57 +0000 | [diff] [blame] | 1099 | if (const VarDecl* VD = dyn_cast<VarDecl>(D)) { |
| 1100 | const Expr* E = VD->getInit(); |
| 1101 | St = SetValue(St, LValueDecl(VD), |
| 1102 | E ? GetValue(St, E) : UninitializedValue()); |
| 1103 | } |
Ted Kremenek | 9de04c4 | 2008-01-24 20:55:43 +0000 | [diff] [blame] | 1104 | |
| 1105 | Nodify(Dst, DS, Pred, St); |
| 1106 | |
| 1107 | if (Dst.empty()) |
| 1108 | Dst.Add(Pred); |
| 1109 | } |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 1110 | |
Ted Kremenek | 7b8009a | 2008-01-24 02:28:56 +0000 | [diff] [blame] | 1111 | void GRConstants::VisitUnaryOperator(UnaryOperator* U, |
| 1112 | GRConstants::NodeTy* Pred, |
| 1113 | GRConstants::NodeSet& Dst) { |
| 1114 | NodeSet S1; |
| 1115 | Visit(U->getSubExpr(), Pred, S1); |
| 1116 | |
| 1117 | for (NodeSet::iterator I1=S1.begin(), E1=S1.end(); I1 != E1; ++I1) { |
| 1118 | NodeTy* N1 = *I1; |
| 1119 | StateTy St = N1->getState(); |
| 1120 | |
| 1121 | switch (U->getOpcode()) { |
| 1122 | case UnaryOperator::PostInc: { |
| 1123 | const LValue& L1 = GetLValue(St, U->getSubExpr()); |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 1124 | NonLValue R1 = cast<NonLValue>(GetValue(St, L1)); |
Ted Kremenek | 687af80 | 2008-01-29 19:43:15 +0000 | [diff] [blame] | 1125 | NonLValue R2 = NonLValue::GetValue(ValMgr, 1U, U->getType(), |
| 1126 | U->getLocStart()); |
Ted Kremenek | e0cf9c8 | 2008-01-24 19:00:57 +0000 | [diff] [blame] | 1127 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 1128 | NonLValue Result = R1.Add(ValMgr, R2); |
Ted Kremenek | 7b8009a | 2008-01-24 02:28:56 +0000 | [diff] [blame] | 1129 | Nodify(Dst, U, N1, SetValue(SetValue(St, U, R1), L1, Result)); |
| 1130 | break; |
| 1131 | } |
| 1132 | |
| 1133 | case UnaryOperator::PostDec: { |
| 1134 | const LValue& L1 = GetLValue(St, U->getSubExpr()); |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 1135 | NonLValue R1 = cast<NonLValue>(GetValue(St, L1)); |
Ted Kremenek | 687af80 | 2008-01-29 19:43:15 +0000 | [diff] [blame] | 1136 | NonLValue R2 = NonLValue::GetValue(ValMgr, 1U, U->getType(), |
| 1137 | U->getLocStart()); |
Ted Kremenek | 7b8009a | 2008-01-24 02:28:56 +0000 | [diff] [blame] | 1138 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 1139 | NonLValue Result = R1.Sub(ValMgr, R2); |
Ted Kremenek | 7b8009a | 2008-01-24 02:28:56 +0000 | [diff] [blame] | 1140 | Nodify(Dst, U, N1, SetValue(SetValue(St, U, R1), L1, Result)); |
| 1141 | break; |
| 1142 | } |
| 1143 | |
| 1144 | case UnaryOperator::PreInc: { |
| 1145 | const LValue& L1 = GetLValue(St, U->getSubExpr()); |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 1146 | NonLValue R1 = cast<NonLValue>(GetValue(St, L1)); |
Ted Kremenek | 687af80 | 2008-01-29 19:43:15 +0000 | [diff] [blame] | 1147 | NonLValue R2 = NonLValue::GetValue(ValMgr, 1U, U->getType(), |
| 1148 | U->getLocStart()); |
Ted Kremenek | 7b8009a | 2008-01-24 02:28:56 +0000 | [diff] [blame] | 1149 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 1150 | NonLValue Result = R1.Add(ValMgr, R2); |
Ted Kremenek | 7b8009a | 2008-01-24 02:28:56 +0000 | [diff] [blame] | 1151 | Nodify(Dst, U, N1, SetValue(SetValue(St, U, Result), L1, Result)); |
| 1152 | break; |
| 1153 | } |
| 1154 | |
| 1155 | case UnaryOperator::PreDec: { |
| 1156 | const LValue& L1 = GetLValue(St, U->getSubExpr()); |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 1157 | NonLValue R1 = cast<NonLValue>(GetValue(St, L1)); |
Ted Kremenek | 687af80 | 2008-01-29 19:43:15 +0000 | [diff] [blame] | 1158 | NonLValue R2 = NonLValue::GetValue(ValMgr, 1U, U->getType(), |
| 1159 | U->getLocStart()); |
Ted Kremenek | 7b8009a | 2008-01-24 02:28:56 +0000 | [diff] [blame] | 1160 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 1161 | NonLValue Result = R1.Sub(ValMgr, R2); |
Ted Kremenek | 7b8009a | 2008-01-24 02:28:56 +0000 | [diff] [blame] | 1162 | Nodify(Dst, U, N1, SetValue(SetValue(St, U, Result), L1, Result)); |
| 1163 | break; |
| 1164 | } |
| 1165 | |
Ted Kremenek | dacbb4f | 2008-01-24 08:20:02 +0000 | [diff] [blame] | 1166 | case UnaryOperator::Minus: { |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 1167 | const NonLValue& R1 = cast<NonLValue>(GetValue(St, U->getSubExpr())); |
| 1168 | Nodify(Dst, U, N1, SetValue(St, U, R1.UnaryMinus(ValMgr, U))); |
Ted Kremenek | dacbb4f | 2008-01-24 08:20:02 +0000 | [diff] [blame] | 1169 | break; |
| 1170 | } |
| 1171 | |
Ted Kremenek | 7b8009a | 2008-01-24 02:28:56 +0000 | [diff] [blame] | 1172 | default: ; |
| 1173 | assert (false && "Not implemented."); |
| 1174 | } |
| 1175 | } |
| 1176 | } |
| 1177 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 1178 | void GRConstants::VisitBinaryOperator(BinaryOperator* B, |
| 1179 | GRConstants::NodeTy* Pred, |
| 1180 | GRConstants::NodeSet& Dst) { |
| 1181 | NodeSet S1; |
| 1182 | Visit(B->getLHS(), Pred, S1); |
Ted Kremenek | cb448ca | 2008-01-16 00:53:15 +0000 | [diff] [blame] | 1183 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 1184 | for (NodeSet::iterator I1=S1.begin(), E1=S1.end(); I1 != E1; ++I1) { |
| 1185 | NodeTy* N1 = *I1; |
Ted Kremenek | e00fe3f | 2008-01-17 00:52:48 +0000 | [diff] [blame] | 1186 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 1187 | // When getting the value for the LHS, check if we are in an assignment. |
| 1188 | // In such cases, we want to (initially) treat the LHS as an LValue, |
| 1189 | // so we use GetLValue instead of GetValue so that DeclRefExpr's are |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 1190 | // evaluated to LValueDecl's instead of to an NonLValue. |
| 1191 | const RValue& V1 = |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 1192 | B->isAssignmentOp() ? GetLValue(N1->getState(), B->getLHS()) |
| 1193 | : GetValue(N1->getState(), B->getLHS()); |
Ted Kremenek | cb448ca | 2008-01-16 00:53:15 +0000 | [diff] [blame] | 1194 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 1195 | NodeSet S2; |
| 1196 | Visit(B->getRHS(), N1, S2); |
| 1197 | |
| 1198 | for (NodeSet::iterator I2=S2.begin(), E2=S2.end(); I2 != E2; ++I2) { |
| 1199 | NodeTy* N2 = *I2; |
| 1200 | StateTy St = N2->getState(); |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 1201 | const RValue& V2 = GetValue(St, B->getRHS()); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 1202 | |
| 1203 | switch (B->getOpcode()) { |
Ted Kremenek | 687af80 | 2008-01-29 19:43:15 +0000 | [diff] [blame] | 1204 | default: |
| 1205 | Dst.Add(N2); |
| 1206 | break; |
| 1207 | |
| 1208 | // Arithmetic opreators. |
| 1209 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 1210 | case BinaryOperator::Add: { |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 1211 | const NonLValue& R1 = cast<NonLValue>(V1); |
| 1212 | const NonLValue& R2 = cast<NonLValue>(V2); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 1213 | |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 1214 | Nodify(Dst, B, N2, SetValue(St, B, R1.Add(ValMgr, R2))); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 1215 | break; |
| 1216 | } |
| 1217 | |
| 1218 | case BinaryOperator::Sub: { |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 1219 | const NonLValue& R1 = cast<NonLValue>(V1); |
| 1220 | const NonLValue& R2 = cast<NonLValue>(V2); |
| 1221 | Nodify(Dst, B, N2, SetValue(St, B, R1.Sub(ValMgr, R2))); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 1222 | break; |
| 1223 | } |
| 1224 | |
Ted Kremenek | 2eafd0e | 2008-01-23 23:42:27 +0000 | [diff] [blame] | 1225 | case BinaryOperator::Mul: { |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 1226 | const NonLValue& R1 = cast<NonLValue>(V1); |
| 1227 | const NonLValue& R2 = cast<NonLValue>(V2); |
| 1228 | Nodify(Dst, B, N2, SetValue(St, B, R1.Mul(ValMgr, R2))); |
Ted Kremenek | 2eafd0e | 2008-01-23 23:42:27 +0000 | [diff] [blame] | 1229 | break; |
| 1230 | } |
| 1231 | |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 1232 | case BinaryOperator::Div: { |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 1233 | const NonLValue& R1 = cast<NonLValue>(V1); |
| 1234 | const NonLValue& R2 = cast<NonLValue>(V2); |
| 1235 | Nodify(Dst, B, N2, SetValue(St, B, R1.Div(ValMgr, R2))); |
Ted Kremenek | 5ee4ff8 | 2008-01-25 22:55:56 +0000 | [diff] [blame] | 1236 | break; |
| 1237 | } |
| 1238 | |
Ted Kremenek | cce207d | 2008-01-28 22:26:15 +0000 | [diff] [blame] | 1239 | case BinaryOperator::Rem: { |
| 1240 | const NonLValue& R1 = cast<NonLValue>(V1); |
| 1241 | const NonLValue& R2 = cast<NonLValue>(V2); |
| 1242 | Nodify(Dst, B, N2, SetValue(St, B, R1.Rem(ValMgr, R2))); |
| 1243 | break; |
| 1244 | } |
| 1245 | |
Ted Kremenek | 687af80 | 2008-01-29 19:43:15 +0000 | [diff] [blame] | 1246 | // Assignment operators. |
| 1247 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 1248 | case BinaryOperator::Assign: { |
| 1249 | const LValue& L1 = cast<LValue>(V1); |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 1250 | const NonLValue& R2 = cast<NonLValue>(V2); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 1251 | Nodify(Dst, B, N2, SetValue(SetValue(St, B, R2), L1, R2)); |
| 1252 | break; |
| 1253 | } |
Ted Kremenek | b4ae33f | 2008-01-23 23:38:00 +0000 | [diff] [blame] | 1254 | |
| 1255 | case BinaryOperator::AddAssign: { |
| 1256 | const LValue& L1 = cast<LValue>(V1); |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 1257 | NonLValue R1 = cast<NonLValue>(GetValue(N1->getState(), L1)); |
| 1258 | NonLValue Result = R1.Add(ValMgr, cast<NonLValue>(V2)); |
Ted Kremenek | b4ae33f | 2008-01-23 23:38:00 +0000 | [diff] [blame] | 1259 | Nodify(Dst, B, N2, SetValue(SetValue(St, B, Result), L1, Result)); |
| 1260 | break; |
| 1261 | } |
| 1262 | |
| 1263 | case BinaryOperator::SubAssign: { |
| 1264 | const LValue& L1 = cast<LValue>(V1); |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 1265 | NonLValue R1 = cast<NonLValue>(GetValue(N1->getState(), L1)); |
| 1266 | NonLValue Result = R1.Sub(ValMgr, cast<NonLValue>(V2)); |
Ted Kremenek | b4ae33f | 2008-01-23 23:38:00 +0000 | [diff] [blame] | 1267 | Nodify(Dst, B, N2, SetValue(SetValue(St, B, Result), L1, Result)); |
| 1268 | break; |
| 1269 | } |
Ted Kremenek | 2eafd0e | 2008-01-23 23:42:27 +0000 | [diff] [blame] | 1270 | |
| 1271 | case BinaryOperator::MulAssign: { |
| 1272 | const LValue& L1 = cast<LValue>(V1); |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 1273 | NonLValue R1 = cast<NonLValue>(GetValue(N1->getState(), L1)); |
| 1274 | NonLValue Result = R1.Mul(ValMgr, cast<NonLValue>(V2)); |
Ted Kremenek | 2eafd0e | 2008-01-23 23:42:27 +0000 | [diff] [blame] | 1275 | Nodify(Dst, B, N2, SetValue(SetValue(St, B, Result), L1, Result)); |
| 1276 | break; |
| 1277 | } |
Ted Kremenek | 5c1e262 | 2008-01-25 23:45:34 +0000 | [diff] [blame] | 1278 | |
| 1279 | case BinaryOperator::DivAssign: { |
| 1280 | const LValue& L1 = cast<LValue>(V1); |
Ted Kremenek | bd03f1d | 2008-01-28 22:09:13 +0000 | [diff] [blame] | 1281 | NonLValue R1 = cast<NonLValue>(GetValue(N1->getState(), L1)); |
| 1282 | NonLValue Result = R1.Div(ValMgr, cast<NonLValue>(V2)); |
Ted Kremenek | 5c1e262 | 2008-01-25 23:45:34 +0000 | [diff] [blame] | 1283 | Nodify(Dst, B, N2, SetValue(SetValue(St, B, Result), L1, Result)); |
| 1284 | break; |
| 1285 | } |
Ted Kremenek | 10099a6 | 2008-01-28 22:28:54 +0000 | [diff] [blame] | 1286 | |
| 1287 | case BinaryOperator::RemAssign: { |
| 1288 | const LValue& L1 = cast<LValue>(V1); |
| 1289 | NonLValue R1 = cast<NonLValue>(GetValue(N1->getState(), L1)); |
| 1290 | NonLValue Result = R1.Rem(ValMgr, cast<NonLValue>(V2)); |
| 1291 | Nodify(Dst, B, N2, SetValue(SetValue(St, B, Result), L1, Result)); |
| 1292 | break; |
| 1293 | } |
Ted Kremenek | 687af80 | 2008-01-29 19:43:15 +0000 | [diff] [blame] | 1294 | |
| 1295 | // Equality operators. |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 1296 | |
Ted Kremenek | 687af80 | 2008-01-29 19:43:15 +0000 | [diff] [blame] | 1297 | case BinaryOperator::EQ: |
| 1298 | // FIXME: should we allow XX.EQ() to return a set of values, |
| 1299 | // allowing state bifurcation? In such cases, they will also |
| 1300 | // modify the state (meaning that a new state will be returned |
| 1301 | // as well). |
| 1302 | assert (B->getType() == getContext().IntTy); |
| 1303 | |
| 1304 | if (isa<LValue>(V1)) { |
| 1305 | const LValue& L1 = cast<LValue>(V1); |
| 1306 | const LValue& L2 = cast<LValue>(V2); |
| 1307 | St = SetValue(St, B, L1.EQ(ValMgr, L2)); |
| 1308 | } |
| 1309 | else { |
| 1310 | const NonLValue& R1 = cast<NonLValue>(V1); |
| 1311 | const NonLValue& R2 = cast<NonLValue>(V2); |
| 1312 | St = SetValue(St, B, R1.EQ(ValMgr, R2)); |
| 1313 | } |
| 1314 | |
| 1315 | Nodify(Dst, B, N2, St); |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 1316 | break; |
| 1317 | } |
Ted Kremenek | cb448ca | 2008-01-16 00:53:15 +0000 | [diff] [blame] | 1318 | } |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 1319 | } |
Ted Kremenek | d27f816 | 2008-01-15 23:55:06 +0000 | [diff] [blame] | 1320 | } |
Ted Kremenek | ee98546 | 2008-01-16 18:18:48 +0000 | [diff] [blame] | 1321 | |
Ted Kremenek | 1ccd31c | 2008-01-16 19:42:59 +0000 | [diff] [blame] | 1322 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 1323 | void GRConstants::Visit(Stmt* S, GRConstants::NodeTy* Pred, |
| 1324 | GRConstants::NodeSet& Dst) { |
| 1325 | |
| 1326 | // FIXME: add metadata to the CFG so that we can disable |
| 1327 | // this check when we KNOW that there is no block-level subexpression. |
| 1328 | // The motivation is that this check requires a hashtable lookup. |
| 1329 | |
| 1330 | if (S != CurrentStmt && getCFG().isBlkExpr(S)) { |
| 1331 | Dst.Add(Pred); |
| 1332 | return; |
| 1333 | } |
| 1334 | |
| 1335 | switch (S->getStmtClass()) { |
| 1336 | case Stmt::BinaryOperatorClass: |
Ted Kremenek | b4ae33f | 2008-01-23 23:38:00 +0000 | [diff] [blame] | 1337 | case Stmt::CompoundAssignOperatorClass: |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 1338 | VisitBinaryOperator(cast<BinaryOperator>(S), Pred, Dst); |
| 1339 | break; |
| 1340 | |
Ted Kremenek | 7b8009a | 2008-01-24 02:28:56 +0000 | [diff] [blame] | 1341 | case Stmt::UnaryOperatorClass: |
| 1342 | VisitUnaryOperator(cast<UnaryOperator>(S), Pred, Dst); |
| 1343 | break; |
| 1344 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 1345 | case Stmt::ParenExprClass: |
| 1346 | Visit(cast<ParenExpr>(S)->getSubExpr(), Pred, Dst); |
| 1347 | break; |
| 1348 | |
Ted Kremenek | 874d63f | 2008-01-24 02:02:54 +0000 | [diff] [blame] | 1349 | case Stmt::ImplicitCastExprClass: { |
| 1350 | ImplicitCastExpr* C = cast<ImplicitCastExpr>(S); |
| 1351 | VisitCast(C, C->getSubExpr(), Pred, Dst); |
| 1352 | break; |
| 1353 | } |
| 1354 | |
| 1355 | case Stmt::CastExprClass: { |
| 1356 | CastExpr* C = cast<CastExpr>(S); |
| 1357 | VisitCast(C, C->getSubExpr(), Pred, Dst); |
| 1358 | break; |
| 1359 | } |
| 1360 | |
Ted Kremenek | 9de04c4 | 2008-01-24 20:55:43 +0000 | [diff] [blame] | 1361 | case Stmt::DeclStmtClass: |
| 1362 | VisitDeclStmt(cast<DeclStmt>(S), Pred, Dst); |
| 1363 | break; |
| 1364 | |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 1365 | default: |
| 1366 | Dst.Add(Pred); // No-op. Simply propagate the current state unchanged. |
| 1367 | break; |
Ted Kremenek | 79649df | 2008-01-17 18:25:22 +0000 | [diff] [blame] | 1368 | } |
Ted Kremenek | 1ccd31c | 2008-01-16 19:42:59 +0000 | [diff] [blame] | 1369 | } |
| 1370 | |
Ted Kremenek | ee98546 | 2008-01-16 18:18:48 +0000 | [diff] [blame] | 1371 | //===----------------------------------------------------------------------===// |
| 1372 | // Driver. |
| 1373 | //===----------------------------------------------------------------------===// |
| 1374 | |
Ted Kremenek | aa66a32 | 2008-01-16 21:46:15 +0000 | [diff] [blame] | 1375 | #ifndef NDEBUG |
| 1376 | namespace llvm { |
| 1377 | template<> |
| 1378 | struct VISIBILITY_HIDDEN DOTGraphTraits<GRConstants::NodeTy*> : |
| 1379 | public DefaultDOTGraphTraits { |
Ted Kremenek | 9ff731d | 2008-01-24 22:27:20 +0000 | [diff] [blame] | 1380 | |
| 1381 | static void PrintKindLabel(std::ostream& Out, ValueKey::Kind kind) { |
Ted Kremenek | 803c9ed | 2008-01-23 22:30:44 +0000 | [diff] [blame] | 1382 | switch (kind) { |
Ted Kremenek | 565256e | 2008-01-24 22:44:24 +0000 | [diff] [blame] | 1383 | case ValueKey::IsSubExpr: Out << "Sub-Expressions:\\l"; break; |
Ted Kremenek | 803c9ed | 2008-01-23 22:30:44 +0000 | [diff] [blame] | 1384 | case ValueKey::IsDecl: Out << "Variables:\\l"; break; |
| 1385 | case ValueKey::IsBlkExpr: Out << "Block-level Expressions:\\l"; break; |
| 1386 | default: assert (false && "Unknown ValueKey type."); |
| 1387 | } |
| 1388 | } |
| 1389 | |
Ted Kremenek | 9ff731d | 2008-01-24 22:27:20 +0000 | [diff] [blame] | 1390 | static void PrintKind(std::ostream& Out, GRConstants::StateTy M, |
| 1391 | ValueKey::Kind kind, bool isFirstGroup = false) { |
| 1392 | bool isFirst = true; |
| 1393 | |
| 1394 | for (GRConstants::StateTy::iterator I=M.begin(), E=M.end();I!=E;++I) { |
| 1395 | if (I.getKey().getKind() != kind) |
| 1396 | continue; |
| 1397 | |
| 1398 | if (isFirst) { |
| 1399 | if (!isFirstGroup) Out << "\\l\\l"; |
| 1400 | PrintKindLabel(Out, kind); |
| 1401 | isFirst = false; |
| 1402 | } |
| 1403 | else |
| 1404 | Out << "\\l"; |
| 1405 | |
| 1406 | Out << ' '; |
| 1407 | |
| 1408 | if (ValueDecl* V = dyn_cast<ValueDecl>(I.getKey())) |
| 1409 | Out << V->getName(); |
| 1410 | else { |
| 1411 | Stmt* E = cast<Stmt>(I.getKey()); |
| 1412 | Out << " (" << (void*) E << ") "; |
| 1413 | E->printPretty(Out); |
| 1414 | } |
| 1415 | |
| 1416 | Out << " : "; |
| 1417 | I.getData().print(Out); |
| 1418 | } |
| 1419 | } |
| 1420 | |
Ted Kremenek | aa66a32 | 2008-01-16 21:46:15 +0000 | [diff] [blame] | 1421 | static std::string getNodeLabel(const GRConstants::NodeTy* N, void*) { |
| 1422 | std::ostringstream Out; |
Ted Kremenek | 803c9ed | 2008-01-23 22:30:44 +0000 | [diff] [blame] | 1423 | |
| 1424 | // Program Location. |
Ted Kremenek | aa66a32 | 2008-01-16 21:46:15 +0000 | [diff] [blame] | 1425 | ProgramPoint Loc = N->getLocation(); |
| 1426 | |
| 1427 | switch (Loc.getKind()) { |
| 1428 | case ProgramPoint::BlockEntranceKind: |
| 1429 | Out << "Block Entrance: B" |
| 1430 | << cast<BlockEntrance>(Loc).getBlock()->getBlockID(); |
| 1431 | break; |
| 1432 | |
| 1433 | case ProgramPoint::BlockExitKind: |
| 1434 | assert (false); |
| 1435 | break; |
| 1436 | |
| 1437 | case ProgramPoint::PostStmtKind: { |
| 1438 | const PostStmt& L = cast<PostStmt>(Loc); |
Ted Kremenek | 9ff731d | 2008-01-24 22:27:20 +0000 | [diff] [blame] | 1439 | Out << L.getStmt()->getStmtClassName() << ':' |
| 1440 | << (void*) L.getStmt() << ' '; |
| 1441 | |
Ted Kremenek | aa66a32 | 2008-01-16 21:46:15 +0000 | [diff] [blame] | 1442 | L.getStmt()->printPretty(Out); |
| 1443 | break; |
| 1444 | } |
| 1445 | |
| 1446 | default: { |
| 1447 | const BlockEdge& E = cast<BlockEdge>(Loc); |
| 1448 | Out << "Edge: (B" << E.getSrc()->getBlockID() << ", B" |
| 1449 | << E.getDst()->getBlockID() << ')'; |
| 1450 | } |
| 1451 | } |
| 1452 | |
Ted Kremenek | 803c9ed | 2008-01-23 22:30:44 +0000 | [diff] [blame] | 1453 | Out << "\\|"; |
Ted Kremenek | aa66a32 | 2008-01-16 21:46:15 +0000 | [diff] [blame] | 1454 | |
Ted Kremenek | 9ff731d | 2008-01-24 22:27:20 +0000 | [diff] [blame] | 1455 | PrintKind(Out, N->getState(), ValueKey::IsDecl, true); |
| 1456 | PrintKind(Out, N->getState(), ValueKey::IsBlkExpr); |
Ted Kremenek | 565256e | 2008-01-24 22:44:24 +0000 | [diff] [blame] | 1457 | PrintKind(Out, N->getState(), ValueKey::IsSubExpr); |
Ted Kremenek | 803c9ed | 2008-01-23 22:30:44 +0000 | [diff] [blame] | 1458 | |
Ted Kremenek | 803c9ed | 2008-01-23 22:30:44 +0000 | [diff] [blame] | 1459 | Out << "\\l"; |
Ted Kremenek | aa66a32 | 2008-01-16 21:46:15 +0000 | [diff] [blame] | 1460 | return Out.str(); |
| 1461 | } |
| 1462 | }; |
| 1463 | } // end llvm namespace |
| 1464 | #endif |
| 1465 | |
Ted Kremenek | ee98546 | 2008-01-16 18:18:48 +0000 | [diff] [blame] | 1466 | namespace clang { |
Ted Kremenek | cb48b9c | 2008-01-29 00:33:40 +0000 | [diff] [blame] | 1467 | void RunGRConstants(CFG& cfg, FunctionDecl& FD, ASTContext& Ctx) { |
| 1468 | GREngine<GRConstants> Engine(cfg, FD, Ctx); |
Ted Kremenek | ee98546 | 2008-01-16 18:18:48 +0000 | [diff] [blame] | 1469 | Engine.ExecuteWorkList(); |
Ted Kremenek | aa66a32 | 2008-01-16 21:46:15 +0000 | [diff] [blame] | 1470 | #ifndef NDEBUG |
| 1471 | llvm::ViewGraph(*Engine.getGraph().roots_begin(),"GRConstants"); |
| 1472 | #endif |
Ted Kremenek | ee98546 | 2008-01-16 18:18:48 +0000 | [diff] [blame] | 1473 | } |
Ted Kremenek | ab2b8c5 | 2008-01-23 19:59:44 +0000 | [diff] [blame] | 1474 | } // end clang namespace |