Zhongxing Xu | 1789275 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 1 | //== RegionStore.cpp - Field-sensitive store model --------------*- 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 a basic region store model. In this model, we do have field |
| 11 | // sensitivity. But we assume nothing about the heap shape. So recursive data |
| 12 | // structures are largely ignored. Basically we do 1-limiting analysis. |
| 13 | // Parameter pointers are assumed with no aliasing. Pointee objects of |
| 14 | // parameters are created lazily. |
| 15 | // |
| 16 | //===----------------------------------------------------------------------===// |
| 17 | #include "clang/Analysis/PathSensitive/MemRegion.h" |
Zhongxing Xu | 0b14331 | 2009-08-21 13:25:15 +0000 | [diff] [blame] | 18 | #include "clang/Analysis/PathSensitive/AnalysisContext.h" |
Zhongxing Xu | 1789275 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 19 | #include "clang/Analysis/PathSensitive/GRState.h" |
Zhongxing Xu | dc0a25d | 2008-11-16 04:07:26 +0000 | [diff] [blame] | 20 | #include "clang/Analysis/PathSensitive/GRStateTrait.h" |
Zhongxing Xu | 1789275 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 21 | #include "clang/Analysis/Analyses/LiveVariables.h" |
Ted Kremenek | d4e5a60 | 2009-08-06 21:43:54 +0000 | [diff] [blame] | 22 | #include "clang/Analysis/Support/Optional.h" |
Zhongxing Xu | 41fd018 | 2009-05-06 11:51:48 +0000 | [diff] [blame] | 23 | #include "clang/Basic/TargetInfo.h" |
Zhongxing Xu | 1789275 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 24 | |
| 25 | #include "llvm/ADT/ImmutableMap.h" |
Zhongxing Xu | dc0a25d | 2008-11-16 04:07:26 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/ImmutableList.h" |
Zhongxing Xu | a071eb0 | 2008-10-24 06:01:33 +0000 | [diff] [blame] | 27 | #include "llvm/Support/raw_ostream.h" |
Zhongxing Xu | 1789275 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 28 | |
| 29 | using namespace clang; |
| 30 | |
Ted Kremenek | 356e9d6 | 2009-07-22 04:35:42 +0000 | [diff] [blame] | 31 | #define HEAP_UNDEFINED 0 |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 32 | #define USE_EXPLICIT_COMPOUND 0 |
Ted Kremenek | 356e9d6 | 2009-07-22 04:35:42 +0000 | [diff] [blame] | 33 | |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 34 | namespace { |
| 35 | class BindingVal { |
| 36 | public: |
| 37 | enum BindingKind { Direct, Default }; |
| 38 | private: |
| 39 | SVal Value; |
| 40 | BindingKind Kind; |
| 41 | |
| 42 | public: |
| 43 | BindingVal(SVal V, BindingKind K) : Value(V), Kind(K) {} |
| 44 | |
| 45 | bool isDefault() const { return Kind == Default; } |
| 46 | |
| 47 | const SVal *getValue() const { return &Value; } |
| 48 | |
| 49 | const SVal *getDirectValue() const { return isDefault() ? 0 : &Value; } |
| 50 | |
| 51 | const SVal *getDefaultValue() const { return isDefault() ? &Value : 0; } |
| 52 | |
| 53 | void Profile(llvm::FoldingSetNodeID& ID) const { |
| 54 | Value.Profile(ID); |
| 55 | ID.AddInteger(Kind); |
| 56 | } |
| 57 | |
| 58 | inline bool operator==(const BindingVal& R) const { |
| 59 | return Value == R.Value && Kind == R.Kind; |
| 60 | } |
| 61 | |
| 62 | inline bool operator!=(const BindingVal& R) const { |
| 63 | return !(*this == R); |
| 64 | } |
| 65 | }; |
| 66 | } |
| 67 | |
| 68 | namespace llvm { |
| 69 | static inline |
| 70 | llvm::raw_ostream& operator<<(llvm::raw_ostream& os, BindingVal V) { |
| 71 | if (V.isDefault()) |
| 72 | os << "(default) "; |
| 73 | else |
| 74 | os << "(direct) "; |
| 75 | os << *V.getValue(); |
| 76 | return os; |
| 77 | } |
| 78 | } // end llvm namespace |
| 79 | |
Zhongxing Xu | baf03a7 | 2008-11-24 09:44:56 +0000 | [diff] [blame] | 80 | // Actual Store type. |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 81 | typedef llvm::ImmutableMap<const MemRegion*, BindingVal> RegionBindings; |
Zhongxing Xu | baf03a7 | 2008-11-24 09:44:56 +0000 | [diff] [blame] | 82 | |
Ted Kremenek | 50dc1b3 | 2008-12-24 01:05:03 +0000 | [diff] [blame] | 83 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 84 | // Fine-grained control of RegionStoreManager. |
| 85 | //===----------------------------------------------------------------------===// |
| 86 | |
| 87 | namespace { |
Kovarththanan Rajaratnam | ba5fb5a | 2009-11-28 06:07:30 +0000 | [diff] [blame] | 88 | struct minimal_features_tag {}; |
| 89 | struct maximal_features_tag {}; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 90 | |
Kovarththanan Rajaratnam | ba5fb5a | 2009-11-28 06:07:30 +0000 | [diff] [blame] | 91 | class RegionStoreFeatures { |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 92 | bool SupportsFields; |
| 93 | bool SupportsRemaining; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 94 | |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 95 | public: |
| 96 | RegionStoreFeatures(minimal_features_tag) : |
| 97 | SupportsFields(false), SupportsRemaining(false) {} |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 98 | |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 99 | RegionStoreFeatures(maximal_features_tag) : |
| 100 | SupportsFields(true), SupportsRemaining(false) {} |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 101 | |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 102 | void enableFields(bool t) { SupportsFields = t; } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 103 | |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 104 | bool supportsFields() const { return SupportsFields; } |
| 105 | bool supportsRemaining() const { return SupportsRemaining; } |
| 106 | }; |
| 107 | } |
| 108 | |
| 109 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 50dc1b3 | 2008-12-24 01:05:03 +0000 | [diff] [blame] | 110 | // Region "Extents" |
| 111 | //===----------------------------------------------------------------------===// |
| 112 | // |
| 113 | // MemRegions represent chunks of memory with a size (their "extent"). This |
| 114 | // GDM entry tracks the extents for regions. Extents are in bytes. |
Ted Kremenek | d6cfbe4 | 2009-01-07 22:18:50 +0000 | [diff] [blame] | 115 | // |
Kovarththanan Rajaratnam | ba5fb5a | 2009-11-28 06:07:30 +0000 | [diff] [blame] | 116 | namespace { class RegionExtents {}; } |
Ted Kremenek | 50dc1b3 | 2008-12-24 01:05:03 +0000 | [diff] [blame] | 117 | static int RegionExtentsIndex = 0; |
Zhongxing Xu | baf03a7 | 2008-11-24 09:44:56 +0000 | [diff] [blame] | 118 | namespace clang { |
Ted Kremenek | 50dc1b3 | 2008-12-24 01:05:03 +0000 | [diff] [blame] | 119 | template<> struct GRStateTrait<RegionExtents> |
| 120 | : public GRStatePartialTrait<llvm::ImmutableMap<const MemRegion*, SVal> > { |
| 121 | static void* GDMIndex() { return &RegionExtentsIndex; } |
| 122 | }; |
Zhongxing Xu | baf03a7 | 2008-11-24 09:44:56 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Ted Kremenek | 50dc1b3 | 2008-12-24 01:05:03 +0000 | [diff] [blame] | 125 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 126 | // Utility functions. |
| 127 | //===----------------------------------------------------------------------===// |
| 128 | |
| 129 | static bool IsAnyPointerOrIntptr(QualType ty, ASTContext &Ctx) { |
| 130 | if (ty->isAnyPointerType()) |
| 131 | return true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 132 | |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 133 | return ty->isIntegerType() && ty->isScalarType() && |
| 134 | Ctx.getTypeSize(ty) == Ctx.getTypeSize(Ctx.VoidPtrTy); |
| 135 | } |
| 136 | |
| 137 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 50dc1b3 | 2008-12-24 01:05:03 +0000 | [diff] [blame] | 138 | // Main RegionStore logic. |
| 139 | //===----------------------------------------------------------------------===// |
Ted Kremenek | c48ea6e | 2008-12-04 02:08:27 +0000 | [diff] [blame] | 140 | |
Zhongxing Xu | 1789275 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 141 | namespace { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 142 | |
Kovarththanan Rajaratnam | ba5fb5a | 2009-11-28 06:07:30 +0000 | [diff] [blame] | 143 | class RegionStoreSubRegionMap : public SubRegionMap { |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 144 | typedef llvm::ImmutableSet<const MemRegion*> SetTy; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 145 | typedef llvm::DenseMap<const MemRegion*, SetTy> Map; |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 146 | SetTy::Factory F; |
Ted Kremenek | 59e8f11 | 2009-03-03 01:35:36 +0000 | [diff] [blame] | 147 | Map M; |
Ted Kremenek | 59e8f11 | 2009-03-03 01:35:36 +0000 | [diff] [blame] | 148 | public: |
Ted Kremenek | d8c0192 | 2009-08-05 19:09:24 +0000 | [diff] [blame] | 149 | bool add(const MemRegion* Parent, const MemRegion* SubRegion) { |
Ted Kremenek | 59e8f11 | 2009-03-03 01:35:36 +0000 | [diff] [blame] | 150 | Map::iterator I = M.find(Parent); |
Ted Kremenek | d8c0192 | 2009-08-05 19:09:24 +0000 | [diff] [blame] | 151 | |
| 152 | if (I == M.end()) { |
Ted Kremenek | 4ed4598 | 2009-08-05 05:31:02 +0000 | [diff] [blame] | 153 | M.insert(std::make_pair(Parent, F.Add(F.GetEmptySet(), SubRegion))); |
Ted Kremenek | d8c0192 | 2009-08-05 19:09:24 +0000 | [diff] [blame] | 154 | return true; |
| 155 | } |
| 156 | |
| 157 | I->second = F.Add(I->second, SubRegion); |
| 158 | return false; |
Ted Kremenek | 59e8f11 | 2009-03-03 01:35:36 +0000 | [diff] [blame] | 159 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 160 | |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 161 | void process(llvm::SmallVectorImpl<const SubRegion*> &WL, const SubRegion *R); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 162 | |
Ted Kremenek | 59e8f11 | 2009-03-03 01:35:36 +0000 | [diff] [blame] | 163 | ~RegionStoreSubRegionMap() {} |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 164 | |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 165 | bool iterSubRegions(const MemRegion* Parent, Visitor& V) const { |
Jeffrey Yasskin | 3958b50 | 2009-11-10 01:17:45 +0000 | [diff] [blame] | 166 | Map::const_iterator I = M.find(Parent); |
Ted Kremenek | 59e8f11 | 2009-03-03 01:35:36 +0000 | [diff] [blame] | 167 | |
| 168 | if (I == M.end()) |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 169 | return true; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 170 | |
Ted Kremenek | 59e8f11 | 2009-03-03 01:35:36 +0000 | [diff] [blame] | 171 | llvm::ImmutableSet<const MemRegion*> S = I->second; |
| 172 | for (llvm::ImmutableSet<const MemRegion*>::iterator SI=S.begin(),SE=S.end(); |
| 173 | SI != SE; ++SI) { |
| 174 | if (!V.Visit(Parent, *SI)) |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 175 | return false; |
Ted Kremenek | 59e8f11 | 2009-03-03 01:35:36 +0000 | [diff] [blame] | 176 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 177 | |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 178 | return true; |
Ted Kremenek | 59e8f11 | 2009-03-03 01:35:36 +0000 | [diff] [blame] | 179 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 180 | |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 181 | typedef SetTy::iterator iterator; |
| 182 | |
| 183 | std::pair<iterator, iterator> begin_end(const MemRegion *R) { |
| 184 | Map::iterator I = M.find(R); |
| 185 | SetTy S = I == M.end() ? F.GetEmptySet() : I->second; |
| 186 | return std::make_pair(S.begin(), S.end()); |
| 187 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 188 | }; |
Ted Kremenek | 59e8f11 | 2009-03-03 01:35:36 +0000 | [diff] [blame] | 189 | |
Kovarththanan Rajaratnam | ba5fb5a | 2009-11-28 06:07:30 +0000 | [diff] [blame] | 190 | class RegionStoreManager : public StoreManager { |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 191 | const RegionStoreFeatures Features; |
Ted Kremenek | 451ac09 | 2009-08-06 04:50:20 +0000 | [diff] [blame] | 192 | RegionBindings::Factory RBFactory; |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 193 | |
| 194 | typedef llvm::DenseMap<const GRState *, RegionStoreSubRegionMap*> SMCache; |
| 195 | SMCache SC; |
| 196 | |
Zhongxing Xu | 1789275 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 197 | public: |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 198 | RegionStoreManager(GRStateManager& mgr, const RegionStoreFeatures &f) |
Ted Kremenek | f7a0cf4 | 2009-07-29 21:43:22 +0000 | [diff] [blame] | 199 | : StoreManager(mgr), |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 200 | Features(f), |
Ted Kremenek | 82cd37c | 2009-08-21 23:25:54 +0000 | [diff] [blame] | 201 | RBFactory(mgr.getAllocator()) {} |
Zhongxing Xu | 1789275 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 202 | |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 203 | virtual ~RegionStoreManager() { |
| 204 | for (SMCache::iterator I = SC.begin(), E = SC.end(); I != E; ++I) |
| 205 | delete (*I).second; |
| 206 | } |
Zhongxing Xu | 1789275 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 207 | |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 208 | SubRegionMap *getSubRegionMap(const GRState *state); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 209 | |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 210 | RegionStoreSubRegionMap *getRegionStoreSubRegionMap(Store store); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 211 | |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 212 | Optional<SVal> getBinding(RegionBindings B, const MemRegion *R); |
| 213 | Optional<SVal> getDirectBinding(RegionBindings B, const MemRegion *R); |
Ted Kremenek | d4e5a60 | 2009-08-06 21:43:54 +0000 | [diff] [blame] | 214 | /// getDefaultBinding - Returns an SVal* representing an optional default |
| 215 | /// binding associated with a region and its subregions. |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 216 | Optional<SVal> getDefaultBinding(RegionBindings B, const MemRegion *R); |
Ted Kremenek | 027e266 | 2009-11-19 20:20:24 +0000 | [diff] [blame] | 217 | |
| 218 | /// setImplicitDefaultValue - Set the default binding for the provided |
| 219 | /// MemRegion to the value implicitly defined for compound literals when |
| 220 | /// the value is not specified. |
| 221 | const GRState *setImplicitDefaultValue(const GRState *state, |
| 222 | const MemRegion *R, |
| 223 | QualType T); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 224 | |
Ted Kremenek | 869fb4a | 2008-12-24 07:46:32 +0000 | [diff] [blame] | 225 | /// getLValueString - Returns an SVal representing the lvalue of a |
| 226 | /// StringLiteral. Within RegionStore a StringLiteral has an |
| 227 | /// associated StringRegion, and the lvalue of a StringLiteral is |
| 228 | /// the lvalue of that region. |
Zhongxing Xu | d0f8bb1 | 2009-10-14 03:33:08 +0000 | [diff] [blame] | 229 | SVal getLValueString(const StringLiteral* S); |
Zhongxing Xu | 143bf82 | 2008-10-25 14:18:57 +0000 | [diff] [blame] | 230 | |
Ted Kremenek | 869fb4a | 2008-12-24 07:46:32 +0000 | [diff] [blame] | 231 | /// getLValueCompoundLiteral - Returns an SVal representing the |
| 232 | /// lvalue of a compound literal. Within RegionStore a compound |
| 233 | /// literal has an associated region, and the lvalue of the |
| 234 | /// compound literal is the lvalue of that region. |
Zhongxing Xu | d0f8bb1 | 2009-10-14 03:33:08 +0000 | [diff] [blame] | 235 | SVal getLValueCompoundLiteral(const CompoundLiteralExpr*); |
Zhongxing Xu | f22679e | 2008-11-07 10:38:33 +0000 | [diff] [blame] | 236 | |
Ted Kremenek | 869fb4a | 2008-12-24 07:46:32 +0000 | [diff] [blame] | 237 | /// getLValueVar - Returns an SVal that represents the lvalue of a |
| 238 | /// variable. Within RegionStore a variable has an associated |
| 239 | /// VarRegion, and the lvalue of the variable is the lvalue of that region. |
Zhongxing Xu | d0f8bb1 | 2009-10-14 03:33:08 +0000 | [diff] [blame] | 240 | SVal getLValueVar(const VarDecl *VD, const LocationContext *LC); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 241 | |
Zhongxing Xu | d0f8bb1 | 2009-10-14 03:33:08 +0000 | [diff] [blame] | 242 | SVal getLValueIvar(const ObjCIvarDecl* D, SVal Base); |
Zhongxing Xu | c4bf72c | 2008-10-22 13:44:38 +0000 | [diff] [blame] | 243 | |
Zhongxing Xu | d0f8bb1 | 2009-10-14 03:33:08 +0000 | [diff] [blame] | 244 | SVal getLValueField(const FieldDecl* D, SVal Base); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 245 | |
Zhongxing Xu | d0f8bb1 | 2009-10-14 03:33:08 +0000 | [diff] [blame] | 246 | SVal getLValueFieldOrIvar(const Decl* D, SVal Base); |
Zhongxing Xu | c4bf72c | 2008-10-22 13:44:38 +0000 | [diff] [blame] | 247 | |
Zhongxing Xu | d0f8bb1 | 2009-10-14 03:33:08 +0000 | [diff] [blame] | 248 | SVal getLValueElement(QualType elementType, SVal Offset, SVal Base); |
Zhongxing Xu | b1d542a | 2008-10-24 01:09:32 +0000 | [diff] [blame] | 249 | |
Zhongxing Xu | e8a964b | 2008-11-22 13:21:46 +0000 | [diff] [blame] | 250 | |
Ted Kremenek | 869fb4a | 2008-12-24 07:46:32 +0000 | [diff] [blame] | 251 | /// ArrayToPointer - Emulates the "decay" of an array to a pointer |
| 252 | /// type. 'Array' represents the lvalue of the array being decayed |
| 253 | /// to a pointer, and the returned SVal represents the decayed |
| 254 | /// version of that lvalue (i.e., a pointer to the first element of |
| 255 | /// the array). This is called by GRExprEngine when evaluating |
| 256 | /// casts from arrays to pointers. |
Zhongxing Xu | f1d537f | 2009-03-30 05:55:46 +0000 | [diff] [blame] | 257 | SVal ArrayToPointer(Loc Array); |
Zhongxing Xu | b1d542a | 2008-10-24 01:09:32 +0000 | [diff] [blame] | 258 | |
Ted Kremenek | 53ba0b6 | 2009-06-24 23:06:47 +0000 | [diff] [blame] | 259 | SVal EvalBinOp(const GRState *state, BinaryOperator::Opcode Op,Loc L, |
Ted Kremenek | 5c73462 | 2009-06-26 00:41:43 +0000 | [diff] [blame] | 260 | NonLoc R, QualType resultTy); |
Zhongxing Xu | 24194ef | 2008-10-24 01:38:55 +0000 | [diff] [blame] | 261 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 262 | Store getInitialStore(const LocationContext *InitLoc) { |
Ted Kremenek | 82cd37c | 2009-08-21 23:25:54 +0000 | [diff] [blame] | 263 | return RBFactory.GetEmptyMap().getRoot(); |
Zhongxing Xu | 17fd863 | 2009-08-17 06:19:58 +0000 | [diff] [blame] | 264 | } |
Ted Kremenek | 82cd37c | 2009-08-21 23:25:54 +0000 | [diff] [blame] | 265 | |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 266 | //===-------------------------------------------------------------------===// |
| 267 | // Binding values to regions. |
| 268 | //===-------------------------------------------------------------------===// |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 269 | |
Ted Kremenek | 1004a9f | 2009-07-29 18:16:25 +0000 | [diff] [blame] | 270 | const GRState *InvalidateRegion(const GRState *state, const MemRegion *R, |
Ted Kremenek | 473e167 | 2009-10-16 00:30:49 +0000 | [diff] [blame] | 271 | const Expr *E, unsigned Count, |
Ted Kremenek | 81a9583 | 2009-12-03 03:27:11 +0000 | [diff] [blame] | 272 | InvalidatedSymbols *IS) { |
| 273 | return RegionStoreManager::InvalidateRegions(state, &R, &R+1, E, Count, IS); |
| 274 | } |
| 275 | |
| 276 | const GRState *InvalidateRegions(const GRState *state, |
| 277 | const MemRegion * const *Begin, |
| 278 | const MemRegion * const *End, |
| 279 | const Expr *E, unsigned Count, |
| 280 | InvalidatedSymbols *IS); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 281 | |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 282 | private: |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 283 | void RemoveSubRegionBindings(RegionBindings &B, const MemRegion *R, |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 284 | RegionStoreSubRegionMap &M); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 285 | |
| 286 | public: |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 287 | const GRState *Bind(const GRState *state, Loc LV, SVal V); |
| 288 | |
| 289 | const GRState *BindCompoundLiteral(const GRState *state, |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 290 | const CompoundLiteralExpr* CL, |
| 291 | const LocationContext *LC, |
| 292 | SVal V); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 293 | |
Ted Kremenek | f6f56d4 | 2009-11-04 00:09:15 +0000 | [diff] [blame] | 294 | const GRState *BindDecl(const GRState *ST, const VarRegion *VR, |
| 295 | SVal InitVal); |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 296 | |
Ted Kremenek | f6f56d4 | 2009-11-04 00:09:15 +0000 | [diff] [blame] | 297 | const GRState *BindDeclWithNoInit(const GRState *state, |
| 298 | const VarRegion *) { |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 299 | return state; |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 300 | } |
Zhongxing Xu | 53bcdd4 | 2008-10-21 05:29:26 +0000 | [diff] [blame] | 301 | |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 302 | /// BindStruct - Bind a compound value to a structure. |
| 303 | const GRState *BindStruct(const GRState *, const TypedRegion* R, SVal V); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 304 | |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 305 | const GRState *BindArray(const GRState *state, const TypedRegion* R, SVal V); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 306 | |
| 307 | /// KillStruct - Set the entire struct to unknown. |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 308 | Store KillStruct(Store store, const TypedRegion* R); |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 309 | |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 310 | Store Remove(Store store, Loc LV); |
| 311 | |
| 312 | //===------------------------------------------------------------------===// |
| 313 | // Loading values from regions. |
| 314 | //===------------------------------------------------------------------===// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 315 | |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 316 | /// The high level logic for this method is this: |
| 317 | /// Retrieve (L) |
| 318 | /// if L has binding |
| 319 | /// return L's binding |
| 320 | /// else if L is in killset |
| 321 | /// return unknown |
| 322 | /// else |
| 323 | /// if L is on stack or heap |
| 324 | /// return undefined |
| 325 | /// else |
| 326 | /// return symbolic |
Ted Kremenek | 32c3fa4 | 2009-07-21 21:03:30 +0000 | [diff] [blame] | 327 | SValuator::CastResult Retrieve(const GRState *state, Loc L, |
| 328 | QualType T = QualType()); |
Zhongxing Xu | 490b0f0 | 2009-06-25 04:50:44 +0000 | [diff] [blame] | 329 | |
Ted Kremenek | 5bd2fe3 | 2009-07-15 06:09:28 +0000 | [diff] [blame] | 330 | SVal RetrieveElement(const GRState *state, const ElementRegion *R); |
Zhongxing Xu | c00346f | 2009-06-25 05:29:39 +0000 | [diff] [blame] | 331 | |
Ted Kremenek | 5bd2fe3 | 2009-07-15 06:09:28 +0000 | [diff] [blame] | 332 | SVal RetrieveField(const GRState *state, const FieldRegion *R); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 333 | |
Ted Kremenek | 5bd2fe3 | 2009-07-15 06:09:28 +0000 | [diff] [blame] | 334 | SVal RetrieveObjCIvar(const GRState *state, const ObjCIvarRegion *R); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 335 | |
Ted Kremenek | 9031dd7 | 2009-07-21 00:12:07 +0000 | [diff] [blame] | 336 | SVal RetrieveVar(const GRState *state, const VarRegion *R); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 337 | |
Ted Kremenek | 25c5457 | 2009-07-20 22:58:02 +0000 | [diff] [blame] | 338 | SVal RetrieveLazySymbol(const GRState *state, const TypedRegion *R); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 339 | |
Ted Kremenek | 566a6fa | 2009-08-06 22:33:36 +0000 | [diff] [blame] | 340 | SVal RetrieveFieldOrElementCommon(const GRState *state, const TypedRegion *R, |
| 341 | QualType Ty, const MemRegion *superR); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 342 | |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 343 | /// Retrieve the values in a struct and return a CompoundVal, used when doing |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 344 | /// struct copy: |
| 345 | /// struct s x, y; |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 346 | /// x = y; |
| 347 | /// y's value is retrieved by this method. |
| 348 | SVal RetrieveStruct(const GRState *St, const TypedRegion* R); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 349 | |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 350 | SVal RetrieveArray(const GRState *St, const TypedRegion* R); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 351 | |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 352 | std::pair<const GRState*, const MemRegion*> |
Ted Kremenek | 451ac09 | 2009-08-06 04:50:20 +0000 | [diff] [blame] | 353 | GetLazyBinding(RegionBindings B, const MemRegion *R); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 354 | |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 355 | const GRState* CopyLazyBindings(nonloc::LazyCompoundVal V, |
| 356 | const GRState *state, |
| 357 | const TypedRegion *R); |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 358 | |
Ted Kremenek | 0954cde | 2009-09-24 04:11:44 +0000 | [diff] [blame] | 359 | const ElementRegion *GetElementZeroRegion(const SymbolicRegion *SR, |
| 360 | QualType T); |
| 361 | |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 362 | //===------------------------------------------------------------------===// |
| 363 | // State pruning. |
| 364 | //===------------------------------------------------------------------===// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 365 | |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 366 | /// RemoveDeadBindings - Scans the RegionStore of 'state' for dead values. |
| 367 | /// It returns a new Store with these values removed. |
Ted Kremenek | 2f26bc3 | 2009-08-02 04:45:08 +0000 | [diff] [blame] | 368 | void RemoveDeadBindings(GRState &state, Stmt* Loc, SymbolReaper& SymReaper, |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 369 | llvm::SmallVectorImpl<const MemRegion*>& RegionRoots); |
| 370 | |
Zhongxing Xu | 4e3c1f7 | 2009-10-13 02:24:55 +0000 | [diff] [blame] | 371 | const GRState *EnterStackFrame(const GRState *state, |
| 372 | const StackFrameContext *frame); |
| 373 | |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 374 | //===------------------------------------------------------------------===// |
| 375 | // Region "extents". |
| 376 | //===------------------------------------------------------------------===// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 377 | |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 378 | const GRState *setExtent(const GRState *state, const MemRegion* R, SVal Extent); |
Zhongxing Xu | e884ff8 | 2009-11-12 02:48:32 +0000 | [diff] [blame] | 379 | DefinedOrUnknownSVal getSizeInElements(const GRState *state, |
| 380 | const MemRegion* R); |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 381 | |
| 382 | //===------------------------------------------------------------------===// |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 383 | // Utility methods. |
| 384 | //===------------------------------------------------------------------===// |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 385 | |
Ted Kremenek | 451ac09 | 2009-08-06 04:50:20 +0000 | [diff] [blame] | 386 | static inline RegionBindings GetRegionBindings(Store store) { |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 387 | return RegionBindings(static_cast<const RegionBindings::TreeTy*>(store)); |
Zhongxing Xu | 1789275 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 388 | } |
Zhongxing Xu | 24194ef | 2008-10-24 01:38:55 +0000 | [diff] [blame] | 389 | |
Ted Kremenek | 53ba0b6 | 2009-06-24 23:06:47 +0000 | [diff] [blame] | 390 | void print(Store store, llvm::raw_ostream& Out, const char* nl, |
| 391 | const char *sep); |
Zhongxing Xu | 24194ef | 2008-10-24 01:38:55 +0000 | [diff] [blame] | 392 | |
| 393 | void iterBindings(Store store, BindingsHandler& f) { |
| 394 | // FIXME: Implement. |
| 395 | } |
Zhongxing Xu | 6e3f01c | 2008-10-31 07:16:08 +0000 | [diff] [blame] | 396 | |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 397 | // FIXME: Remove. |
| 398 | BasicValueFactory& getBasicVals() { |
| 399 | return StateMgr.getBasicVals(); |
| 400 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 401 | |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 402 | // FIXME: Remove. |
Zhongxing Xu | 6e3f01c | 2008-10-31 07:16:08 +0000 | [diff] [blame] | 403 | ASTContext& getContext() { return StateMgr.getContext(); } |
Zhongxing Xu | 1789275 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 404 | }; |
| 405 | |
| 406 | } // end anonymous namespace |
| 407 | |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 408 | //===----------------------------------------------------------------------===// |
| 409 | // RegionStore creation. |
| 410 | //===----------------------------------------------------------------------===// |
| 411 | |
| 412 | StoreManager *clang::CreateRegionStoreManager(GRStateManager& StMgr) { |
| 413 | RegionStoreFeatures F = maximal_features_tag(); |
| 414 | return new RegionStoreManager(StMgr, F); |
| 415 | } |
| 416 | |
| 417 | StoreManager *clang::CreateFieldsOnlyRegionStoreManager(GRStateManager &StMgr) { |
| 418 | RegionStoreFeatures F = minimal_features_tag(); |
| 419 | F.enableFields(true); |
| 420 | return new RegionStoreManager(StMgr, F); |
Ted Kremenek | 95c7b00 | 2008-10-24 01:04:59 +0000 | [diff] [blame] | 421 | } |
| 422 | |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 423 | void |
| 424 | RegionStoreSubRegionMap::process(llvm::SmallVectorImpl<const SubRegion*> &WL, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 425 | const SubRegion *R) { |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 426 | const MemRegion *superR = R->getSuperRegion(); |
| 427 | if (add(superR, R)) |
| 428 | if (const SubRegion *sr = dyn_cast<SubRegion>(superR)) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 429 | WL.push_back(sr); |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 430 | } |
| 431 | |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 432 | RegionStoreSubRegionMap* |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 433 | RegionStoreManager::getRegionStoreSubRegionMap(Store store) { |
| 434 | RegionBindings B = GetRegionBindings(store); |
Ted Kremenek | 59e8f11 | 2009-03-03 01:35:36 +0000 | [diff] [blame] | 435 | RegionStoreSubRegionMap *M = new RegionStoreSubRegionMap(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 436 | |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 437 | llvm::SmallVector<const SubRegion*, 10> WL; |
| 438 | |
Ted Kremenek | 451ac09 | 2009-08-06 04:50:20 +0000 | [diff] [blame] | 439 | for (RegionBindings::iterator I=B.begin(), E=B.end(); I!=E; ++I) |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 440 | if (const SubRegion *R = dyn_cast<SubRegion>(I.getKey())) |
| 441 | M->process(WL, R); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 442 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 443 | // We also need to record in the subregion map "intermediate" regions that |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 444 | // don't have direct bindings but are super regions of those that do. |
| 445 | while (!WL.empty()) { |
| 446 | const SubRegion *R = WL.back(); |
| 447 | WL.pop_back(); |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 448 | M->process(WL, R); |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 449 | } |
| 450 | |
Ted Kremenek | 14453bf | 2009-03-03 19:02:42 +0000 | [diff] [blame] | 451 | return M; |
Ted Kremenek | 59e8f11 | 2009-03-03 01:35:36 +0000 | [diff] [blame] | 452 | } |
Ted Kremenek | 869fb4a | 2008-12-24 07:46:32 +0000 | [diff] [blame] | 453 | |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 454 | SubRegionMap *RegionStoreManager::getSubRegionMap(const GRState *state) { |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 455 | return getRegionStoreSubRegionMap(state->getStore()); |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 456 | } |
| 457 | |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 458 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 1004a9f | 2009-07-29 18:16:25 +0000 | [diff] [blame] | 459 | // Binding invalidation. |
| 460 | //===----------------------------------------------------------------------===// |
| 461 | |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 462 | void RegionStoreManager::RemoveSubRegionBindings(RegionBindings &B, |
| 463 | const MemRegion *R, |
| 464 | RegionStoreSubRegionMap &M) { |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 465 | RegionStoreSubRegionMap::iterator I, E; |
| 466 | |
| 467 | for (llvm::tie(I, E) = M.begin_end(R); I != E; ++I) |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 468 | RemoveSubRegionBindings(B, *I, M); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 469 | |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 470 | B = RBFactory.Remove(B, R); |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 471 | } |
| 472 | |
Ted Kremenek | 81a9583 | 2009-12-03 03:27:11 +0000 | [diff] [blame] | 473 | const GRState *RegionStoreManager::InvalidateRegions(const GRState *state, |
| 474 | const MemRegion * const *I, |
| 475 | const MemRegion * const *E, |
| 476 | const Expr *Ex, |
| 477 | unsigned Count, |
| 478 | InvalidatedSymbols *IS) { |
Ted Kremenek | 1004a9f | 2009-07-29 18:16:25 +0000 | [diff] [blame] | 479 | ASTContext& Ctx = StateMgr.getContext(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 480 | |
Ted Kremenek | 8780679 | 2009-09-27 20:45:21 +0000 | [diff] [blame] | 481 | // Get the mapping of regions -> subregions. |
| 482 | llvm::OwningPtr<RegionStoreSubRegionMap> |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 483 | SubRegions(getRegionStoreSubRegionMap(state->getStore())); |
Ted Kremenek | 8780679 | 2009-09-27 20:45:21 +0000 | [diff] [blame] | 484 | |
| 485 | RegionBindings B = GetRegionBindings(state->getStore()); |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 486 | |
Ted Kremenek | 8780679 | 2009-09-27 20:45:21 +0000 | [diff] [blame] | 487 | llvm::DenseMap<const MemRegion *, unsigned> Visited; |
| 488 | llvm::SmallVector<const MemRegion *, 10> WorkList; |
Ted Kremenek | 81a9583 | 2009-12-03 03:27:11 +0000 | [diff] [blame] | 489 | |
| 490 | for ( ; I != E; ++I) { |
| 491 | // Strip away casts. |
| 492 | WorkList.push_back((*I)->StripCasts()); |
| 493 | } |
Ted Kremenek | 8780679 | 2009-09-27 20:45:21 +0000 | [diff] [blame] | 494 | |
| 495 | while (!WorkList.empty()) { |
Ted Kremenek | 81a9583 | 2009-12-03 03:27:11 +0000 | [diff] [blame] | 496 | const MemRegion *R = WorkList.back(); |
Ted Kremenek | 8780679 | 2009-09-27 20:45:21 +0000 | [diff] [blame] | 497 | WorkList.pop_back(); |
| 498 | |
| 499 | // Have we visited this region before? |
| 500 | unsigned &visited = Visited[R]; |
| 501 | if (visited) |
| 502 | continue; |
| 503 | visited = 1; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 504 | |
Ted Kremenek | 8780679 | 2009-09-27 20:45:21 +0000 | [diff] [blame] | 505 | // Add subregions to work list. |
| 506 | RegionStoreSubRegionMap::iterator I, E; |
| 507 | for (llvm::tie(I, E) = SubRegions->begin_end(R); I!=E; ++I) |
| 508 | WorkList.push_back(*I); |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 509 | |
| 510 | // Get the old binding. Is it a region? If so, add it to the worklist. |
| 511 | if (Optional<SVal> V = getDirectBinding(B, R)) { |
| 512 | if (const MemRegion *RV = V->getAsRegion()) |
| 513 | WorkList.push_back(RV); |
Ted Kremenek | 473e167 | 2009-10-16 00:30:49 +0000 | [diff] [blame] | 514 | |
| 515 | // A symbol? Mark it touched by the invalidation. |
| 516 | if (IS) { |
| 517 | if (SymbolRef Sym = V->getAsSymbol()) |
| 518 | IS->insert(Sym); |
| 519 | } |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 520 | } |
| 521 | |
Ted Kremenek | 473e167 | 2009-10-16 00:30:49 +0000 | [diff] [blame] | 522 | // Symbolic region? Mark that symbol touched by the invalidation. |
| 523 | if (IS) { |
| 524 | if (const SymbolicRegion *SR = dyn_cast<SymbolicRegion>(R)) |
| 525 | IS->insert(SR->getSymbol()); |
| 526 | } |
Ted Kremenek | 2ffbfd9 | 2009-12-03 08:25:47 +0000 | [diff] [blame] | 527 | |
| 528 | // BlockDataRegion? If so, invalidate captured variables that are passed |
| 529 | // by reference. |
| 530 | if (const BlockDataRegion *BR = dyn_cast<BlockDataRegion>(R)) { |
| 531 | for (BlockDataRegion::referenced_vars_iterator |
| 532 | I = BR->referenced_vars_begin(), E = BR->referenced_vars_end() ; |
| 533 | I != E; ++I) { |
| 534 | const VarRegion *VR = *I; |
| 535 | if (VR->getDecl()->getAttr<BlocksAttr>()) |
| 536 | WorkList.push_back(VR); |
| 537 | } |
| 538 | continue; |
| 539 | } |
Ted Kremenek | 473e167 | 2009-10-16 00:30:49 +0000 | [diff] [blame] | 540 | |
| 541 | // Handle the region itself. |
Ted Kremenek | 8780679 | 2009-09-27 20:45:21 +0000 | [diff] [blame] | 542 | if (isa<AllocaRegion>(R) || isa<SymbolicRegion>(R) || |
| 543 | isa<ObjCObjectRegion>(R)) { |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 544 | // Invalidate the region by setting its default value to |
| 545 | // conjured symbol. The type of the symbol is irrelavant. |
Ted Kremenek | 8780679 | 2009-09-27 20:45:21 +0000 | [diff] [blame] | 546 | DefinedOrUnknownSVal V = ValMgr.getConjuredSymbolVal(R, Ex, Ctx.IntTy, |
| 547 | Count); |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 548 | B = RBFactory.Add(B, R, BindingVal(V, BindingVal::Default)); |
Ted Kremenek | 8780679 | 2009-09-27 20:45:21 +0000 | [diff] [blame] | 549 | continue; |
| 550 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 551 | |
Ted Kremenek | 8780679 | 2009-09-27 20:45:21 +0000 | [diff] [blame] | 552 | if (!R->isBoundable()) |
| 553 | continue; |
| 554 | |
| 555 | const TypedRegion *TR = cast<TypedRegion>(R); |
| 556 | QualType T = TR->getValueType(Ctx); |
| 557 | |
| 558 | if (const RecordType *RT = T->getAsStructureType()) { |
Ted Kremenek | 8780679 | 2009-09-27 20:45:21 +0000 | [diff] [blame] | 559 | const RecordDecl *RD = RT->getDecl()->getDefinition(Ctx); |
| 560 | |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 561 | // No record definition. There is nothing we can do. |
Ted Kremenek | 8780679 | 2009-09-27 20:45:21 +0000 | [diff] [blame] | 562 | if (!RD) |
| 563 | continue; |
| 564 | |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 565 | // Invalidate the region by setting its default value to |
| 566 | // conjured symbol. The type of the symbol is irrelavant. |
Ted Kremenek | 8780679 | 2009-09-27 20:45:21 +0000 | [diff] [blame] | 567 | DefinedOrUnknownSVal V = ValMgr.getConjuredSymbolVal(R, Ex, Ctx.IntTy, |
| 568 | Count); |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 569 | B = RBFactory.Add(B, R, BindingVal(V, BindingVal::Default)); |
Ted Kremenek | 8780679 | 2009-09-27 20:45:21 +0000 | [diff] [blame] | 570 | continue; |
| 571 | } |
| 572 | |
| 573 | if (const ArrayType *AT = Ctx.getAsArrayType(T)) { |
| 574 | // Set the default value of the array to conjured symbol. |
| 575 | DefinedOrUnknownSVal V = |
| 576 | ValMgr.getConjuredSymbolVal(R, Ex, AT->getElementType(), Count); |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 577 | B = RBFactory.Add(B, R, BindingVal(V, BindingVal::Default)); |
Ted Kremenek | 8780679 | 2009-09-27 20:45:21 +0000 | [diff] [blame] | 578 | continue; |
| 579 | } |
Ted Kremenek | a5971b3 | 2009-09-29 03:34:03 +0000 | [diff] [blame] | 580 | |
| 581 | if ((isa<FieldRegion>(R)||isa<ElementRegion>(R)||isa<ObjCIvarRegion>(R)) |
| 582 | && Visited[cast<SubRegion>(R)->getSuperRegion()]) { |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 583 | // For fields and elements whose super region has also been invalidated, |
| 584 | // only remove the old binding. The super region will get set with a |
| 585 | // default value from which we can lazily derive a new symbolic value. |
Ted Kremenek | a5971b3 | 2009-09-29 03:34:03 +0000 | [diff] [blame] | 586 | B = RBFactory.Remove(B, R); |
| 587 | continue; |
| 588 | } |
Ted Kremenek | 8780679 | 2009-09-27 20:45:21 +0000 | [diff] [blame] | 589 | |
Ted Kremenek | 389c44c | 2009-09-29 03:12:50 +0000 | [diff] [blame] | 590 | // Invalidate the binding. |
Ted Kremenek | 8780679 | 2009-09-27 20:45:21 +0000 | [diff] [blame] | 591 | DefinedOrUnknownSVal V = ValMgr.getConjuredSymbolVal(R, Ex, T, Count); |
| 592 | assert(SymbolManager::canSymbolicate(T) || V.isUnknown()); |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 593 | B = RBFactory.Add(B, R, BindingVal(V, BindingVal::Direct)); |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 594 | } |
| 595 | |
Ted Kremenek | 8780679 | 2009-09-27 20:45:21 +0000 | [diff] [blame] | 596 | // Create a new state with the updated bindings. |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 597 | return state->makeWithStore(B.getRoot()); |
Ted Kremenek | 1004a9f | 2009-07-29 18:16:25 +0000 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 601 | // getLValueXXX methods. |
| 602 | //===----------------------------------------------------------------------===// |
| 603 | |
Ted Kremenek | 869fb4a | 2008-12-24 07:46:32 +0000 | [diff] [blame] | 604 | /// getLValueString - Returns an SVal representing the lvalue of a |
| 605 | /// StringLiteral. Within RegionStore a StringLiteral has an |
| 606 | /// associated StringRegion, and the lvalue of a StringLiteral is the |
| 607 | /// lvalue of that region. |
Zhongxing Xu | d0f8bb1 | 2009-10-14 03:33:08 +0000 | [diff] [blame] | 608 | SVal RegionStoreManager::getLValueString(const StringLiteral* S) { |
Zhongxing Xu | 143bf82 | 2008-10-25 14:18:57 +0000 | [diff] [blame] | 609 | return loc::MemRegionVal(MRMgr.getStringRegion(S)); |
| 610 | } |
| 611 | |
Ted Kremenek | 869fb4a | 2008-12-24 07:46:32 +0000 | [diff] [blame] | 612 | /// getLValueVar - Returns an SVal that represents the lvalue of a |
| 613 | /// variable. Within RegionStore a variable has an associated |
| 614 | /// VarRegion, and the lvalue of the variable is the lvalue of that region. |
Zhongxing Xu | d0f8bb1 | 2009-10-14 03:33:08 +0000 | [diff] [blame] | 615 | SVal RegionStoreManager::getLValueVar(const VarDecl *VD, |
Ted Kremenek | d17da2b | 2009-08-21 22:28:32 +0000 | [diff] [blame] | 616 | const LocationContext *LC) { |
| 617 | return loc::MemRegionVal(MRMgr.getVarRegion(VD, LC)); |
Zhongxing Xu | c4bf72c | 2008-10-22 13:44:38 +0000 | [diff] [blame] | 618 | } |
Zhongxing Xu | f22679e | 2008-11-07 10:38:33 +0000 | [diff] [blame] | 619 | |
Zhongxing Xu | d0f8bb1 | 2009-10-14 03:33:08 +0000 | [diff] [blame] | 620 | SVal RegionStoreManager::getLValueIvar(const ObjCIvarDecl* D, SVal Base) { |
| 621 | return getLValueFieldOrIvar(D, Base); |
Zhongxing Xu | c4bf72c | 2008-10-22 13:44:38 +0000 | [diff] [blame] | 622 | } |
| 623 | |
Zhongxing Xu | d0f8bb1 | 2009-10-14 03:33:08 +0000 | [diff] [blame] | 624 | SVal RegionStoreManager::getLValueField(const FieldDecl* D, SVal Base) { |
| 625 | return getLValueFieldOrIvar(D, Base); |
Ted Kremenek | 3de2d3c | 2009-03-05 04:50:08 +0000 | [diff] [blame] | 626 | } |
| 627 | |
Zhongxing Xu | d0f8bb1 | 2009-10-14 03:33:08 +0000 | [diff] [blame] | 628 | SVal RegionStoreManager::getLValueFieldOrIvar(const Decl* D, SVal Base) { |
Zhongxing Xu | c4bf72c | 2008-10-22 13:44:38 +0000 | [diff] [blame] | 629 | if (Base.isUnknownOrUndef()) |
| 630 | return Base; |
| 631 | |
| 632 | Loc BaseL = cast<Loc>(Base); |
| 633 | const MemRegion* BaseR = 0; |
| 634 | |
| 635 | switch (BaseL.getSubKind()) { |
| 636 | case loc::MemRegionKind: |
| 637 | BaseR = cast<loc::MemRegionVal>(BaseL).getRegion(); |
| 638 | break; |
| 639 | |
Zhongxing Xu | c4bf72c | 2008-10-22 13:44:38 +0000 | [diff] [blame] | 640 | case loc::GotoLabelKind: |
Zhongxing Xu | c4bf72c | 2008-10-22 13:44:38 +0000 | [diff] [blame] | 641 | // These are anormal cases. Flag an undefined value. |
| 642 | return UndefinedVal(); |
| 643 | |
| 644 | case loc::ConcreteIntKind: |
Zhongxing Xu | c4bf72c | 2008-10-22 13:44:38 +0000 | [diff] [blame] | 645 | // While these seem funny, this can happen through casts. |
| 646 | // FIXME: What we should return is the field offset. For example, |
| 647 | // add the field offset to the integer value. That way funny things |
| 648 | // like this work properly: &(((struct foo *) 0xa)->f) |
| 649 | return Base; |
| 650 | |
| 651 | default: |
Zhongxing Xu | 13d1ee2 | 2008-11-07 08:57:30 +0000 | [diff] [blame] | 652 | assert(0 && "Unhandled Base."); |
Zhongxing Xu | c4bf72c | 2008-10-22 13:44:38 +0000 | [diff] [blame] | 653 | return Base; |
| 654 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 655 | |
Ted Kremenek | 3de2d3c | 2009-03-05 04:50:08 +0000 | [diff] [blame] | 656 | // NOTE: We must have this check first because ObjCIvarDecl is a subclass |
| 657 | // of FieldDecl. |
| 658 | if (const ObjCIvarDecl *ID = dyn_cast<ObjCIvarDecl>(D)) |
| 659 | return loc::MemRegionVal(MRMgr.getObjCIvarRegion(ID, BaseR)); |
Zhongxing Xu | c4bf72c | 2008-10-22 13:44:38 +0000 | [diff] [blame] | 660 | |
Ted Kremenek | 3de2d3c | 2009-03-05 04:50:08 +0000 | [diff] [blame] | 661 | return loc::MemRegionVal(MRMgr.getFieldRegion(cast<FieldDecl>(D), BaseR)); |
Zhongxing Xu | c4bf72c | 2008-10-22 13:44:38 +0000 | [diff] [blame] | 662 | } |
| 663 | |
Zhongxing Xu | d0f8bb1 | 2009-10-14 03:33:08 +0000 | [diff] [blame] | 664 | SVal RegionStoreManager::getLValueElement(QualType elementType, SVal Offset, |
| 665 | SVal Base) { |
Zhongxing Xu | b1d542a | 2008-10-24 01:09:32 +0000 | [diff] [blame] | 666 | |
Ted Kremenek | de7ec63 | 2009-03-09 22:44:49 +0000 | [diff] [blame] | 667 | // If the base is an unknown or undefined value, just return it back. |
| 668 | // FIXME: For absolute pointer addresses, we just return that value back as |
| 669 | // well, although in reality we should return the offset added to that |
| 670 | // value. |
| 671 | if (Base.isUnknownOrUndef() || isa<loc::ConcreteInt>(Base)) |
Zhongxing Xu | 4a1513e | 2008-10-27 12:23:17 +0000 | [diff] [blame] | 672 | return Base; |
| 673 | |
Ted Kremenek | a7ac944 | 2009-01-22 20:27:48 +0000 | [diff] [blame] | 674 | // Only handle integer offsets... for now. |
| 675 | if (!isa<nonloc::ConcreteInt>(Offset)) |
Zhongxing Xu | e4d1393 | 2008-11-13 09:48:44 +0000 | [diff] [blame] | 676 | return UnknownVal(); |
Ted Kremenek | a7ac944 | 2009-01-22 20:27:48 +0000 | [diff] [blame] | 677 | |
Zhongxing Xu | ce76078 | 2009-05-09 13:20:07 +0000 | [diff] [blame] | 678 | const MemRegion* BaseRegion = cast<loc::MemRegionVal>(Base).getRegion(); |
Ted Kremenek | a7ac944 | 2009-01-22 20:27:48 +0000 | [diff] [blame] | 679 | |
| 680 | // Pointer of any type can be cast and used as array base. |
| 681 | const ElementRegion *ElemR = dyn_cast<ElementRegion>(BaseRegion); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 682 | |
Ted Kremenek | 4653739 | 2009-07-16 01:33:37 +0000 | [diff] [blame] | 683 | // Convert the offset to the appropriate size and signedness. |
| 684 | Offset = ValMgr.convertToArrayIndex(Offset); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 685 | |
Ted Kremenek | a7ac944 | 2009-01-22 20:27:48 +0000 | [diff] [blame] | 686 | if (!ElemR) { |
| 687 | // |
| 688 | // If the base region is not an ElementRegion, create one. |
| 689 | // This can happen in the following example: |
| 690 | // |
| 691 | // char *p = __builtin_alloc(10); |
| 692 | // p[1] = 8; |
| 693 | // |
Zhongxing Xu | ce76078 | 2009-05-09 13:20:07 +0000 | [diff] [blame] | 694 | // Observe that 'p' binds to an AllocaRegion. |
Ted Kremenek | a7ac944 | 2009-01-22 20:27:48 +0000 | [diff] [blame] | 695 | // |
Ted Kremenek | f936f45 | 2009-05-04 06:18:28 +0000 | [diff] [blame] | 696 | return loc::MemRegionVal(MRMgr.getElementRegion(elementType, Offset, |
Zhongxing Xu | 143b2fc | 2009-06-16 09:55:50 +0000 | [diff] [blame] | 697 | BaseRegion, getContext())); |
Zhongxing Xu | e4d1393 | 2008-11-13 09:48:44 +0000 | [diff] [blame] | 698 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 699 | |
Ted Kremenek | a7ac944 | 2009-01-22 20:27:48 +0000 | [diff] [blame] | 700 | SVal BaseIdx = ElemR->getIndex(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 701 | |
Ted Kremenek | a7ac944 | 2009-01-22 20:27:48 +0000 | [diff] [blame] | 702 | if (!isa<nonloc::ConcreteInt>(BaseIdx)) |
| 703 | return UnknownVal(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 704 | |
Ted Kremenek | a7ac944 | 2009-01-22 20:27:48 +0000 | [diff] [blame] | 705 | const llvm::APSInt& BaseIdxI = cast<nonloc::ConcreteInt>(BaseIdx).getValue(); |
| 706 | const llvm::APSInt& OffI = cast<nonloc::ConcreteInt>(Offset).getValue(); |
| 707 | assert(BaseIdxI.isSigned()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 708 | |
Ted Kremenek | 4653739 | 2009-07-16 01:33:37 +0000 | [diff] [blame] | 709 | // Compute the new index. |
| 710 | SVal NewIdx = nonloc::ConcreteInt(getBasicVals().getValue(BaseIdxI + OffI)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 711 | |
Ted Kremenek | 4653739 | 2009-07-16 01:33:37 +0000 | [diff] [blame] | 712 | // Construct the new ElementRegion. |
| 713 | const MemRegion *ArrayR = ElemR->getSuperRegion(); |
Zhongxing Xu | 143b2fc | 2009-06-16 09:55:50 +0000 | [diff] [blame] | 714 | return loc::MemRegionVal(MRMgr.getElementRegion(elementType, NewIdx, ArrayR, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 715 | getContext())); |
Zhongxing Xu | b1d542a | 2008-10-24 01:09:32 +0000 | [diff] [blame] | 716 | } |
| 717 | |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 718 | //===----------------------------------------------------------------------===// |
| 719 | // Extents for regions. |
| 720 | //===----------------------------------------------------------------------===// |
| 721 | |
Zhongxing Xu | e884ff8 | 2009-11-12 02:48:32 +0000 | [diff] [blame] | 722 | DefinedOrUnknownSVal RegionStoreManager::getSizeInElements(const GRState *state, |
| 723 | const MemRegion *R) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 724 | |
Ted Kremenek | 7ecbfbc | 2009-07-10 22:30:06 +0000 | [diff] [blame] | 725 | switch (R->getKind()) { |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 726 | case MemRegion::GenericMemSpaceRegionKind: |
| 727 | case MemRegion::StackLocalsSpaceRegionKind: |
| 728 | case MemRegion::StackArgumentsSpaceRegionKind: |
| 729 | case MemRegion::HeapSpaceRegionKind: |
| 730 | case MemRegion::GlobalsSpaceRegionKind: |
Ted Kremenek | 2b87ae4 | 2009-12-11 06:43:27 +0000 | [diff] [blame] | 731 | case MemRegion::UnknownSpaceRegionKind: |
Ted Kremenek | 7ecbfbc | 2009-07-10 22:30:06 +0000 | [diff] [blame] | 732 | assert(0 && "Cannot index into a MemSpace"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 733 | return UnknownVal(); |
| 734 | |
Ted Kremenek | eb1c7a0 | 2009-11-25 01:32:22 +0000 | [diff] [blame] | 735 | case MemRegion::FunctionTextRegionKind: |
| 736 | case MemRegion::BlockTextRegionKind: |
Ted Kremenek | 0a8112a | 2009-11-25 23:53:07 +0000 | [diff] [blame] | 737 | case MemRegion::BlockDataRegionKind: |
Ted Kremenek | 7ecbfbc | 2009-07-10 22:30:06 +0000 | [diff] [blame] | 738 | // Technically this can happen if people do funny things with casts. |
Ted Kremenek | 14553ab | 2009-01-30 00:08:43 +0000 | [diff] [blame] | 739 | return UnknownVal(); |
Ted Kremenek | 7ecbfbc | 2009-07-10 22:30:06 +0000 | [diff] [blame] | 740 | |
| 741 | // Not yet handled. |
| 742 | case MemRegion::AllocaRegionKind: |
| 743 | case MemRegion::CompoundLiteralRegionKind: |
| 744 | case MemRegion::ElementRegionKind: |
| 745 | case MemRegion::FieldRegionKind: |
| 746 | case MemRegion::ObjCIvarRegionKind: |
| 747 | case MemRegion::ObjCObjectRegionKind: |
| 748 | case MemRegion::SymbolicRegionKind: |
| 749 | return UnknownVal(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 750 | |
Ted Kremenek | 7ecbfbc | 2009-07-10 22:30:06 +0000 | [diff] [blame] | 751 | case MemRegion::StringRegionKind: { |
| 752 | const StringLiteral* Str = cast<StringRegion>(R)->getStringLiteral(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 753 | // We intentionally made the size value signed because it participates in |
Ted Kremenek | 7ecbfbc | 2009-07-10 22:30:06 +0000 | [diff] [blame] | 754 | // operations with signed indices. |
| 755 | return ValMgr.makeIntVal(Str->getByteLength()+1, false); |
Ted Kremenek | 14553ab | 2009-01-30 00:08:43 +0000 | [diff] [blame] | 756 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 757 | |
Ted Kremenek | 7ecbfbc | 2009-07-10 22:30:06 +0000 | [diff] [blame] | 758 | case MemRegion::VarRegionKind: { |
| 759 | const VarRegion* VR = cast<VarRegion>(R); |
| 760 | // Get the type of the variable. |
| 761 | QualType T = VR->getDesugaredValueType(getContext()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 762 | |
Ted Kremenek | 7ecbfbc | 2009-07-10 22:30:06 +0000 | [diff] [blame] | 763 | // FIXME: Handle variable-length arrays. |
| 764 | if (isa<VariableArrayType>(T)) |
| 765 | return UnknownVal(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 766 | |
Ted Kremenek | 7ecbfbc | 2009-07-10 22:30:06 +0000 | [diff] [blame] | 767 | if (const ConstantArrayType* CAT = dyn_cast<ConstantArrayType>(T)) { |
| 768 | // return the size as signed integer. |
| 769 | return ValMgr.makeIntVal(CAT->getSize(), false); |
| 770 | } |
Ted Kremenek | df74e25 | 2009-08-02 05:15:23 +0000 | [diff] [blame] | 771 | |
Ted Kremenek | 7ecbfbc | 2009-07-10 22:30:06 +0000 | [diff] [blame] | 772 | // Clients can use ordinary variables as if they were arrays. These |
| 773 | // essentially are arrays of size 1. |
| 774 | return ValMgr.makeIntVal(1, false); |
Zhongxing Xu | 41fd018 | 2009-05-06 11:51:48 +0000 | [diff] [blame] | 775 | } |
Zhongxing Xu | e8a964b | 2008-11-22 13:21:46 +0000 | [diff] [blame] | 776 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 777 | |
Ted Kremenek | 7ecbfbc | 2009-07-10 22:30:06 +0000 | [diff] [blame] | 778 | assert(0 && "Unreachable"); |
Ted Kremenek | a21362d | 2009-01-06 19:12:06 +0000 | [diff] [blame] | 779 | return UnknownVal(); |
Zhongxing Xu | e8a964b | 2008-11-22 13:21:46 +0000 | [diff] [blame] | 780 | } |
| 781 | |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 782 | const GRState *RegionStoreManager::setExtent(const GRState *state, |
| 783 | const MemRegion *region, |
| 784 | SVal extent) { |
| 785 | return state->set<RegionExtents>(region, extent); |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | //===----------------------------------------------------------------------===// |
| 789 | // Location and region casting. |
| 790 | //===----------------------------------------------------------------------===// |
| 791 | |
Ted Kremenek | 869fb4a | 2008-12-24 07:46:32 +0000 | [diff] [blame] | 792 | /// ArrayToPointer - Emulates the "decay" of an array to a pointer |
| 793 | /// type. 'Array' represents the lvalue of the array being decayed |
| 794 | /// to a pointer, and the returned SVal represents the decayed |
| 795 | /// version of that lvalue (i.e., a pointer to the first element of |
| 796 | /// the array). This is called by GRExprEngine when evaluating casts |
| 797 | /// from arrays to pointers. |
Zhongxing Xu | f1d537f | 2009-03-30 05:55:46 +0000 | [diff] [blame] | 798 | SVal RegionStoreManager::ArrayToPointer(Loc Array) { |
Ted Kremenek | abb042f | 2008-12-13 19:24:37 +0000 | [diff] [blame] | 799 | if (!isa<loc::MemRegionVal>(Array)) |
| 800 | return UnknownVal(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 801 | |
Ted Kremenek | abb042f | 2008-12-13 19:24:37 +0000 | [diff] [blame] | 802 | const MemRegion* R = cast<loc::MemRegionVal>(&Array)->getRegion(); |
| 803 | const TypedRegion* ArrayR = dyn_cast<TypedRegion>(R); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 804 | |
Ted Kremenek | bbee1a7 | 2009-01-13 01:03:27 +0000 | [diff] [blame] | 805 | if (!ArrayR) |
Ted Kremenek | abb042f | 2008-12-13 19:24:37 +0000 | [diff] [blame] | 806 | return UnknownVal(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 807 | |
Zhongxing Xu | a82d8aa | 2009-05-09 03:57:34 +0000 | [diff] [blame] | 808 | // Strip off typedefs from the ArrayRegion's ValueType. |
John McCall | bf1cc05 | 2009-09-29 23:03:30 +0000 | [diff] [blame] | 809 | QualType T = ArrayR->getValueType(getContext()).getDesugaredType(); |
Ted Kremenek | f936f45 | 2009-05-04 06:18:28 +0000 | [diff] [blame] | 810 | ArrayType *AT = cast<ArrayType>(T); |
| 811 | T = AT->getElementType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 812 | |
Ted Kremenek | 75185b5 | 2009-07-16 00:00:11 +0000 | [diff] [blame] | 813 | SVal ZeroIdx = ValMgr.makeZeroArrayIndex(); |
Ted Kremenek | b48ad64 | 2009-12-04 00:26:31 +0000 | [diff] [blame] | 814 | return loc::MemRegionVal(MRMgr.getElementRegion(T, ZeroIdx, ArrayR, |
| 815 | getContext())); |
Zhongxing Xu | b1d542a | 2008-10-24 01:09:32 +0000 | [diff] [blame] | 816 | } |
| 817 | |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 818 | //===----------------------------------------------------------------------===// |
| 819 | // Pointer arithmetic. |
| 820 | //===----------------------------------------------------------------------===// |
| 821 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 822 | SVal RegionStoreManager::EvalBinOp(const GRState *state, |
Ted Kremenek | 5c73462 | 2009-06-26 00:41:43 +0000 | [diff] [blame] | 823 | BinaryOperator::Opcode Op, Loc L, NonLoc R, |
| 824 | QualType resultTy) { |
Zhongxing Xu | c4761f5 | 2009-05-09 15:18:12 +0000 | [diff] [blame] | 825 | // Assume the base location is MemRegionVal. |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 826 | if (!isa<loc::MemRegionVal>(L)) |
Zhongxing Xu | 94aa6c1 | 2009-03-02 07:52:23 +0000 | [diff] [blame] | 827 | return UnknownVal(); |
Zhongxing Xu | 94aa6c1 | 2009-03-02 07:52:23 +0000 | [diff] [blame] | 828 | |
Zhongxing Xu | a1718c7 | 2009-04-03 07:33:13 +0000 | [diff] [blame] | 829 | const MemRegion* MR = cast<loc::MemRegionVal>(L).getRegion(); |
Zhongxing Xu | c4761f5 | 2009-05-09 15:18:12 +0000 | [diff] [blame] | 830 | const ElementRegion *ER = 0; |
Zhongxing Xu | 262fd03 | 2009-05-20 09:00:16 +0000 | [diff] [blame] | 831 | |
Ted Kremenek | 3bccf08 | 2009-07-11 00:58:27 +0000 | [diff] [blame] | 832 | switch (MR->getKind()) { |
| 833 | case MemRegion::SymbolicRegionKind: { |
| 834 | const SymbolicRegion *SR = cast<SymbolicRegion>(MR); |
Ted Kremenek | df74e25 | 2009-08-02 05:15:23 +0000 | [diff] [blame] | 835 | SymbolRef Sym = SR->getSymbol(); |
Ted Kremenek | bcf62a9 | 2009-08-25 22:55:09 +0000 | [diff] [blame] | 836 | QualType T = Sym->getType(getContext()); |
| 837 | QualType EleTy; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 838 | |
Ted Kremenek | bcf62a9 | 2009-08-25 22:55:09 +0000 | [diff] [blame] | 839 | if (const PointerType *PT = T->getAs<PointerType>()) |
| 840 | EleTy = PT->getPointeeType(); |
| 841 | else |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 842 | EleTy = T->getAs<ObjCObjectPointerType>()->getPointeeType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 843 | |
Ted Kremenek | 3bccf08 | 2009-07-11 00:58:27 +0000 | [diff] [blame] | 844 | SVal ZeroIdx = ValMgr.makeZeroArrayIndex(); |
| 845 | ER = MRMgr.getElementRegion(EleTy, ZeroIdx, SR, getContext()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 846 | break; |
Zhongxing Xu | 005f07b | 2009-06-19 04:51:14 +0000 | [diff] [blame] | 847 | } |
Ted Kremenek | 3bccf08 | 2009-07-11 00:58:27 +0000 | [diff] [blame] | 848 | case MemRegion::AllocaRegionKind: { |
Ted Kremenek | 3bccf08 | 2009-07-11 00:58:27 +0000 | [diff] [blame] | 849 | const AllocaRegion *AR = cast<AllocaRegion>(MR); |
Ted Kremenek | df74e25 | 2009-08-02 05:15:23 +0000 | [diff] [blame] | 850 | QualType T = getContext().CharTy; // Create an ElementRegion of bytes. |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 851 | QualType EleTy = T->getAs<PointerType>()->getPointeeType(); |
Ted Kremenek | 3bccf08 | 2009-07-11 00:58:27 +0000 | [diff] [blame] | 852 | SVal ZeroIdx = ValMgr.makeZeroArrayIndex(); |
| 853 | ER = MRMgr.getElementRegion(EleTy, ZeroIdx, AR, getContext()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 854 | break; |
Ted Kremenek | 3bccf08 | 2009-07-11 00:58:27 +0000 | [diff] [blame] | 855 | } |
Zhongxing Xu | a1718c7 | 2009-04-03 07:33:13 +0000 | [diff] [blame] | 856 | |
Ted Kremenek | 3bccf08 | 2009-07-11 00:58:27 +0000 | [diff] [blame] | 857 | case MemRegion::ElementRegionKind: { |
| 858 | ER = cast<ElementRegion>(MR); |
| 859 | break; |
| 860 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 861 | |
Ted Kremenek | 3bccf08 | 2009-07-11 00:58:27 +0000 | [diff] [blame] | 862 | // Not yet handled. |
| 863 | case MemRegion::VarRegionKind: |
Ted Kremenek | cd8f6ac | 2009-10-06 01:39:48 +0000 | [diff] [blame] | 864 | case MemRegion::StringRegionKind: { |
| 865 | |
| 866 | } |
| 867 | // Fall-through. |
Ted Kremenek | 3bccf08 | 2009-07-11 00:58:27 +0000 | [diff] [blame] | 868 | case MemRegion::CompoundLiteralRegionKind: |
| 869 | case MemRegion::FieldRegionKind: |
| 870 | case MemRegion::ObjCObjectRegionKind: |
| 871 | case MemRegion::ObjCIvarRegionKind: |
| 872 | return UnknownVal(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 873 | |
Ted Kremenek | eb1c7a0 | 2009-11-25 01:32:22 +0000 | [diff] [blame] | 874 | case MemRegion::FunctionTextRegionKind: |
| 875 | case MemRegion::BlockTextRegionKind: |
Ted Kremenek | 0a8112a | 2009-11-25 23:53:07 +0000 | [diff] [blame] | 876 | case MemRegion::BlockDataRegionKind: |
Ted Kremenek | 3bccf08 | 2009-07-11 00:58:27 +0000 | [diff] [blame] | 877 | // Technically this can happen if people do funny things with casts. |
| 878 | return UnknownVal(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 879 | |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 880 | case MemRegion::GenericMemSpaceRegionKind: |
| 881 | case MemRegion::StackLocalsSpaceRegionKind: |
| 882 | case MemRegion::StackArgumentsSpaceRegionKind: |
| 883 | case MemRegion::HeapSpaceRegionKind: |
| 884 | case MemRegion::GlobalsSpaceRegionKind: |
Ted Kremenek | 2b87ae4 | 2009-12-11 06:43:27 +0000 | [diff] [blame] | 885 | case MemRegion::UnknownSpaceRegionKind: |
Ted Kremenek | 3bccf08 | 2009-07-11 00:58:27 +0000 | [diff] [blame] | 886 | assert(0 && "Cannot perform pointer arithmetic on a MemSpace"); |
| 887 | return UnknownVal(); |
Zhongxing Xu | 5414a5c | 2009-06-21 13:24:24 +0000 | [diff] [blame] | 888 | } |
Zhongxing Xu | 2b1dc17 | 2009-03-11 07:43:49 +0000 | [diff] [blame] | 889 | |
Zhongxing Xu | 94aa6c1 | 2009-03-02 07:52:23 +0000 | [diff] [blame] | 890 | SVal Idx = ER->getIndex(); |
Zhongxing Xu | 94aa6c1 | 2009-03-02 07:52:23 +0000 | [diff] [blame] | 891 | nonloc::ConcreteInt* Base = dyn_cast<nonloc::ConcreteInt>(&Idx); |
Zhongxing Xu | 94aa6c1 | 2009-03-02 07:52:23 +0000 | [diff] [blame] | 892 | |
Ted Kremenek | cd8f6ac | 2009-10-06 01:39:48 +0000 | [diff] [blame] | 893 | // For now, only support: |
| 894 | // (a) concrete integer indices that can easily be resolved |
| 895 | // (b) 0 + symbolic index |
| 896 | if (Base) { |
| 897 | if (nonloc::ConcreteInt *Offset = dyn_cast<nonloc::ConcreteInt>(&R)) { |
| 898 | // FIXME: Should use SValuator here. |
| 899 | SVal NewIdx = |
| 900 | Base->evalBinOp(ValMgr, Op, |
Ted Kremenek | 4653739 | 2009-07-16 01:33:37 +0000 | [diff] [blame] | 901 | cast<nonloc::ConcreteInt>(ValMgr.convertToArrayIndex(*Offset))); |
Ted Kremenek | cd8f6ac | 2009-10-06 01:39:48 +0000 | [diff] [blame] | 902 | const MemRegion* NewER = |
| 903 | MRMgr.getElementRegion(ER->getElementType(), NewIdx, |
| 904 | ER->getSuperRegion(), getContext()); |
| 905 | return ValMgr.makeLoc(NewER); |
| 906 | } |
| 907 | if (0 == Base->getValue()) { |
| 908 | const MemRegion* NewER = |
| 909 | MRMgr.getElementRegion(ER->getElementType(), R, |
| 910 | ER->getSuperRegion(), getContext()); |
| 911 | return ValMgr.makeLoc(NewER); |
| 912 | } |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 913 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 914 | |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 915 | return UnknownVal(); |
Zhongxing Xu | 94aa6c1 | 2009-03-02 07:52:23 +0000 | [diff] [blame] | 916 | } |
| 917 | |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 918 | //===----------------------------------------------------------------------===// |
| 919 | // Loading values from regions. |
| 920 | //===----------------------------------------------------------------------===// |
| 921 | |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 922 | Optional<SVal> RegionStoreManager::getDirectBinding(RegionBindings B, |
| 923 | const MemRegion *R) { |
| 924 | if (const BindingVal *BV = B.lookup(R)) |
| 925 | return Optional<SVal>::create(BV->getDirectValue()); |
| 926 | |
| 927 | return Optional<SVal>(); |
| 928 | } |
| 929 | |
| 930 | Optional<SVal> RegionStoreManager::getDefaultBinding(RegionBindings B, |
Ted Kremenek | d4e5a60 | 2009-08-06 21:43:54 +0000 | [diff] [blame] | 931 | const MemRegion *R) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 932 | |
Ted Kremenek | d4e5a60 | 2009-08-06 21:43:54 +0000 | [diff] [blame] | 933 | if (R->isBoundable()) |
| 934 | if (const TypedRegion *TR = dyn_cast<TypedRegion>(R)) |
| 935 | if (TR->getValueType(getContext())->isUnionType()) |
| 936 | return UnknownVal(); |
| 937 | |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 938 | if (BindingVal const *V = B.lookup(R)) |
| 939 | return Optional<SVal>::create(V->getDefaultValue()); |
| 940 | |
| 941 | return Optional<SVal>(); |
| 942 | } |
| 943 | |
| 944 | Optional<SVal> RegionStoreManager::getBinding(RegionBindings B, |
| 945 | const MemRegion *R) { |
| 946 | if (const BindingVal *BV = B.lookup(R)) |
| 947 | return Optional<SVal>::create(BV->getValue()); |
| 948 | |
| 949 | return Optional<SVal>(); |
Ted Kremenek | d4e5a60 | 2009-08-06 21:43:54 +0000 | [diff] [blame] | 950 | } |
| 951 | |
Ted Kremenek | a6275a5 | 2009-07-15 02:31:43 +0000 | [diff] [blame] | 952 | static bool IsReinterpreted(QualType RTy, QualType UsedTy, ASTContext &Ctx) { |
| 953 | RTy = Ctx.getCanonicalType(RTy); |
| 954 | UsedTy = Ctx.getCanonicalType(UsedTy); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 955 | |
Ted Kremenek | a6275a5 | 2009-07-15 02:31:43 +0000 | [diff] [blame] | 956 | if (RTy == UsedTy) |
| 957 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 958 | |
| 959 | |
Ted Kremenek | 25c5457 | 2009-07-20 22:58:02 +0000 | [diff] [blame] | 960 | // Recursively check the types. We basically want to see if a pointer value |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 961 | // is ever reinterpreted as a non-pointer, e.g. void** and intptr_t* |
Ted Kremenek | 25c5457 | 2009-07-20 22:58:02 +0000 | [diff] [blame] | 962 | // represents a reinterpretation. |
| 963 | if (Loc::IsLocType(RTy) && Loc::IsLocType(UsedTy)) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 964 | const PointerType *PRTy = RTy->getAs<PointerType>(); |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 965 | const PointerType *PUsedTy = UsedTy->getAs<PointerType>(); |
Ted Kremenek | 25c5457 | 2009-07-20 22:58:02 +0000 | [diff] [blame] | 966 | |
| 967 | return PUsedTy && PRTy && |
| 968 | IsReinterpreted(PRTy->getPointeeType(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 969 | PUsedTy->getPointeeType(), Ctx); |
Ted Kremenek | 25c5457 | 2009-07-20 22:58:02 +0000 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | return true; |
Ted Kremenek | a6275a5 | 2009-07-15 02:31:43 +0000 | [diff] [blame] | 973 | } |
| 974 | |
Ted Kremenek | 0954cde | 2009-09-24 04:11:44 +0000 | [diff] [blame] | 975 | const ElementRegion * |
| 976 | RegionStoreManager::GetElementZeroRegion(const SymbolicRegion *SR, QualType T) { |
| 977 | ASTContext &Ctx = getContext(); |
| 978 | SVal idx = ValMgr.makeZeroArrayIndex(); |
| 979 | assert(!T.isNull()); |
| 980 | return MRMgr.getElementRegion(T, idx, SR, Ctx); |
| 981 | } |
| 982 | |
| 983 | |
| 984 | |
Ted Kremenek | 32c3fa4 | 2009-07-21 21:03:30 +0000 | [diff] [blame] | 985 | SValuator::CastResult |
| 986 | RegionStoreManager::Retrieve(const GRState *state, Loc L, QualType T) { |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 987 | |
Zhongxing Xu | 53bcdd4 | 2008-10-21 05:29:26 +0000 | [diff] [blame] | 988 | assert(!isa<UnknownVal>(L) && "location unknown"); |
| 989 | assert(!isa<UndefinedVal>(L) && "location undefined"); |
Ted Kremenek | 28172a2 | 2009-12-15 23:23:27 +0000 | [diff] [blame^] | 990 | |
Ted Kremenek | 869fb4a | 2008-12-24 07:46:32 +0000 | [diff] [blame] | 991 | // FIXME: Is this even possible? Shouldn't this be treated as a null |
| 992 | // dereference at a higher level? |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 993 | if (isa<loc::ConcreteInt>(L)) |
Ted Kremenek | 32c3fa4 | 2009-07-21 21:03:30 +0000 | [diff] [blame] | 994 | return SValuator::CastResult(state, UndefinedVal()); |
Ted Kremenek | 28172a2 | 2009-12-15 23:23:27 +0000 | [diff] [blame^] | 995 | |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 996 | const MemRegion *MR = cast<loc::MemRegionVal>(L).getRegion(); |
Zhongxing Xu | a1718c7 | 2009-04-03 07:33:13 +0000 | [diff] [blame] | 997 | |
Zhongxing Xu | 9184412 | 2009-05-20 09:18:48 +0000 | [diff] [blame] | 998 | // FIXME: return symbolic value for these cases. |
Zhongxing Xu | a1718c7 | 2009-04-03 07:33:13 +0000 | [diff] [blame] | 999 | // Example: |
| 1000 | // void f(int* p) { int x = *p; } |
Zhongxing Xu | 9184412 | 2009-05-20 09:18:48 +0000 | [diff] [blame] | 1001 | // char* p = alloca(); |
| 1002 | // read(p); |
| 1003 | // c = *p; |
Ted Kremenek | 60fbe8f | 2009-07-14 20:48:22 +0000 | [diff] [blame] | 1004 | if (isa<AllocaRegion>(MR)) |
Ted Kremenek | 32c3fa4 | 2009-07-21 21:03:30 +0000 | [diff] [blame] | 1005 | return SValuator::CastResult(state, UnknownVal()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1006 | |
Ted Kremenek | 0954cde | 2009-09-24 04:11:44 +0000 | [diff] [blame] | 1007 | if (const SymbolicRegion *SR = dyn_cast<SymbolicRegion>(MR)) |
| 1008 | MR = GetElementZeroRegion(SR, T); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1009 | |
Ted Kremenek | 968f0a6 | 2009-08-03 21:41:46 +0000 | [diff] [blame] | 1010 | if (isa<CodeTextRegion>(MR)) |
| 1011 | return SValuator::CastResult(state, UnknownVal()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1012 | |
Ted Kremenek | 869fb4a | 2008-12-24 07:46:32 +0000 | [diff] [blame] | 1013 | // FIXME: Perhaps this method should just take a 'const MemRegion*' argument |
| 1014 | // instead of 'Loc', and have the other Loc cases handled at a higher level. |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 1015 | const TypedRegion *R = cast<TypedRegion>(MR); |
Ted Kremenek | a6275a5 | 2009-07-15 02:31:43 +0000 | [diff] [blame] | 1016 | QualType RTy = R->getValueType(getContext()); |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 1017 | |
Ted Kremenek | 869fb4a | 2008-12-24 07:46:32 +0000 | [diff] [blame] | 1018 | // FIXME: We should eventually handle funny addressing. e.g.: |
| 1019 | // |
| 1020 | // int x = ...; |
| 1021 | // int *p = &x; |
| 1022 | // char *q = (char*) p; |
| 1023 | // char c = *q; // returns the first byte of 'x'. |
| 1024 | // |
| 1025 | // Such funny addressing will occur due to layering of regions. |
| 1026 | |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1027 | #if 0 |
Ted Kremenek | a6275a5 | 2009-07-15 02:31:43 +0000 | [diff] [blame] | 1028 | ASTContext &Ctx = getContext(); |
| 1029 | if (!T.isNull() && IsReinterpreted(RTy, T, Ctx)) { |
Ted Kremenek | 4653739 | 2009-07-16 01:33:37 +0000 | [diff] [blame] | 1030 | SVal ZeroIdx = ValMgr.makeZeroArrayIndex(); |
| 1031 | R = MRMgr.getElementRegion(T, ZeroIdx, R, Ctx); |
Ted Kremenek | a6275a5 | 2009-07-15 02:31:43 +0000 | [diff] [blame] | 1032 | RTy = T; |
Ted Kremenek | 41fb0df | 2009-07-15 04:23:32 +0000 | [diff] [blame] | 1033 | assert(Ctx.getCanonicalType(RTy) == |
| 1034 | Ctx.getCanonicalType(R->getValueType(Ctx))); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1035 | } |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1036 | #endif |
Zhongxing Xu | 3e001f3 | 2009-05-03 00:27:40 +0000 | [diff] [blame] | 1037 | |
Zhongxing Xu | 1038f9f | 2009-03-09 09:15:51 +0000 | [diff] [blame] | 1038 | if (RTy->isStructureType()) |
Ted Kremenek | 32c3fa4 | 2009-07-21 21:03:30 +0000 | [diff] [blame] | 1039 | return SValuator::CastResult(state, RetrieveStruct(state, R)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1040 | |
Ted Kremenek | d4e5a60 | 2009-08-06 21:43:54 +0000 | [diff] [blame] | 1041 | // FIXME: Handle unions. |
| 1042 | if (RTy->isUnionType()) |
| 1043 | return SValuator::CastResult(state, UnknownVal()); |
Zhongxing Xu | 3e001f3 | 2009-05-03 00:27:40 +0000 | [diff] [blame] | 1044 | |
| 1045 | if (RTy->isArrayType()) |
Ted Kremenek | 32c3fa4 | 2009-07-21 21:03:30 +0000 | [diff] [blame] | 1046 | return SValuator::CastResult(state, RetrieveArray(state, R)); |
Zhongxing Xu | 3e001f3 | 2009-05-03 00:27:40 +0000 | [diff] [blame] | 1047 | |
Zhongxing Xu | 1038f9f | 2009-03-09 09:15:51 +0000 | [diff] [blame] | 1048 | // FIXME: handle Vector types. |
| 1049 | if (RTy->isVectorType()) |
Ted Kremenek | 32c3fa4 | 2009-07-21 21:03:30 +0000 | [diff] [blame] | 1050 | return SValuator::CastResult(state, UnknownVal()); |
Zhongxing Xu | 99c2030 | 2009-06-28 14:16:39 +0000 | [diff] [blame] | 1051 | |
| 1052 | if (const FieldRegion* FR = dyn_cast<FieldRegion>(R)) |
Zhongxing Xu | 652be34 | 2009-11-16 04:49:44 +0000 | [diff] [blame] | 1053 | return SValuator::CastResult(state, |
| 1054 | CastRetrievedVal(RetrieveField(state, FR), FR, T)); |
Zhongxing Xu | 99c2030 | 2009-06-28 14:16:39 +0000 | [diff] [blame] | 1055 | |
| 1056 | if (const ElementRegion* ER = dyn_cast<ElementRegion>(R)) |
Zhongxing Xu | 652be34 | 2009-11-16 04:49:44 +0000 | [diff] [blame] | 1057 | return SValuator::CastResult(state, |
| 1058 | CastRetrievedVal(RetrieveElement(state, ER), ER, T)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1059 | |
Ted Kremenek | 25c5457 | 2009-07-20 22:58:02 +0000 | [diff] [blame] | 1060 | if (const ObjCIvarRegion *IVR = dyn_cast<ObjCIvarRegion>(R)) |
Zhongxing Xu | 652be34 | 2009-11-16 04:49:44 +0000 | [diff] [blame] | 1061 | return SValuator::CastResult(state, |
| 1062 | CastRetrievedVal(RetrieveObjCIvar(state, IVR), IVR, T)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1063 | |
Ted Kremenek | 9031dd7 | 2009-07-21 00:12:07 +0000 | [diff] [blame] | 1064 | if (const VarRegion *VR = dyn_cast<VarRegion>(R)) |
Zhongxing Xu | 652be34 | 2009-11-16 04:49:44 +0000 | [diff] [blame] | 1065 | return SValuator::CastResult(state, |
| 1066 | CastRetrievedVal(RetrieveVar(state, VR), VR, T)); |
Ted Kremenek | 25c5457 | 2009-07-20 22:58:02 +0000 | [diff] [blame] | 1067 | |
Ted Kremenek | 451ac09 | 2009-08-06 04:50:20 +0000 | [diff] [blame] | 1068 | RegionBindings B = GetRegionBindings(state->getStore()); |
| 1069 | RegionBindings::data_type* V = B.lookup(R); |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 1070 | |
| 1071 | // Check if the region has a binding. |
| 1072 | if (V) |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1073 | if (SVal const *SV = V->getValue()) |
| 1074 | return SValuator::CastResult(state, *SV); |
Ted Kremenek | 869fb4a | 2008-12-24 07:46:32 +0000 | [diff] [blame] | 1075 | |
Ted Kremenek | 869fb4a | 2008-12-24 07:46:32 +0000 | [diff] [blame] | 1076 | // The location does not have a bound value. This means that it has |
| 1077 | // the value it had upon its creation and/or entry to the analyzed |
| 1078 | // function/method. These are either symbolic values or 'undefined'. |
| 1079 | |
Ted Kremenek | 356e9d6 | 2009-07-22 04:35:42 +0000 | [diff] [blame] | 1080 | #if HEAP_UNDEFINED |
Ted Kremenek | bb7c96f | 2009-06-23 18:17:08 +0000 | [diff] [blame] | 1081 | if (R->hasHeapOrStackStorage()) { |
Ted Kremenek | 356e9d6 | 2009-07-22 04:35:42 +0000 | [diff] [blame] | 1082 | #else |
| 1083 | if (R->hasStackStorage()) { |
| 1084 | #endif |
Ted Kremenek | 869fb4a | 2008-12-24 07:46:32 +0000 | [diff] [blame] | 1085 | // All stack variables are considered to have undefined values |
| 1086 | // upon creation. All heap allocated blocks are considered to |
| 1087 | // have undefined values as well unless they are explicitly bound |
| 1088 | // to specific values. |
Ted Kremenek | 32c3fa4 | 2009-07-21 21:03:30 +0000 | [diff] [blame] | 1089 | return SValuator::CastResult(state, UndefinedVal()); |
Ted Kremenek | 869fb4a | 2008-12-24 07:46:32 +0000 | [diff] [blame] | 1090 | } |
| 1091 | |
Ted Kremenek | bb2b433 | 2009-07-02 22:16:42 +0000 | [diff] [blame] | 1092 | // All other values are symbolic. |
Ted Kremenek | 28172a2 | 2009-12-15 23:23:27 +0000 | [diff] [blame^] | 1093 | return SValuator::CastResult(state, ValMgr.getRegionValueSymbolVal(R, RTy)); |
Zhongxing Xu | 53bcdd4 | 2008-10-21 05:29:26 +0000 | [diff] [blame] | 1094 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1095 | |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1096 | std::pair<const GRState*, const MemRegion*> |
Ted Kremenek | 451ac09 | 2009-08-06 04:50:20 +0000 | [diff] [blame] | 1097 | RegionStoreManager::GetLazyBinding(RegionBindings B, const MemRegion *R) { |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1098 | if (Optional<SVal> OV = getDirectBinding(B, R)) |
| 1099 | if (const nonloc::LazyCompoundVal *V = |
| 1100 | dyn_cast<nonloc::LazyCompoundVal>(OV.getPointer())) |
| 1101 | return std::make_pair(V->getState(), V->getRegion()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1102 | |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1103 | if (const ElementRegion *ER = dyn_cast<ElementRegion>(R)) { |
| 1104 | const std::pair<const GRState *, const MemRegion *> &X = |
| 1105 | GetLazyBinding(B, ER->getSuperRegion()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1106 | |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1107 | if (X.first) |
| 1108 | return std::make_pair(X.first, |
| 1109 | MRMgr.getElementRegionWithSuper(ER, X.second)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1110 | } |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1111 | else if (const FieldRegion *FR = dyn_cast<FieldRegion>(R)) { |
| 1112 | const std::pair<const GRState *, const MemRegion *> &X = |
| 1113 | GetLazyBinding(B, FR->getSuperRegion()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1114 | |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1115 | if (X.first) |
| 1116 | return std::make_pair(X.first, |
| 1117 | MRMgr.getFieldRegionWithSuper(FR, X.second)); |
| 1118 | } |
| 1119 | |
| 1120 | return std::make_pair((const GRState*) 0, (const MemRegion *) 0); |
| 1121 | } |
Zhongxing Xu | 53bcdd4 | 2008-10-21 05:29:26 +0000 | [diff] [blame] | 1122 | |
Zhongxing Xu | c00346f | 2009-06-25 05:29:39 +0000 | [diff] [blame] | 1123 | SVal RegionStoreManager::RetrieveElement(const GRState* state, |
| 1124 | const ElementRegion* R) { |
| 1125 | // Check if the region has a binding. |
Ted Kremenek | 451ac09 | 2009-08-06 04:50:20 +0000 | [diff] [blame] | 1126 | RegionBindings B = GetRegionBindings(state->getStore()); |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1127 | if (Optional<SVal> V = getDirectBinding(B, R)) |
Zhongxing Xu | c00346f | 2009-06-25 05:29:39 +0000 | [diff] [blame] | 1128 | return *V; |
| 1129 | |
Ted Kremenek | 921109a | 2009-07-01 23:19:52 +0000 | [diff] [blame] | 1130 | const MemRegion* superR = R->getSuperRegion(); |
| 1131 | |
Zhongxing Xu | c00346f | 2009-06-25 05:29:39 +0000 | [diff] [blame] | 1132 | // Check if the region is an element region of a string literal. |
Ted Kremenek | 921109a | 2009-07-01 23:19:52 +0000 | [diff] [blame] | 1133 | if (const StringRegion *StrR=dyn_cast<StringRegion>(superR)) { |
Ted Kremenek | 95efe0f | 2009-09-29 16:36:48 +0000 | [diff] [blame] | 1134 | // FIXME: Handle loads from strings where the literal is treated as |
| 1135 | // an integer, e.g., *((unsigned int*)"hello") |
| 1136 | ASTContext &Ctx = getContext(); |
Douglas Gregor | 89c49f0 | 2009-11-09 22:08:55 +0000 | [diff] [blame] | 1137 | QualType T = Ctx.getAsArrayType(StrR->getValueType(Ctx))->getElementType(); |
Ted Kremenek | 95efe0f | 2009-09-29 16:36:48 +0000 | [diff] [blame] | 1138 | if (T != Ctx.getCanonicalType(R->getElementType())) |
| 1139 | return UnknownVal(); |
| 1140 | |
Zhongxing Xu | c00346f | 2009-06-25 05:29:39 +0000 | [diff] [blame] | 1141 | const StringLiteral *Str = StrR->getStringLiteral(); |
| 1142 | SVal Idx = R->getIndex(); |
| 1143 | if (nonloc::ConcreteInt *CI = dyn_cast<nonloc::ConcreteInt>(&Idx)) { |
| 1144 | int64_t i = CI->getValue().getSExtValue(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1145 | int64_t byteLength = Str->getByteLength(); |
Ted Kremenek | 0667db3 | 2009-09-05 17:59:01 +0000 | [diff] [blame] | 1146 | if (i > byteLength) { |
| 1147 | // Buffer overflow checking in GRExprEngine should handle this case, |
| 1148 | // but we shouldn't rely on it to not overflow here if that checking |
| 1149 | // is disabled. |
| 1150 | return UnknownVal(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1151 | } |
Ted Kremenek | 0667db3 | 2009-09-05 17:59:01 +0000 | [diff] [blame] | 1152 | char c = (i == byteLength) ? '\0' : Str->getStrData()[i]; |
Ted Kremenek | 95efe0f | 2009-09-29 16:36:48 +0000 | [diff] [blame] | 1153 | return ValMgr.makeIntVal(c, T); |
Zhongxing Xu | c00346f | 2009-06-25 05:29:39 +0000 | [diff] [blame] | 1154 | } |
| 1155 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1156 | |
Ted Kremenek | 566a6fa | 2009-08-06 22:33:36 +0000 | [diff] [blame] | 1157 | // Check if the immediate super region has a direct binding. |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1158 | if (Optional<SVal> V = getDirectBinding(B, superR)) { |
Ted Kremenek | a6275a5 | 2009-07-15 02:31:43 +0000 | [diff] [blame] | 1159 | if (SymbolRef parentSym = V->getAsSymbol()) |
| 1160 | return ValMgr.getDerivedRegionValueSymbolVal(parentSym, R); |
Ted Kremenek | 356e9d6 | 2009-07-22 04:35:42 +0000 | [diff] [blame] | 1161 | |
| 1162 | if (V->isUnknownOrUndef()) |
| 1163 | return *V; |
Ted Kremenek | 566a6fa | 2009-08-06 22:33:36 +0000 | [diff] [blame] | 1164 | |
| 1165 | // Handle LazyCompoundVals for the immediate super region. Other cases |
| 1166 | // are handled in 'RetrieveFieldOrElementCommon'. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1167 | if (const nonloc::LazyCompoundVal *LCV = |
Ted Kremenek | 566a6fa | 2009-08-06 22:33:36 +0000 | [diff] [blame] | 1168 | dyn_cast<nonloc::LazyCompoundVal>(V)) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1169 | |
Ted Kremenek | 566a6fa | 2009-08-06 22:33:36 +0000 | [diff] [blame] | 1170 | R = MRMgr.getElementRegionWithSuper(R, LCV->getRegion()); |
| 1171 | return RetrieveElement(LCV->getState(), R); |
| 1172 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1173 | |
Ted Kremenek | a6275a5 | 2009-07-15 02:31:43 +0000 | [diff] [blame] | 1174 | // Other cases: give up. |
Zhongxing Xu | 8834af3 | 2009-07-03 06:11:41 +0000 | [diff] [blame] | 1175 | return UnknownVal(); |
Zhongxing Xu | 7abe019 | 2009-06-30 12:32:59 +0000 | [diff] [blame] | 1176 | } |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1177 | |
Ted Kremenek | 566a6fa | 2009-08-06 22:33:36 +0000 | [diff] [blame] | 1178 | return RetrieveFieldOrElementCommon(state, R, R->getElementType(), superR); |
Zhongxing Xu | c00346f | 2009-06-25 05:29:39 +0000 | [diff] [blame] | 1179 | } |
| 1180 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1181 | SVal RegionStoreManager::RetrieveField(const GRState* state, |
Zhongxing Xu | 490b0f0 | 2009-06-25 04:50:44 +0000 | [diff] [blame] | 1182 | const FieldRegion* R) { |
Zhongxing Xu | 490b0f0 | 2009-06-25 04:50:44 +0000 | [diff] [blame] | 1183 | |
| 1184 | // Check if the region has a binding. |
Ted Kremenek | 451ac09 | 2009-08-06 04:50:20 +0000 | [diff] [blame] | 1185 | RegionBindings B = GetRegionBindings(state->getStore()); |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1186 | if (Optional<SVal> V = getDirectBinding(B, R)) |
Zhongxing Xu | 490b0f0 | 2009-06-25 04:50:44 +0000 | [diff] [blame] | 1187 | return *V; |
| 1188 | |
Ted Kremenek | 566a6fa | 2009-08-06 22:33:36 +0000 | [diff] [blame] | 1189 | QualType Ty = R->getValueType(getContext()); |
| 1190 | return RetrieveFieldOrElementCommon(state, R, Ty, R->getSuperRegion()); |
| 1191 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1192 | |
Ted Kremenek | 566a6fa | 2009-08-06 22:33:36 +0000 | [diff] [blame] | 1193 | SVal RegionStoreManager::RetrieveFieldOrElementCommon(const GRState *state, |
| 1194 | const TypedRegion *R, |
| 1195 | QualType Ty, |
| 1196 | const MemRegion *superR) { |
| 1197 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1198 | // At this point we have already checked in either RetrieveElement or |
Ted Kremenek | 566a6fa | 2009-08-06 22:33:36 +0000 | [diff] [blame] | 1199 | // RetrieveField if 'R' has a direct binding. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1200 | |
Ted Kremenek | 566a6fa | 2009-08-06 22:33:36 +0000 | [diff] [blame] | 1201 | RegionBindings B = GetRegionBindings(state->getStore()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1202 | |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1203 | while (superR) { |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1204 | if (const Optional<SVal> &D = getDefaultBinding(B, superR)) { |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1205 | if (SymbolRef parentSym = D->getAsSymbol()) |
| 1206 | return ValMgr.getDerivedRegionValueSymbolVal(parentSym, R); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1207 | |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1208 | if (D->isZeroConstant()) |
| 1209 | return ValMgr.makeZeroVal(Ty); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1210 | |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1211 | if (D->isUnknown()) |
| 1212 | return *D; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1213 | |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1214 | assert(0 && "Unknown default value"); |
| 1215 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1216 | |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1217 | // If our super region is a field or element itself, walk up the region |
| 1218 | // hierarchy to see if there is a default value installed in an ancestor. |
| 1219 | if (isa<FieldRegion>(superR) || isa<ElementRegion>(superR)) { |
| 1220 | superR = cast<SubRegion>(superR)->getSuperRegion(); |
| 1221 | continue; |
| 1222 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1223 | |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1224 | break; |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1225 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1226 | |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1227 | // Lazy binding? |
| 1228 | const GRState *lazyBindingState = NULL; |
Ted Kremenek | 566a6fa | 2009-08-06 22:33:36 +0000 | [diff] [blame] | 1229 | const MemRegion *lazyBindingRegion = NULL; |
| 1230 | llvm::tie(lazyBindingState, lazyBindingRegion) = GetLazyBinding(B, R); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1231 | |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1232 | if (lazyBindingState) { |
Ted Kremenek | 566a6fa | 2009-08-06 22:33:36 +0000 | [diff] [blame] | 1233 | assert(lazyBindingRegion && "Lazy-binding region not set"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1234 | |
Ted Kremenek | 566a6fa | 2009-08-06 22:33:36 +0000 | [diff] [blame] | 1235 | if (isa<ElementRegion>(R)) |
| 1236 | return RetrieveElement(lazyBindingState, |
| 1237 | cast<ElementRegion>(lazyBindingRegion)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1238 | |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1239 | return RetrieveField(lazyBindingState, |
Ted Kremenek | 566a6fa | 2009-08-06 22:33:36 +0000 | [diff] [blame] | 1240 | cast<FieldRegion>(lazyBindingRegion)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1241 | } |
| 1242 | |
Ted Kremenek | 566a6fa | 2009-08-06 22:33:36 +0000 | [diff] [blame] | 1243 | if (R->hasStackStorage() && !R->hasParametersStorage()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1244 | |
Ted Kremenek | 566a6fa | 2009-08-06 22:33:36 +0000 | [diff] [blame] | 1245 | if (isa<ElementRegion>(R)) { |
| 1246 | // Currently we don't reason specially about Clang-style vectors. Check |
| 1247 | // if superR is a vector and if so return Unknown. |
| 1248 | if (const TypedRegion *typedSuperR = dyn_cast<TypedRegion>(superR)) { |
| 1249 | if (typedSuperR->getValueType(getContext())->isVectorType()) |
| 1250 | return UnknownVal(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1251 | } |
Ted Kremenek | 566a6fa | 2009-08-06 22:33:36 +0000 | [diff] [blame] | 1252 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1253 | |
Zhongxing Xu | 490b0f0 | 2009-06-25 04:50:44 +0000 | [diff] [blame] | 1254 | return UndefinedVal(); |
Ted Kremenek | 566a6fa | 2009-08-06 22:33:36 +0000 | [diff] [blame] | 1255 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1256 | |
Ted Kremenek | bb2b433 | 2009-07-02 22:16:42 +0000 | [diff] [blame] | 1257 | // All other values are symbolic. |
Ted Kremenek | 28172a2 | 2009-12-15 23:23:27 +0000 | [diff] [blame^] | 1258 | return ValMgr.getRegionValueSymbolVal(R, Ty); |
Zhongxing Xu | 490b0f0 | 2009-06-25 04:50:44 +0000 | [diff] [blame] | 1259 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1260 | |
| 1261 | SVal RegionStoreManager::RetrieveObjCIvar(const GRState* state, |
Ted Kremenek | 5bd2fe3 | 2009-07-15 06:09:28 +0000 | [diff] [blame] | 1262 | const ObjCIvarRegion* R) { |
| 1263 | |
Ted Kremenek | 5bd2fe3 | 2009-07-15 06:09:28 +0000 | [diff] [blame] | 1264 | // Check if the region has a binding. |
Ted Kremenek | 451ac09 | 2009-08-06 04:50:20 +0000 | [diff] [blame] | 1265 | RegionBindings B = GetRegionBindings(state->getStore()); |
Ted Kremenek | 5bd2fe3 | 2009-07-15 06:09:28 +0000 | [diff] [blame] | 1266 | |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1267 | if (Optional<SVal> V = getDirectBinding(B, R)) |
Ted Kremenek | 5bd2fe3 | 2009-07-15 06:09:28 +0000 | [diff] [blame] | 1268 | return *V; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1269 | |
Ted Kremenek | 5bd2fe3 | 2009-07-15 06:09:28 +0000 | [diff] [blame] | 1270 | const MemRegion *superR = R->getSuperRegion(); |
| 1271 | |
Ted Kremenek | ab22ee9 | 2009-10-20 01:20:57 +0000 | [diff] [blame] | 1272 | // Check if the super region has a default binding. |
| 1273 | if (Optional<SVal> V = getDefaultBinding(B, superR)) { |
Ted Kremenek | 5bd2fe3 | 2009-07-15 06:09:28 +0000 | [diff] [blame] | 1274 | if (SymbolRef parentSym = V->getAsSymbol()) |
| 1275 | return ValMgr.getDerivedRegionValueSymbolVal(parentSym, R); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1276 | |
Ted Kremenek | 5bd2fe3 | 2009-07-15 06:09:28 +0000 | [diff] [blame] | 1277 | // Other cases: give up. |
| 1278 | return UnknownVal(); |
| 1279 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1280 | |
Ted Kremenek | 25c5457 | 2009-07-20 22:58:02 +0000 | [diff] [blame] | 1281 | return RetrieveLazySymbol(state, R); |
| 1282 | } |
| 1283 | |
Ted Kremenek | 9031dd7 | 2009-07-21 00:12:07 +0000 | [diff] [blame] | 1284 | SVal RegionStoreManager::RetrieveVar(const GRState *state, |
| 1285 | const VarRegion *R) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1286 | |
Ted Kremenek | 9031dd7 | 2009-07-21 00:12:07 +0000 | [diff] [blame] | 1287 | // Check if the region has a binding. |
Ted Kremenek | 451ac09 | 2009-08-06 04:50:20 +0000 | [diff] [blame] | 1288 | RegionBindings B = GetRegionBindings(state->getStore()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1289 | |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1290 | if (Optional<SVal> V = getDirectBinding(B, R)) |
Ted Kremenek | 9031dd7 | 2009-07-21 00:12:07 +0000 | [diff] [blame] | 1291 | return *V; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1292 | |
Ted Kremenek | 9031dd7 | 2009-07-21 00:12:07 +0000 | [diff] [blame] | 1293 | // Lazily derive a value for the VarRegion. |
| 1294 | const VarDecl *VD = R->getDecl(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1295 | |
Ted Kremenek | 2b87ae4 | 2009-12-11 06:43:27 +0000 | [diff] [blame] | 1296 | if (R->hasGlobalsOrParametersStorage() || |
| 1297 | isa<UnknownSpaceRegion>(R->getMemorySpace())) |
Ted Kremenek | 28172a2 | 2009-12-15 23:23:27 +0000 | [diff] [blame^] | 1298 | return ValMgr.getRegionValueSymbolVal(R, VD->getType()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1299 | |
Ted Kremenek | 9031dd7 | 2009-07-21 00:12:07 +0000 | [diff] [blame] | 1300 | return UndefinedVal(); |
| 1301 | } |
| 1302 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1303 | SVal RegionStoreManager::RetrieveLazySymbol(const GRState *state, |
Ted Kremenek | 25c5457 | 2009-07-20 22:58:02 +0000 | [diff] [blame] | 1304 | const TypedRegion *R) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1305 | |
Ted Kremenek | 25c5457 | 2009-07-20 22:58:02 +0000 | [diff] [blame] | 1306 | QualType valTy = R->getValueType(getContext()); |
Ted Kremenek | 356e9d6 | 2009-07-22 04:35:42 +0000 | [diff] [blame] | 1307 | |
Ted Kremenek | 5bd2fe3 | 2009-07-15 06:09:28 +0000 | [diff] [blame] | 1308 | // All other values are symbolic. |
Ted Kremenek | 28172a2 | 2009-12-15 23:23:27 +0000 | [diff] [blame^] | 1309 | return ValMgr.getRegionValueSymbolVal(R, valTy); |
Ted Kremenek | 5bd2fe3 | 2009-07-15 06:09:28 +0000 | [diff] [blame] | 1310 | } |
| 1311 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1312 | SVal RegionStoreManager::RetrieveStruct(const GRState *state, |
| 1313 | const TypedRegion* R) { |
Zhongxing Xu | a82d8aa | 2009-05-09 03:57:34 +0000 | [diff] [blame] | 1314 | QualType T = R->getValueType(getContext()); |
Zhongxing Xu | 6e3f01c | 2008-10-31 07:16:08 +0000 | [diff] [blame] | 1315 | assert(T->isStructureType()); |
| 1316 | |
Zhongxing Xu | b7507d1 | 2009-06-11 07:27:30 +0000 | [diff] [blame] | 1317 | const RecordType* RT = T->getAsStructureType(); |
Zhongxing Xu | 6e3f01c | 2008-10-31 07:16:08 +0000 | [diff] [blame] | 1318 | RecordDecl* RD = RT->getDecl(); |
| 1319 | assert(RD->isDefinition()); |
Mike Stump | 1aeb247 | 2009-08-06 12:56:50 +0000 | [diff] [blame] | 1320 | (void)RD; |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1321 | #if USE_EXPLICIT_COMPOUND |
Zhongxing Xu | 6e3f01c | 2008-10-31 07:16:08 +0000 | [diff] [blame] | 1322 | llvm::ImmutableList<SVal> StructVal = getBasicVals().getEmptySValList(); |
| 1323 | |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 1324 | // FIXME: We shouldn't use a std::vector. If RecordDecl doesn't have a |
| 1325 | // reverse iterator, we should implement one. |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1326 | std::vector<FieldDecl *> Fields(RD->field_begin(), RD->field_end()); |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 1327 | |
Douglas Gregor | e267ff3 | 2008-12-11 20:41:00 +0000 | [diff] [blame] | 1328 | for (std::vector<FieldDecl *>::reverse_iterator Field = Fields.rbegin(), |
| 1329 | FieldEnd = Fields.rend(); |
| 1330 | Field != FieldEnd; ++Field) { |
| 1331 | FieldRegion* FR = MRMgr.getFieldRegion(*Field, R); |
Zhongxing Xu | 3e001f3 | 2009-05-03 00:27:40 +0000 | [diff] [blame] | 1332 | QualType FTy = (*Field)->getType(); |
Ted Kremenek | 32c3fa4 | 2009-07-21 21:03:30 +0000 | [diff] [blame] | 1333 | SVal FieldValue = Retrieve(state, loc::MemRegionVal(FR), FTy).getSVal(); |
Zhongxing Xu | 6e3f01c | 2008-10-31 07:16:08 +0000 | [diff] [blame] | 1334 | StructVal = getBasicVals().consVals(FieldValue, StructVal); |
| 1335 | } |
| 1336 | |
Zhongxing Xu | d91ee27 | 2009-06-23 09:02:15 +0000 | [diff] [blame] | 1337 | return ValMgr.makeCompoundVal(T, StructVal); |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1338 | #else |
| 1339 | return ValMgr.makeLazyCompoundVal(state, R); |
| 1340 | #endif |
Zhongxing Xu | 6e3f01c | 2008-10-31 07:16:08 +0000 | [diff] [blame] | 1341 | } |
| 1342 | |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 1343 | SVal RegionStoreManager::RetrieveArray(const GRState *state, |
| 1344 | const TypedRegion * R) { |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1345 | #if USE_EXPLICIT_COMPOUND |
Zhongxing Xu | a82d8aa | 2009-05-09 03:57:34 +0000 | [diff] [blame] | 1346 | QualType T = R->getValueType(getContext()); |
Zhongxing Xu | 3e001f3 | 2009-05-03 00:27:40 +0000 | [diff] [blame] | 1347 | ConstantArrayType* CAT = cast<ConstantArrayType>(T.getTypePtr()); |
| 1348 | |
| 1349 | llvm::ImmutableList<SVal> ArrayVal = getBasicVals().getEmptySValList(); |
Ted Kremenek | 4653739 | 2009-07-16 01:33:37 +0000 | [diff] [blame] | 1350 | uint64_t size = CAT->getSize().getZExtValue(); |
| 1351 | for (uint64_t i = 0; i < size; ++i) { |
| 1352 | SVal Idx = ValMgr.makeArrayIndex(i); |
Zhongxing Xu | 143b2fc | 2009-06-16 09:55:50 +0000 | [diff] [blame] | 1353 | ElementRegion* ER = MRMgr.getElementRegion(CAT->getElementType(), Idx, R, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1354 | getContext()); |
Ted Kremenek | f936f45 | 2009-05-04 06:18:28 +0000 | [diff] [blame] | 1355 | QualType ETy = ER->getElementType(); |
Ted Kremenek | 32c3fa4 | 2009-07-21 21:03:30 +0000 | [diff] [blame] | 1356 | SVal ElementVal = Retrieve(state, loc::MemRegionVal(ER), ETy).getSVal(); |
Zhongxing Xu | 3e001f3 | 2009-05-03 00:27:40 +0000 | [diff] [blame] | 1357 | ArrayVal = getBasicVals().consVals(ElementVal, ArrayVal); |
| 1358 | } |
| 1359 | |
Zhongxing Xu | d91ee27 | 2009-06-23 09:02:15 +0000 | [diff] [blame] | 1360 | return ValMgr.makeCompoundVal(T, ArrayVal); |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1361 | #else |
| 1362 | assert(isa<ConstantArrayType>(R->getValueType(getContext()))); |
| 1363 | return ValMgr.makeLazyCompoundVal(state, R); |
| 1364 | #endif |
Zhongxing Xu | 3e001f3 | 2009-05-03 00:27:40 +0000 | [diff] [blame] | 1365 | } |
| 1366 | |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1367 | //===----------------------------------------------------------------------===// |
| 1368 | // Binding values to regions. |
| 1369 | //===----------------------------------------------------------------------===// |
Zhongxing Xu | 1789275 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 1370 | |
Zhongxing Xu | 9c9ca08 | 2008-12-16 02:36:30 +0000 | [diff] [blame] | 1371 | Store RegionStoreManager::Remove(Store store, Loc L) { |
Ted Kremenek | 0964a06 | 2009-01-21 06:57:53 +0000 | [diff] [blame] | 1372 | const MemRegion* R = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1373 | |
Ted Kremenek | 0964a06 | 2009-01-21 06:57:53 +0000 | [diff] [blame] | 1374 | if (isa<loc::MemRegionVal>(L)) |
| 1375 | R = cast<loc::MemRegionVal>(L).getRegion(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1376 | |
Ted Kremenek | 0964a06 | 2009-01-21 06:57:53 +0000 | [diff] [blame] | 1377 | if (R) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1378 | RegionBindings B = GetRegionBindings(store); |
Ted Kremenek | 0964a06 | 2009-01-21 06:57:53 +0000 | [diff] [blame] | 1379 | return RBFactory.Remove(B, R).getRoot(); |
| 1380 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1381 | |
Ted Kremenek | 0964a06 | 2009-01-21 06:57:53 +0000 | [diff] [blame] | 1382 | return store; |
Zhongxing Xu | 9c9ca08 | 2008-12-16 02:36:30 +0000 | [diff] [blame] | 1383 | } |
| 1384 | |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 1385 | const GRState *RegionStoreManager::Bind(const GRState *state, Loc L, SVal V) { |
Zhongxing Xu | 87453d1 | 2009-06-28 10:16:11 +0000 | [diff] [blame] | 1386 | if (isa<loc::ConcreteInt>(L)) |
| 1387 | return state; |
| 1388 | |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1389 | // If we get here, the location should be a region. |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1390 | const MemRegion *R = cast<loc::MemRegionVal>(L).getRegion(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1391 | |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1392 | // Check if the region is a struct region. |
| 1393 | if (const TypedRegion* TR = dyn_cast<TypedRegion>(R)) |
| 1394 | if (TR->getValueType(getContext())->isStructureType()) |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 1395 | return BindStruct(state, TR, V); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1396 | |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1397 | // Special case: the current region represents a cast and it and the super |
| 1398 | // region both have pointer types or intptr_t types. If so, perform the |
| 1399 | // bind to the super region. |
| 1400 | // This is needed to support OSAtomicCompareAndSwap and friends or other |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1401 | // loads that treat integers as pointers and vis versa. |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1402 | if (const ElementRegion *ER = dyn_cast<ElementRegion>(R)) { |
| 1403 | if (ER->getIndex().isZeroConstant()) { |
| 1404 | if (const TypedRegion *superR = |
| 1405 | dyn_cast<TypedRegion>(ER->getSuperRegion())) { |
| 1406 | ASTContext &Ctx = getContext(); |
| 1407 | QualType superTy = superR->getValueType(Ctx); |
| 1408 | QualType erTy = ER->getValueType(Ctx); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1409 | |
| 1410 | if (IsAnyPointerOrIntptr(superTy, Ctx) && |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1411 | IsAnyPointerOrIntptr(erTy, Ctx)) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1412 | SValuator::CastResult cr = |
| 1413 | ValMgr.getSValuator().EvalCast(V, state, superTy, erTy); |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1414 | return Bind(cr.getState(), loc::MemRegionVal(superR), cr.getSVal()); |
| 1415 | } |
Ted Kremenek | 69181a8 | 2009-09-21 22:58:52 +0000 | [diff] [blame] | 1416 | // For now, just invalidate the fields of the struct/union/class. |
| 1417 | // FIXME: Precisely handle the fields of the record. |
| 1418 | if (superTy->isRecordType()) |
Ted Kremenek | 473e167 | 2009-10-16 00:30:49 +0000 | [diff] [blame] | 1419 | return InvalidateRegion(state, superR, NULL, 0, NULL); |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1420 | } |
| 1421 | } |
| 1422 | } |
Ted Kremenek | 0954cde | 2009-09-24 04:11:44 +0000 | [diff] [blame] | 1423 | else if (const SymbolicRegion *SR = dyn_cast<SymbolicRegion>(R)) { |
| 1424 | // Binding directly to a symbolic region should be treated as binding |
| 1425 | // to element 0. |
| 1426 | QualType T = SR->getSymbol()->getType(getContext()); |
Ted Kremenek | 35dcad8 | 2009-09-24 06:24:32 +0000 | [diff] [blame] | 1427 | T = T->getAs<PointerType>()->getPointeeType(); |
Ted Kremenek | 0954cde | 2009-09-24 04:11:44 +0000 | [diff] [blame] | 1428 | R = GetElementZeroRegion(SR, T); |
| 1429 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1430 | |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1431 | // Perform the binding. |
Ted Kremenek | 451ac09 | 2009-08-06 04:50:20 +0000 | [diff] [blame] | 1432 | RegionBindings B = GetRegionBindings(state->getStore()); |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1433 | return state->makeWithStore( |
| 1434 | RBFactory.Add(B, R, BindingVal(V, BindingVal::Direct)).getRoot()); |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1435 | } |
| 1436 | |
Ted Kremenek | d17da2b | 2009-08-21 22:28:32 +0000 | [diff] [blame] | 1437 | const GRState *RegionStoreManager::BindDecl(const GRState *ST, |
Ted Kremenek | f6f56d4 | 2009-11-04 00:09:15 +0000 | [diff] [blame] | 1438 | const VarRegion *VR, |
Ted Kremenek | d17da2b | 2009-08-21 22:28:32 +0000 | [diff] [blame] | 1439 | SVal InitVal) { |
Zhongxing Xu | a4f28ff | 2008-11-13 08:41:36 +0000 | [diff] [blame] | 1440 | |
Ted Kremenek | f6f56d4 | 2009-11-04 00:09:15 +0000 | [diff] [blame] | 1441 | QualType T = VR->getDecl()->getType(); |
Zhongxing Xu | f0dfa8d | 2008-10-31 08:10:01 +0000 | [diff] [blame] | 1442 | |
Ted Kremenek | 0964a06 | 2009-01-21 06:57:53 +0000 | [diff] [blame] | 1443 | if (T->isArrayType()) |
Ted Kremenek | d17da2b | 2009-08-21 22:28:32 +0000 | [diff] [blame] | 1444 | return BindArray(ST, VR, InitVal); |
Ted Kremenek | 0964a06 | 2009-01-21 06:57:53 +0000 | [diff] [blame] | 1445 | if (T->isStructureType()) |
Ted Kremenek | d17da2b | 2009-08-21 22:28:32 +0000 | [diff] [blame] | 1446 | return BindStruct(ST, VR, InitVal); |
Zhongxing Xu | d463d44 | 2008-11-02 12:13:30 +0000 | [diff] [blame] | 1447 | |
Ted Kremenek | d17da2b | 2009-08-21 22:28:32 +0000 | [diff] [blame] | 1448 | return Bind(ST, ValMgr.makeLoc(VR), InitVal); |
Zhongxing Xu | 1789275 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 1449 | } |
Zhongxing Xu | 53bcdd4 | 2008-10-21 05:29:26 +0000 | [diff] [blame] | 1450 | |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 1451 | // FIXME: this method should be merged into Bind(). |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 1452 | const GRState * |
| 1453 | RegionStoreManager::BindCompoundLiteral(const GRState *state, |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 1454 | const CompoundLiteralExpr *CL, |
| 1455 | const LocationContext *LC, |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 1456 | SVal V) { |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 1457 | return Bind(state, loc::MemRegionVal(MRMgr.getCompoundLiteralRegion(CL, LC)), |
| 1458 | V); |
Zhongxing Xu | f22679e | 2008-11-07 10:38:33 +0000 | [diff] [blame] | 1459 | } |
| 1460 | |
Ted Kremenek | 027e266 | 2009-11-19 20:20:24 +0000 | [diff] [blame] | 1461 | const GRState *RegionStoreManager::setImplicitDefaultValue(const GRState *state, |
| 1462 | const MemRegion *R, |
| 1463 | QualType T) { |
| 1464 | Store store = state->getStore(); |
| 1465 | RegionBindings B = GetRegionBindings(store); |
| 1466 | SVal V; |
| 1467 | |
| 1468 | if (Loc::IsLocType(T)) |
| 1469 | V = ValMgr.makeNull(); |
| 1470 | else if (T->isIntegerType()) |
| 1471 | V = ValMgr.makeZeroVal(T); |
| 1472 | else if (T->isStructureType() || T->isArrayType()) { |
| 1473 | // Set the default value to a zero constant when it is a structure |
| 1474 | // or array. The type doesn't really matter. |
| 1475 | V = ValMgr.makeZeroVal(ValMgr.getContext().IntTy); |
| 1476 | } |
| 1477 | else { |
| 1478 | return state; |
| 1479 | } |
| 1480 | |
| 1481 | B = RBFactory.Add(B, R, BindingVal(V, BindingVal::Default)); |
| 1482 | return state->makeWithStore(B.getRoot()); |
| 1483 | } |
| 1484 | |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 1485 | const GRState *RegionStoreManager::BindArray(const GRState *state, |
Ted Kremenek | 4653739 | 2009-07-16 01:33:37 +0000 | [diff] [blame] | 1486 | const TypedRegion* R, |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 1487 | SVal Init) { |
| 1488 | |
Zhongxing Xu | a82d8aa | 2009-05-09 03:57:34 +0000 | [diff] [blame] | 1489 | QualType T = R->getValueType(getContext()); |
Zhongxing Xu | 1a12a0e | 2008-10-31 10:24:47 +0000 | [diff] [blame] | 1490 | ConstantArrayType* CAT = cast<ConstantArrayType>(T.getTypePtr()); |
Zhongxing Xu | 087d6c2 | 2009-06-23 05:23:38 +0000 | [diff] [blame] | 1491 | QualType ElementTy = CAT->getElementType(); |
Zhongxing Xu | 1a12a0e | 2008-10-31 10:24:47 +0000 | [diff] [blame] | 1492 | |
Ted Kremenek | 4653739 | 2009-07-16 01:33:37 +0000 | [diff] [blame] | 1493 | uint64_t size = CAT->getSize().getZExtValue(); |
Zhongxing Xu | 6987c7b | 2008-11-30 05:49:49 +0000 | [diff] [blame] | 1494 | |
| 1495 | // Check if the init expr is a StringLiteral. |
| 1496 | if (isa<loc::MemRegionVal>(Init)) { |
| 1497 | const MemRegion* InitR = cast<loc::MemRegionVal>(Init).getRegion(); |
| 1498 | const StringLiteral* S = cast<StringRegion>(InitR)->getStringLiteral(); |
| 1499 | const char* str = S->getStrData(); |
| 1500 | unsigned len = S->getByteLength(); |
| 1501 | unsigned j = 0; |
| 1502 | |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 1503 | // Copy bytes from the string literal into the target array. Trailing bytes |
| 1504 | // in the array that are not covered by the string literal are initialized |
| 1505 | // to zero. |
Ted Kremenek | 4653739 | 2009-07-16 01:33:37 +0000 | [diff] [blame] | 1506 | for (uint64_t i = 0; i < size; ++i, ++j) { |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 1507 | if (j >= len) |
| 1508 | break; |
| 1509 | |
Ted Kremenek | 4653739 | 2009-07-16 01:33:37 +0000 | [diff] [blame] | 1510 | SVal Idx = ValMgr.makeArrayIndex(i); |
Ted Kremenek | b48ad64 | 2009-12-04 00:26:31 +0000 | [diff] [blame] | 1511 | const ElementRegion* ER = MRMgr.getElementRegion(ElementTy, Idx, R, |
| 1512 | getContext()); |
Zhongxing Xu | 6987c7b | 2008-11-30 05:49:49 +0000 | [diff] [blame] | 1513 | |
Zhongxing Xu | d91ee27 | 2009-06-23 09:02:15 +0000 | [diff] [blame] | 1514 | SVal V = ValMgr.makeIntVal(str[j], sizeof(char)*8, true); |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 1515 | state = Bind(state, loc::MemRegionVal(ER), V); |
Zhongxing Xu | 6987c7b | 2008-11-30 05:49:49 +0000 | [diff] [blame] | 1516 | } |
| 1517 | |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 1518 | return state; |
Zhongxing Xu | 6987c7b | 2008-11-30 05:49:49 +0000 | [diff] [blame] | 1519 | } |
| 1520 | |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1521 | // Handle lazy compound values. |
| 1522 | if (nonloc::LazyCompoundVal *LCV = dyn_cast<nonloc::LazyCompoundVal>(&Init)) |
| 1523 | return CopyLazyBindings(*LCV, state, R); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1524 | |
| 1525 | // Remaining case: explicit compound values. |
Ted Kremenek | 027e266 | 2009-11-19 20:20:24 +0000 | [diff] [blame] | 1526 | |
| 1527 | if (Init.isUnknown()) |
| 1528 | return setImplicitDefaultValue(state, R, ElementTy); |
| 1529 | |
Zhongxing Xu | 1a12a0e | 2008-10-31 10:24:47 +0000 | [diff] [blame] | 1530 | nonloc::CompoundVal& CV = cast<nonloc::CompoundVal>(Init); |
Zhongxing Xu | 1a12a0e | 2008-10-31 10:24:47 +0000 | [diff] [blame] | 1531 | nonloc::CompoundVal::iterator VI = CV.begin(), VE = CV.end(); |
Ted Kremenek | 4653739 | 2009-07-16 01:33:37 +0000 | [diff] [blame] | 1532 | uint64_t i = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1533 | |
Ted Kremenek | 4653739 | 2009-07-16 01:33:37 +0000 | [diff] [blame] | 1534 | for (; i < size; ++i, ++VI) { |
Zhongxing Xu | 087d6c2 | 2009-06-23 05:23:38 +0000 | [diff] [blame] | 1535 | // The init list might be shorter than the array length. |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 1536 | if (VI == VE) |
| 1537 | break; |
| 1538 | |
Ted Kremenek | 4653739 | 2009-07-16 01:33:37 +0000 | [diff] [blame] | 1539 | SVal Idx = ValMgr.makeArrayIndex(i); |
Ted Kremenek | b48ad64 | 2009-12-04 00:26:31 +0000 | [diff] [blame] | 1540 | const ElementRegion *ER = MRMgr.getElementRegion(ElementTy, Idx, R, getContext()); |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 1541 | |
| 1542 | if (CAT->getElementType()->isStructureType()) |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 1543 | state = BindStruct(state, ER, *VI); |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 1544 | else |
Ted Kremenek | cf54959 | 2009-09-22 21:19:14 +0000 | [diff] [blame] | 1545 | // FIXME: Do we need special handling of nested arrays? |
Zhongxing Xu | d91ee27 | 2009-06-23 09:02:15 +0000 | [diff] [blame] | 1546 | state = Bind(state, ValMgr.makeLoc(ER), *VI); |
Zhongxing Xu | 1a12a0e | 2008-10-31 10:24:47 +0000 | [diff] [blame] | 1547 | } |
| 1548 | |
Ted Kremenek | 027e266 | 2009-11-19 20:20:24 +0000 | [diff] [blame] | 1549 | // If the init list is shorter than the array length, set the |
| 1550 | // array default value. |
| 1551 | if (i < size) |
| 1552 | state = setImplicitDefaultValue(state, R, ElementTy); |
Zhongxing Xu | 087d6c2 | 2009-06-23 05:23:38 +0000 | [diff] [blame] | 1553 | |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 1554 | return state; |
Zhongxing Xu | 1a12a0e | 2008-10-31 10:24:47 +0000 | [diff] [blame] | 1555 | } |
| 1556 | |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 1557 | const GRState * |
| 1558 | RegionStoreManager::BindStruct(const GRState *state, const TypedRegion* R, |
| 1559 | SVal V) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1560 | |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 1561 | if (!Features.supportsFields()) |
| 1562 | return state; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1563 | |
Zhongxing Xu | a82d8aa | 2009-05-09 03:57:34 +0000 | [diff] [blame] | 1564 | QualType T = R->getValueType(getContext()); |
Zhongxing Xu | af0a844 | 2008-10-31 10:53:01 +0000 | [diff] [blame] | 1565 | assert(T->isStructureType()); |
| 1566 | |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 1567 | const RecordType* RT = T->getAs<RecordType>(); |
Zhongxing Xu | af0a844 | 2008-10-31 10:53:01 +0000 | [diff] [blame] | 1568 | RecordDecl* RD = RT->getDecl(); |
Zhongxing Xu | c45a825 | 2009-03-11 09:07:35 +0000 | [diff] [blame] | 1569 | |
| 1570 | if (!RD->isDefinition()) |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 1571 | return state; |
Zhongxing Xu | af0a844 | 2008-10-31 10:53:01 +0000 | [diff] [blame] | 1572 | |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1573 | // Handle lazy compound values. |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1574 | if (const nonloc::LazyCompoundVal *LCV=dyn_cast<nonloc::LazyCompoundVal>(&V)) |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1575 | return CopyLazyBindings(*LCV, state, R); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1576 | |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 1577 | // We may get non-CompoundVal accidentally due to imprecise cast logic. |
| 1578 | // Ignore them and kill the field values. |
| 1579 | if (V.isUnknown() || !isa<nonloc::CompoundVal>(V)) |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1580 | return state->makeWithStore(KillStruct(state->getStore(), R)); |
Zhongxing Xu | 3f6978a | 2009-06-11 09:11:27 +0000 | [diff] [blame] | 1581 | |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 1582 | nonloc::CompoundVal& CV = cast<nonloc::CompoundVal>(V); |
Zhongxing Xu | af0a844 | 2008-10-31 10:53:01 +0000 | [diff] [blame] | 1583 | nonloc::CompoundVal::iterator VI = CV.begin(), VE = CV.end(); |
Zhongxing Xu | dbdf219 | 2009-06-23 05:43:16 +0000 | [diff] [blame] | 1584 | |
| 1585 | RecordDecl::field_iterator FI, FE; |
| 1586 | |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1587 | for (FI = RD->field_begin(), FE = RD->field_end(); FI != FE; ++FI, ++VI) { |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 1588 | |
Zhongxing Xu | dbdf219 | 2009-06-23 05:43:16 +0000 | [diff] [blame] | 1589 | if (VI == VE) |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 1590 | break; |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 1591 | |
Zhongxing Xu | af0a844 | 2008-10-31 10:53:01 +0000 | [diff] [blame] | 1592 | QualType FTy = (*FI)->getType(); |
Ted Kremenek | cf54959 | 2009-09-22 21:19:14 +0000 | [diff] [blame] | 1593 | const FieldRegion* FR = MRMgr.getFieldRegion(*FI, R); |
Zhongxing Xu | af0a844 | 2008-10-31 10:53:01 +0000 | [diff] [blame] | 1594 | |
Ted Kremenek | cf54959 | 2009-09-22 21:19:14 +0000 | [diff] [blame] | 1595 | if (FTy->isArrayType()) |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 1596 | state = BindArray(state, FR, *VI); |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 1597 | else if (FTy->isStructureType()) |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 1598 | state = BindStruct(state, FR, *VI); |
Ted Kremenek | cf54959 | 2009-09-22 21:19:14 +0000 | [diff] [blame] | 1599 | else |
| 1600 | state = Bind(state, ValMgr.makeLoc(FR), *VI); |
Zhongxing Xu | a82512a | 2008-10-24 08:42:28 +0000 | [diff] [blame] | 1601 | } |
| 1602 | |
Zhongxing Xu | dbdf219 | 2009-06-23 05:43:16 +0000 | [diff] [blame] | 1603 | // There may be fewer values in the initialize list than the fields of struct. |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1604 | if (FI != FE) { |
| 1605 | Store store = state->getStore(); |
| 1606 | RegionBindings B = GetRegionBindings(store); |
| 1607 | B = RBFactory.Add(B, R, |
| 1608 | BindingVal(ValMgr.makeIntVal(0, false), BindingVal::Default)); |
| 1609 | state = state->makeWithStore(B.getRoot()); |
| 1610 | } |
Zhongxing Xu | dbdf219 | 2009-06-23 05:43:16 +0000 | [diff] [blame] | 1611 | |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 1612 | return state; |
Zhongxing Xu | c3a0599 | 2008-11-19 11:06:24 +0000 | [diff] [blame] | 1613 | } |
| 1614 | |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1615 | Store RegionStoreManager::KillStruct(Store store, const TypedRegion* R) { |
| 1616 | RegionBindings B = GetRegionBindings(store); |
| 1617 | llvm::OwningPtr<RegionStoreSubRegionMap> |
| 1618 | SubRegions(getRegionStoreSubRegionMap(store)); |
| 1619 | RemoveSubRegionBindings(B, R, *SubRegions); |
Zhongxing Xu | 5834ed6 | 2009-01-13 01:49:57 +0000 | [diff] [blame] | 1620 | |
Zhongxing Xu | e4df9c4 | 2009-06-25 05:52:16 +0000 | [diff] [blame] | 1621 | // Set the default value of the struct region to "unknown". |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1622 | B = RBFactory.Add(B, R, BindingVal(UnknownVal(), BindingVal::Default)); |
Zhongxing Xu | 5834ed6 | 2009-01-13 01:49:57 +0000 | [diff] [blame] | 1623 | |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1624 | return B.getRoot(); |
Zhongxing Xu | 5834ed6 | 2009-01-13 01:49:57 +0000 | [diff] [blame] | 1625 | } |
| 1626 | |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1627 | const GRState* |
| 1628 | RegionStoreManager::CopyLazyBindings(nonloc::LazyCompoundVal V, |
| 1629 | const GRState *state, |
| 1630 | const TypedRegion *R) { |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1631 | |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1632 | // Nuke the old bindings stemming from R. |
Ted Kremenek | 451ac09 | 2009-08-06 04:50:20 +0000 | [diff] [blame] | 1633 | RegionBindings B = GetRegionBindings(state->getStore()); |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1634 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1635 | llvm::OwningPtr<RegionStoreSubRegionMap> |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1636 | SubRegions(getRegionStoreSubRegionMap(state->getStore())); |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1637 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1638 | // B and DVM are updated after the call to RemoveSubRegionBindings. |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1639 | RemoveSubRegionBindings(B, R, *SubRegions.get()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1640 | |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1641 | // Now copy the bindings. This amounts to just binding 'V' to 'R'. This |
| 1642 | // results in a zero-copy algorithm. |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1643 | return state->makeWithStore( |
| 1644 | RBFactory.Add(B, R, BindingVal(V, BindingVal::Direct)).getRoot()); |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1645 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1646 | |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1647 | //===----------------------------------------------------------------------===// |
| 1648 | // State pruning. |
| 1649 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1650 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1651 | void RegionStoreManager::RemoveDeadBindings(GRState &state, Stmt* Loc, |
Ted Kremenek | 2f26bc3 | 2009-08-02 04:45:08 +0000 | [diff] [blame] | 1652 | SymbolReaper& SymReaper, |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1653 | llvm::SmallVectorImpl<const MemRegion*>& RegionRoots) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1654 | { |
Ted Kremenek | 781115c | 2009-10-17 17:45:11 +0000 | [diff] [blame] | 1655 | typedef std::pair<const GRState*, const MemRegion *> RBDNode; |
| 1656 | |
Ted Kremenek | 2f26bc3 | 2009-08-02 04:45:08 +0000 | [diff] [blame] | 1657 | Store store = state.getStore(); |
Ted Kremenek | 451ac09 | 2009-08-06 04:50:20 +0000 | [diff] [blame] | 1658 | RegionBindings B = GetRegionBindings(store); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1659 | |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1660 | // The backmap from regions to subregions. |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1661 | llvm::OwningPtr<RegionStoreSubRegionMap> |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1662 | SubRegions(getRegionStoreSubRegionMap(store)); |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1663 | |
Ted Kremenek | a6d73af | 2009-11-26 02:35:42 +0000 | [diff] [blame] | 1664 | // Do a pass over the regions in the store. For VarRegions we check if |
| 1665 | // the variable is still live and if so add it to the list of live roots. |
| 1666 | // For other regions we populate our region backmap. |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1667 | llvm::SmallVector<const MemRegion*, 10> IntermediateRoots; |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1668 | |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1669 | // Scan the direct bindings for "intermediate" roots. |
Ted Kremenek | 451ac09 | 2009-08-06 04:50:20 +0000 | [diff] [blame] | 1670 | for (RegionBindings::iterator I = B.begin(), E = B.end(); I != E; ++I) { |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1671 | const MemRegion *R = I.getKey(); |
| 1672 | IntermediateRoots.push_back(R); |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1673 | } |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1674 | |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1675 | // Process the "intermediate" roots to find if they are referenced by |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1676 | // real roots. |
Zhongxing Xu | f77869f | 2009-10-17 08:39:24 +0000 | [diff] [blame] | 1677 | llvm::SmallVector<RBDNode, 10> WorkList; |
Ted Kremenek | 0175619 | 2009-10-29 05:14:17 +0000 | [diff] [blame] | 1678 | llvm::SmallVector<RBDNode, 10> Postponed; |
| 1679 | |
Zhongxing Xu | 6800b33 | 2009-10-18 04:15:47 +0000 | [diff] [blame] | 1680 | llvm::DenseSet<const MemRegion*> IntermediateVisited; |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1681 | |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1682 | while (!IntermediateRoots.empty()) { |
| 1683 | const MemRegion* R = IntermediateRoots.back(); |
| 1684 | IntermediateRoots.pop_back(); |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1685 | |
Zhongxing Xu | f77869f | 2009-10-17 08:39:24 +0000 | [diff] [blame] | 1686 | if (IntermediateVisited.count(R)) |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1687 | continue; |
Zhongxing Xu | f77869f | 2009-10-17 08:39:24 +0000 | [diff] [blame] | 1688 | IntermediateVisited.insert(R); |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1689 | |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1690 | if (const VarRegion* VR = dyn_cast<VarRegion>(R)) { |
Ted Kremenek | edeb5b6 | 2009-12-04 20:32:20 +0000 | [diff] [blame] | 1691 | if (SymReaper.isLive(Loc, VR)) |
Zhongxing Xu | f77869f | 2009-10-17 08:39:24 +0000 | [diff] [blame] | 1692 | WorkList.push_back(std::make_pair(&state, VR)); |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1693 | continue; |
| 1694 | } |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1695 | |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1696 | if (const SymbolicRegion* SR = dyn_cast<SymbolicRegion>(R)) { |
Ted Kremenek | 0175619 | 2009-10-29 05:14:17 +0000 | [diff] [blame] | 1697 | llvm::SmallVectorImpl<RBDNode> &Q = |
| 1698 | SymReaper.isLive(SR->getSymbol()) ? WorkList : Postponed; |
| 1699 | |
| 1700 | Q.push_back(std::make_pair(&state, SR)); |
| 1701 | |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1702 | continue; |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1703 | } |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1704 | |
| 1705 | // Add the super region for R to the worklist if it is a subregion. |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1706 | if (const SubRegion* superR = |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1707 | dyn_cast<SubRegion>(cast<SubRegion>(R)->getSuperRegion())) |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1708 | IntermediateRoots.push_back(superR); |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1709 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1710 | |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1711 | // Enqueue the RegionRoots onto WorkList. |
| 1712 | for (llvm::SmallVectorImpl<const MemRegion*>::iterator I=RegionRoots.begin(), |
| 1713 | E=RegionRoots.end(); I!=E; ++I) { |
Zhongxing Xu | f77869f | 2009-10-17 08:39:24 +0000 | [diff] [blame] | 1714 | WorkList.push_back(std::make_pair(&state, *I)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1715 | } |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1716 | RegionRoots.clear(); |
| 1717 | |
Zhongxing Xu | 6800b33 | 2009-10-18 04:15:47 +0000 | [diff] [blame] | 1718 | llvm::DenseSet<RBDNode> Visited; |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1719 | |
Ted Kremenek | 0175619 | 2009-10-29 05:14:17 +0000 | [diff] [blame] | 1720 | tryAgain: |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1721 | while (!WorkList.empty()) { |
Zhongxing Xu | f77869f | 2009-10-17 08:39:24 +0000 | [diff] [blame] | 1722 | RBDNode N = WorkList.back(); |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1723 | WorkList.pop_back(); |
| 1724 | |
| 1725 | // Have we visited this node before? |
Zhongxing Xu | f77869f | 2009-10-17 08:39:24 +0000 | [diff] [blame] | 1726 | if (Visited.count(N)) |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1727 | continue; |
Zhongxing Xu | f77869f | 2009-10-17 08:39:24 +0000 | [diff] [blame] | 1728 | Visited.insert(N); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1729 | |
Zhongxing Xu | f77869f | 2009-10-17 08:39:24 +0000 | [diff] [blame] | 1730 | const MemRegion *R = N.second; |
| 1731 | const GRState *state_N = N.first; |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1732 | |
Zhongxing Xu | f77869f | 2009-10-17 08:39:24 +0000 | [diff] [blame] | 1733 | // Enqueue subregions. |
| 1734 | RegionStoreSubRegionMap *M; |
| 1735 | |
| 1736 | if (&state == state_N) |
| 1737 | M = SubRegions.get(); |
| 1738 | else { |
| 1739 | RegionStoreSubRegionMap *& SM = SC[state_N]; |
| 1740 | if (!SM) |
| 1741 | SM = getRegionStoreSubRegionMap(state_N->getStore()); |
| 1742 | M = SM; |
| 1743 | } |
| 1744 | |
| 1745 | RegionStoreSubRegionMap::iterator I, E; |
| 1746 | for (llvm::tie(I, E) = M->begin_end(R); I != E; ++I) |
| 1747 | WorkList.push_back(std::make_pair(state_N, *I)); |
| 1748 | |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1749 | // Enqueue the super region. |
| 1750 | if (const SubRegion *SR = dyn_cast<SubRegion>(R)) { |
| 1751 | const MemRegion *superR = SR->getSuperRegion(); |
| 1752 | if (!isa<MemSpaceRegion>(superR)) { |
| 1753 | // If 'R' is a field or an element, we want to keep the bindings |
| 1754 | // for the other fields and elements around. The reason is that |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1755 | // pointer arithmetic can get us to the other fields or elements. |
Zhongxing Xu | 8801beb | 2009-10-17 07:32:08 +0000 | [diff] [blame] | 1756 | assert(isa<FieldRegion>(R) || isa<ElementRegion>(R) |
| 1757 | || isa<ObjCIvarRegion>(R)); |
Zhongxing Xu | f77869f | 2009-10-17 08:39:24 +0000 | [diff] [blame] | 1758 | WorkList.push_back(std::make_pair(state_N, superR)); |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1759 | } |
| 1760 | } |
| 1761 | |
| 1762 | // Mark the symbol for any live SymbolicRegion as "live". This means we |
| 1763 | // should continue to track that symbol. |
Ted Kremenek | a6d73af | 2009-11-26 02:35:42 +0000 | [diff] [blame] | 1764 | if (const SymbolicRegion *SymR = dyn_cast<SymbolicRegion>(R)) |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1765 | SymReaper.markLive(SymR->getSymbol()); |
Ted Kremenek | a6d73af | 2009-11-26 02:35:42 +0000 | [diff] [blame] | 1766 | |
Ted Kremenek | a7a8dfd | 2009-12-03 17:48:05 +0000 | [diff] [blame] | 1767 | // For BlockDataRegions, enqueue the VarRegions for variables marked |
| 1768 | // with __block (passed-by-reference). |
Ted Kremenek | a6d73af | 2009-11-26 02:35:42 +0000 | [diff] [blame] | 1769 | // via BlockDeclRefExprs. |
| 1770 | if (const BlockDataRegion *BD = dyn_cast<BlockDataRegion>(R)) { |
| 1771 | for (BlockDataRegion::referenced_vars_iterator |
| 1772 | RI = BD->referenced_vars_begin(), RE = BD->referenced_vars_end(); |
Ted Kremenek | a7a8dfd | 2009-12-03 17:48:05 +0000 | [diff] [blame] | 1773 | RI != RE; ++RI) { |
| 1774 | if ((*RI)->getDecl()->getAttr<BlocksAttr>()) |
| 1775 | WorkList.push_back(std::make_pair(state_N, *RI)); |
| 1776 | } |
Ted Kremenek | a6d73af | 2009-11-26 02:35:42 +0000 | [diff] [blame] | 1777 | // No possible data bindings on a BlockDataRegion. Continue to the |
| 1778 | // next region in the worklist. |
| 1779 | continue; |
| 1780 | } |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1781 | |
| 1782 | Store store_N = state_N->getStore(); |
| 1783 | RegionBindings B_N = GetRegionBindings(store_N); |
| 1784 | |
| 1785 | // Get the data binding for R (if any). |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1786 | Optional<SVal> V = getBinding(B_N, R); |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1787 | |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1788 | if (V) { |
| 1789 | // Check for lazy bindings. |
| 1790 | if (const nonloc::LazyCompoundVal *LCV = |
| 1791 | dyn_cast<nonloc::LazyCompoundVal>(V.getPointer())) { |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1792 | |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1793 | const LazyCompoundValData *D = LCV->getCVData(); |
Zhongxing Xu | f77869f | 2009-10-17 08:39:24 +0000 | [diff] [blame] | 1794 | WorkList.push_back(std::make_pair(D->getState(), D->getRegion())); |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1795 | } |
| 1796 | else { |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1797 | // Update the set of live symbols. |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1798 | for (SVal::symbol_iterator SI=V->symbol_begin(), SE=V->symbol_end(); |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1799 | SI!=SE;++SI) |
| 1800 | SymReaper.markLive(*SI); |
| 1801 | |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1802 | // If V is a region, then add it to the worklist. |
| 1803 | if (const MemRegion *RX = V->getAsRegion()) |
Zhongxing Xu | f77869f | 2009-10-17 08:39:24 +0000 | [diff] [blame] | 1804 | WorkList.push_back(std::make_pair(state_N, RX)); |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1805 | } |
| 1806 | } |
| 1807 | } |
| 1808 | |
Ted Kremenek | 0175619 | 2009-10-29 05:14:17 +0000 | [diff] [blame] | 1809 | // See if any postponed SymbolicRegions are actually live now, after |
| 1810 | // having done a scan. |
| 1811 | for (llvm::SmallVectorImpl<RBDNode>::iterator I = Postponed.begin(), |
| 1812 | E = Postponed.end() ; I != E ; ++I) { |
| 1813 | if (const SymbolicRegion *SR = cast_or_null<SymbolicRegion>(I->second)) { |
| 1814 | if (SymReaper.isLive(SR->getSymbol())) { |
| 1815 | WorkList.push_back(*I); |
| 1816 | I->second = NULL; |
| 1817 | } |
| 1818 | } |
| 1819 | } |
| 1820 | |
| 1821 | if (!WorkList.empty()) |
| 1822 | goto tryAgain; |
| 1823 | |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1824 | // We have now scanned the store, marking reachable regions and symbols |
| 1825 | // as live. We now remove all the regions that are dead from the store |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1826 | // as well as update DSymbols with the set symbols that are now dead. |
Ted Kremenek | 451ac09 | 2009-08-06 04:50:20 +0000 | [diff] [blame] | 1827 | for (RegionBindings::iterator I = B.begin(), E = B.end(); I != E; ++I) { |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1828 | const MemRegion* R = I.getKey(); |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1829 | // If this region live? Is so, none of its symbols are dead. |
Zhongxing Xu | f77869f | 2009-10-17 08:39:24 +0000 | [diff] [blame] | 1830 | if (Visited.count(std::make_pair(&state, R))) |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1831 | continue; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1832 | |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1833 | // Remove this dead region from the store. |
Zhongxing Xu | d91ee27 | 2009-06-23 09:02:15 +0000 | [diff] [blame] | 1834 | store = Remove(store, ValMgr.makeLoc(R)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1835 | |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1836 | // Mark all non-live symbols that this region references as dead. |
| 1837 | if (const SymbolicRegion* SymR = dyn_cast<SymbolicRegion>(R)) |
| 1838 | SymReaper.maybeDead(SymR->getSymbol()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1839 | |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1840 | SVal X = *I.getData().getValue(); |
Ted Kremenek | 093569c | 2009-08-02 05:00:15 +0000 | [diff] [blame] | 1841 | SVal::symbol_iterator SI = X.symbol_begin(), SE = X.symbol_end(); |
| 1842 | for (; SI != SE; ++SI) |
| 1843 | SymReaper.maybeDead(*SI); |
| 1844 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1845 | |
Ted Kremenek | 2f26bc3 | 2009-08-02 04:45:08 +0000 | [diff] [blame] | 1846 | // Write the store back. |
| 1847 | state.setStore(store); |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1848 | } |
| 1849 | |
Zhongxing Xu | 4e3c1f7 | 2009-10-13 02:24:55 +0000 | [diff] [blame] | 1850 | GRState const *RegionStoreManager::EnterStackFrame(GRState const *state, |
| 1851 | StackFrameContext const *frame) { |
| 1852 | FunctionDecl const *FD = cast<FunctionDecl>(frame->getDecl()); |
| 1853 | CallExpr const *CE = cast<CallExpr>(frame->getCallSite()); |
| 1854 | |
| 1855 | FunctionDecl::param_const_iterator PI = FD->param_begin(); |
| 1856 | |
| 1857 | CallExpr::const_arg_iterator AI = CE->arg_begin(), AE = CE->arg_end(); |
| 1858 | |
| 1859 | // Copy the arg expression value to the arg variables. |
| 1860 | for (; AI != AE; ++AI, ++PI) { |
| 1861 | SVal ArgVal = state->getSVal(*AI); |
Ted Kremenek | b48ad64 | 2009-12-04 00:26:31 +0000 | [diff] [blame] | 1862 | state = Bind(state, ValMgr.makeLoc(MRMgr.getVarRegion(*PI, frame)), ArgVal); |
Zhongxing Xu | 4e3c1f7 | 2009-10-13 02:24:55 +0000 | [diff] [blame] | 1863 | } |
| 1864 | |
| 1865 | return state; |
| 1866 | } |
| 1867 | |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1868 | //===----------------------------------------------------------------------===// |
| 1869 | // Utility methods. |
| 1870 | //===----------------------------------------------------------------------===// |
| 1871 | |
Ted Kremenek | 53ba0b6 | 2009-06-24 23:06:47 +0000 | [diff] [blame] | 1872 | void RegionStoreManager::print(Store store, llvm::raw_ostream& OS, |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1873 | const char* nl, const char *sep) { |
Ted Kremenek | 451ac09 | 2009-08-06 04:50:20 +0000 | [diff] [blame] | 1874 | RegionBindings B = GetRegionBindings(store); |
Ted Kremenek | ab22ee9 | 2009-10-20 01:20:57 +0000 | [diff] [blame] | 1875 | OS << "Store (direct and default bindings):" << nl; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1876 | |
Ted Kremenek | 451ac09 | 2009-08-06 04:50:20 +0000 | [diff] [blame] | 1877 | for (RegionBindings::iterator I = B.begin(), E = B.end(); I != E; ++I) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1878 | OS << ' ' << I.getKey() << " : " << I.getData() << nl; |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1879 | } |