Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 1 | //== MemRegion.cpp - Abstract memory regions for static analysis --*- C++ -*--// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file defines MemRegion and its subclasses. MemRegion defines a |
| 11 | // partially-typed abstraction of memory useful for path-sensitive dataflow |
| 12 | // analyses. |
| 13 | // |
| 14 | //===----------------------------------------------------------------------===// |
| 15 | |
Ted Kremenek | 1309f9a | 2010-01-25 04:41:41 +0000 | [diff] [blame] | 16 | #include "clang/Checker/PathSensitive/MemRegion.h" |
Jordy Rose | 32f2656 | 2010-07-04 00:00:41 +0000 | [diff] [blame] | 17 | #include "clang/Checker/PathSensitive/ValueManager.h" |
Benjamin Kramer | 5e2d2c2 | 2010-03-27 21:19:47 +0000 | [diff] [blame] | 18 | #include "clang/Analysis/AnalysisContext.h" |
| 19 | #include "clang/Analysis/Support/BumpVector.h" |
Ken Dyck | 199c3d6 | 2010-01-11 17:06:35 +0000 | [diff] [blame] | 20 | #include "clang/AST/CharUnits.h" |
Ted Kremenek | 1309f9a | 2010-01-25 04:41:41 +0000 | [diff] [blame] | 21 | #include "llvm/Support/raw_ostream.h" |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 22 | |
| 23 | using namespace clang; |
| 24 | |
Ted Kremenek | 2501013 | 2009-06-22 23:13:13 +0000 | [diff] [blame] | 25 | //===----------------------------------------------------------------------===// |
Ted Kremenek | bcd7f9f | 2009-12-04 00:05:57 +0000 | [diff] [blame] | 26 | // MemRegion Construction. |
| 27 | //===----------------------------------------------------------------------===// |
| 28 | |
| 29 | template<typename RegionTy> struct MemRegionManagerTrait; |
| 30 | |
| 31 | template <typename RegionTy, typename A1> |
| 32 | RegionTy* MemRegionManager::getRegion(const A1 a1) { |
Ted Kremenek | dcee3ce | 2010-07-01 20:16:50 +0000 | [diff] [blame] | 33 | |
Ted Kremenek | bcd7f9f | 2009-12-04 00:05:57 +0000 | [diff] [blame] | 34 | const typename MemRegionManagerTrait<RegionTy>::SuperRegionTy *superRegion = |
| 35 | MemRegionManagerTrait<RegionTy>::getSuperRegion(*this, a1); |
Ted Kremenek | dcee3ce | 2010-07-01 20:16:50 +0000 | [diff] [blame] | 36 | |
Ted Kremenek | bcd7f9f | 2009-12-04 00:05:57 +0000 | [diff] [blame] | 37 | llvm::FoldingSetNodeID ID; |
| 38 | RegionTy::ProfileRegion(ID, a1, superRegion); |
| 39 | void* InsertPos; |
| 40 | RegionTy* R = cast_or_null<RegionTy>(Regions.FindNodeOrInsertPos(ID, |
| 41 | InsertPos)); |
Ted Kremenek | dcee3ce | 2010-07-01 20:16:50 +0000 | [diff] [blame] | 42 | |
Ted Kremenek | bcd7f9f | 2009-12-04 00:05:57 +0000 | [diff] [blame] | 43 | if (!R) { |
| 44 | R = (RegionTy*) A.Allocate<RegionTy>(); |
| 45 | new (R) RegionTy(a1, superRegion); |
| 46 | Regions.InsertNode(R, InsertPos); |
| 47 | } |
Ted Kremenek | dcee3ce | 2010-07-01 20:16:50 +0000 | [diff] [blame] | 48 | |
Ted Kremenek | bcd7f9f | 2009-12-04 00:05:57 +0000 | [diff] [blame] | 49 | return R; |
| 50 | } |
| 51 | |
| 52 | template <typename RegionTy, typename A1> |
| 53 | RegionTy* MemRegionManager::getSubRegion(const A1 a1, |
| 54 | const MemRegion *superRegion) { |
| 55 | llvm::FoldingSetNodeID ID; |
| 56 | RegionTy::ProfileRegion(ID, a1, superRegion); |
| 57 | void* InsertPos; |
| 58 | RegionTy* R = cast_or_null<RegionTy>(Regions.FindNodeOrInsertPos(ID, |
| 59 | InsertPos)); |
Ted Kremenek | dcee3ce | 2010-07-01 20:16:50 +0000 | [diff] [blame] | 60 | |
Ted Kremenek | bcd7f9f | 2009-12-04 00:05:57 +0000 | [diff] [blame] | 61 | if (!R) { |
| 62 | R = (RegionTy*) A.Allocate<RegionTy>(); |
| 63 | new (R) RegionTy(a1, superRegion); |
| 64 | Regions.InsertNode(R, InsertPos); |
| 65 | } |
Ted Kremenek | dcee3ce | 2010-07-01 20:16:50 +0000 | [diff] [blame] | 66 | |
Ted Kremenek | bcd7f9f | 2009-12-04 00:05:57 +0000 | [diff] [blame] | 67 | return R; |
| 68 | } |
| 69 | |
| 70 | template <typename RegionTy, typename A1, typename A2> |
| 71 | RegionTy* MemRegionManager::getRegion(const A1 a1, const A2 a2) { |
Ted Kremenek | dcee3ce | 2010-07-01 20:16:50 +0000 | [diff] [blame] | 72 | |
Ted Kremenek | bcd7f9f | 2009-12-04 00:05:57 +0000 | [diff] [blame] | 73 | const typename MemRegionManagerTrait<RegionTy>::SuperRegionTy *superRegion = |
| 74 | MemRegionManagerTrait<RegionTy>::getSuperRegion(*this, a1, a2); |
Ted Kremenek | dcee3ce | 2010-07-01 20:16:50 +0000 | [diff] [blame] | 75 | |
Ted Kremenek | bcd7f9f | 2009-12-04 00:05:57 +0000 | [diff] [blame] | 76 | llvm::FoldingSetNodeID ID; |
| 77 | RegionTy::ProfileRegion(ID, a1, a2, superRegion); |
| 78 | void* InsertPos; |
| 79 | RegionTy* R = cast_or_null<RegionTy>(Regions.FindNodeOrInsertPos(ID, |
| 80 | InsertPos)); |
Ted Kremenek | dcee3ce | 2010-07-01 20:16:50 +0000 | [diff] [blame] | 81 | |
Ted Kremenek | bcd7f9f | 2009-12-04 00:05:57 +0000 | [diff] [blame] | 82 | if (!R) { |
| 83 | R = (RegionTy*) A.Allocate<RegionTy>(); |
| 84 | new (R) RegionTy(a1, a2, superRegion); |
| 85 | Regions.InsertNode(R, InsertPos); |
| 86 | } |
Ted Kremenek | dcee3ce | 2010-07-01 20:16:50 +0000 | [diff] [blame] | 87 | |
Ted Kremenek | bcd7f9f | 2009-12-04 00:05:57 +0000 | [diff] [blame] | 88 | return R; |
| 89 | } |
| 90 | |
| 91 | template <typename RegionTy, typename A1, typename A2> |
| 92 | RegionTy* MemRegionManager::getSubRegion(const A1 a1, const A2 a2, |
| 93 | const MemRegion *superRegion) { |
Ted Kremenek | dcee3ce | 2010-07-01 20:16:50 +0000 | [diff] [blame] | 94 | |
Ted Kremenek | bcd7f9f | 2009-12-04 00:05:57 +0000 | [diff] [blame] | 95 | llvm::FoldingSetNodeID ID; |
| 96 | RegionTy::ProfileRegion(ID, a1, a2, superRegion); |
| 97 | void* InsertPos; |
| 98 | RegionTy* R = cast_or_null<RegionTy>(Regions.FindNodeOrInsertPos(ID, |
| 99 | InsertPos)); |
Ted Kremenek | dcee3ce | 2010-07-01 20:16:50 +0000 | [diff] [blame] | 100 | |
Ted Kremenek | bcd7f9f | 2009-12-04 00:05:57 +0000 | [diff] [blame] | 101 | if (!R) { |
| 102 | R = (RegionTy*) A.Allocate<RegionTy>(); |
| 103 | new (R) RegionTy(a1, a2, superRegion); |
| 104 | Regions.InsertNode(R, InsertPos); |
| 105 | } |
Ted Kremenek | dcee3ce | 2010-07-01 20:16:50 +0000 | [diff] [blame] | 106 | |
Ted Kremenek | bcd7f9f | 2009-12-04 00:05:57 +0000 | [diff] [blame] | 107 | return R; |
| 108 | } |
| 109 | |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 110 | template <typename RegionTy, typename A1, typename A2, typename A3> |
| 111 | RegionTy* MemRegionManager::getSubRegion(const A1 a1, const A2 a2, const A3 a3, |
| 112 | const MemRegion *superRegion) { |
Ted Kremenek | dcee3ce | 2010-07-01 20:16:50 +0000 | [diff] [blame] | 113 | |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 114 | llvm::FoldingSetNodeID ID; |
| 115 | RegionTy::ProfileRegion(ID, a1, a2, a3, superRegion); |
| 116 | void* InsertPos; |
| 117 | RegionTy* R = cast_or_null<RegionTy>(Regions.FindNodeOrInsertPos(ID, |
| 118 | InsertPos)); |
Ted Kremenek | dcee3ce | 2010-07-01 20:16:50 +0000 | [diff] [blame] | 119 | |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 120 | if (!R) { |
| 121 | R = (RegionTy*) A.Allocate<RegionTy>(); |
| 122 | new (R) RegionTy(a1, a2, a3, superRegion); |
| 123 | Regions.InsertNode(R, InsertPos); |
Ted Kremenek | bcd7f9f | 2009-12-04 00:05:57 +0000 | [diff] [blame] | 124 | } |
Ted Kremenek | dcee3ce | 2010-07-01 20:16:50 +0000 | [diff] [blame] | 125 | |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 126 | return R; |
| 127 | } |
Ted Kremenek | bcd7f9f | 2009-12-04 00:05:57 +0000 | [diff] [blame] | 128 | |
| 129 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 4240096 | 2009-11-26 02:34:36 +0000 | [diff] [blame] | 130 | // Object destruction. |
Ted Kremenek | 2501013 | 2009-06-22 23:13:13 +0000 | [diff] [blame] | 131 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 132 | |
| 133 | MemRegion::~MemRegion() {} |
| 134 | |
Ted Kremenek | 4240096 | 2009-11-26 02:34:36 +0000 | [diff] [blame] | 135 | MemRegionManager::~MemRegionManager() { |
| 136 | // All regions and their data are BumpPtrAllocated. No need to call |
| 137 | // their destructors. |
| 138 | } |
| 139 | |
| 140 | //===----------------------------------------------------------------------===// |
| 141 | // Basic methods. |
| 142 | //===----------------------------------------------------------------------===// |
| 143 | |
Zhongxing Xu | 7e5d6ed | 2009-01-08 13:17:14 +0000 | [diff] [blame] | 144 | bool SubRegion::isSubRegionOf(const MemRegion* R) const { |
| 145 | const MemRegion* r = getSuperRegion(); |
| 146 | while (r != 0) { |
| 147 | if (r == R) |
| 148 | return true; |
| 149 | if (const SubRegion* sr = dyn_cast<SubRegion>(r)) |
| 150 | r = sr->getSuperRegion(); |
| 151 | else |
| 152 | break; |
| 153 | } |
| 154 | return false; |
| 155 | } |
| 156 | |
Ted Kremenek | a43484a | 2009-06-23 00:46:41 +0000 | [diff] [blame] | 157 | MemRegionManager* SubRegion::getMemRegionManager() const { |
| 158 | const SubRegion* r = this; |
| 159 | do { |
| 160 | const MemRegion *superRegion = r->getSuperRegion(); |
| 161 | if (const SubRegion *sr = dyn_cast<SubRegion>(superRegion)) { |
| 162 | r = sr; |
| 163 | continue; |
| 164 | } |
| 165 | return superRegion->getMemRegionManager(); |
| 166 | } while (1); |
| 167 | } |
| 168 | |
Ted Kremenek | 5348f94 | 2009-12-14 22:15:06 +0000 | [diff] [blame] | 169 | const StackFrameContext *VarRegion::getStackFrame() const { |
| 170 | const StackSpaceRegion *SSR = dyn_cast<StackSpaceRegion>(getMemorySpace()); |
| 171 | return SSR ? SSR->getStackFrame() : NULL; |
| 172 | } |
| 173 | |
| 174 | //===----------------------------------------------------------------------===// |
Jordy Rose | 32f2656 | 2010-07-04 00:00:41 +0000 | [diff] [blame] | 175 | // Region extents. |
| 176 | //===----------------------------------------------------------------------===// |
| 177 | |
| 178 | DefinedOrUnknownSVal DeclRegion::getExtent(ValueManager& ValMgr) const { |
| 179 | ASTContext& Ctx = ValMgr.getContext(); |
| 180 | QualType T = getDesugaredValueType(Ctx); |
| 181 | |
Jordy Rose | 52e04c5 | 2010-07-05 00:50:15 +0000 | [diff] [blame] | 182 | if (isa<VariableArrayType>(T)) |
| 183 | return nonloc::SymbolVal(ValMgr.getSymbolManager().getExtentSymbol(this)); |
| 184 | if (isa<IncompleteArrayType>(T)) |
Jordy Rose | 32f2656 | 2010-07-04 00:00:41 +0000 | [diff] [blame] | 185 | return UnknownVal(); |
| 186 | |
| 187 | CharUnits Size = Ctx.getTypeSizeInChars(T); |
| 188 | QualType SizeTy = Ctx.getSizeType(); |
| 189 | return ValMgr.makeIntVal(Size.getQuantity(), SizeTy); |
| 190 | } |
| 191 | |
| 192 | DefinedOrUnknownSVal FieldRegion::getExtent(ValueManager& ValMgr) const { |
| 193 | DefinedOrUnknownSVal Extent = DeclRegion::getExtent(ValMgr); |
| 194 | |
| 195 | // A zero-length array at the end of a struct often stands for dynamically- |
| 196 | // allocated extra memory. |
| 197 | if (Extent.isZeroConstant()) { |
| 198 | ASTContext& Ctx = ValMgr.getContext(); |
| 199 | QualType T = getDesugaredValueType(Ctx); |
| 200 | |
| 201 | if (isa<ConstantArrayType>(T)) |
| 202 | return UnknownVal(); |
| 203 | } |
| 204 | |
| 205 | return Extent; |
| 206 | } |
| 207 | |
| 208 | DefinedOrUnknownSVal AllocaRegion::getExtent(ValueManager& ValMgr) const { |
| 209 | return nonloc::SymbolVal(ValMgr.getSymbolManager().getExtentSymbol(this)); |
| 210 | } |
| 211 | |
| 212 | DefinedOrUnknownSVal SymbolicRegion::getExtent(ValueManager& ValMgr) const { |
| 213 | return nonloc::SymbolVal(ValMgr.getSymbolManager().getExtentSymbol(this)); |
| 214 | } |
| 215 | |
| 216 | DefinedOrUnknownSVal StringRegion::getExtent(ValueManager& ValMgr) const { |
| 217 | QualType SizeTy = ValMgr.getContext().getSizeType(); |
| 218 | return ValMgr.makeIntVal(getStringLiteral()->getByteLength()+1, SizeTy); |
| 219 | } |
| 220 | |
| 221 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 5348f94 | 2009-12-14 22:15:06 +0000 | [diff] [blame] | 222 | // FoldingSet profiling. |
| 223 | //===----------------------------------------------------------------------===// |
| 224 | |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 225 | void MemSpaceRegion::Profile(llvm::FoldingSetNodeID& ID) const { |
| 226 | ID.AddInteger((unsigned)getKind()); |
| 227 | } |
| 228 | |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 229 | void StackSpaceRegion::Profile(llvm::FoldingSetNodeID &ID) const { |
| 230 | ID.AddInteger((unsigned)getKind()); |
| 231 | ID.AddPointer(getStackFrame()); |
| 232 | } |
| 233 | |
Ted Kremenek | dcee3ce | 2010-07-01 20:16:50 +0000 | [diff] [blame] | 234 | void StaticGlobalSpaceRegion::Profile(llvm::FoldingSetNodeID &ID) const { |
| 235 | ID.AddInteger((unsigned)getKind()); |
| 236 | ID.AddPointer(getCodeRegion()); |
| 237 | } |
| 238 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 239 | void StringRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, |
| 240 | const StringLiteral* Str, |
Zhongxing Xu | e9f4e54 | 2008-10-25 14:13:41 +0000 | [diff] [blame] | 241 | const MemRegion* superRegion) { |
| 242 | ID.AddInteger((unsigned) StringRegionKind); |
| 243 | ID.AddPointer(Str); |
| 244 | ID.AddPointer(superRegion); |
| 245 | } |
| 246 | |
Ted Kremenek | 7090ae1 | 2008-11-02 00:34:33 +0000 | [diff] [blame] | 247 | void AllocaRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, |
Ted Kremenek | 7ae7ad9 | 2009-06-23 00:15:41 +0000 | [diff] [blame] | 248 | const Expr* Ex, unsigned cnt, |
| 249 | const MemRegion *) { |
Ted Kremenek | 7090ae1 | 2008-11-02 00:34:33 +0000 | [diff] [blame] | 250 | ID.AddInteger((unsigned) AllocaRegionKind); |
| 251 | ID.AddPointer(Ex); |
| 252 | ID.AddInteger(cnt); |
| 253 | } |
| 254 | |
| 255 | void AllocaRegion::Profile(llvm::FoldingSetNodeID& ID) const { |
Ted Kremenek | 7ae7ad9 | 2009-06-23 00:15:41 +0000 | [diff] [blame] | 256 | ProfileRegion(ID, Ex, Cnt, superRegion); |
Ted Kremenek | 7090ae1 | 2008-11-02 00:34:33 +0000 | [diff] [blame] | 257 | } |
| 258 | |
Ted Kremenek | 329d6fd | 2008-10-27 20:57:58 +0000 | [diff] [blame] | 259 | void CompoundLiteralRegion::Profile(llvm::FoldingSetNodeID& ID) const { |
| 260 | CompoundLiteralRegion::ProfileRegion(ID, CL, superRegion); |
| 261 | } |
| 262 | |
| 263 | void CompoundLiteralRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, |
| 264 | const CompoundLiteralExpr* CL, |
| 265 | const MemRegion* superRegion) { |
| 266 | ID.AddInteger((unsigned) CompoundLiteralRegionKind); |
| 267 | ID.AddPointer(CL); |
| 268 | ID.AddPointer(superRegion); |
| 269 | } |
| 270 | |
Ted Kremenek | de0d263 | 2010-01-05 02:18:06 +0000 | [diff] [blame] | 271 | void CXXThisRegion::ProfileRegion(llvm::FoldingSetNodeID &ID, |
| 272 | const PointerType *PT, |
| 273 | const MemRegion *sRegion) { |
| 274 | ID.AddInteger((unsigned) CXXThisRegionKind); |
| 275 | ID.AddPointer(PT); |
| 276 | ID.AddPointer(sRegion); |
| 277 | } |
| 278 | |
| 279 | void CXXThisRegion::Profile(llvm::FoldingSetNodeID &ID) const { |
| 280 | CXXThisRegion::ProfileRegion(ID, ThisPointerTy, superRegion); |
| 281 | } |
Ted Kremenek | dcee3ce | 2010-07-01 20:16:50 +0000 | [diff] [blame] | 282 | |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 283 | void DeclRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, const Decl* D, |
| 284 | const MemRegion* superRegion, Kind k) { |
| 285 | ID.AddInteger((unsigned) k); |
| 286 | ID.AddPointer(D); |
| 287 | ID.AddPointer(superRegion); |
| 288 | } |
| 289 | |
| 290 | void DeclRegion::Profile(llvm::FoldingSetNodeID& ID) const { |
| 291 | DeclRegion::ProfileRegion(ID, D, superRegion, getKind()); |
| 292 | } |
| 293 | |
Ted Kremenek | d17da2b | 2009-08-21 22:28:32 +0000 | [diff] [blame] | 294 | void VarRegion::Profile(llvm::FoldingSetNodeID &ID) const { |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 295 | VarRegion::ProfileRegion(ID, getDecl(), superRegion); |
Ted Kremenek | d17da2b | 2009-08-21 22:28:32 +0000 | [diff] [blame] | 296 | } |
| 297 | |
Ted Kremenek | 2501013 | 2009-06-22 23:13:13 +0000 | [diff] [blame] | 298 | void SymbolicRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, SymbolRef sym, |
| 299 | const MemRegion *sreg) { |
Ted Kremenek | 993f1c7 | 2008-10-17 20:28:54 +0000 | [diff] [blame] | 300 | ID.AddInteger((unsigned) MemRegion::SymbolicRegionKind); |
Ted Kremenek | 6d0e2d2 | 2008-12-05 02:39:38 +0000 | [diff] [blame] | 301 | ID.Add(sym); |
Ted Kremenek | 2501013 | 2009-06-22 23:13:13 +0000 | [diff] [blame] | 302 | ID.AddPointer(sreg); |
Ted Kremenek | 993f1c7 | 2008-10-17 20:28:54 +0000 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | void SymbolicRegion::Profile(llvm::FoldingSetNodeID& ID) const { |
Ted Kremenek | 2501013 | 2009-06-22 23:13:13 +0000 | [diff] [blame] | 306 | SymbolicRegion::ProfileRegion(ID, sym, getSuperRegion()); |
Ted Kremenek | 993f1c7 | 2008-10-17 20:28:54 +0000 | [diff] [blame] | 307 | } |
| 308 | |
Ted Kremenek | f936f45 | 2009-05-04 06:18:28 +0000 | [diff] [blame] | 309 | void ElementRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 310 | QualType ElementType, SVal Idx, |
Zhongxing Xu | 511191c | 2008-10-21 05:27:10 +0000 | [diff] [blame] | 311 | const MemRegion* superRegion) { |
| 312 | ID.AddInteger(MemRegion::ElementRegionKind); |
Ted Kremenek | f936f45 | 2009-05-04 06:18:28 +0000 | [diff] [blame] | 313 | ID.Add(ElementType); |
Zhongxing Xu | 511191c | 2008-10-21 05:27:10 +0000 | [diff] [blame] | 314 | ID.AddPointer(superRegion); |
| 315 | Idx.Profile(ID); |
| 316 | } |
| 317 | |
| 318 | void ElementRegion::Profile(llvm::FoldingSetNodeID& ID) const { |
Ted Kremenek | f936f45 | 2009-05-04 06:18:28 +0000 | [diff] [blame] | 319 | ElementRegion::ProfileRegion(ID, ElementType, Index, superRegion); |
Zhongxing Xu | 511191c | 2008-10-21 05:27:10 +0000 | [diff] [blame] | 320 | } |
Zhongxing Xu | 27b5706 | 2008-10-27 13:17:02 +0000 | [diff] [blame] | 321 | |
Ted Kremenek | eb1c7a0 | 2009-11-25 01:32:22 +0000 | [diff] [blame] | 322 | void FunctionTextRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, |
| 323 | const FunctionDecl *FD, |
| 324 | const MemRegion*) { |
| 325 | ID.AddInteger(MemRegion::FunctionTextRegionKind); |
Ted Kremenek | abd46e1 | 2009-08-28 04:49:15 +0000 | [diff] [blame] | 326 | ID.AddPointer(FD); |
Zhongxing Xu | ec13d92 | 2009-04-10 08:45:10 +0000 | [diff] [blame] | 327 | } |
| 328 | |
Ted Kremenek | eb1c7a0 | 2009-11-25 01:32:22 +0000 | [diff] [blame] | 329 | void FunctionTextRegion::Profile(llvm::FoldingSetNodeID& ID) const { |
| 330 | FunctionTextRegion::ProfileRegion(ID, FD, superRegion); |
| 331 | } |
| 332 | |
| 333 | void BlockTextRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 334 | const BlockDecl *BD, CanQualType, |
| 335 | const AnalysisContext *AC, |
| 336 | const MemRegion*) { |
Ted Kremenek | eb1c7a0 | 2009-11-25 01:32:22 +0000 | [diff] [blame] | 337 | ID.AddInteger(MemRegion::BlockTextRegionKind); |
| 338 | ID.AddPointer(BD); |
| 339 | } |
| 340 | |
| 341 | void BlockTextRegion::Profile(llvm::FoldingSetNodeID& ID) const { |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 342 | BlockTextRegion::ProfileRegion(ID, BD, locTy, AC, superRegion); |
Zhongxing Xu | ec13d92 | 2009-04-10 08:45:10 +0000 | [diff] [blame] | 343 | } |
| 344 | |
Ted Kremenek | 0a8112a | 2009-11-25 23:53:07 +0000 | [diff] [blame] | 345 | void BlockDataRegion::ProfileRegion(llvm::FoldingSetNodeID& ID, |
| 346 | const BlockTextRegion *BC, |
| 347 | const LocationContext *LC, |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 348 | const MemRegion *sReg) { |
Ted Kremenek | 0a8112a | 2009-11-25 23:53:07 +0000 | [diff] [blame] | 349 | ID.AddInteger(MemRegion::BlockDataRegionKind); |
| 350 | ID.AddPointer(BC); |
| 351 | ID.AddPointer(LC); |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 352 | ID.AddPointer(sReg); |
Ted Kremenek | 0a8112a | 2009-11-25 23:53:07 +0000 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | void BlockDataRegion::Profile(llvm::FoldingSetNodeID& ID) const { |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 356 | BlockDataRegion::ProfileRegion(ID, BC, LC, getSuperRegion()); |
Ted Kremenek | 0a8112a | 2009-11-25 23:53:07 +0000 | [diff] [blame] | 357 | } |
| 358 | |
Zhongxing Xu | bb14121 | 2009-12-16 11:27:52 +0000 | [diff] [blame] | 359 | void CXXObjectRegion::ProfileRegion(llvm::FoldingSetNodeID &ID, |
Zhongxing Xu | bc37b8d | 2010-01-09 09:16:47 +0000 | [diff] [blame] | 360 | Expr const *Ex, |
Zhongxing Xu | bb14121 | 2009-12-16 11:27:52 +0000 | [diff] [blame] | 361 | const MemRegion *sReg) { |
Zhongxing Xu | bc37b8d | 2010-01-09 09:16:47 +0000 | [diff] [blame] | 362 | ID.AddPointer(Ex); |
Zhongxing Xu | bb14121 | 2009-12-16 11:27:52 +0000 | [diff] [blame] | 363 | ID.AddPointer(sReg); |
| 364 | } |
| 365 | |
| 366 | void CXXObjectRegion::Profile(llvm::FoldingSetNodeID &ID) const { |
Zhongxing Xu | bc37b8d | 2010-01-09 09:16:47 +0000 | [diff] [blame] | 367 | ProfileRegion(ID, Ex, getSuperRegion()); |
Zhongxing Xu | bb14121 | 2009-12-16 11:27:52 +0000 | [diff] [blame] | 368 | } |
| 369 | |
Zhongxing Xu | 026c663 | 2009-02-05 06:57:29 +0000 | [diff] [blame] | 370 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 371 | // Region pretty-printing. |
| 372 | //===----------------------------------------------------------------------===// |
| 373 | |
Ted Kremenek | 8800ad4 | 2009-07-13 23:31:04 +0000 | [diff] [blame] | 374 | void MemRegion::dump() const { |
| 375 | dumpToStream(llvm::errs()); |
Ted Kremenek | 7f39d29 | 2009-07-02 17:24:10 +0000 | [diff] [blame] | 376 | } |
| 377 | |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 378 | std::string MemRegion::getString() const { |
| 379 | std::string s; |
| 380 | llvm::raw_string_ostream os(s); |
Ted Kremenek | 8800ad4 | 2009-07-13 23:31:04 +0000 | [diff] [blame] | 381 | dumpToStream(os); |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 382 | return os.str(); |
| 383 | } |
| 384 | |
Ted Kremenek | 8800ad4 | 2009-07-13 23:31:04 +0000 | [diff] [blame] | 385 | void MemRegion::dumpToStream(llvm::raw_ostream& os) const { |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 386 | os << "<Unknown Region>"; |
| 387 | } |
| 388 | |
Ted Kremenek | 8800ad4 | 2009-07-13 23:31:04 +0000 | [diff] [blame] | 389 | void AllocaRegion::dumpToStream(llvm::raw_ostream& os) const { |
Ted Kremenek | 7090ae1 | 2008-11-02 00:34:33 +0000 | [diff] [blame] | 390 | os << "alloca{" << (void*) Ex << ',' << Cnt << '}'; |
| 391 | } |
| 392 | |
Ted Kremenek | eb1c7a0 | 2009-11-25 01:32:22 +0000 | [diff] [blame] | 393 | void FunctionTextRegion::dumpToStream(llvm::raw_ostream& os) const { |
Ted Kremenek | abd46e1 | 2009-08-28 04:49:15 +0000 | [diff] [blame] | 394 | os << "code{" << getDecl()->getDeclName().getAsString() << '}'; |
Ted Kremenek | 72e0320 | 2009-04-21 19:56:58 +0000 | [diff] [blame] | 395 | } |
| 396 | |
Ted Kremenek | eb1c7a0 | 2009-11-25 01:32:22 +0000 | [diff] [blame] | 397 | void BlockTextRegion::dumpToStream(llvm::raw_ostream& os) const { |
Ted Kremenek | 0a8112a | 2009-11-25 23:53:07 +0000 | [diff] [blame] | 398 | os << "block_code{" << (void*) this << '}'; |
Ted Kremenek | eb1c7a0 | 2009-11-25 01:32:22 +0000 | [diff] [blame] | 399 | } |
| 400 | |
Ted Kremenek | 0a8112a | 2009-11-25 23:53:07 +0000 | [diff] [blame] | 401 | void BlockDataRegion::dumpToStream(llvm::raw_ostream& os) const { |
| 402 | os << "block_data{" << BC << '}'; |
| 403 | } |
| 404 | |
Ted Kremenek | 8800ad4 | 2009-07-13 23:31:04 +0000 | [diff] [blame] | 405 | void CompoundLiteralRegion::dumpToStream(llvm::raw_ostream& os) const { |
Ted Kremenek | 5639a3e | 2009-04-21 18:09:22 +0000 | [diff] [blame] | 406 | // FIXME: More elaborate pretty-printing. |
| 407 | os << "{ " << (void*) CL << " }"; |
| 408 | } |
| 409 | |
Ted Kremenek | de0d263 | 2010-01-05 02:18:06 +0000 | [diff] [blame] | 410 | void CXXThisRegion::dumpToStream(llvm::raw_ostream &os) const { |
| 411 | os << "this"; |
| 412 | } |
| 413 | |
Ted Kremenek | 8800ad4 | 2009-07-13 23:31:04 +0000 | [diff] [blame] | 414 | void ElementRegion::dumpToStream(llvm::raw_ostream& os) const { |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 415 | os << "element{" << superRegion << ',' |
| 416 | << Index << ',' << getElementType().getAsString() << '}'; |
Ted Kremenek | 5639a3e | 2009-04-21 18:09:22 +0000 | [diff] [blame] | 417 | } |
| 418 | |
Ted Kremenek | 8800ad4 | 2009-07-13 23:31:04 +0000 | [diff] [blame] | 419 | void FieldRegion::dumpToStream(llvm::raw_ostream& os) const { |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 420 | os << superRegion << "->" << getDecl(); |
Ted Kremenek | 5639a3e | 2009-04-21 18:09:22 +0000 | [diff] [blame] | 421 | } |
| 422 | |
Ted Kremenek | fa87d81 | 2010-07-06 23:37:21 +0000 | [diff] [blame] | 423 | void NonStaticGlobalSpaceRegion::dumpToStream(llvm::raw_ostream &os) const { |
| 424 | os << "NonStaticGlobalSpaceRegion"; |
| 425 | } |
| 426 | |
Ted Kremenek | bcfe03a | 2009-07-19 20:36:24 +0000 | [diff] [blame] | 427 | void ObjCIvarRegion::dumpToStream(llvm::raw_ostream& os) const { |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 428 | os << "ivar{" << superRegion << ',' << getDecl() << '}'; |
Ted Kremenek | bcfe03a | 2009-07-19 20:36:24 +0000 | [diff] [blame] | 429 | } |
| 430 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 431 | void StringRegion::dumpToStream(llvm::raw_ostream& os) const { |
Ted Kremenek | b27ed3d | 2009-07-19 20:38:24 +0000 | [diff] [blame] | 432 | Str->printPretty(os, 0, PrintingPolicy(getContext().getLangOptions())); |
Ted Kremenek | 5639a3e | 2009-04-21 18:09:22 +0000 | [diff] [blame] | 433 | } |
| 434 | |
Ted Kremenek | 8800ad4 | 2009-07-13 23:31:04 +0000 | [diff] [blame] | 435 | void SymbolicRegion::dumpToStream(llvm::raw_ostream& os) const { |
Ted Kremenek | aef5d22 | 2009-07-13 23:38:57 +0000 | [diff] [blame] | 436 | os << "SymRegion{" << sym << '}'; |
Ted Kremenek | 5639a3e | 2009-04-21 18:09:22 +0000 | [diff] [blame] | 437 | } |
| 438 | |
Ted Kremenek | 8800ad4 | 2009-07-13 23:31:04 +0000 | [diff] [blame] | 439 | void VarRegion::dumpToStream(llvm::raw_ostream& os) const { |
Benjamin Kramer | 900fc63 | 2010-04-17 09:33:03 +0000 | [diff] [blame] | 440 | os << cast<VarDecl>(D); |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 441 | } |
| 442 | |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 443 | void RegionRawOffset::dump() const { |
| 444 | dumpToStream(llvm::errs()); |
| 445 | } |
| 446 | |
| 447 | void RegionRawOffset::dumpToStream(llvm::raw_ostream& os) const { |
| 448 | os << "raw_offset{" << getRegion() << ',' << getByteOffset() << '}'; |
| 449 | } |
| 450 | |
Ted Kremenek | fa87d81 | 2010-07-06 23:37:21 +0000 | [diff] [blame] | 451 | void StaticGlobalSpaceRegion::dumpToStream(llvm::raw_ostream &os) const { |
| 452 | os << "StaticGlobalsMemSpace{" << CR << '}'; |
| 453 | } |
| 454 | |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 455 | //===----------------------------------------------------------------------===// |
| 456 | // MemRegionManager methods. |
| 457 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 458 | |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 459 | template <typename REG> |
| 460 | const REG *MemRegionManager::LazyAllocate(REG*& region) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 461 | if (!region) { |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 462 | region = (REG*) A.Allocate<REG>(); |
| 463 | new (region) REG(this); |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 464 | } |
Ted Kremenek | a43484a | 2009-06-23 00:46:41 +0000 | [diff] [blame] | 465 | |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 466 | return region; |
| 467 | } |
| 468 | |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 469 | template <typename REG, typename ARG> |
| 470 | const REG *MemRegionManager::LazyAllocate(REG*& region, ARG a) { |
| 471 | if (!region) { |
| 472 | region = (REG*) A.Allocate<REG>(); |
| 473 | new (region) REG(this, a); |
| 474 | } |
Ted Kremenek | dcee3ce | 2010-07-01 20:16:50 +0000 | [diff] [blame] | 475 | |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 476 | return region; |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 477 | } |
| 478 | |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 479 | const StackLocalsSpaceRegion* |
Ted Kremenek | 2b87ae4 | 2009-12-11 06:43:27 +0000 | [diff] [blame] | 480 | MemRegionManager::getStackLocalsRegion(const StackFrameContext *STC) { |
| 481 | assert(STC); |
Zhongxing Xu | c30470d | 2010-02-17 08:46:50 +0000 | [diff] [blame] | 482 | StackLocalsSpaceRegion *&R = StackLocalsSpaceRegions[STC]; |
| 483 | |
| 484 | if (R) |
| 485 | return R; |
| 486 | |
| 487 | R = A.Allocate<StackLocalsSpaceRegion>(); |
| 488 | new (R) StackLocalsSpaceRegion(this, STC); |
| 489 | return R; |
Ted Kremenek | d05552a | 2009-07-02 18:14:59 +0000 | [diff] [blame] | 490 | } |
| 491 | |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 492 | const StackArgumentsSpaceRegion * |
| 493 | MemRegionManager::getStackArgumentsRegion(const StackFrameContext *STC) { |
Ted Kremenek | 2b87ae4 | 2009-12-11 06:43:27 +0000 | [diff] [blame] | 494 | assert(STC); |
Zhongxing Xu | c30470d | 2010-02-17 08:46:50 +0000 | [diff] [blame] | 495 | StackArgumentsSpaceRegion *&R = StackArgumentsSpaceRegions[STC]; |
| 496 | |
| 497 | if (R) |
| 498 | return R; |
| 499 | |
| 500 | R = A.Allocate<StackArgumentsSpaceRegion>(); |
| 501 | new (R) StackArgumentsSpaceRegion(this, STC); |
| 502 | return R; |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 503 | } |
| 504 | |
Ted Kremenek | dcee3ce | 2010-07-01 20:16:50 +0000 | [diff] [blame] | 505 | const GlobalsSpaceRegion |
| 506 | *MemRegionManager::getGlobalsRegion(const CodeTextRegion *CR) { |
| 507 | if (!CR) |
| 508 | return LazyAllocate(globals); |
| 509 | |
| 510 | StaticGlobalSpaceRegion *&R = StaticsGlobalSpaceRegions[CR]; |
| 511 | if (R) |
| 512 | return R; |
| 513 | |
| 514 | R = A.Allocate<StaticGlobalSpaceRegion>(); |
| 515 | new (R) StaticGlobalSpaceRegion(this, CR); |
| 516 | return R; |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 517 | } |
| 518 | |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 519 | const HeapSpaceRegion *MemRegionManager::getHeapRegion() { |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 520 | return LazyAllocate(heap); |
| 521 | } |
| 522 | |
Ted Kremenek | b48ad64 | 2009-12-04 00:26:31 +0000 | [diff] [blame] | 523 | const MemSpaceRegion *MemRegionManager::getUnknownRegion() { |
Zhongxing Xu | 1789275 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 524 | return LazyAllocate(unknown); |
| 525 | } |
| 526 | |
Ted Kremenek | b48ad64 | 2009-12-04 00:26:31 +0000 | [diff] [blame] | 527 | const MemSpaceRegion *MemRegionManager::getCodeRegion() { |
Zhongxing Xu | ec13d92 | 2009-04-10 08:45:10 +0000 | [diff] [blame] | 528 | return LazyAllocate(code); |
| 529 | } |
| 530 | |
Ted Kremenek | 2501013 | 2009-06-22 23:13:13 +0000 | [diff] [blame] | 531 | //===----------------------------------------------------------------------===// |
| 532 | // Constructing regions. |
| 533 | //===----------------------------------------------------------------------===// |
| 534 | |
Ted Kremenek | dcee3ce | 2010-07-01 20:16:50 +0000 | [diff] [blame] | 535 | const StringRegion* MemRegionManager::getStringRegion(const StringLiteral* Str){ |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 536 | return getSubRegion<StringRegion>(Str, getGlobalsRegion()); |
Zhongxing Xu | e9f4e54 | 2008-10-25 14:13:41 +0000 | [diff] [blame] | 537 | } |
| 538 | |
Ted Kremenek | b48ad64 | 2009-12-04 00:26:31 +0000 | [diff] [blame] | 539 | const VarRegion* MemRegionManager::getVarRegion(const VarDecl *D, |
| 540 | const LocationContext *LC) { |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 541 | const MemRegion *sReg = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 542 | |
Ted Kremenek | dcee3ce | 2010-07-01 20:16:50 +0000 | [diff] [blame] | 543 | if (D->hasGlobalStorage() && !D->isStaticLocal()) |
| 544 | sReg = getGlobalsRegion(); |
| 545 | else { |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 546 | // FIXME: Once we implement scope handling, we will need to properly lookup |
| 547 | // 'D' to the proper LocationContext. |
Ted Kremenek | 2b87ae4 | 2009-12-11 06:43:27 +0000 | [diff] [blame] | 548 | const DeclContext *DC = D->getDeclContext(); |
| 549 | const StackFrameContext *STC = LC->getStackFrameForDeclContext(DC); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 550 | |
Ted Kremenek | 2b87ae4 | 2009-12-11 06:43:27 +0000 | [diff] [blame] | 551 | if (!STC) |
| 552 | sReg = getUnknownRegion(); |
| 553 | else { |
Ted Kremenek | dcee3ce | 2010-07-01 20:16:50 +0000 | [diff] [blame] | 554 | if (D->hasLocalStorage()) { |
| 555 | sReg = isa<ParmVarDecl>(D) || isa<ImplicitParamDecl>(D) |
| 556 | ? static_cast<const MemRegion*>(getStackArgumentsRegion(STC)) |
| 557 | : static_cast<const MemRegion*>(getStackLocalsRegion(STC)); |
| 558 | } |
| 559 | else { |
| 560 | assert(D->isStaticLocal()); |
| 561 | const Decl *D = STC->getDecl(); |
| 562 | if (const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) |
| 563 | sReg = getGlobalsRegion(getFunctionTextRegion(FD)); |
| 564 | else if (const BlockDecl *BD = dyn_cast<BlockDecl>(D)) { |
| 565 | const BlockTextRegion *BTR = |
| 566 | getBlockTextRegion(BD, |
| 567 | C.getCanonicalType(BD->getSignatureAsWritten()->getType()), |
| 568 | STC->getAnalysisContext()); |
| 569 | sReg = getGlobalsRegion(BTR); |
| 570 | } |
| 571 | else { |
| 572 | // FIXME: For ObjC-methods, we need a new CodeTextRegion. For now |
| 573 | // just use the main global memspace. |
| 574 | sReg = getGlobalsRegion(); |
| 575 | } |
| 576 | } |
Ted Kremenek | 2b87ae4 | 2009-12-11 06:43:27 +0000 | [diff] [blame] | 577 | } |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 578 | } |
Ted Kremenek | dcee3ce | 2010-07-01 20:16:50 +0000 | [diff] [blame] | 579 | |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 580 | return getSubRegion<VarRegion>(D, sReg); |
| 581 | } |
| 582 | |
| 583 | const VarRegion *MemRegionManager::getVarRegion(const VarDecl *D, |
| 584 | const MemRegion *superR) { |
| 585 | return getSubRegion<VarRegion>(D, superR); |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 586 | } |
| 587 | |
Ted Kremenek | b48ad64 | 2009-12-04 00:26:31 +0000 | [diff] [blame] | 588 | const BlockDataRegion * |
| 589 | MemRegionManager::getBlockDataRegion(const BlockTextRegion *BC, |
| 590 | const LocationContext *LC) { |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 591 | const MemRegion *sReg = 0; |
Ted Kremenek | dcee3ce | 2010-07-01 20:16:50 +0000 | [diff] [blame] | 592 | |
| 593 | if (LC) { |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 594 | // FIXME: Once we implement scope handling, we want the parent region |
Ted Kremenek | dcee3ce | 2010-07-01 20:16:50 +0000 | [diff] [blame] | 595 | // to be the scope. |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 596 | const StackFrameContext *STC = LC->getCurrentStackFrame(); |
| 597 | assert(STC); |
| 598 | sReg = getStackLocalsRegion(STC); |
| 599 | } |
| 600 | else { |
| 601 | // We allow 'LC' to be NULL for cases where want BlockDataRegions |
| 602 | // without context-sensitivity. |
| 603 | sReg = getUnknownRegion(); |
| 604 | } |
| 605 | |
| 606 | return getSubRegion<BlockDataRegion>(BC, LC, sReg); |
Ted Kremenek | 0a8112a | 2009-11-25 23:53:07 +0000 | [diff] [blame] | 607 | } |
| 608 | |
Ted Kremenek | b48ad64 | 2009-12-04 00:26:31 +0000 | [diff] [blame] | 609 | const CompoundLiteralRegion* |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 610 | MemRegionManager::getCompoundLiteralRegion(const CompoundLiteralExpr* CL, |
| 611 | const LocationContext *LC) { |
Ted Kremenek | dcee3ce | 2010-07-01 20:16:50 +0000 | [diff] [blame] | 612 | |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 613 | const MemRegion *sReg = 0; |
Ted Kremenek | dcee3ce | 2010-07-01 20:16:50 +0000 | [diff] [blame] | 614 | |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 615 | if (CL->isFileScope()) |
| 616 | sReg = getGlobalsRegion(); |
| 617 | else { |
| 618 | const StackFrameContext *STC = LC->getCurrentStackFrame(); |
| 619 | assert(STC); |
| 620 | sReg = getStackLocalsRegion(STC); |
| 621 | } |
Ted Kremenek | dcee3ce | 2010-07-01 20:16:50 +0000 | [diff] [blame] | 622 | |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 623 | return getSubRegion<CompoundLiteralRegion>(CL, sReg); |
Ted Kremenek | 329d6fd | 2008-10-27 20:57:58 +0000 | [diff] [blame] | 624 | } |
| 625 | |
Ted Kremenek | b48ad64 | 2009-12-04 00:26:31 +0000 | [diff] [blame] | 626 | const ElementRegion* |
Ted Kremenek | f936f45 | 2009-05-04 06:18:28 +0000 | [diff] [blame] | 627 | MemRegionManager::getElementRegion(QualType elementType, SVal Idx, |
Ted Kremenek | 4653739 | 2009-07-16 01:33:37 +0000 | [diff] [blame] | 628 | const MemRegion* superRegion, |
| 629 | ASTContext& Ctx){ |
Zhongxing Xu | 143b2fc | 2009-06-16 09:55:50 +0000 | [diff] [blame] | 630 | |
Ted Kremenek | 32f9010 | 2010-05-27 00:29:00 +0000 | [diff] [blame] | 631 | QualType T = Ctx.getCanonicalType(elementType).getUnqualifiedType(); |
Ted Kremenek | abb042f | 2008-12-13 19:24:37 +0000 | [diff] [blame] | 632 | |
Zhongxing Xu | 511191c | 2008-10-21 05:27:10 +0000 | [diff] [blame] | 633 | llvm::FoldingSetNodeID ID; |
Zhongxing Xu | 143b2fc | 2009-06-16 09:55:50 +0000 | [diff] [blame] | 634 | ElementRegion::ProfileRegion(ID, T, Idx, superRegion); |
Zhongxing Xu | 511191c | 2008-10-21 05:27:10 +0000 | [diff] [blame] | 635 | |
| 636 | void* InsertPos; |
| 637 | MemRegion* data = Regions.FindNodeOrInsertPos(ID, InsertPos); |
| 638 | ElementRegion* R = cast_or_null<ElementRegion>(data); |
| 639 | |
| 640 | if (!R) { |
| 641 | R = (ElementRegion*) A.Allocate<ElementRegion>(); |
Zhongxing Xu | 143b2fc | 2009-06-16 09:55:50 +0000 | [diff] [blame] | 642 | new (R) ElementRegion(T, Idx, superRegion); |
Zhongxing Xu | 511191c | 2008-10-21 05:27:10 +0000 | [diff] [blame] | 643 | Regions.InsertNode(R, InsertPos); |
| 644 | } |
| 645 | |
| 646 | return R; |
| 647 | } |
| 648 | |
Ted Kremenek | b48ad64 | 2009-12-04 00:26:31 +0000 | [diff] [blame] | 649 | const FunctionTextRegion * |
Ted Kremenek | eb1c7a0 | 2009-11-25 01:32:22 +0000 | [diff] [blame] | 650 | MemRegionManager::getFunctionTextRegion(const FunctionDecl *FD) { |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 651 | return getSubRegion<FunctionTextRegion>(FD, getCodeRegion()); |
Zhongxing Xu | ec13d92 | 2009-04-10 08:45:10 +0000 | [diff] [blame] | 652 | } |
| 653 | |
Ted Kremenek | b48ad64 | 2009-12-04 00:26:31 +0000 | [diff] [blame] | 654 | const BlockTextRegion * |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 655 | MemRegionManager::getBlockTextRegion(const BlockDecl *BD, CanQualType locTy, |
| 656 | AnalysisContext *AC) { |
| 657 | return getSubRegion<BlockTextRegion>(BD, locTy, AC, getCodeRegion()); |
Ted Kremenek | eb1c7a0 | 2009-11-25 01:32:22 +0000 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | |
Ted Kremenek | 993f1c7 | 2008-10-17 20:28:54 +0000 | [diff] [blame] | 661 | /// getSymbolicRegion - Retrieve or create a "symbolic" memory region. |
Ted Kremenek | b48ad64 | 2009-12-04 00:26:31 +0000 | [diff] [blame] | 662 | const SymbolicRegion *MemRegionManager::getSymbolicRegion(SymbolRef sym) { |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 663 | return getSubRegion<SymbolicRegion>(sym, getUnknownRegion()); |
Ted Kremenek | 993f1c7 | 2008-10-17 20:28:54 +0000 | [diff] [blame] | 664 | } |
| 665 | |
Ted Kremenek | de0d263 | 2010-01-05 02:18:06 +0000 | [diff] [blame] | 666 | const FieldRegion* |
Ted Kremenek | b48ad64 | 2009-12-04 00:26:31 +0000 | [diff] [blame] | 667 | MemRegionManager::getFieldRegion(const FieldDecl* d, |
| 668 | const MemRegion* superRegion){ |
Ted Kremenek | eeea456 | 2009-07-10 16:51:45 +0000 | [diff] [blame] | 669 | return getSubRegion<FieldRegion>(d, superRegion); |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 670 | } |
| 671 | |
Ted Kremenek | b48ad64 | 2009-12-04 00:26:31 +0000 | [diff] [blame] | 672 | const ObjCIvarRegion* |
Ted Kremenek | 993f1c7 | 2008-10-17 20:28:54 +0000 | [diff] [blame] | 673 | MemRegionManager::getObjCIvarRegion(const ObjCIvarDecl* d, |
| 674 | const MemRegion* superRegion) { |
Ted Kremenek | eeea456 | 2009-07-10 16:51:45 +0000 | [diff] [blame] | 675 | return getSubRegion<ObjCIvarRegion>(d, superRegion); |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 676 | } |
| 677 | |
Ted Kremenek | de0d263 | 2010-01-05 02:18:06 +0000 | [diff] [blame] | 678 | const CXXObjectRegion* |
Zhongxing Xu | bc37b8d | 2010-01-09 09:16:47 +0000 | [diff] [blame] | 679 | MemRegionManager::getCXXObjectRegion(Expr const *E, |
| 680 | LocationContext const *LC) { |
| 681 | const StackFrameContext *SFC = LC->getCurrentStackFrame(); |
| 682 | assert(SFC); |
| 683 | return getSubRegion<CXXObjectRegion>(E, getStackLocalsRegion(SFC)); |
Zhongxing Xu | bb14121 | 2009-12-16 11:27:52 +0000 | [diff] [blame] | 684 | } |
| 685 | |
Ted Kremenek | de0d263 | 2010-01-05 02:18:06 +0000 | [diff] [blame] | 686 | const CXXThisRegion* |
| 687 | MemRegionManager::getCXXThisRegion(QualType thisPointerTy, |
| 688 | const LocationContext *LC) { |
| 689 | const StackFrameContext *STC = LC->getCurrentStackFrame(); |
| 690 | assert(STC); |
| 691 | const PointerType *PT = thisPointerTy->getAs<PointerType>(); |
| 692 | assert(PT); |
| 693 | return getSubRegion<CXXThisRegion>(PT, getStackArgumentsRegion(STC)); |
| 694 | } |
| 695 | |
Ted Kremenek | b48ad64 | 2009-12-04 00:26:31 +0000 | [diff] [blame] | 696 | const AllocaRegion* |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 697 | MemRegionManager::getAllocaRegion(const Expr* E, unsigned cnt, |
| 698 | const LocationContext *LC) { |
| 699 | const StackFrameContext *STC = LC->getCurrentStackFrame(); |
| 700 | assert(STC); |
| 701 | return getSubRegion<AllocaRegion>(E, cnt, getStackLocalsRegion(STC)); |
Ted Kremenek | 7090ae1 | 2008-11-02 00:34:33 +0000 | [diff] [blame] | 702 | } |
| 703 | |
Ted Kremenek | bb7c96f | 2009-06-23 18:17:08 +0000 | [diff] [blame] | 704 | const MemSpaceRegion *MemRegion::getMemorySpace() const { |
| 705 | const MemRegion *R = this; |
Ted Kremenek | ea20cd7 | 2009-06-23 18:05:21 +0000 | [diff] [blame] | 706 | const SubRegion* SR = dyn_cast<SubRegion>(this); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 707 | |
Ted Kremenek | 993f1c7 | 2008-10-17 20:28:54 +0000 | [diff] [blame] | 708 | while (SR) { |
Ted Kremenek | bb7c96f | 2009-06-23 18:17:08 +0000 | [diff] [blame] | 709 | R = SR->getSuperRegion(); |
| 710 | SR = dyn_cast<SubRegion>(R); |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 711 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 712 | |
Ted Kremenek | bb7c96f | 2009-06-23 18:17:08 +0000 | [diff] [blame] | 713 | return dyn_cast<MemSpaceRegion>(R); |
| 714 | } |
| 715 | |
| 716 | bool MemRegion::hasStackStorage() const { |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 717 | return isa<StackSpaceRegion>(getMemorySpace()); |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 718 | } |
Ted Kremenek | 1670e40 | 2009-04-11 00:11:10 +0000 | [diff] [blame] | 719 | |
Ted Kremenek | de0d263 | 2010-01-05 02:18:06 +0000 | [diff] [blame] | 720 | bool MemRegion::hasStackNonParametersStorage() const { |
| 721 | return isa<StackLocalsSpaceRegion>(getMemorySpace()); |
Zhongxing Xu | dd198f0 | 2009-06-23 02:51:21 +0000 | [diff] [blame] | 722 | } |
Ted Kremenek | 1670e40 | 2009-04-11 00:11:10 +0000 | [diff] [blame] | 723 | |
Ted Kremenek | de0d263 | 2010-01-05 02:18:06 +0000 | [diff] [blame] | 724 | bool MemRegion::hasStackParametersStorage() const { |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 725 | return isa<StackArgumentsSpaceRegion>(getMemorySpace()); |
Ted Kremenek | dc14726 | 2009-07-02 22:02:15 +0000 | [diff] [blame] | 726 | } |
| 727 | |
Ted Kremenek | 1508636 | 2009-07-02 18:25:09 +0000 | [diff] [blame] | 728 | bool MemRegion::hasGlobalsOrParametersStorage() const { |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 729 | const MemSpaceRegion *MS = getMemorySpace(); |
| 730 | return isa<StackArgumentsSpaceRegion>(MS) || |
| 731 | isa<GlobalsSpaceRegion>(MS); |
Ted Kremenek | 1508636 | 2009-07-02 18:25:09 +0000 | [diff] [blame] | 732 | } |
Ted Kremenek | bb7c96f | 2009-06-23 18:17:08 +0000 | [diff] [blame] | 733 | |
Zhongxing Xu | adca271 | 2009-11-10 02:37:53 +0000 | [diff] [blame] | 734 | // getBaseRegion strips away all elements and fields, and get the base region |
| 735 | // of them. |
| 736 | const MemRegion *MemRegion::getBaseRegion() const { |
| 737 | const MemRegion *R = this; |
| 738 | while (true) { |
Ted Kremenek | 68b9a59 | 2010-04-06 22:06:03 +0000 | [diff] [blame] | 739 | switch (R->getKind()) { |
| 740 | case MemRegion::ElementRegionKind: |
| 741 | case MemRegion::FieldRegionKind: |
| 742 | case MemRegion::ObjCIvarRegionKind: |
| 743 | R = cast<SubRegion>(R)->getSuperRegion(); |
| 744 | continue; |
| 745 | default: |
| 746 | break; |
Zhongxing Xu | adca271 | 2009-11-10 02:37:53 +0000 | [diff] [blame] | 747 | } |
| 748 | break; |
| 749 | } |
| 750 | return R; |
| 751 | } |
| 752 | |
Ted Kremenek | 1670e40 | 2009-04-11 00:11:10 +0000 | [diff] [blame] | 753 | //===----------------------------------------------------------------------===// |
| 754 | // View handling. |
| 755 | //===----------------------------------------------------------------------===// |
| 756 | |
Zhongxing Xu | 479529e | 2009-11-10 02:17:20 +0000 | [diff] [blame] | 757 | const MemRegion *MemRegion::StripCasts() const { |
Ted Kremenek | 0e3ec3f | 2009-07-29 18:14:27 +0000 | [diff] [blame] | 758 | const MemRegion *R = this; |
| 759 | while (true) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 760 | if (const ElementRegion *ER = dyn_cast<ElementRegion>(R)) { |
Ted Kremenek | 0e3ec3f | 2009-07-29 18:14:27 +0000 | [diff] [blame] | 761 | // FIXME: generalize. Essentially we want to strip away ElementRegions |
| 762 | // that were layered on a symbolic region because of casts. We only |
| 763 | // want to strip away ElementRegions, however, where the index is 0. |
| 764 | SVal index = ER->getIndex(); |
| 765 | if (nonloc::ConcreteInt *CI = dyn_cast<nonloc::ConcreteInt>(&index)) { |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 766 | if (CI->getValue().getSExtValue() == 0) { |
Ted Kremenek | 0e3ec3f | 2009-07-29 18:14:27 +0000 | [diff] [blame] | 767 | R = ER->getSuperRegion(); |
| 768 | continue; |
| 769 | } |
| 770 | } |
| 771 | } |
| 772 | break; |
| 773 | } |
| 774 | return R; |
| 775 | } |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 776 | |
| 777 | // FIXME: Merge with the implementation of the same method in Store.cpp |
| 778 | static bool IsCompleteType(ASTContext &Ctx, QualType Ty) { |
| 779 | if (const RecordType *RT = Ty->getAs<RecordType>()) { |
| 780 | const RecordDecl *D = RT->getDecl(); |
Douglas Gregor | 952b017 | 2010-02-11 01:04:33 +0000 | [diff] [blame] | 781 | if (!D->getDefinition()) |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 782 | return false; |
| 783 | } |
| 784 | |
| 785 | return true; |
| 786 | } |
| 787 | |
| 788 | RegionRawOffset ElementRegion::getAsRawOffset() const { |
Ken Dyck | 199c3d6 | 2010-01-11 17:06:35 +0000 | [diff] [blame] | 789 | CharUnits offset = CharUnits::Zero(); |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 790 | const ElementRegion *ER = this; |
| 791 | const MemRegion *superR = NULL; |
| 792 | ASTContext &C = getContext(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 793 | |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 794 | // FIXME: Handle multi-dimensional arrays. |
| 795 | |
| 796 | while (ER) { |
| 797 | superR = ER->getSuperRegion(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 798 | |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 799 | // FIXME: generalize to symbolic offsets. |
| 800 | SVal index = ER->getIndex(); |
| 801 | if (nonloc::ConcreteInt *CI = dyn_cast<nonloc::ConcreteInt>(&index)) { |
| 802 | // Update the offset. |
| 803 | int64_t i = CI->getValue().getSExtValue(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 804 | |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 805 | if (i != 0) { |
| 806 | QualType elemType = ER->getElementType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 807 | |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 808 | // If we are pointing to an incomplete type, go no further. |
| 809 | if (!IsCompleteType(C, elemType)) { |
| 810 | superR = ER; |
| 811 | break; |
| 812 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 813 | |
Ken Dyck | 199c3d6 | 2010-01-11 17:06:35 +0000 | [diff] [blame] | 814 | CharUnits size = C.getTypeSizeInChars(elemType); |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 815 | offset += (i * size); |
| 816 | } |
| 817 | |
| 818 | // Go to the next ElementRegion (if any). |
| 819 | ER = dyn_cast<ElementRegion>(superR); |
| 820 | continue; |
| 821 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 822 | |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 823 | return NULL; |
| 824 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 825 | |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 826 | assert(superR && "super region cannot be NULL"); |
Ken Dyck | 199c3d6 | 2010-01-11 17:06:35 +0000 | [diff] [blame] | 827 | return RegionRawOffset(superR, offset.getQuantity()); |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 828 | } |
| 829 | |
Ted Kremenek | 4240096 | 2009-11-26 02:34:36 +0000 | [diff] [blame] | 830 | //===----------------------------------------------------------------------===// |
| 831 | // BlockDataRegion |
| 832 | //===----------------------------------------------------------------------===// |
| 833 | |
| 834 | void BlockDataRegion::LazyInitializeReferencedVars() { |
| 835 | if (ReferencedVars) |
| 836 | return; |
| 837 | |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 838 | AnalysisContext *AC = getCodeRegion()->getAnalysisContext(); |
Ted Kremenek | 4240096 | 2009-11-26 02:34:36 +0000 | [diff] [blame] | 839 | AnalysisContext::referenced_decls_iterator I, E; |
| 840 | llvm::tie(I, E) = AC->getReferencedBlockVars(BC->getDecl()); |
Ted Kremenek | dcee3ce | 2010-07-01 20:16:50 +0000 | [diff] [blame] | 841 | |
Ted Kremenek | 4240096 | 2009-11-26 02:34:36 +0000 | [diff] [blame] | 842 | if (I == E) { |
| 843 | ReferencedVars = (void*) 0x1; |
| 844 | return; |
| 845 | } |
Ted Kremenek | dcee3ce | 2010-07-01 20:16:50 +0000 | [diff] [blame] | 846 | |
Ted Kremenek | 4240096 | 2009-11-26 02:34:36 +0000 | [diff] [blame] | 847 | MemRegionManager &MemMgr = *getMemRegionManager(); |
| 848 | llvm::BumpPtrAllocator &A = MemMgr.getAllocator(); |
| 849 | BumpVectorContext BC(A); |
Ted Kremenek | dcee3ce | 2010-07-01 20:16:50 +0000 | [diff] [blame] | 850 | |
Ted Kremenek | 4240096 | 2009-11-26 02:34:36 +0000 | [diff] [blame] | 851 | typedef BumpVector<const MemRegion*> VarVec; |
| 852 | VarVec *BV = (VarVec*) A.Allocate<VarVec>(); |
Ted Kremenek | 02b1df6 | 2009-12-01 22:12:34 +0000 | [diff] [blame] | 853 | new (BV) VarVec(BC, E - I); |
Ted Kremenek | dcee3ce | 2010-07-01 20:16:50 +0000 | [diff] [blame] | 854 | |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 855 | for ( ; I != E; ++I) { |
| 856 | const VarDecl *VD = *I; |
| 857 | const VarRegion *VR = 0; |
Ted Kremenek | dcee3ce | 2010-07-01 20:16:50 +0000 | [diff] [blame] | 858 | |
Ted Kremenek | 8524873 | 2010-02-06 00:30:00 +0000 | [diff] [blame] | 859 | if (!VD->getAttr<BlocksAttr>() && VD->hasLocalStorage()) |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 860 | VR = MemMgr.getVarRegion(VD, this); |
| 861 | else { |
| 862 | if (LC) |
| 863 | VR = MemMgr.getVarRegion(VD, LC); |
| 864 | else { |
| 865 | VR = MemMgr.getVarRegion(VD, MemMgr.getUnknownRegion()); |
| 866 | } |
| 867 | } |
Ted Kremenek | dcee3ce | 2010-07-01 20:16:50 +0000 | [diff] [blame] | 868 | |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 869 | assert(VR); |
| 870 | BV->push_back(VR, BC); |
| 871 | } |
Ted Kremenek | dcee3ce | 2010-07-01 20:16:50 +0000 | [diff] [blame] | 872 | |
Ted Kremenek | 4240096 | 2009-11-26 02:34:36 +0000 | [diff] [blame] | 873 | ReferencedVars = BV; |
| 874 | } |
| 875 | |
| 876 | BlockDataRegion::referenced_vars_iterator |
| 877 | BlockDataRegion::referenced_vars_begin() const { |
| 878 | const_cast<BlockDataRegion*>(this)->LazyInitializeReferencedVars(); |
| 879 | |
| 880 | BumpVector<const MemRegion*> *Vec = |
| 881 | static_cast<BumpVector<const MemRegion*>*>(ReferencedVars); |
Ted Kremenek | dcee3ce | 2010-07-01 20:16:50 +0000 | [diff] [blame] | 882 | |
Ted Kremenek | 81cef58 | 2009-12-03 08:09:21 +0000 | [diff] [blame] | 883 | return BlockDataRegion::referenced_vars_iterator(Vec == (void*) 0x1 ? |
| 884 | NULL : Vec->begin()); |
Ted Kremenek | 4240096 | 2009-11-26 02:34:36 +0000 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | BlockDataRegion::referenced_vars_iterator |
| 888 | BlockDataRegion::referenced_vars_end() const { |
| 889 | const_cast<BlockDataRegion*>(this)->LazyInitializeReferencedVars(); |
| 890 | |
| 891 | BumpVector<const MemRegion*> *Vec = |
| 892 | static_cast<BumpVector<const MemRegion*>*>(ReferencedVars); |
Ted Kremenek | dcee3ce | 2010-07-01 20:16:50 +0000 | [diff] [blame] | 893 | |
Ted Kremenek | 81cef58 | 2009-12-03 08:09:21 +0000 | [diff] [blame] | 894 | return BlockDataRegion::referenced_vars_iterator(Vec == (void*) 0x1 ? |
| 895 | NULL : Vec->end()); |
Ted Kremenek | 4240096 | 2009-11-26 02:34:36 +0000 | [diff] [blame] | 896 | } |