Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 1 | //== BasicStore.cpp - Basic map from Locations to Values --------*- 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 defined the BasicStore and BasicStoreManager classes. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Ted Kremenek | f684d56 | 2009-03-05 18:08:28 +0000 | [diff] [blame] | 14 | #include "clang/AST/ExprObjC.h" |
Ted Kremenek | 5f81c44 | 2008-08-28 23:31:31 +0000 | [diff] [blame] | 15 | #include "clang/Analysis/Analyses/LiveVariables.h" |
Ted Kremenek | 1309f9a | 2010-01-25 04:41:41 +0000 | [diff] [blame] | 16 | #include "clang/Analysis/AnalysisContext.h" |
| 17 | #include "clang/Checker/PathSensitive/GRState.h" |
Benjamin Kramer | 6cb7c1a | 2009-08-23 12:08:50 +0000 | [diff] [blame] | 18 | #include "llvm/ADT/ImmutableMap.h" |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 19 | |
| 20 | using namespace clang; |
| 21 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 22 | typedef llvm::ImmutableMap<const MemRegion*,SVal> BindingsTy; |
Ted Kremenek | 60dbad8 | 2008-09-03 03:06:11 +0000 | [diff] [blame] | 23 | |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 24 | namespace { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 25 | |
Kovarththanan Rajaratnam | ba5fb5a | 2009-11-28 06:07:30 +0000 | [diff] [blame] | 26 | class BasicStoreSubRegionMap : public SubRegionMap { |
Ted Kremenek | 59e8f11 | 2009-03-03 01:35:36 +0000 | [diff] [blame] | 27 | public: |
| 28 | BasicStoreSubRegionMap() {} |
| 29 | |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 30 | bool iterSubRegions(const MemRegion* R, Visitor& V) const { |
Ted Kremenek | 39fc715 | 2009-03-05 16:41:21 +0000 | [diff] [blame] | 31 | return true; // Do nothing. No subregions. |
Ted Kremenek | 59e8f11 | 2009-03-03 01:35:36 +0000 | [diff] [blame] | 32 | } |
| 33 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 34 | |
Kovarththanan Rajaratnam | ba5fb5a | 2009-11-28 06:07:30 +0000 | [diff] [blame] | 35 | class BasicStoreManager : public StoreManager { |
Ted Kremenek | 2c8e788 | 2009-03-05 16:32:59 +0000 | [diff] [blame] | 36 | BindingsTy::Factory VBFactory; |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 37 | public: |
Ted Kremenek | f7a0cf4 | 2009-07-29 21:43:22 +0000 | [diff] [blame] | 38 | BasicStoreManager(GRStateManager& mgr) |
Ted Kremenek | 82cd37c | 2009-08-21 23:25:54 +0000 | [diff] [blame] | 39 | : StoreManager(mgr), VBFactory(mgr.getAllocator()) {} |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 40 | |
Ted Kremenek | 9deb0e3 | 2008-10-24 20:32:16 +0000 | [diff] [blame] | 41 | ~BasicStoreManager() {} |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 42 | |
Zhongxing Xu | f5416bd | 2010-02-05 05:18:47 +0000 | [diff] [blame] | 43 | SubRegionMap *getSubRegionMap(Store store) { |
Ted Kremenek | 14453bf | 2009-03-03 19:02:42 +0000 | [diff] [blame] | 44 | return new BasicStoreSubRegionMap(); |
Ted Kremenek | 59e8f11 | 2009-03-03 01:35:36 +0000 | [diff] [blame] | 45 | } |
| 46 | |
Zhongxing Xu | 576bb92 | 2010-02-05 03:01:53 +0000 | [diff] [blame] | 47 | SVal Retrieve(Store store, Loc loc, QualType T = QualType()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 48 | |
Zhongxing Xu | b4a9c61 | 2010-02-05 05:06:13 +0000 | [diff] [blame] | 49 | Store InvalidateRegion(Store store, const MemRegion *R, const Expr *E, |
| 50 | unsigned Count, InvalidatedSymbols *IS); |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 51 | |
Ted Kremenek | 82cd37c | 2009-08-21 23:25:54 +0000 | [diff] [blame] | 52 | Store scanForIvars(Stmt *B, const Decl* SelfDecl, |
| 53 | const MemRegion *SelfRegion, Store St); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 54 | |
Zhongxing Xu | b241cf6 | 2010-02-08 08:48:05 +0000 | [diff] [blame] | 55 | Store Bind(Store St, Loc loc, SVal V); |
Ted Kremenek | c6ed384 | 2009-01-07 22:56:17 +0000 | [diff] [blame] | 56 | Store Remove(Store St, Loc loc); |
Zhongxing Xu | 17fd863 | 2009-08-17 06:19:58 +0000 | [diff] [blame] | 57 | Store getInitialStore(const LocationContext *InitLoc); |
Zhongxing Xu | bc678fd | 2008-10-07 01:31:04 +0000 | [diff] [blame] | 58 | |
Zhongxing Xu | 6d69b5d | 2008-10-16 06:09:51 +0000 | [diff] [blame] | 59 | // FIXME: Investigate what is using this. This method should be removed. |
Ted Kremenek | d17da2b | 2009-08-21 22:28:32 +0000 | [diff] [blame] | 60 | virtual Loc getLoc(const VarDecl* VD, const LocationContext *LC) { |
| 61 | return ValMgr.makeLoc(MRMgr.getVarRegion(VD, LC)); |
Zhongxing Xu | bc678fd | 2008-10-07 01:31:04 +0000 | [diff] [blame] | 62 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 63 | |
Zhongxing Xu | b4a9c61 | 2010-02-05 05:06:13 +0000 | [diff] [blame] | 64 | Store BindCompoundLiteral(Store store, const CompoundLiteralExpr*, |
| 65 | const LocationContext*, SVal val) { |
| 66 | return store; |
Ted Kremenek | 4f09027 | 2008-10-27 21:54:31 +0000 | [diff] [blame] | 67 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 68 | |
Ted Kremenek | 9deb0e3 | 2008-10-24 20:32:16 +0000 | [diff] [blame] | 69 | /// ArrayToPointer - Used by GRExprEngine::VistCast to handle implicit |
| 70 | /// conversions between arrays and pointers. |
Zhongxing Xu | f1d537f | 2009-03-30 05:55:46 +0000 | [diff] [blame] | 71 | SVal ArrayToPointer(Loc Array) { return Array; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 72 | |
Ted Kremenek | 2ed14be | 2008-12-05 00:47:52 +0000 | [diff] [blame] | 73 | /// RemoveDeadBindings - Scans a BasicStore of 'state' for dead values. |
Ted Kremenek | 2f26bc3 | 2009-08-02 04:45:08 +0000 | [diff] [blame] | 74 | /// It updatees the GRState object in place with the values removed. |
Zhongxing Xu | 72119c4 | 2010-02-05 05:34:29 +0000 | [diff] [blame] | 75 | Store RemoveDeadBindings(Store store, Stmt* Loc, SymbolReaper& SymReaper, |
Ted Kremenek | 2f26bc3 | 2009-08-02 04:45:08 +0000 | [diff] [blame] | 76 | llvm::SmallVectorImpl<const MemRegion*>& RegionRoots); |
Zhongxing Xu | bbe8ff4 | 2008-08-21 22:34:01 +0000 | [diff] [blame] | 77 | |
Ted Kremenek | 9deb0e3 | 2008-10-24 20:32:16 +0000 | [diff] [blame] | 78 | void iterBindings(Store store, BindingsHandler& f); |
Ted Kremenek | 60dbad8 | 2008-09-03 03:06:11 +0000 | [diff] [blame] | 79 | |
Zhongxing Xu | b4a9c61 | 2010-02-05 05:06:13 +0000 | [diff] [blame] | 80 | Store BindDecl(Store store, const VarRegion *VR, SVal InitVal) { |
| 81 | return BindDeclInternal(store, VR, &InitVal); |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 82 | } |
| 83 | |
Zhongxing Xu | b4a9c61 | 2010-02-05 05:06:13 +0000 | [diff] [blame] | 84 | Store BindDeclWithNoInit(Store store, const VarRegion *VR) { |
| 85 | return BindDeclInternal(store, VR, 0); |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 86 | } |
| 87 | |
Ted Kremenek | f6f56d4 | 2009-11-04 00:09:15 +0000 | [diff] [blame] | 88 | Store BindDeclInternal(Store store, const VarRegion *VR, SVal *InitVal); |
Zhongxing Xu | bbe8ff4 | 2008-08-21 22:34:01 +0000 | [diff] [blame] | 89 | |
Ted Kremenek | 2c8e788 | 2009-03-05 16:32:59 +0000 | [diff] [blame] | 90 | static inline BindingsTy GetBindings(Store store) { |
| 91 | return BindingsTy(static_cast<const BindingsTy::TreeTy*>(store)); |
Ted Kremenek | a622d8c | 2008-08-19 22:24:03 +0000 | [diff] [blame] | 92 | } |
| 93 | |
Ted Kremenek | 53ba0b6 | 2009-06-24 23:06:47 +0000 | [diff] [blame] | 94 | void print(Store store, llvm::raw_ostream& Out, const char* nl, |
| 95 | const char *sep); |
Zhongxing Xu | a1718c7 | 2009-04-03 07:33:13 +0000 | [diff] [blame] | 96 | |
| 97 | private: |
| 98 | ASTContext& getContext() { return StateMgr.getContext(); } |
Ted Kremenek | 60dbad8 | 2008-09-03 03:06:11 +0000 | [diff] [blame] | 99 | }; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 100 | |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 101 | } // end anonymous namespace |
| 102 | |
| 103 | |
Ted Kremenek | 5f81c44 | 2008-08-28 23:31:31 +0000 | [diff] [blame] | 104 | StoreManager* clang::CreateBasicStoreManager(GRStateManager& StMgr) { |
| 105 | return new BasicStoreManager(StMgr); |
Ted Kremenek | d0c4b28 | 2008-08-25 19:33:03 +0000 | [diff] [blame] | 106 | } |
Zhongxing Xu | 933c3e1 | 2008-10-21 06:54:23 +0000 | [diff] [blame] | 107 | |
Ted Kremenek | 5fa93d5 | 2009-04-29 16:03:27 +0000 | [diff] [blame] | 108 | static bool isHigherOrderRawPtr(QualType T, ASTContext &C) { |
Ted Kremenek | 1670e40 | 2009-04-11 00:11:10 +0000 | [diff] [blame] | 109 | bool foundPointer = false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 110 | while (1) { |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 111 | const PointerType *PT = T->getAs<PointerType>(); |
Ted Kremenek | 1670e40 | 2009-04-11 00:11:10 +0000 | [diff] [blame] | 112 | if (!PT) { |
| 113 | if (!foundPointer) |
| 114 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 115 | |
Ted Kremenek | 5fa93d5 | 2009-04-29 16:03:27 +0000 | [diff] [blame] | 116 | // intptr_t* or intptr_t**, etc? |
| 117 | if (T->isIntegerType() && C.getTypeSize(T) == C.getTypeSize(C.VoidPtrTy)) |
| 118 | return true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 119 | |
Ted Kremenek | 1670e40 | 2009-04-11 00:11:10 +0000 | [diff] [blame] | 120 | QualType X = C.getCanonicalType(T).getUnqualifiedType(); |
| 121 | return X == C.VoidTy; |
| 122 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 123 | |
Ted Kremenek | 1670e40 | 2009-04-11 00:11:10 +0000 | [diff] [blame] | 124 | foundPointer = true; |
| 125 | T = PT->getPointeeType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 126 | } |
Ted Kremenek | 1670e40 | 2009-04-11 00:11:10 +0000 | [diff] [blame] | 127 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 128 | |
Zhongxing Xu | 576bb92 | 2010-02-05 03:01:53 +0000 | [diff] [blame] | 129 | SVal BasicStoreManager::Retrieve(Store store, Loc loc, QualType T) { |
Ted Kremenek | c6ed384 | 2009-01-07 22:56:17 +0000 | [diff] [blame] | 130 | if (isa<UnknownVal>(loc)) |
Zhongxing Xu | c999ed7 | 2010-02-04 02:39:47 +0000 | [diff] [blame] | 131 | return UnknownVal(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 132 | |
Ted Kremenek | 1894dce | 2009-08-25 20:51:30 +0000 | [diff] [blame] | 133 | assert(!isa<UndefinedVal>(loc)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 134 | |
Ted Kremenek | c6ed384 | 2009-01-07 22:56:17 +0000 | [diff] [blame] | 135 | switch (loc.getSubKind()) { |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 136 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 137 | case loc::MemRegionKind: { |
Ted Kremenek | f684d56 | 2009-03-05 18:08:28 +0000 | [diff] [blame] | 138 | const MemRegion* R = cast<loc::MemRegionVal>(loc).getRegion(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 139 | |
Ted Kremenek | f684d56 | 2009-03-05 18:08:28 +0000 | [diff] [blame] | 140 | if (!(isa<VarRegion>(R) || isa<ObjCIvarRegion>(R))) |
Zhongxing Xu | c999ed7 | 2010-02-04 02:39:47 +0000 | [diff] [blame] | 141 | return UnknownVal(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 142 | |
Zhongxing Xu | 576bb92 | 2010-02-05 03:01:53 +0000 | [diff] [blame] | 143 | BindingsTy B = GetBindings(store); |
Ted Kremenek | 1894dce | 2009-08-25 20:51:30 +0000 | [diff] [blame] | 144 | BindingsTy::data_type *Val = B.lookup(R); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 145 | |
Ted Kremenek | 1894dce | 2009-08-25 20:51:30 +0000 | [diff] [blame] | 146 | if (!Val) |
| 147 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 148 | |
Zhongxing Xu | c999ed7 | 2010-02-04 02:39:47 +0000 | [diff] [blame] | 149 | return CastRetrievedVal(*Val, cast<TypedRegion>(R), T); |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 150 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 151 | |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 152 | case loc::ConcreteIntKind: |
| 153 | // Some clients may call GetSVal with such an option simply because |
| 154 | // they are doing a quick scan through their Locs (potentially to |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 155 | // invalidate their bindings). Just return Undefined. |
Zhongxing Xu | c999ed7 | 2010-02-04 02:39:47 +0000 | [diff] [blame] | 156 | return UndefinedVal(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 157 | |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 158 | default: |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 159 | assert (false && "Invalid Loc."); |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 160 | break; |
| 161 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 162 | |
Zhongxing Xu | c999ed7 | 2010-02-04 02:39:47 +0000 | [diff] [blame] | 163 | return UnknownVal(); |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 164 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 165 | |
Zhongxing Xu | b241cf6 | 2010-02-08 08:48:05 +0000 | [diff] [blame] | 166 | Store BasicStoreManager::Bind(Store store, Loc loc, SVal V) { |
Zhongxing Xu | 87453d1 | 2009-06-28 10:16:11 +0000 | [diff] [blame] | 167 | if (isa<loc::ConcreteInt>(loc)) |
| 168 | return store; |
| 169 | |
Zhongxing Xu | c2a650a | 2009-06-28 09:26:15 +0000 | [diff] [blame] | 170 | const MemRegion* R = cast<loc::MemRegionVal>(loc).getRegion(); |
| 171 | ASTContext &C = StateMgr.getContext(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 172 | |
Zhongxing Xu | c2a650a | 2009-06-28 09:26:15 +0000 | [diff] [blame] | 173 | // Special case: handle store of pointer values (Loc) to pointers via |
| 174 | // a cast to intXX_t*, void*, etc. This is needed to handle |
| 175 | // OSCompareAndSwap32Barrier/OSCompareAndSwap64Barrier. |
| 176 | if (isa<Loc>(V) || isa<nonloc::LocAsInteger>(V)) |
| 177 | if (const ElementRegion *ER = dyn_cast<ElementRegion>(R)) { |
| 178 | // FIXME: Should check for index 0. |
| 179 | QualType T = ER->getLocationType(C); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 180 | |
Zhongxing Xu | c2a650a | 2009-06-28 09:26:15 +0000 | [diff] [blame] | 181 | if (isHigherOrderRawPtr(T, C)) |
| 182 | R = ER->getSuperRegion(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 183 | } |
| 184 | |
Zhongxing Xu | c2a650a | 2009-06-28 09:26:15 +0000 | [diff] [blame] | 185 | if (!(isa<VarRegion>(R) || isa<ObjCIvarRegion>(R))) |
| 186 | return store; |
Ted Kremenek | 82cd37c | 2009-08-21 23:25:54 +0000 | [diff] [blame] | 187 | |
Ted Kremenek | ab2f43c | 2009-08-25 23:29:04 +0000 | [diff] [blame] | 188 | const TypedRegion *TyR = cast<TypedRegion>(R); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 189 | |
Ted Kremenek | ab2f43c | 2009-08-25 23:29:04 +0000 | [diff] [blame] | 190 | // Do not bind to arrays. We need to explicitly check for this so that |
| 191 | // we do not encounter any weirdness of trying to load/store from arrays. |
| 192 | if (TyR->isBoundable() && TyR->getValueType(C)->isArrayType()) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 193 | return store; |
Ted Kremenek | ab2f43c | 2009-08-25 23:29:04 +0000 | [diff] [blame] | 194 | |
Zhongxing Xu | c2a650a | 2009-06-28 09:26:15 +0000 | [diff] [blame] | 195 | if (nonloc::LocAsInteger *X = dyn_cast<nonloc::LocAsInteger>(&V)) { |
| 196 | // Only convert 'V' to a location iff the underlying region type |
| 197 | // is a location as well. |
| 198 | // FIXME: We are allowing a store of an arbitrary location to |
| 199 | // a pointer. We may wish to flag a type error here if the types |
| 200 | // are incompatible. This may also cause lots of breakage |
| 201 | // elsewhere. Food for thought. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 202 | if (TyR->isBoundable() && Loc::IsLocType(TyR->getValueType(C))) |
Ted Kremenek | ab2f43c | 2009-08-25 23:29:04 +0000 | [diff] [blame] | 203 | V = X->getLoc(); |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 204 | } |
Zhongxing Xu | c2a650a | 2009-06-28 09:26:15 +0000 | [diff] [blame] | 205 | |
| 206 | BindingsTy B = GetBindings(store); |
| 207 | return V.isUnknown() |
| 208 | ? VBFactory.Remove(B, R).getRoot() |
| 209 | : VBFactory.Add(B, R, V).getRoot(); |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 210 | } |
| 211 | |
Ted Kremenek | c6ed384 | 2009-01-07 22:56:17 +0000 | [diff] [blame] | 212 | Store BasicStoreManager::Remove(Store store, Loc loc) { |
| 213 | switch (loc.getSubKind()) { |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 214 | case loc::MemRegionKind: { |
Ted Kremenek | f684d56 | 2009-03-05 18:08:28 +0000 | [diff] [blame] | 215 | const MemRegion* R = cast<loc::MemRegionVal>(loc).getRegion(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 216 | |
Ted Kremenek | f684d56 | 2009-03-05 18:08:28 +0000 | [diff] [blame] | 217 | if (!(isa<VarRegion>(R) || isa<ObjCIvarRegion>(R))) |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 218 | return store; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 219 | |
Ted Kremenek | f684d56 | 2009-03-05 18:08:28 +0000 | [diff] [blame] | 220 | return VBFactory.Remove(GetBindings(store), R).getRoot(); |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 221 | } |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 222 | default: |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 223 | assert ("Remove for given Loc type not yet implemented."); |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 224 | return store; |
Ted Kremenek | 4323a57 | 2008-07-10 22:03:41 +0000 | [diff] [blame] | 225 | } |
| 226 | } |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 227 | |
Zhongxing Xu | 72119c4 | 2010-02-05 05:34:29 +0000 | [diff] [blame] | 228 | Store BasicStoreManager::RemoveDeadBindings(Store store, Stmt* Loc, |
| 229 | SymbolReaper& SymReaper, |
Ted Kremenek | 2f26bc3 | 2009-08-02 04:45:08 +0000 | [diff] [blame] | 230 | llvm::SmallVectorImpl<const MemRegion*>& RegionRoots) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 231 | { |
Ted Kremenek | 2c8e788 | 2009-03-05 16:32:59 +0000 | [diff] [blame] | 232 | BindingsTy B = GetBindings(store); |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 233 | typedef SVal::symbol_iterator symbol_iterator; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 234 | |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 235 | // Iterate over the variable bindings. |
Ted Kremenek | 2c8e788 | 2009-03-05 16:32:59 +0000 | [diff] [blame] | 236 | for (BindingsTy::iterator I=B.begin(), E=B.end(); I!=E ; ++I) { |
Ted Kremenek | f684d56 | 2009-03-05 18:08:28 +0000 | [diff] [blame] | 237 | if (const VarRegion *VR = dyn_cast<VarRegion>(I.getKey())) { |
Ted Kremenek | edeb5b6 | 2009-12-04 20:32:20 +0000 | [diff] [blame] | 238 | if (SymReaper.isLive(Loc, VR)) |
Ted Kremenek | f684d56 | 2009-03-05 18:08:28 +0000 | [diff] [blame] | 239 | RegionRoots.push_back(VR); |
| 240 | else |
| 241 | continue; |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 242 | } |
Ted Kremenek | f684d56 | 2009-03-05 18:08:28 +0000 | [diff] [blame] | 243 | else if (isa<ObjCIvarRegion>(I.getKey())) { |
| 244 | RegionRoots.push_back(I.getKey()); |
| 245 | } |
| 246 | else |
| 247 | continue; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 248 | |
Ted Kremenek | f684d56 | 2009-03-05 18:08:28 +0000 | [diff] [blame] | 249 | // Mark the bindings in the data as live. |
| 250 | SVal X = I.getData(); |
| 251 | for (symbol_iterator SI=X.symbol_begin(), SE=X.symbol_end(); SI!=SE; ++SI) |
| 252 | SymReaper.markLive(*SI); |
Ted Kremenek | be91224 | 2009-03-05 16:31:07 +0000 | [diff] [blame] | 253 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 254 | |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 255 | // Scan for live variables and live symbols. |
Ted Kremenek | f684d56 | 2009-03-05 18:08:28 +0000 | [diff] [blame] | 256 | llvm::SmallPtrSet<const MemRegion*, 10> Marked; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 257 | |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 258 | while (!RegionRoots.empty()) { |
Ted Kremenek | 134e749 | 2008-10-17 22:52:40 +0000 | [diff] [blame] | 259 | const MemRegion* MR = RegionRoots.back(); |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 260 | RegionRoots.pop_back(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 261 | |
Ted Kremenek | 134e749 | 2008-10-17 22:52:40 +0000 | [diff] [blame] | 262 | while (MR) { |
| 263 | if (const SymbolicRegion* SymR = dyn_cast<SymbolicRegion>(MR)) { |
Ted Kremenek | 241677a | 2009-01-21 22:26:05 +0000 | [diff] [blame] | 264 | SymReaper.markLive(SymR->getSymbol()); |
Ted Kremenek | 134e749 | 2008-10-17 22:52:40 +0000 | [diff] [blame] | 265 | break; |
| 266 | } |
Ted Kremenek | f684d56 | 2009-03-05 18:08:28 +0000 | [diff] [blame] | 267 | else if (isa<VarRegion>(MR) || isa<ObjCIvarRegion>(MR)) { |
| 268 | if (Marked.count(MR)) |
Ted Kremenek | 134e749 | 2008-10-17 22:52:40 +0000 | [diff] [blame] | 269 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 270 | |
| 271 | Marked.insert(MR); |
Zhongxing Xu | 72119c4 | 2010-02-05 05:34:29 +0000 | [diff] [blame] | 272 | SVal X = Retrieve(store, loc::MemRegionVal(MR)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 273 | |
Ted Kremenek | 134e749 | 2008-10-17 22:52:40 +0000 | [diff] [blame] | 274 | // FIXME: We need to handle symbols nested in region definitions. |
Ted Kremenek | 241677a | 2009-01-21 22:26:05 +0000 | [diff] [blame] | 275 | for (symbol_iterator SI=X.symbol_begin(),SE=X.symbol_end();SI!=SE;++SI) |
| 276 | SymReaper.markLive(*SI); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 277 | |
Ted Kremenek | 134e749 | 2008-10-17 22:52:40 +0000 | [diff] [blame] | 278 | if (!isa<loc::MemRegionVal>(X)) |
| 279 | break; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 280 | |
Ted Kremenek | 134e749 | 2008-10-17 22:52:40 +0000 | [diff] [blame] | 281 | const loc::MemRegionVal& LVD = cast<loc::MemRegionVal>(X); |
| 282 | RegionRoots.push_back(LVD.getRegion()); |
| 283 | break; |
| 284 | } |
| 285 | else if (const SubRegion* R = dyn_cast<SubRegion>(MR)) |
| 286 | MR = R->getSuperRegion(); |
| 287 | else |
| 288 | break; |
| 289 | } |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 290 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 291 | |
| 292 | // Remove dead variable bindings. |
Ted Kremenek | 2c8e788 | 2009-03-05 16:32:59 +0000 | [diff] [blame] | 293 | for (BindingsTy::iterator I=B.begin(), E=B.end(); I!=E ; ++I) { |
Ted Kremenek | f684d56 | 2009-03-05 18:08:28 +0000 | [diff] [blame] | 294 | const MemRegion* R = I.getKey(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 295 | |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 296 | if (!Marked.count(R)) { |
Zhongxing Xu | d91ee27 | 2009-06-23 09:02:15 +0000 | [diff] [blame] | 297 | store = Remove(store, ValMgr.makeLoc(R)); |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 298 | SVal X = I.getData(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 299 | |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 300 | for (symbol_iterator SI=X.symbol_begin(), SE=X.symbol_end(); SI!=SE; ++SI) |
Ted Kremenek | 241677a | 2009-01-21 22:26:05 +0000 | [diff] [blame] | 301 | SymReaper.maybeDead(*SI); |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 302 | } |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 303 | } |
Ted Kremenek | f684d56 | 2009-03-05 18:08:28 +0000 | [diff] [blame] | 304 | |
Zhongxing Xu | 72119c4 | 2010-02-05 05:34:29 +0000 | [diff] [blame] | 305 | return store; |
Ted Kremenek | f59bf48 | 2008-07-17 18:38:48 +0000 | [diff] [blame] | 306 | } |
Ted Kremenek | caa3724 | 2008-08-19 16:51:45 +0000 | [diff] [blame] | 307 | |
Ted Kremenek | 82cd37c | 2009-08-21 23:25:54 +0000 | [diff] [blame] | 308 | Store BasicStoreManager::scanForIvars(Stmt *B, const Decl* SelfDecl, |
| 309 | const MemRegion *SelfRegion, Store St) { |
Ted Kremenek | f684d56 | 2009-03-05 18:08:28 +0000 | [diff] [blame] | 310 | for (Stmt::child_iterator CI=B->child_begin(), CE=B->child_end(); |
| 311 | CI != CE; ++CI) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 312 | |
Ted Kremenek | f684d56 | 2009-03-05 18:08:28 +0000 | [diff] [blame] | 313 | if (!*CI) |
| 314 | continue; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 315 | |
Ted Kremenek | f684d56 | 2009-03-05 18:08:28 +0000 | [diff] [blame] | 316 | // Check if the statement is an ivar reference. We only |
| 317 | // care about self.ivar. |
| 318 | if (ObjCIvarRefExpr *IV = dyn_cast<ObjCIvarRefExpr>(*CI)) { |
| 319 | const Expr *Base = IV->getBase()->IgnoreParenCasts(); |
| 320 | if (const DeclRefExpr *DR = dyn_cast<DeclRefExpr>(Base)) { |
| 321 | if (DR->getDecl() == SelfDecl) { |
| 322 | const MemRegion *IVR = MRMgr.getObjCIvarRegion(IV->getDecl(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 323 | SelfRegion); |
| 324 | SVal X = ValMgr.getRegionValueSymbolVal(IVR); |
Zhongxing Xu | b241cf6 | 2010-02-08 08:48:05 +0000 | [diff] [blame] | 325 | St = Bind(St, ValMgr.makeLoc(IVR), X); |
Ted Kremenek | f684d56 | 2009-03-05 18:08:28 +0000 | [diff] [blame] | 326 | } |
| 327 | } |
| 328 | } |
| 329 | else |
Ted Kremenek | 82cd37c | 2009-08-21 23:25:54 +0000 | [diff] [blame] | 330 | St = scanForIvars(*CI, SelfDecl, SelfRegion, St); |
Ted Kremenek | f684d56 | 2009-03-05 18:08:28 +0000 | [diff] [blame] | 331 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 332 | |
Ted Kremenek | f684d56 | 2009-03-05 18:08:28 +0000 | [diff] [blame] | 333 | return St; |
| 334 | } |
| 335 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 336 | Store BasicStoreManager::getInitialStore(const LocationContext *InitLoc) { |
Ted Kremenek | caa3724 | 2008-08-19 16:51:45 +0000 | [diff] [blame] | 337 | // The LiveVariables information already has a compilation of all VarDecls |
| 338 | // used in the function. Iterate through this set, and "symbolicate" |
| 339 | // any VarDecl whose value originally comes from outside the function. |
Ted Kremenek | caa3724 | 2008-08-19 16:51:45 +0000 | [diff] [blame] | 340 | typedef LiveVariables::AnalysisDataTy LVDataTy; |
Zhongxing Xu | 17fd863 | 2009-08-17 06:19:58 +0000 | [diff] [blame] | 341 | LVDataTy& D = InitLoc->getLiveVariables()->getAnalysisData(); |
Ted Kremenek | caa3724 | 2008-08-19 16:51:45 +0000 | [diff] [blame] | 342 | Store St = VBFactory.GetEmptyMap().getRoot(); |
| 343 | |
| 344 | for (LVDataTy::decl_iterator I=D.begin_decl(), E=D.end_decl(); I != E; ++I) { |
Douglas Gregor | 8e9bebd | 2008-10-21 16:13:35 +0000 | [diff] [blame] | 345 | NamedDecl* ND = const_cast<NamedDecl*>(I->first); |
Ted Kremenek | caa3724 | 2008-08-19 16:51:45 +0000 | [diff] [blame] | 346 | |
Ted Kremenek | 9deb0e3 | 2008-10-24 20:32:16 +0000 | [diff] [blame] | 347 | // Handle implicit parameters. |
| 348 | if (ImplicitParamDecl* PD = dyn_cast<ImplicitParamDecl>(ND)) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 349 | const Decl& CD = *InitLoc->getDecl(); |
Ted Kremenek | 9deb0e3 | 2008-10-24 20:32:16 +0000 | [diff] [blame] | 350 | if (const ObjCMethodDecl* MD = dyn_cast<ObjCMethodDecl>(&CD)) { |
| 351 | if (MD->getSelfDecl() == PD) { |
Ted Kremenek | c410d4d | 2009-12-16 23:53:37 +0000 | [diff] [blame] | 352 | // FIXME: Add type constraints (when they become available) to |
| 353 | // SelfRegion? (i.e., it implements MD->getClassInterface()). |
| 354 | const MemRegion *VR = MRMgr.getVarRegion(PD, InitLoc); |
| 355 | const MemRegion *SelfRegion = |
| 356 | ValMgr.getRegionValueSymbolVal(VR).getAsRegion(); |
| 357 | assert(SelfRegion); |
Zhongxing Xu | b241cf6 | 2010-02-08 08:48:05 +0000 | [diff] [blame] | 358 | St = Bind(St, ValMgr.makeLoc(VR), loc::MemRegionVal(SelfRegion)); |
Ted Kremenek | f684d56 | 2009-03-05 18:08:28 +0000 | [diff] [blame] | 359 | // Scan the method for ivar references. While this requires an |
| 360 | // entire AST scan, the cost should not be high in practice. |
Ted Kremenek | 82cd37c | 2009-08-21 23:25:54 +0000 | [diff] [blame] | 361 | St = scanForIvars(MD->getBody(), PD, SelfRegion, St); |
Ted Kremenek | 9deb0e3 | 2008-10-24 20:32:16 +0000 | [diff] [blame] | 362 | } |
| 363 | } |
| 364 | } |
| 365 | else if (VarDecl* VD = dyn_cast<VarDecl>(ND)) { |
Ted Kremenek | 693de5d | 2009-03-23 15:42:58 +0000 | [diff] [blame] | 366 | // Only handle simple types that we can symbolicate. |
| 367 | if (!SymbolManager::canSymbolicate(VD->getType())) |
| 368 | continue; |
Ted Kremenek | caa3724 | 2008-08-19 16:51:45 +0000 | [diff] [blame] | 369 | |
Ted Kremenek | ec099f1 | 2009-03-18 22:10:22 +0000 | [diff] [blame] | 370 | // Initialize globals and parameters to symbolic values. |
| 371 | // Initialize local variables to undefined. |
Ted Kremenek | d17da2b | 2009-08-21 22:28:32 +0000 | [diff] [blame] | 372 | const MemRegion *R = ValMgr.getRegionManager().getVarRegion(VD, InitLoc); |
Ted Kremenek | 5b9bd21 | 2009-09-11 22:07:28 +0000 | [diff] [blame] | 373 | SVal X = UndefinedVal(); |
| 374 | if (R->hasGlobalsOrParametersStorage()) |
| 375 | X = ValMgr.getRegionValueSymbolVal(R); |
Ted Kremenek | caa3724 | 2008-08-19 16:51:45 +0000 | [diff] [blame] | 376 | |
Zhongxing Xu | b241cf6 | 2010-02-08 08:48:05 +0000 | [diff] [blame] | 377 | St = Bind(St, ValMgr.makeLoc(R), X); |
Ted Kremenek | caa3724 | 2008-08-19 16:51:45 +0000 | [diff] [blame] | 378 | } |
| 379 | } |
| 380 | return St; |
| 381 | } |
Ted Kremenek | a622d8c | 2008-08-19 22:24:03 +0000 | [diff] [blame] | 382 | |
Ted Kremenek | f6f56d4 | 2009-11-04 00:09:15 +0000 | [diff] [blame] | 383 | Store BasicStoreManager::BindDeclInternal(Store store, const VarRegion* VR, |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 384 | SVal* InitVal) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 385 | |
Ted Kremenek | e53c069 | 2008-08-23 00:50:55 +0000 | [diff] [blame] | 386 | BasicValueFactory& BasicVals = StateMgr.getBasicVals(); |
Ted Kremenek | f6f56d4 | 2009-11-04 00:09:15 +0000 | [diff] [blame] | 387 | const VarDecl *VD = VR->getDecl(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 388 | |
Zhongxing Xu | bbe8ff4 | 2008-08-21 22:34:01 +0000 | [diff] [blame] | 389 | // BasicStore does not model arrays and structs. |
| 390 | if (VD->getType()->isArrayType() || VD->getType()->isStructureType()) |
| 391 | return store; |
| 392 | |
| 393 | if (VD->hasGlobalStorage()) { |
| 394 | // Handle variables with global storage: extern, static, PrivateExtern. |
| 395 | |
| 396 | // FIXME:: static variables may have an initializer, but the second time a |
| 397 | // function is called those values may not be current. Currently, a function |
| 398 | // will not be called more than once. |
| 399 | |
| 400 | // Static global variables should not be visited here. |
| 401 | assert(!(VD->getStorageClass() == VarDecl::Static && |
| 402 | VD->isFileVarDecl())); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 403 | |
Zhongxing Xu | bbe8ff4 | 2008-08-21 22:34:01 +0000 | [diff] [blame] | 404 | // Process static variables. |
| 405 | if (VD->getStorageClass() == VarDecl::Static) { |
| 406 | // C99: 6.7.8 Initialization |
| 407 | // If an object that has static storage duration is not initialized |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 408 | // explicitly, then: |
| 409 | // —if it has pointer type, it is initialized to a null pointer; |
| 410 | // —if it has arithmetic type, it is initialized to (positive or |
Zhongxing Xu | bbe8ff4 | 2008-08-21 22:34:01 +0000 | [diff] [blame] | 411 | // unsigned) zero; |
Ted Kremenek | 42577d1 | 2008-11-12 19:18:35 +0000 | [diff] [blame] | 412 | if (!InitVal) { |
Zhongxing Xu | bbe8ff4 | 2008-08-21 22:34:01 +0000 | [diff] [blame] | 413 | QualType T = VD->getType(); |
Zhongxing Xu | 1c96b24 | 2008-10-17 05:57:07 +0000 | [diff] [blame] | 414 | if (Loc::IsLocType(T)) |
Zhongxing Xu | b241cf6 | 2010-02-08 08:48:05 +0000 | [diff] [blame] | 415 | store = Bind(store, loc::MemRegionVal(VR), |
Zhongxing Xu | 8485ec6 | 2008-10-21 06:27:32 +0000 | [diff] [blame] | 416 | loc::ConcreteInt(BasicVals.getValue(0, T))); |
Zhongxing Xu | bbe8ff4 | 2008-08-21 22:34:01 +0000 | [diff] [blame] | 417 | else if (T->isIntegerType()) |
Zhongxing Xu | b241cf6 | 2010-02-08 08:48:05 +0000 | [diff] [blame] | 418 | store = Bind(store, loc::MemRegionVal(VR), |
Zhongxing Xu | 8485ec6 | 2008-10-21 06:27:32 +0000 | [diff] [blame] | 419 | nonloc::ConcreteInt(BasicVals.getValue(0, T))); |
Zhongxing Xu | bbe8ff4 | 2008-08-21 22:34:01 +0000 | [diff] [blame] | 420 | else { |
| 421 | // assert(0 && "ignore other types of variables"); |
| 422 | } |
| 423 | } else { |
Zhongxing Xu | b241cf6 | 2010-02-08 08:48:05 +0000 | [diff] [blame] | 424 | store = Bind(store, loc::MemRegionVal(VR), *InitVal); |
Zhongxing Xu | bbe8ff4 | 2008-08-21 22:34:01 +0000 | [diff] [blame] | 425 | } |
| 426 | } |
| 427 | } else { |
| 428 | // Process local scalar variables. |
| 429 | QualType T = VD->getType(); |
Ted Kremenek | f6c9f42 | 2009-07-03 00:36:16 +0000 | [diff] [blame] | 430 | if (ValMgr.getSymbolManager().canSymbolicate(T)) { |
Ted Kremenek | 42577d1 | 2008-11-12 19:18:35 +0000 | [diff] [blame] | 431 | SVal V = InitVal ? *InitVal : UndefinedVal(); |
Zhongxing Xu | b241cf6 | 2010-02-08 08:48:05 +0000 | [diff] [blame] | 432 | store = Bind(store, loc::MemRegionVal(VR), V); |
Zhongxing Xu | bbe8ff4 | 2008-08-21 22:34:01 +0000 | [diff] [blame] | 433 | } |
| 434 | } |
| 435 | |
| 436 | return store; |
| 437 | } |
| 438 | |
Ted Kremenek | 53ba0b6 | 2009-06-24 23:06:47 +0000 | [diff] [blame] | 439 | void BasicStoreManager::print(Store store, llvm::raw_ostream& Out, |
Ted Kremenek | a622d8c | 2008-08-19 22:24:03 +0000 | [diff] [blame] | 440 | const char* nl, const char *sep) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 441 | |
Ted Kremenek | 2c8e788 | 2009-03-05 16:32:59 +0000 | [diff] [blame] | 442 | BindingsTy B = GetBindings(store); |
Ted Kremenek | a622d8c | 2008-08-19 22:24:03 +0000 | [diff] [blame] | 443 | Out << "Variables:" << nl; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 444 | |
Ted Kremenek | a622d8c | 2008-08-19 22:24:03 +0000 | [diff] [blame] | 445 | bool isFirst = true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 446 | |
Ted Kremenek | 2c8e788 | 2009-03-05 16:32:59 +0000 | [diff] [blame] | 447 | for (BindingsTy::iterator I=B.begin(), E=B.end(); I != E; ++I) { |
Ted Kremenek | 53ba0b6 | 2009-06-24 23:06:47 +0000 | [diff] [blame] | 448 | if (isFirst) |
| 449 | isFirst = false; |
| 450 | else |
| 451 | Out << nl; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 452 | |
Ted Kremenek | 6f9b3a4 | 2009-07-13 23:53:06 +0000 | [diff] [blame] | 453 | Out << ' ' << I.getKey() << " : " << I.getData(); |
Ted Kremenek | a622d8c | 2008-08-19 22:24:03 +0000 | [diff] [blame] | 454 | } |
| 455 | } |
Ted Kremenek | 2bc39c6 | 2008-08-29 00:47:32 +0000 | [diff] [blame] | 456 | |
Ted Kremenek | 60dbad8 | 2008-09-03 03:06:11 +0000 | [diff] [blame] | 457 | |
| 458 | void BasicStoreManager::iterBindings(Store store, BindingsHandler& f) { |
Ted Kremenek | 2c8e788 | 2009-03-05 16:32:59 +0000 | [diff] [blame] | 459 | BindingsTy B = GetBindings(store); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 460 | |
Ted Kremenek | 2c8e788 | 2009-03-05 16:32:59 +0000 | [diff] [blame] | 461 | for (BindingsTy::iterator I=B.begin(), E=B.end(); I != E; ++I) |
Ted Kremenek | be91224 | 2009-03-05 16:31:07 +0000 | [diff] [blame] | 462 | f.HandleBinding(*this, store, I.getKey(), I.getData()); |
Ted Kremenek | 9e24049 | 2008-10-04 05:50:14 +0000 | [diff] [blame] | 463 | |
Ted Kremenek | 2bc39c6 | 2008-08-29 00:47:32 +0000 | [diff] [blame] | 464 | } |
| 465 | |
Ted Kremenek | 60dbad8 | 2008-09-03 03:06:11 +0000 | [diff] [blame] | 466 | StoreManager::BindingsHandler::~BindingsHandler() {} |
Ted Kremenek | 1004a9f | 2009-07-29 18:16:25 +0000 | [diff] [blame] | 467 | |
| 468 | //===----------------------------------------------------------------------===// |
| 469 | // Binding invalidation. |
| 470 | //===----------------------------------------------------------------------===// |
| 471 | |
Zhongxing Xu | b4a9c61 | 2010-02-05 05:06:13 +0000 | [diff] [blame] | 472 | Store BasicStoreManager::InvalidateRegion(Store store, |
| 473 | const MemRegion *R, |
| 474 | const Expr *E, |
| 475 | unsigned Count, |
| 476 | InvalidatedSymbols *IS) { |
Zhongxing Xu | 479529e | 2009-11-10 02:17:20 +0000 | [diff] [blame] | 477 | R = R->StripCasts(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 478 | |
Ted Kremenek | 1004a9f | 2009-07-29 18:16:25 +0000 | [diff] [blame] | 479 | if (!(isa<VarRegion>(R) || isa<ObjCIvarRegion>(R))) |
Zhongxing Xu | b4a9c61 | 2010-02-05 05:06:13 +0000 | [diff] [blame] | 480 | return store; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 481 | |
Ted Kremenek | 473e167 | 2009-10-16 00:30:49 +0000 | [diff] [blame] | 482 | if (IS) { |
Zhongxing Xu | b4a9c61 | 2010-02-05 05:06:13 +0000 | [diff] [blame] | 483 | BindingsTy B = GetBindings(store); |
Ted Kremenek | 473e167 | 2009-10-16 00:30:49 +0000 | [diff] [blame] | 484 | if (BindingsTy::data_type *Val = B.lookup(R)) { |
| 485 | if (SymbolRef Sym = Val->getAsSymbol()) |
| 486 | IS->insert(Sym); |
| 487 | } |
| 488 | } |
| 489 | |
Ted Kremenek | 1004a9f | 2009-07-29 18:16:25 +0000 | [diff] [blame] | 490 | QualType T = cast<TypedRegion>(R)->getValueType(R->getContext()); |
Ted Kremenek | 8780679 | 2009-09-27 20:45:21 +0000 | [diff] [blame] | 491 | SVal V = ValMgr.getConjuredSymbolVal(R, E, T, Count); |
Zhongxing Xu | b4a9c61 | 2010-02-05 05:06:13 +0000 | [diff] [blame] | 492 | return Bind(store, loc::MemRegionVal(R), V); |
Ted Kremenek | 1004a9f | 2009-07-29 18:16:25 +0000 | [diff] [blame] | 493 | } |
| 494 | |