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 | 7ecbfbc | 2009-07-10 22:30:06 +0000 | [diff] [blame] | 731 | assert(0 && "Cannot index into a MemSpace"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 732 | return UnknownVal(); |
| 733 | |
Ted Kremenek | eb1c7a0 | 2009-11-25 01:32:22 +0000 | [diff] [blame] | 734 | case MemRegion::FunctionTextRegionKind: |
| 735 | case MemRegion::BlockTextRegionKind: |
Ted Kremenek | 0a8112a | 2009-11-25 23:53:07 +0000 | [diff] [blame] | 736 | case MemRegion::BlockDataRegionKind: |
Ted Kremenek | 7ecbfbc | 2009-07-10 22:30:06 +0000 | [diff] [blame] | 737 | // Technically this can happen if people do funny things with casts. |
Ted Kremenek | 14553ab | 2009-01-30 00:08:43 +0000 | [diff] [blame] | 738 | return UnknownVal(); |
Ted Kremenek | 7ecbfbc | 2009-07-10 22:30:06 +0000 | [diff] [blame] | 739 | |
| 740 | // Not yet handled. |
| 741 | case MemRegion::AllocaRegionKind: |
| 742 | case MemRegion::CompoundLiteralRegionKind: |
| 743 | case MemRegion::ElementRegionKind: |
| 744 | case MemRegion::FieldRegionKind: |
| 745 | case MemRegion::ObjCIvarRegionKind: |
| 746 | case MemRegion::ObjCObjectRegionKind: |
| 747 | case MemRegion::SymbolicRegionKind: |
| 748 | return UnknownVal(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 749 | |
Ted Kremenek | 7ecbfbc | 2009-07-10 22:30:06 +0000 | [diff] [blame] | 750 | case MemRegion::StringRegionKind: { |
| 751 | const StringLiteral* Str = cast<StringRegion>(R)->getStringLiteral(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 752 | // We intentionally made the size value signed because it participates in |
Ted Kremenek | 7ecbfbc | 2009-07-10 22:30:06 +0000 | [diff] [blame] | 753 | // operations with signed indices. |
| 754 | return ValMgr.makeIntVal(Str->getByteLength()+1, false); |
Ted Kremenek | 14553ab | 2009-01-30 00:08:43 +0000 | [diff] [blame] | 755 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 756 | |
Ted Kremenek | 7ecbfbc | 2009-07-10 22:30:06 +0000 | [diff] [blame] | 757 | case MemRegion::VarRegionKind: { |
| 758 | const VarRegion* VR = cast<VarRegion>(R); |
| 759 | // Get the type of the variable. |
| 760 | QualType T = VR->getDesugaredValueType(getContext()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 761 | |
Ted Kremenek | 7ecbfbc | 2009-07-10 22:30:06 +0000 | [diff] [blame] | 762 | // FIXME: Handle variable-length arrays. |
| 763 | if (isa<VariableArrayType>(T)) |
| 764 | return UnknownVal(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 765 | |
Ted Kremenek | 7ecbfbc | 2009-07-10 22:30:06 +0000 | [diff] [blame] | 766 | if (const ConstantArrayType* CAT = dyn_cast<ConstantArrayType>(T)) { |
| 767 | // return the size as signed integer. |
| 768 | return ValMgr.makeIntVal(CAT->getSize(), false); |
| 769 | } |
Ted Kremenek | df74e25 | 2009-08-02 05:15:23 +0000 | [diff] [blame] | 770 | |
Ted Kremenek | 7ecbfbc | 2009-07-10 22:30:06 +0000 | [diff] [blame] | 771 | // Clients can use ordinary variables as if they were arrays. These |
| 772 | // essentially are arrays of size 1. |
| 773 | return ValMgr.makeIntVal(1, false); |
Zhongxing Xu | 41fd018 | 2009-05-06 11:51:48 +0000 | [diff] [blame] | 774 | } |
Zhongxing Xu | e8a964b | 2008-11-22 13:21:46 +0000 | [diff] [blame] | 775 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 776 | |
Ted Kremenek | 7ecbfbc | 2009-07-10 22:30:06 +0000 | [diff] [blame] | 777 | assert(0 && "Unreachable"); |
Ted Kremenek | a21362d | 2009-01-06 19:12:06 +0000 | [diff] [blame] | 778 | return UnknownVal(); |
Zhongxing Xu | e8a964b | 2008-11-22 13:21:46 +0000 | [diff] [blame] | 779 | } |
| 780 | |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 781 | const GRState *RegionStoreManager::setExtent(const GRState *state, |
| 782 | const MemRegion *region, |
| 783 | SVal extent) { |
| 784 | return state->set<RegionExtents>(region, extent); |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 785 | } |
| 786 | |
| 787 | //===----------------------------------------------------------------------===// |
| 788 | // Location and region casting. |
| 789 | //===----------------------------------------------------------------------===// |
| 790 | |
Ted Kremenek | 869fb4a | 2008-12-24 07:46:32 +0000 | [diff] [blame] | 791 | /// ArrayToPointer - Emulates the "decay" of an array to a pointer |
| 792 | /// type. 'Array' represents the lvalue of the array being decayed |
| 793 | /// to a pointer, and the returned SVal represents the decayed |
| 794 | /// version of that lvalue (i.e., a pointer to the first element of |
| 795 | /// the array). This is called by GRExprEngine when evaluating casts |
| 796 | /// from arrays to pointers. |
Zhongxing Xu | f1d537f | 2009-03-30 05:55:46 +0000 | [diff] [blame] | 797 | SVal RegionStoreManager::ArrayToPointer(Loc Array) { |
Ted Kremenek | abb042f | 2008-12-13 19:24:37 +0000 | [diff] [blame] | 798 | if (!isa<loc::MemRegionVal>(Array)) |
| 799 | return UnknownVal(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 800 | |
Ted Kremenek | abb042f | 2008-12-13 19:24:37 +0000 | [diff] [blame] | 801 | const MemRegion* R = cast<loc::MemRegionVal>(&Array)->getRegion(); |
| 802 | const TypedRegion* ArrayR = dyn_cast<TypedRegion>(R); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 803 | |
Ted Kremenek | bbee1a7 | 2009-01-13 01:03:27 +0000 | [diff] [blame] | 804 | if (!ArrayR) |
Ted Kremenek | abb042f | 2008-12-13 19:24:37 +0000 | [diff] [blame] | 805 | return UnknownVal(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 806 | |
Zhongxing Xu | a82d8aa | 2009-05-09 03:57:34 +0000 | [diff] [blame] | 807 | // Strip off typedefs from the ArrayRegion's ValueType. |
John McCall | bf1cc05 | 2009-09-29 23:03:30 +0000 | [diff] [blame] | 808 | QualType T = ArrayR->getValueType(getContext()).getDesugaredType(); |
Ted Kremenek | f936f45 | 2009-05-04 06:18:28 +0000 | [diff] [blame] | 809 | ArrayType *AT = cast<ArrayType>(T); |
| 810 | T = AT->getElementType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 811 | |
Ted Kremenek | 75185b5 | 2009-07-16 00:00:11 +0000 | [diff] [blame] | 812 | SVal ZeroIdx = ValMgr.makeZeroArrayIndex(); |
Ted Kremenek | b48ad64 | 2009-12-04 00:26:31 +0000 | [diff] [blame] | 813 | return loc::MemRegionVal(MRMgr.getElementRegion(T, ZeroIdx, ArrayR, |
| 814 | getContext())); |
Zhongxing Xu | b1d542a | 2008-10-24 01:09:32 +0000 | [diff] [blame] | 815 | } |
| 816 | |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 817 | //===----------------------------------------------------------------------===// |
| 818 | // Pointer arithmetic. |
| 819 | //===----------------------------------------------------------------------===// |
| 820 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 821 | SVal RegionStoreManager::EvalBinOp(const GRState *state, |
Ted Kremenek | 5c73462 | 2009-06-26 00:41:43 +0000 | [diff] [blame] | 822 | BinaryOperator::Opcode Op, Loc L, NonLoc R, |
| 823 | QualType resultTy) { |
Zhongxing Xu | c4761f5 | 2009-05-09 15:18:12 +0000 | [diff] [blame] | 824 | // Assume the base location is MemRegionVal. |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 825 | if (!isa<loc::MemRegionVal>(L)) |
Zhongxing Xu | 94aa6c1 | 2009-03-02 07:52:23 +0000 | [diff] [blame] | 826 | return UnknownVal(); |
Zhongxing Xu | 94aa6c1 | 2009-03-02 07:52:23 +0000 | [diff] [blame] | 827 | |
Zhongxing Xu | a1718c7 | 2009-04-03 07:33:13 +0000 | [diff] [blame] | 828 | const MemRegion* MR = cast<loc::MemRegionVal>(L).getRegion(); |
Zhongxing Xu | c4761f5 | 2009-05-09 15:18:12 +0000 | [diff] [blame] | 829 | const ElementRegion *ER = 0; |
Zhongxing Xu | 262fd03 | 2009-05-20 09:00:16 +0000 | [diff] [blame] | 830 | |
Ted Kremenek | 3bccf08 | 2009-07-11 00:58:27 +0000 | [diff] [blame] | 831 | switch (MR->getKind()) { |
| 832 | case MemRegion::SymbolicRegionKind: { |
| 833 | const SymbolicRegion *SR = cast<SymbolicRegion>(MR); |
Ted Kremenek | df74e25 | 2009-08-02 05:15:23 +0000 | [diff] [blame] | 834 | SymbolRef Sym = SR->getSymbol(); |
Ted Kremenek | bcf62a9 | 2009-08-25 22:55:09 +0000 | [diff] [blame] | 835 | QualType T = Sym->getType(getContext()); |
| 836 | QualType EleTy; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 837 | |
Ted Kremenek | bcf62a9 | 2009-08-25 22:55:09 +0000 | [diff] [blame] | 838 | if (const PointerType *PT = T->getAs<PointerType>()) |
| 839 | EleTy = PT->getPointeeType(); |
| 840 | else |
John McCall | 183700f | 2009-09-21 23:43:11 +0000 | [diff] [blame] | 841 | EleTy = T->getAs<ObjCObjectPointerType>()->getPointeeType(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 842 | |
Ted Kremenek | 3bccf08 | 2009-07-11 00:58:27 +0000 | [diff] [blame] | 843 | SVal ZeroIdx = ValMgr.makeZeroArrayIndex(); |
| 844 | ER = MRMgr.getElementRegion(EleTy, ZeroIdx, SR, getContext()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 845 | break; |
Zhongxing Xu | 005f07b | 2009-06-19 04:51:14 +0000 | [diff] [blame] | 846 | } |
Ted Kremenek | 3bccf08 | 2009-07-11 00:58:27 +0000 | [diff] [blame] | 847 | case MemRegion::AllocaRegionKind: { |
Ted Kremenek | 3bccf08 | 2009-07-11 00:58:27 +0000 | [diff] [blame] | 848 | const AllocaRegion *AR = cast<AllocaRegion>(MR); |
Ted Kremenek | df74e25 | 2009-08-02 05:15:23 +0000 | [diff] [blame] | 849 | QualType T = getContext().CharTy; // Create an ElementRegion of bytes. |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 850 | QualType EleTy = T->getAs<PointerType>()->getPointeeType(); |
Ted Kremenek | 3bccf08 | 2009-07-11 00:58:27 +0000 | [diff] [blame] | 851 | SVal ZeroIdx = ValMgr.makeZeroArrayIndex(); |
| 852 | ER = MRMgr.getElementRegion(EleTy, ZeroIdx, AR, getContext()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 853 | break; |
Ted Kremenek | 3bccf08 | 2009-07-11 00:58:27 +0000 | [diff] [blame] | 854 | } |
Zhongxing Xu | a1718c7 | 2009-04-03 07:33:13 +0000 | [diff] [blame] | 855 | |
Ted Kremenek | 3bccf08 | 2009-07-11 00:58:27 +0000 | [diff] [blame] | 856 | case MemRegion::ElementRegionKind: { |
| 857 | ER = cast<ElementRegion>(MR); |
| 858 | break; |
| 859 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 860 | |
Ted Kremenek | 3bccf08 | 2009-07-11 00:58:27 +0000 | [diff] [blame] | 861 | // Not yet handled. |
| 862 | case MemRegion::VarRegionKind: |
Ted Kremenek | cd8f6ac | 2009-10-06 01:39:48 +0000 | [diff] [blame] | 863 | case MemRegion::StringRegionKind: { |
| 864 | |
| 865 | } |
| 866 | // Fall-through. |
Ted Kremenek | 3bccf08 | 2009-07-11 00:58:27 +0000 | [diff] [blame] | 867 | case MemRegion::CompoundLiteralRegionKind: |
| 868 | case MemRegion::FieldRegionKind: |
| 869 | case MemRegion::ObjCObjectRegionKind: |
| 870 | case MemRegion::ObjCIvarRegionKind: |
| 871 | return UnknownVal(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 872 | |
Ted Kremenek | eb1c7a0 | 2009-11-25 01:32:22 +0000 | [diff] [blame] | 873 | case MemRegion::FunctionTextRegionKind: |
| 874 | case MemRegion::BlockTextRegionKind: |
Ted Kremenek | 0a8112a | 2009-11-25 23:53:07 +0000 | [diff] [blame] | 875 | case MemRegion::BlockDataRegionKind: |
Ted Kremenek | 3bccf08 | 2009-07-11 00:58:27 +0000 | [diff] [blame] | 876 | // Technically this can happen if people do funny things with casts. |
| 877 | return UnknownVal(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 878 | |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 879 | case MemRegion::GenericMemSpaceRegionKind: |
| 880 | case MemRegion::StackLocalsSpaceRegionKind: |
| 881 | case MemRegion::StackArgumentsSpaceRegionKind: |
| 882 | case MemRegion::HeapSpaceRegionKind: |
| 883 | case MemRegion::GlobalsSpaceRegionKind: |
Ted Kremenek | 3bccf08 | 2009-07-11 00:58:27 +0000 | [diff] [blame] | 884 | assert(0 && "Cannot perform pointer arithmetic on a MemSpace"); |
| 885 | return UnknownVal(); |
Zhongxing Xu | 5414a5c | 2009-06-21 13:24:24 +0000 | [diff] [blame] | 886 | } |
Zhongxing Xu | 2b1dc17 | 2009-03-11 07:43:49 +0000 | [diff] [blame] | 887 | |
Zhongxing Xu | 94aa6c1 | 2009-03-02 07:52:23 +0000 | [diff] [blame] | 888 | SVal Idx = ER->getIndex(); |
Zhongxing Xu | 94aa6c1 | 2009-03-02 07:52:23 +0000 | [diff] [blame] | 889 | nonloc::ConcreteInt* Base = dyn_cast<nonloc::ConcreteInt>(&Idx); |
Zhongxing Xu | 94aa6c1 | 2009-03-02 07:52:23 +0000 | [diff] [blame] | 890 | |
Ted Kremenek | cd8f6ac | 2009-10-06 01:39:48 +0000 | [diff] [blame] | 891 | // For now, only support: |
| 892 | // (a) concrete integer indices that can easily be resolved |
| 893 | // (b) 0 + symbolic index |
| 894 | if (Base) { |
| 895 | if (nonloc::ConcreteInt *Offset = dyn_cast<nonloc::ConcreteInt>(&R)) { |
| 896 | // FIXME: Should use SValuator here. |
| 897 | SVal NewIdx = |
| 898 | Base->evalBinOp(ValMgr, Op, |
Ted Kremenek | 4653739 | 2009-07-16 01:33:37 +0000 | [diff] [blame] | 899 | cast<nonloc::ConcreteInt>(ValMgr.convertToArrayIndex(*Offset))); |
Ted Kremenek | cd8f6ac | 2009-10-06 01:39:48 +0000 | [diff] [blame] | 900 | const MemRegion* NewER = |
| 901 | MRMgr.getElementRegion(ER->getElementType(), NewIdx, |
| 902 | ER->getSuperRegion(), getContext()); |
| 903 | return ValMgr.makeLoc(NewER); |
| 904 | } |
| 905 | if (0 == Base->getValue()) { |
| 906 | const MemRegion* NewER = |
| 907 | MRMgr.getElementRegion(ER->getElementType(), R, |
| 908 | ER->getSuperRegion(), getContext()); |
| 909 | return ValMgr.makeLoc(NewER); |
| 910 | } |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 911 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 912 | |
Ted Kremenek | 5dc2746 | 2009-03-03 02:51:43 +0000 | [diff] [blame] | 913 | return UnknownVal(); |
Zhongxing Xu | 94aa6c1 | 2009-03-02 07:52:23 +0000 | [diff] [blame] | 914 | } |
| 915 | |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 916 | //===----------------------------------------------------------------------===// |
| 917 | // Loading values from regions. |
| 918 | //===----------------------------------------------------------------------===// |
| 919 | |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 920 | Optional<SVal> RegionStoreManager::getDirectBinding(RegionBindings B, |
| 921 | const MemRegion *R) { |
| 922 | if (const BindingVal *BV = B.lookup(R)) |
| 923 | return Optional<SVal>::create(BV->getDirectValue()); |
| 924 | |
| 925 | return Optional<SVal>(); |
| 926 | } |
| 927 | |
| 928 | Optional<SVal> RegionStoreManager::getDefaultBinding(RegionBindings B, |
Ted Kremenek | d4e5a60 | 2009-08-06 21:43:54 +0000 | [diff] [blame] | 929 | const MemRegion *R) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 930 | |
Ted Kremenek | d4e5a60 | 2009-08-06 21:43:54 +0000 | [diff] [blame] | 931 | if (R->isBoundable()) |
| 932 | if (const TypedRegion *TR = dyn_cast<TypedRegion>(R)) |
| 933 | if (TR->getValueType(getContext())->isUnionType()) |
| 934 | return UnknownVal(); |
| 935 | |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 936 | if (BindingVal const *V = B.lookup(R)) |
| 937 | return Optional<SVal>::create(V->getDefaultValue()); |
| 938 | |
| 939 | return Optional<SVal>(); |
| 940 | } |
| 941 | |
| 942 | Optional<SVal> RegionStoreManager::getBinding(RegionBindings B, |
| 943 | const MemRegion *R) { |
| 944 | if (const BindingVal *BV = B.lookup(R)) |
| 945 | return Optional<SVal>::create(BV->getValue()); |
| 946 | |
| 947 | return Optional<SVal>(); |
Ted Kremenek | d4e5a60 | 2009-08-06 21:43:54 +0000 | [diff] [blame] | 948 | } |
| 949 | |
Ted Kremenek | a6275a5 | 2009-07-15 02:31:43 +0000 | [diff] [blame] | 950 | static bool IsReinterpreted(QualType RTy, QualType UsedTy, ASTContext &Ctx) { |
| 951 | RTy = Ctx.getCanonicalType(RTy); |
| 952 | UsedTy = Ctx.getCanonicalType(UsedTy); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 953 | |
Ted Kremenek | a6275a5 | 2009-07-15 02:31:43 +0000 | [diff] [blame] | 954 | if (RTy == UsedTy) |
| 955 | return false; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 956 | |
| 957 | |
Ted Kremenek | 25c5457 | 2009-07-20 22:58:02 +0000 | [diff] [blame] | 958 | // 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] | 959 | // 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] | 960 | // represents a reinterpretation. |
| 961 | if (Loc::IsLocType(RTy) && Loc::IsLocType(UsedTy)) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 962 | const PointerType *PRTy = RTy->getAs<PointerType>(); |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 963 | const PointerType *PUsedTy = UsedTy->getAs<PointerType>(); |
Ted Kremenek | 25c5457 | 2009-07-20 22:58:02 +0000 | [diff] [blame] | 964 | |
| 965 | return PUsedTy && PRTy && |
| 966 | IsReinterpreted(PRTy->getPointeeType(), |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 967 | PUsedTy->getPointeeType(), Ctx); |
Ted Kremenek | 25c5457 | 2009-07-20 22:58:02 +0000 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | return true; |
Ted Kremenek | a6275a5 | 2009-07-15 02:31:43 +0000 | [diff] [blame] | 971 | } |
| 972 | |
Ted Kremenek | 0954cde | 2009-09-24 04:11:44 +0000 | [diff] [blame] | 973 | const ElementRegion * |
| 974 | RegionStoreManager::GetElementZeroRegion(const SymbolicRegion *SR, QualType T) { |
| 975 | ASTContext &Ctx = getContext(); |
| 976 | SVal idx = ValMgr.makeZeroArrayIndex(); |
| 977 | assert(!T.isNull()); |
| 978 | return MRMgr.getElementRegion(T, idx, SR, Ctx); |
| 979 | } |
| 980 | |
| 981 | |
| 982 | |
Ted Kremenek | 32c3fa4 | 2009-07-21 21:03:30 +0000 | [diff] [blame] | 983 | SValuator::CastResult |
| 984 | RegionStoreManager::Retrieve(const GRState *state, Loc L, QualType T) { |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 985 | |
Zhongxing Xu | 53bcdd4 | 2008-10-21 05:29:26 +0000 | [diff] [blame] | 986 | assert(!isa<UnknownVal>(L) && "location unknown"); |
| 987 | assert(!isa<UndefinedVal>(L) && "location undefined"); |
| 988 | |
Ted Kremenek | 869fb4a | 2008-12-24 07:46:32 +0000 | [diff] [blame] | 989 | // FIXME: Is this even possible? Shouldn't this be treated as a null |
| 990 | // dereference at a higher level? |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 991 | if (isa<loc::ConcreteInt>(L)) |
Ted Kremenek | 32c3fa4 | 2009-07-21 21:03:30 +0000 | [diff] [blame] | 992 | return SValuator::CastResult(state, UndefinedVal()); |
Zhongxing Xu | 53bcdd4 | 2008-10-21 05:29:26 +0000 | [diff] [blame] | 993 | |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 994 | const MemRegion *MR = cast<loc::MemRegionVal>(L).getRegion(); |
Zhongxing Xu | a1718c7 | 2009-04-03 07:33:13 +0000 | [diff] [blame] | 995 | |
Zhongxing Xu | 9184412 | 2009-05-20 09:18:48 +0000 | [diff] [blame] | 996 | // FIXME: return symbolic value for these cases. |
Zhongxing Xu | a1718c7 | 2009-04-03 07:33:13 +0000 | [diff] [blame] | 997 | // Example: |
| 998 | // void f(int* p) { int x = *p; } |
Zhongxing Xu | 9184412 | 2009-05-20 09:18:48 +0000 | [diff] [blame] | 999 | // char* p = alloca(); |
| 1000 | // read(p); |
| 1001 | // c = *p; |
Ted Kremenek | 60fbe8f | 2009-07-14 20:48:22 +0000 | [diff] [blame] | 1002 | if (isa<AllocaRegion>(MR)) |
Ted Kremenek | 32c3fa4 | 2009-07-21 21:03:30 +0000 | [diff] [blame] | 1003 | return SValuator::CastResult(state, UnknownVal()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1004 | |
Ted Kremenek | 0954cde | 2009-09-24 04:11:44 +0000 | [diff] [blame] | 1005 | if (const SymbolicRegion *SR = dyn_cast<SymbolicRegion>(MR)) |
| 1006 | MR = GetElementZeroRegion(SR, T); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1007 | |
Ted Kremenek | 968f0a6 | 2009-08-03 21:41:46 +0000 | [diff] [blame] | 1008 | if (isa<CodeTextRegion>(MR)) |
| 1009 | return SValuator::CastResult(state, UnknownVal()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1010 | |
Ted Kremenek | 869fb4a | 2008-12-24 07:46:32 +0000 | [diff] [blame] | 1011 | // FIXME: Perhaps this method should just take a 'const MemRegion*' argument |
| 1012 | // 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] | 1013 | const TypedRegion *R = cast<TypedRegion>(MR); |
Ted Kremenek | a6275a5 | 2009-07-15 02:31:43 +0000 | [diff] [blame] | 1014 | QualType RTy = R->getValueType(getContext()); |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 1015 | |
Ted Kremenek | 869fb4a | 2008-12-24 07:46:32 +0000 | [diff] [blame] | 1016 | // FIXME: We should eventually handle funny addressing. e.g.: |
| 1017 | // |
| 1018 | // int x = ...; |
| 1019 | // int *p = &x; |
| 1020 | // char *q = (char*) p; |
| 1021 | // char c = *q; // returns the first byte of 'x'. |
| 1022 | // |
| 1023 | // Such funny addressing will occur due to layering of regions. |
| 1024 | |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1025 | #if 0 |
Ted Kremenek | a6275a5 | 2009-07-15 02:31:43 +0000 | [diff] [blame] | 1026 | ASTContext &Ctx = getContext(); |
| 1027 | if (!T.isNull() && IsReinterpreted(RTy, T, Ctx)) { |
Ted Kremenek | 4653739 | 2009-07-16 01:33:37 +0000 | [diff] [blame] | 1028 | SVal ZeroIdx = ValMgr.makeZeroArrayIndex(); |
| 1029 | R = MRMgr.getElementRegion(T, ZeroIdx, R, Ctx); |
Ted Kremenek | a6275a5 | 2009-07-15 02:31:43 +0000 | [diff] [blame] | 1030 | RTy = T; |
Ted Kremenek | 41fb0df | 2009-07-15 04:23:32 +0000 | [diff] [blame] | 1031 | assert(Ctx.getCanonicalType(RTy) == |
| 1032 | Ctx.getCanonicalType(R->getValueType(Ctx))); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1033 | } |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1034 | #endif |
Zhongxing Xu | 3e001f3 | 2009-05-03 00:27:40 +0000 | [diff] [blame] | 1035 | |
Zhongxing Xu | 1038f9f | 2009-03-09 09:15:51 +0000 | [diff] [blame] | 1036 | if (RTy->isStructureType()) |
Ted Kremenek | 32c3fa4 | 2009-07-21 21:03:30 +0000 | [diff] [blame] | 1037 | return SValuator::CastResult(state, RetrieveStruct(state, R)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1038 | |
Ted Kremenek | d4e5a60 | 2009-08-06 21:43:54 +0000 | [diff] [blame] | 1039 | // FIXME: Handle unions. |
| 1040 | if (RTy->isUnionType()) |
| 1041 | return SValuator::CastResult(state, UnknownVal()); |
Zhongxing Xu | 3e001f3 | 2009-05-03 00:27:40 +0000 | [diff] [blame] | 1042 | |
| 1043 | if (RTy->isArrayType()) |
Ted Kremenek | 32c3fa4 | 2009-07-21 21:03:30 +0000 | [diff] [blame] | 1044 | return SValuator::CastResult(state, RetrieveArray(state, R)); |
Zhongxing Xu | 3e001f3 | 2009-05-03 00:27:40 +0000 | [diff] [blame] | 1045 | |
Zhongxing Xu | 1038f9f | 2009-03-09 09:15:51 +0000 | [diff] [blame] | 1046 | // FIXME: handle Vector types. |
| 1047 | if (RTy->isVectorType()) |
Ted Kremenek | 32c3fa4 | 2009-07-21 21:03:30 +0000 | [diff] [blame] | 1048 | return SValuator::CastResult(state, UnknownVal()); |
Zhongxing Xu | 99c2030 | 2009-06-28 14:16:39 +0000 | [diff] [blame] | 1049 | |
| 1050 | if (const FieldRegion* FR = dyn_cast<FieldRegion>(R)) |
Zhongxing Xu | 652be34 | 2009-11-16 04:49:44 +0000 | [diff] [blame] | 1051 | return SValuator::CastResult(state, |
| 1052 | CastRetrievedVal(RetrieveField(state, FR), FR, T)); |
Zhongxing Xu | 99c2030 | 2009-06-28 14:16:39 +0000 | [diff] [blame] | 1053 | |
| 1054 | if (const ElementRegion* ER = dyn_cast<ElementRegion>(R)) |
Zhongxing Xu | 652be34 | 2009-11-16 04:49:44 +0000 | [diff] [blame] | 1055 | return SValuator::CastResult(state, |
| 1056 | CastRetrievedVal(RetrieveElement(state, ER), ER, T)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1057 | |
Ted Kremenek | 25c5457 | 2009-07-20 22:58:02 +0000 | [diff] [blame] | 1058 | if (const ObjCIvarRegion *IVR = dyn_cast<ObjCIvarRegion>(R)) |
Zhongxing Xu | 652be34 | 2009-11-16 04:49:44 +0000 | [diff] [blame] | 1059 | return SValuator::CastResult(state, |
| 1060 | CastRetrievedVal(RetrieveObjCIvar(state, IVR), IVR, T)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1061 | |
Ted Kremenek | 9031dd7 | 2009-07-21 00:12:07 +0000 | [diff] [blame] | 1062 | if (const VarRegion *VR = dyn_cast<VarRegion>(R)) |
Zhongxing Xu | 652be34 | 2009-11-16 04:49:44 +0000 | [diff] [blame] | 1063 | return SValuator::CastResult(state, |
| 1064 | CastRetrievedVal(RetrieveVar(state, VR), VR, T)); |
Ted Kremenek | 25c5457 | 2009-07-20 22:58:02 +0000 | [diff] [blame] | 1065 | |
Ted Kremenek | 451ac09 | 2009-08-06 04:50:20 +0000 | [diff] [blame] | 1066 | RegionBindings B = GetRegionBindings(state->getStore()); |
| 1067 | RegionBindings::data_type* V = B.lookup(R); |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 1068 | |
| 1069 | // Check if the region has a binding. |
| 1070 | if (V) |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1071 | if (SVal const *SV = V->getValue()) |
| 1072 | return SValuator::CastResult(state, *SV); |
Ted Kremenek | 869fb4a | 2008-12-24 07:46:32 +0000 | [diff] [blame] | 1073 | |
Ted Kremenek | 869fb4a | 2008-12-24 07:46:32 +0000 | [diff] [blame] | 1074 | // The location does not have a bound value. This means that it has |
| 1075 | // the value it had upon its creation and/or entry to the analyzed |
| 1076 | // function/method. These are either symbolic values or 'undefined'. |
| 1077 | |
Ted Kremenek | 356e9d6 | 2009-07-22 04:35:42 +0000 | [diff] [blame] | 1078 | #if HEAP_UNDEFINED |
Ted Kremenek | bb7c96f | 2009-06-23 18:17:08 +0000 | [diff] [blame] | 1079 | if (R->hasHeapOrStackStorage()) { |
Ted Kremenek | 356e9d6 | 2009-07-22 04:35:42 +0000 | [diff] [blame] | 1080 | #else |
| 1081 | if (R->hasStackStorage()) { |
| 1082 | #endif |
Ted Kremenek | 869fb4a | 2008-12-24 07:46:32 +0000 | [diff] [blame] | 1083 | // All stack variables are considered to have undefined values |
| 1084 | // upon creation. All heap allocated blocks are considered to |
| 1085 | // have undefined values as well unless they are explicitly bound |
| 1086 | // to specific values. |
Ted Kremenek | 32c3fa4 | 2009-07-21 21:03:30 +0000 | [diff] [blame] | 1087 | return SValuator::CastResult(state, UndefinedVal()); |
Ted Kremenek | 869fb4a | 2008-12-24 07:46:32 +0000 | [diff] [blame] | 1088 | } |
| 1089 | |
Ted Kremenek | bb2b433 | 2009-07-02 22:16:42 +0000 | [diff] [blame] | 1090 | // All other values are symbolic. |
Ted Kremenek | 32c3fa4 | 2009-07-21 21:03:30 +0000 | [diff] [blame] | 1091 | return SValuator::CastResult(state, |
| 1092 | ValMgr.getRegionValueSymbolValOrUnknown(R, RTy)); |
Zhongxing Xu | 53bcdd4 | 2008-10-21 05:29:26 +0000 | [diff] [blame] | 1093 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1094 | |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1095 | std::pair<const GRState*, const MemRegion*> |
Ted Kremenek | 451ac09 | 2009-08-06 04:50:20 +0000 | [diff] [blame] | 1096 | RegionStoreManager::GetLazyBinding(RegionBindings B, const MemRegion *R) { |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1097 | if (Optional<SVal> OV = getDirectBinding(B, R)) |
| 1098 | if (const nonloc::LazyCompoundVal *V = |
| 1099 | dyn_cast<nonloc::LazyCompoundVal>(OV.getPointer())) |
| 1100 | return std::make_pair(V->getState(), V->getRegion()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1101 | |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1102 | if (const ElementRegion *ER = dyn_cast<ElementRegion>(R)) { |
| 1103 | const std::pair<const GRState *, const MemRegion *> &X = |
| 1104 | GetLazyBinding(B, ER->getSuperRegion()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1105 | |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1106 | if (X.first) |
| 1107 | return std::make_pair(X.first, |
| 1108 | MRMgr.getElementRegionWithSuper(ER, X.second)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1109 | } |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1110 | else if (const FieldRegion *FR = dyn_cast<FieldRegion>(R)) { |
| 1111 | const std::pair<const GRState *, const MemRegion *> &X = |
| 1112 | GetLazyBinding(B, FR->getSuperRegion()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1113 | |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1114 | if (X.first) |
| 1115 | return std::make_pair(X.first, |
| 1116 | MRMgr.getFieldRegionWithSuper(FR, X.second)); |
| 1117 | } |
| 1118 | |
| 1119 | return std::make_pair((const GRState*) 0, (const MemRegion *) 0); |
| 1120 | } |
Zhongxing Xu | 53bcdd4 | 2008-10-21 05:29:26 +0000 | [diff] [blame] | 1121 | |
Zhongxing Xu | c00346f | 2009-06-25 05:29:39 +0000 | [diff] [blame] | 1122 | SVal RegionStoreManager::RetrieveElement(const GRState* state, |
| 1123 | const ElementRegion* R) { |
| 1124 | // Check if the region has a binding. |
Ted Kremenek | 451ac09 | 2009-08-06 04:50:20 +0000 | [diff] [blame] | 1125 | RegionBindings B = GetRegionBindings(state->getStore()); |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1126 | if (Optional<SVal> V = getDirectBinding(B, R)) |
Zhongxing Xu | c00346f | 2009-06-25 05:29:39 +0000 | [diff] [blame] | 1127 | return *V; |
| 1128 | |
Ted Kremenek | 921109a | 2009-07-01 23:19:52 +0000 | [diff] [blame] | 1129 | const MemRegion* superR = R->getSuperRegion(); |
| 1130 | |
Zhongxing Xu | c00346f | 2009-06-25 05:29:39 +0000 | [diff] [blame] | 1131 | // Check if the region is an element region of a string literal. |
Ted Kremenek | 921109a | 2009-07-01 23:19:52 +0000 | [diff] [blame] | 1132 | if (const StringRegion *StrR=dyn_cast<StringRegion>(superR)) { |
Ted Kremenek | 95efe0f | 2009-09-29 16:36:48 +0000 | [diff] [blame] | 1133 | // FIXME: Handle loads from strings where the literal is treated as |
| 1134 | // an integer, e.g., *((unsigned int*)"hello") |
| 1135 | ASTContext &Ctx = getContext(); |
Douglas Gregor | 89c49f0 | 2009-11-09 22:08:55 +0000 | [diff] [blame] | 1136 | QualType T = Ctx.getAsArrayType(StrR->getValueType(Ctx))->getElementType(); |
Ted Kremenek | 95efe0f | 2009-09-29 16:36:48 +0000 | [diff] [blame] | 1137 | if (T != Ctx.getCanonicalType(R->getElementType())) |
| 1138 | return UnknownVal(); |
| 1139 | |
Zhongxing Xu | c00346f | 2009-06-25 05:29:39 +0000 | [diff] [blame] | 1140 | const StringLiteral *Str = StrR->getStringLiteral(); |
| 1141 | SVal Idx = R->getIndex(); |
| 1142 | if (nonloc::ConcreteInt *CI = dyn_cast<nonloc::ConcreteInt>(&Idx)) { |
| 1143 | int64_t i = CI->getValue().getSExtValue(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1144 | int64_t byteLength = Str->getByteLength(); |
Ted Kremenek | 0667db3 | 2009-09-05 17:59:01 +0000 | [diff] [blame] | 1145 | if (i > byteLength) { |
| 1146 | // Buffer overflow checking in GRExprEngine should handle this case, |
| 1147 | // but we shouldn't rely on it to not overflow here if that checking |
| 1148 | // is disabled. |
| 1149 | return UnknownVal(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1150 | } |
Ted Kremenek | 0667db3 | 2009-09-05 17:59:01 +0000 | [diff] [blame] | 1151 | char c = (i == byteLength) ? '\0' : Str->getStrData()[i]; |
Ted Kremenek | 95efe0f | 2009-09-29 16:36:48 +0000 | [diff] [blame] | 1152 | return ValMgr.makeIntVal(c, T); |
Zhongxing Xu | c00346f | 2009-06-25 05:29:39 +0000 | [diff] [blame] | 1153 | } |
| 1154 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1155 | |
Ted Kremenek | 566a6fa | 2009-08-06 22:33:36 +0000 | [diff] [blame] | 1156 | // Check if the immediate super region has a direct binding. |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1157 | if (Optional<SVal> V = getDirectBinding(B, superR)) { |
Ted Kremenek | a6275a5 | 2009-07-15 02:31:43 +0000 | [diff] [blame] | 1158 | if (SymbolRef parentSym = V->getAsSymbol()) |
| 1159 | return ValMgr.getDerivedRegionValueSymbolVal(parentSym, R); |
Ted Kremenek | 356e9d6 | 2009-07-22 04:35:42 +0000 | [diff] [blame] | 1160 | |
| 1161 | if (V->isUnknownOrUndef()) |
| 1162 | return *V; |
Ted Kremenek | 566a6fa | 2009-08-06 22:33:36 +0000 | [diff] [blame] | 1163 | |
| 1164 | // Handle LazyCompoundVals for the immediate super region. Other cases |
| 1165 | // are handled in 'RetrieveFieldOrElementCommon'. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1166 | if (const nonloc::LazyCompoundVal *LCV = |
Ted Kremenek | 566a6fa | 2009-08-06 22:33:36 +0000 | [diff] [blame] | 1167 | dyn_cast<nonloc::LazyCompoundVal>(V)) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1168 | |
Ted Kremenek | 566a6fa | 2009-08-06 22:33:36 +0000 | [diff] [blame] | 1169 | R = MRMgr.getElementRegionWithSuper(R, LCV->getRegion()); |
| 1170 | return RetrieveElement(LCV->getState(), R); |
| 1171 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1172 | |
Ted Kremenek | a6275a5 | 2009-07-15 02:31:43 +0000 | [diff] [blame] | 1173 | // Other cases: give up. |
Zhongxing Xu | 8834af3 | 2009-07-03 06:11:41 +0000 | [diff] [blame] | 1174 | return UnknownVal(); |
Zhongxing Xu | 7abe019 | 2009-06-30 12:32:59 +0000 | [diff] [blame] | 1175 | } |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1176 | |
Ted Kremenek | 566a6fa | 2009-08-06 22:33:36 +0000 | [diff] [blame] | 1177 | return RetrieveFieldOrElementCommon(state, R, R->getElementType(), superR); |
Zhongxing Xu | c00346f | 2009-06-25 05:29:39 +0000 | [diff] [blame] | 1178 | } |
| 1179 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1180 | SVal RegionStoreManager::RetrieveField(const GRState* state, |
Zhongxing Xu | 490b0f0 | 2009-06-25 04:50:44 +0000 | [diff] [blame] | 1181 | const FieldRegion* R) { |
Zhongxing Xu | 490b0f0 | 2009-06-25 04:50:44 +0000 | [diff] [blame] | 1182 | |
| 1183 | // Check if the region has a binding. |
Ted Kremenek | 451ac09 | 2009-08-06 04:50:20 +0000 | [diff] [blame] | 1184 | RegionBindings B = GetRegionBindings(state->getStore()); |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1185 | if (Optional<SVal> V = getDirectBinding(B, R)) |
Zhongxing Xu | 490b0f0 | 2009-06-25 04:50:44 +0000 | [diff] [blame] | 1186 | return *V; |
| 1187 | |
Ted Kremenek | 566a6fa | 2009-08-06 22:33:36 +0000 | [diff] [blame] | 1188 | QualType Ty = R->getValueType(getContext()); |
| 1189 | return RetrieveFieldOrElementCommon(state, R, Ty, R->getSuperRegion()); |
| 1190 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1191 | |
Ted Kremenek | 566a6fa | 2009-08-06 22:33:36 +0000 | [diff] [blame] | 1192 | SVal RegionStoreManager::RetrieveFieldOrElementCommon(const GRState *state, |
| 1193 | const TypedRegion *R, |
| 1194 | QualType Ty, |
| 1195 | const MemRegion *superR) { |
| 1196 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1197 | // At this point we have already checked in either RetrieveElement or |
Ted Kremenek | 566a6fa | 2009-08-06 22:33:36 +0000 | [diff] [blame] | 1198 | // RetrieveField if 'R' has a direct binding. |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1199 | |
Ted Kremenek | 566a6fa | 2009-08-06 22:33:36 +0000 | [diff] [blame] | 1200 | RegionBindings B = GetRegionBindings(state->getStore()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1201 | |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1202 | while (superR) { |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1203 | if (const Optional<SVal> &D = getDefaultBinding(B, superR)) { |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1204 | if (SymbolRef parentSym = D->getAsSymbol()) |
| 1205 | return ValMgr.getDerivedRegionValueSymbolVal(parentSym, R); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1206 | |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1207 | if (D->isZeroConstant()) |
| 1208 | return ValMgr.makeZeroVal(Ty); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1209 | |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1210 | if (D->isUnknown()) |
| 1211 | return *D; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1212 | |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1213 | assert(0 && "Unknown default value"); |
| 1214 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1215 | |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1216 | // If our super region is a field or element itself, walk up the region |
| 1217 | // hierarchy to see if there is a default value installed in an ancestor. |
| 1218 | if (isa<FieldRegion>(superR) || isa<ElementRegion>(superR)) { |
| 1219 | superR = cast<SubRegion>(superR)->getSuperRegion(); |
| 1220 | continue; |
| 1221 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1222 | |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1223 | break; |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1224 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1225 | |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1226 | // Lazy binding? |
| 1227 | const GRState *lazyBindingState = NULL; |
Ted Kremenek | 566a6fa | 2009-08-06 22:33:36 +0000 | [diff] [blame] | 1228 | const MemRegion *lazyBindingRegion = NULL; |
| 1229 | llvm::tie(lazyBindingState, lazyBindingRegion) = GetLazyBinding(B, R); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1230 | |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1231 | if (lazyBindingState) { |
Ted Kremenek | 566a6fa | 2009-08-06 22:33:36 +0000 | [diff] [blame] | 1232 | assert(lazyBindingRegion && "Lazy-binding region not set"); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1233 | |
Ted Kremenek | 566a6fa | 2009-08-06 22:33:36 +0000 | [diff] [blame] | 1234 | if (isa<ElementRegion>(R)) |
| 1235 | return RetrieveElement(lazyBindingState, |
| 1236 | cast<ElementRegion>(lazyBindingRegion)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1237 | |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1238 | return RetrieveField(lazyBindingState, |
Ted Kremenek | 566a6fa | 2009-08-06 22:33:36 +0000 | [diff] [blame] | 1239 | cast<FieldRegion>(lazyBindingRegion)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1240 | } |
| 1241 | |
Ted Kremenek | 566a6fa | 2009-08-06 22:33:36 +0000 | [diff] [blame] | 1242 | if (R->hasStackStorage() && !R->hasParametersStorage()) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1243 | |
Ted Kremenek | 566a6fa | 2009-08-06 22:33:36 +0000 | [diff] [blame] | 1244 | if (isa<ElementRegion>(R)) { |
| 1245 | // Currently we don't reason specially about Clang-style vectors. Check |
| 1246 | // if superR is a vector and if so return Unknown. |
| 1247 | if (const TypedRegion *typedSuperR = dyn_cast<TypedRegion>(superR)) { |
| 1248 | if (typedSuperR->getValueType(getContext())->isVectorType()) |
| 1249 | return UnknownVal(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1250 | } |
Ted Kremenek | 566a6fa | 2009-08-06 22:33:36 +0000 | [diff] [blame] | 1251 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1252 | |
Zhongxing Xu | 490b0f0 | 2009-06-25 04:50:44 +0000 | [diff] [blame] | 1253 | return UndefinedVal(); |
Ted Kremenek | 566a6fa | 2009-08-06 22:33:36 +0000 | [diff] [blame] | 1254 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1255 | |
Ted Kremenek | bb2b433 | 2009-07-02 22:16:42 +0000 | [diff] [blame] | 1256 | // All other values are symbolic. |
| 1257 | return ValMgr.getRegionValueSymbolValOrUnknown(R, Ty); |
Zhongxing Xu | 490b0f0 | 2009-06-25 04:50:44 +0000 | [diff] [blame] | 1258 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1259 | |
| 1260 | SVal RegionStoreManager::RetrieveObjCIvar(const GRState* state, |
Ted Kremenek | 5bd2fe3 | 2009-07-15 06:09:28 +0000 | [diff] [blame] | 1261 | const ObjCIvarRegion* R) { |
| 1262 | |
Ted Kremenek | 5bd2fe3 | 2009-07-15 06:09:28 +0000 | [diff] [blame] | 1263 | // Check if the region has a binding. |
Ted Kremenek | 451ac09 | 2009-08-06 04:50:20 +0000 | [diff] [blame] | 1264 | RegionBindings B = GetRegionBindings(state->getStore()); |
Ted Kremenek | 5bd2fe3 | 2009-07-15 06:09:28 +0000 | [diff] [blame] | 1265 | |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1266 | if (Optional<SVal> V = getDirectBinding(B, R)) |
Ted Kremenek | 5bd2fe3 | 2009-07-15 06:09:28 +0000 | [diff] [blame] | 1267 | return *V; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1268 | |
Ted Kremenek | 5bd2fe3 | 2009-07-15 06:09:28 +0000 | [diff] [blame] | 1269 | const MemRegion *superR = R->getSuperRegion(); |
| 1270 | |
Ted Kremenek | ab22ee9 | 2009-10-20 01:20:57 +0000 | [diff] [blame] | 1271 | // Check if the super region has a default binding. |
| 1272 | if (Optional<SVal> V = getDefaultBinding(B, superR)) { |
Ted Kremenek | 5bd2fe3 | 2009-07-15 06:09:28 +0000 | [diff] [blame] | 1273 | if (SymbolRef parentSym = V->getAsSymbol()) |
| 1274 | return ValMgr.getDerivedRegionValueSymbolVal(parentSym, R); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1275 | |
Ted Kremenek | 5bd2fe3 | 2009-07-15 06:09:28 +0000 | [diff] [blame] | 1276 | // Other cases: give up. |
| 1277 | return UnknownVal(); |
| 1278 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1279 | |
Ted Kremenek | 25c5457 | 2009-07-20 22:58:02 +0000 | [diff] [blame] | 1280 | return RetrieveLazySymbol(state, R); |
| 1281 | } |
| 1282 | |
Ted Kremenek | 9031dd7 | 2009-07-21 00:12:07 +0000 | [diff] [blame] | 1283 | SVal RegionStoreManager::RetrieveVar(const GRState *state, |
| 1284 | const VarRegion *R) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1285 | |
Ted Kremenek | 9031dd7 | 2009-07-21 00:12:07 +0000 | [diff] [blame] | 1286 | // Check if the region has a binding. |
Ted Kremenek | 451ac09 | 2009-08-06 04:50:20 +0000 | [diff] [blame] | 1287 | RegionBindings B = GetRegionBindings(state->getStore()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1288 | |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1289 | if (Optional<SVal> V = getDirectBinding(B, R)) |
Ted Kremenek | 9031dd7 | 2009-07-21 00:12:07 +0000 | [diff] [blame] | 1290 | return *V; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1291 | |
Ted Kremenek | 9031dd7 | 2009-07-21 00:12:07 +0000 | [diff] [blame] | 1292 | // Lazily derive a value for the VarRegion. |
| 1293 | const VarDecl *VD = R->getDecl(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1294 | |
Ted Kremenek | 9031dd7 | 2009-07-21 00:12:07 +0000 | [diff] [blame] | 1295 | if (R->hasGlobalsOrParametersStorage()) |
| 1296 | return ValMgr.getRegionValueSymbolValOrUnknown(R, VD->getType()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1297 | |
Ted Kremenek | 9031dd7 | 2009-07-21 00:12:07 +0000 | [diff] [blame] | 1298 | return UndefinedVal(); |
| 1299 | } |
| 1300 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1301 | SVal RegionStoreManager::RetrieveLazySymbol(const GRState *state, |
Ted Kremenek | 25c5457 | 2009-07-20 22:58:02 +0000 | [diff] [blame] | 1302 | const TypedRegion *R) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1303 | |
Ted Kremenek | 25c5457 | 2009-07-20 22:58:02 +0000 | [diff] [blame] | 1304 | QualType valTy = R->getValueType(getContext()); |
Ted Kremenek | 356e9d6 | 2009-07-22 04:35:42 +0000 | [diff] [blame] | 1305 | |
Ted Kremenek | 5bd2fe3 | 2009-07-15 06:09:28 +0000 | [diff] [blame] | 1306 | // All other values are symbolic. |
Ted Kremenek | 25c5457 | 2009-07-20 22:58:02 +0000 | [diff] [blame] | 1307 | return ValMgr.getRegionValueSymbolValOrUnknown(R, valTy); |
Ted Kremenek | 5bd2fe3 | 2009-07-15 06:09:28 +0000 | [diff] [blame] | 1308 | } |
| 1309 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1310 | SVal RegionStoreManager::RetrieveStruct(const GRState *state, |
| 1311 | const TypedRegion* R) { |
Zhongxing Xu | a82d8aa | 2009-05-09 03:57:34 +0000 | [diff] [blame] | 1312 | QualType T = R->getValueType(getContext()); |
Zhongxing Xu | 6e3f01c | 2008-10-31 07:16:08 +0000 | [diff] [blame] | 1313 | assert(T->isStructureType()); |
| 1314 | |
Zhongxing Xu | b7507d1 | 2009-06-11 07:27:30 +0000 | [diff] [blame] | 1315 | const RecordType* RT = T->getAsStructureType(); |
Zhongxing Xu | 6e3f01c | 2008-10-31 07:16:08 +0000 | [diff] [blame] | 1316 | RecordDecl* RD = RT->getDecl(); |
| 1317 | assert(RD->isDefinition()); |
Mike Stump | 1aeb247 | 2009-08-06 12:56:50 +0000 | [diff] [blame] | 1318 | (void)RD; |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1319 | #if USE_EXPLICIT_COMPOUND |
Zhongxing Xu | 6e3f01c | 2008-10-31 07:16:08 +0000 | [diff] [blame] | 1320 | llvm::ImmutableList<SVal> StructVal = getBasicVals().getEmptySValList(); |
| 1321 | |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 1322 | // FIXME: We shouldn't use a std::vector. If RecordDecl doesn't have a |
| 1323 | // reverse iterator, we should implement one. |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1324 | std::vector<FieldDecl *> Fields(RD->field_begin(), RD->field_end()); |
Douglas Gregor | 44b4321 | 2008-12-11 16:49:14 +0000 | [diff] [blame] | 1325 | |
Douglas Gregor | e267ff3 | 2008-12-11 20:41:00 +0000 | [diff] [blame] | 1326 | for (std::vector<FieldDecl *>::reverse_iterator Field = Fields.rbegin(), |
| 1327 | FieldEnd = Fields.rend(); |
| 1328 | Field != FieldEnd; ++Field) { |
| 1329 | FieldRegion* FR = MRMgr.getFieldRegion(*Field, R); |
Zhongxing Xu | 3e001f3 | 2009-05-03 00:27:40 +0000 | [diff] [blame] | 1330 | QualType FTy = (*Field)->getType(); |
Ted Kremenek | 32c3fa4 | 2009-07-21 21:03:30 +0000 | [diff] [blame] | 1331 | SVal FieldValue = Retrieve(state, loc::MemRegionVal(FR), FTy).getSVal(); |
Zhongxing Xu | 6e3f01c | 2008-10-31 07:16:08 +0000 | [diff] [blame] | 1332 | StructVal = getBasicVals().consVals(FieldValue, StructVal); |
| 1333 | } |
| 1334 | |
Zhongxing Xu | d91ee27 | 2009-06-23 09:02:15 +0000 | [diff] [blame] | 1335 | return ValMgr.makeCompoundVal(T, StructVal); |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1336 | #else |
| 1337 | return ValMgr.makeLazyCompoundVal(state, R); |
| 1338 | #endif |
Zhongxing Xu | 6e3f01c | 2008-10-31 07:16:08 +0000 | [diff] [blame] | 1339 | } |
| 1340 | |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 1341 | SVal RegionStoreManager::RetrieveArray(const GRState *state, |
| 1342 | const TypedRegion * R) { |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1343 | #if USE_EXPLICIT_COMPOUND |
Zhongxing Xu | a82d8aa | 2009-05-09 03:57:34 +0000 | [diff] [blame] | 1344 | QualType T = R->getValueType(getContext()); |
Zhongxing Xu | 3e001f3 | 2009-05-03 00:27:40 +0000 | [diff] [blame] | 1345 | ConstantArrayType* CAT = cast<ConstantArrayType>(T.getTypePtr()); |
| 1346 | |
| 1347 | llvm::ImmutableList<SVal> ArrayVal = getBasicVals().getEmptySValList(); |
Ted Kremenek | 4653739 | 2009-07-16 01:33:37 +0000 | [diff] [blame] | 1348 | uint64_t size = CAT->getSize().getZExtValue(); |
| 1349 | for (uint64_t i = 0; i < size; ++i) { |
| 1350 | SVal Idx = ValMgr.makeArrayIndex(i); |
Zhongxing Xu | 143b2fc | 2009-06-16 09:55:50 +0000 | [diff] [blame] | 1351 | ElementRegion* ER = MRMgr.getElementRegion(CAT->getElementType(), Idx, R, |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1352 | getContext()); |
Ted Kremenek | f936f45 | 2009-05-04 06:18:28 +0000 | [diff] [blame] | 1353 | QualType ETy = ER->getElementType(); |
Ted Kremenek | 32c3fa4 | 2009-07-21 21:03:30 +0000 | [diff] [blame] | 1354 | SVal ElementVal = Retrieve(state, loc::MemRegionVal(ER), ETy).getSVal(); |
Zhongxing Xu | 3e001f3 | 2009-05-03 00:27:40 +0000 | [diff] [blame] | 1355 | ArrayVal = getBasicVals().consVals(ElementVal, ArrayVal); |
| 1356 | } |
| 1357 | |
Zhongxing Xu | d91ee27 | 2009-06-23 09:02:15 +0000 | [diff] [blame] | 1358 | return ValMgr.makeCompoundVal(T, ArrayVal); |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1359 | #else |
| 1360 | assert(isa<ConstantArrayType>(R->getValueType(getContext()))); |
| 1361 | return ValMgr.makeLazyCompoundVal(state, R); |
| 1362 | #endif |
Zhongxing Xu | 3e001f3 | 2009-05-03 00:27:40 +0000 | [diff] [blame] | 1363 | } |
| 1364 | |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1365 | //===----------------------------------------------------------------------===// |
| 1366 | // Binding values to regions. |
| 1367 | //===----------------------------------------------------------------------===// |
Zhongxing Xu | 1789275 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 1368 | |
Zhongxing Xu | 9c9ca08 | 2008-12-16 02:36:30 +0000 | [diff] [blame] | 1369 | Store RegionStoreManager::Remove(Store store, Loc L) { |
Ted Kremenek | 0964a06 | 2009-01-21 06:57:53 +0000 | [diff] [blame] | 1370 | const MemRegion* R = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1371 | |
Ted Kremenek | 0964a06 | 2009-01-21 06:57:53 +0000 | [diff] [blame] | 1372 | if (isa<loc::MemRegionVal>(L)) |
| 1373 | R = cast<loc::MemRegionVal>(L).getRegion(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1374 | |
Ted Kremenek | 0964a06 | 2009-01-21 06:57:53 +0000 | [diff] [blame] | 1375 | if (R) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1376 | RegionBindings B = GetRegionBindings(store); |
Ted Kremenek | 0964a06 | 2009-01-21 06:57:53 +0000 | [diff] [blame] | 1377 | return RBFactory.Remove(B, R).getRoot(); |
| 1378 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1379 | |
Ted Kremenek | 0964a06 | 2009-01-21 06:57:53 +0000 | [diff] [blame] | 1380 | return store; |
Zhongxing Xu | 9c9ca08 | 2008-12-16 02:36:30 +0000 | [diff] [blame] | 1381 | } |
| 1382 | |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 1383 | const GRState *RegionStoreManager::Bind(const GRState *state, Loc L, SVal V) { |
Zhongxing Xu | 87453d1 | 2009-06-28 10:16:11 +0000 | [diff] [blame] | 1384 | if (isa<loc::ConcreteInt>(L)) |
| 1385 | return state; |
| 1386 | |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1387 | // If we get here, the location should be a region. |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1388 | const MemRegion *R = cast<loc::MemRegionVal>(L).getRegion(); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1389 | |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1390 | // Check if the region is a struct region. |
| 1391 | if (const TypedRegion* TR = dyn_cast<TypedRegion>(R)) |
| 1392 | if (TR->getValueType(getContext())->isStructureType()) |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 1393 | return BindStruct(state, TR, V); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1394 | |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1395 | // Special case: the current region represents a cast and it and the super |
| 1396 | // region both have pointer types or intptr_t types. If so, perform the |
| 1397 | // bind to the super region. |
| 1398 | // This is needed to support OSAtomicCompareAndSwap and friends or other |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1399 | // loads that treat integers as pointers and vis versa. |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1400 | if (const ElementRegion *ER = dyn_cast<ElementRegion>(R)) { |
| 1401 | if (ER->getIndex().isZeroConstant()) { |
| 1402 | if (const TypedRegion *superR = |
| 1403 | dyn_cast<TypedRegion>(ER->getSuperRegion())) { |
| 1404 | ASTContext &Ctx = getContext(); |
| 1405 | QualType superTy = superR->getValueType(Ctx); |
| 1406 | QualType erTy = ER->getValueType(Ctx); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1407 | |
| 1408 | if (IsAnyPointerOrIntptr(superTy, Ctx) && |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1409 | IsAnyPointerOrIntptr(erTy, Ctx)) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1410 | SValuator::CastResult cr = |
| 1411 | ValMgr.getSValuator().EvalCast(V, state, superTy, erTy); |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1412 | return Bind(cr.getState(), loc::MemRegionVal(superR), cr.getSVal()); |
| 1413 | } |
Ted Kremenek | 69181a8 | 2009-09-21 22:58:52 +0000 | [diff] [blame] | 1414 | // For now, just invalidate the fields of the struct/union/class. |
| 1415 | // FIXME: Precisely handle the fields of the record. |
| 1416 | if (superTy->isRecordType()) |
Ted Kremenek | 473e167 | 2009-10-16 00:30:49 +0000 | [diff] [blame] | 1417 | return InvalidateRegion(state, superR, NULL, 0, NULL); |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1418 | } |
| 1419 | } |
| 1420 | } |
Ted Kremenek | 0954cde | 2009-09-24 04:11:44 +0000 | [diff] [blame] | 1421 | else if (const SymbolicRegion *SR = dyn_cast<SymbolicRegion>(R)) { |
| 1422 | // Binding directly to a symbolic region should be treated as binding |
| 1423 | // to element 0. |
| 1424 | QualType T = SR->getSymbol()->getType(getContext()); |
Ted Kremenek | 35dcad8 | 2009-09-24 06:24:32 +0000 | [diff] [blame] | 1425 | T = T->getAs<PointerType>()->getPointeeType(); |
Ted Kremenek | 0954cde | 2009-09-24 04:11:44 +0000 | [diff] [blame] | 1426 | R = GetElementZeroRegion(SR, T); |
| 1427 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1428 | |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1429 | // Perform the binding. |
Ted Kremenek | 451ac09 | 2009-08-06 04:50:20 +0000 | [diff] [blame] | 1430 | RegionBindings B = GetRegionBindings(state->getStore()); |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1431 | return state->makeWithStore( |
| 1432 | RBFactory.Add(B, R, BindingVal(V, BindingVal::Direct)).getRoot()); |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1433 | } |
| 1434 | |
Ted Kremenek | d17da2b | 2009-08-21 22:28:32 +0000 | [diff] [blame] | 1435 | const GRState *RegionStoreManager::BindDecl(const GRState *ST, |
Ted Kremenek | f6f56d4 | 2009-11-04 00:09:15 +0000 | [diff] [blame] | 1436 | const VarRegion *VR, |
Ted Kremenek | d17da2b | 2009-08-21 22:28:32 +0000 | [diff] [blame] | 1437 | SVal InitVal) { |
Zhongxing Xu | a4f28ff | 2008-11-13 08:41:36 +0000 | [diff] [blame] | 1438 | |
Ted Kremenek | f6f56d4 | 2009-11-04 00:09:15 +0000 | [diff] [blame] | 1439 | QualType T = VR->getDecl()->getType(); |
Zhongxing Xu | f0dfa8d | 2008-10-31 08:10:01 +0000 | [diff] [blame] | 1440 | |
Ted Kremenek | 0964a06 | 2009-01-21 06:57:53 +0000 | [diff] [blame] | 1441 | if (T->isArrayType()) |
Ted Kremenek | d17da2b | 2009-08-21 22:28:32 +0000 | [diff] [blame] | 1442 | return BindArray(ST, VR, InitVal); |
Ted Kremenek | 0964a06 | 2009-01-21 06:57:53 +0000 | [diff] [blame] | 1443 | if (T->isStructureType()) |
Ted Kremenek | d17da2b | 2009-08-21 22:28:32 +0000 | [diff] [blame] | 1444 | return BindStruct(ST, VR, InitVal); |
Zhongxing Xu | d463d44 | 2008-11-02 12:13:30 +0000 | [diff] [blame] | 1445 | |
Ted Kremenek | d17da2b | 2009-08-21 22:28:32 +0000 | [diff] [blame] | 1446 | return Bind(ST, ValMgr.makeLoc(VR), InitVal); |
Zhongxing Xu | 1789275 | 2008-10-08 02:50:44 +0000 | [diff] [blame] | 1447 | } |
Zhongxing Xu | 53bcdd4 | 2008-10-21 05:29:26 +0000 | [diff] [blame] | 1448 | |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 1449 | // FIXME: this method should be merged into Bind(). |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 1450 | const GRState * |
| 1451 | RegionStoreManager::BindCompoundLiteral(const GRState *state, |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 1452 | const CompoundLiteralExpr *CL, |
| 1453 | const LocationContext *LC, |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 1454 | SVal V) { |
Ted Kremenek | 67d1287 | 2009-12-07 22:05:27 +0000 | [diff] [blame] | 1455 | return Bind(state, loc::MemRegionVal(MRMgr.getCompoundLiteralRegion(CL, LC)), |
| 1456 | V); |
Zhongxing Xu | f22679e | 2008-11-07 10:38:33 +0000 | [diff] [blame] | 1457 | } |
| 1458 | |
Ted Kremenek | 027e266 | 2009-11-19 20:20:24 +0000 | [diff] [blame] | 1459 | const GRState *RegionStoreManager::setImplicitDefaultValue(const GRState *state, |
| 1460 | const MemRegion *R, |
| 1461 | QualType T) { |
| 1462 | Store store = state->getStore(); |
| 1463 | RegionBindings B = GetRegionBindings(store); |
| 1464 | SVal V; |
| 1465 | |
| 1466 | if (Loc::IsLocType(T)) |
| 1467 | V = ValMgr.makeNull(); |
| 1468 | else if (T->isIntegerType()) |
| 1469 | V = ValMgr.makeZeroVal(T); |
| 1470 | else if (T->isStructureType() || T->isArrayType()) { |
| 1471 | // Set the default value to a zero constant when it is a structure |
| 1472 | // or array. The type doesn't really matter. |
| 1473 | V = ValMgr.makeZeroVal(ValMgr.getContext().IntTy); |
| 1474 | } |
| 1475 | else { |
| 1476 | return state; |
| 1477 | } |
| 1478 | |
| 1479 | B = RBFactory.Add(B, R, BindingVal(V, BindingVal::Default)); |
| 1480 | return state->makeWithStore(B.getRoot()); |
| 1481 | } |
| 1482 | |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 1483 | const GRState *RegionStoreManager::BindArray(const GRState *state, |
Ted Kremenek | 4653739 | 2009-07-16 01:33:37 +0000 | [diff] [blame] | 1484 | const TypedRegion* R, |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 1485 | SVal Init) { |
| 1486 | |
Zhongxing Xu | a82d8aa | 2009-05-09 03:57:34 +0000 | [diff] [blame] | 1487 | QualType T = R->getValueType(getContext()); |
Zhongxing Xu | 1a12a0e | 2008-10-31 10:24:47 +0000 | [diff] [blame] | 1488 | ConstantArrayType* CAT = cast<ConstantArrayType>(T.getTypePtr()); |
Zhongxing Xu | 087d6c2 | 2009-06-23 05:23:38 +0000 | [diff] [blame] | 1489 | QualType ElementTy = CAT->getElementType(); |
Zhongxing Xu | 1a12a0e | 2008-10-31 10:24:47 +0000 | [diff] [blame] | 1490 | |
Ted Kremenek | 4653739 | 2009-07-16 01:33:37 +0000 | [diff] [blame] | 1491 | uint64_t size = CAT->getSize().getZExtValue(); |
Zhongxing Xu | 6987c7b | 2008-11-30 05:49:49 +0000 | [diff] [blame] | 1492 | |
| 1493 | // Check if the init expr is a StringLiteral. |
| 1494 | if (isa<loc::MemRegionVal>(Init)) { |
| 1495 | const MemRegion* InitR = cast<loc::MemRegionVal>(Init).getRegion(); |
| 1496 | const StringLiteral* S = cast<StringRegion>(InitR)->getStringLiteral(); |
| 1497 | const char* str = S->getStrData(); |
| 1498 | unsigned len = S->getByteLength(); |
| 1499 | unsigned j = 0; |
| 1500 | |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 1501 | // Copy bytes from the string literal into the target array. Trailing bytes |
| 1502 | // in the array that are not covered by the string literal are initialized |
| 1503 | // to zero. |
Ted Kremenek | 4653739 | 2009-07-16 01:33:37 +0000 | [diff] [blame] | 1504 | for (uint64_t i = 0; i < size; ++i, ++j) { |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 1505 | if (j >= len) |
| 1506 | break; |
| 1507 | |
Ted Kremenek | 4653739 | 2009-07-16 01:33:37 +0000 | [diff] [blame] | 1508 | SVal Idx = ValMgr.makeArrayIndex(i); |
Ted Kremenek | b48ad64 | 2009-12-04 00:26:31 +0000 | [diff] [blame] | 1509 | const ElementRegion* ER = MRMgr.getElementRegion(ElementTy, Idx, R, |
| 1510 | getContext()); |
Zhongxing Xu | 6987c7b | 2008-11-30 05:49:49 +0000 | [diff] [blame] | 1511 | |
Zhongxing Xu | d91ee27 | 2009-06-23 09:02:15 +0000 | [diff] [blame] | 1512 | SVal V = ValMgr.makeIntVal(str[j], sizeof(char)*8, true); |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 1513 | state = Bind(state, loc::MemRegionVal(ER), V); |
Zhongxing Xu | 6987c7b | 2008-11-30 05:49:49 +0000 | [diff] [blame] | 1514 | } |
| 1515 | |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 1516 | return state; |
Zhongxing Xu | 6987c7b | 2008-11-30 05:49:49 +0000 | [diff] [blame] | 1517 | } |
| 1518 | |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1519 | // Handle lazy compound values. |
| 1520 | if (nonloc::LazyCompoundVal *LCV = dyn_cast<nonloc::LazyCompoundVal>(&Init)) |
| 1521 | return CopyLazyBindings(*LCV, state, R); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1522 | |
| 1523 | // Remaining case: explicit compound values. |
Ted Kremenek | 027e266 | 2009-11-19 20:20:24 +0000 | [diff] [blame] | 1524 | |
| 1525 | if (Init.isUnknown()) |
| 1526 | return setImplicitDefaultValue(state, R, ElementTy); |
| 1527 | |
Zhongxing Xu | 1a12a0e | 2008-10-31 10:24:47 +0000 | [diff] [blame] | 1528 | nonloc::CompoundVal& CV = cast<nonloc::CompoundVal>(Init); |
Zhongxing Xu | 1a12a0e | 2008-10-31 10:24:47 +0000 | [diff] [blame] | 1529 | nonloc::CompoundVal::iterator VI = CV.begin(), VE = CV.end(); |
Ted Kremenek | 4653739 | 2009-07-16 01:33:37 +0000 | [diff] [blame] | 1530 | uint64_t i = 0; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1531 | |
Ted Kremenek | 4653739 | 2009-07-16 01:33:37 +0000 | [diff] [blame] | 1532 | for (; i < size; ++i, ++VI) { |
Zhongxing Xu | 087d6c2 | 2009-06-23 05:23:38 +0000 | [diff] [blame] | 1533 | // The init list might be shorter than the array length. |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 1534 | if (VI == VE) |
| 1535 | break; |
| 1536 | |
Ted Kremenek | 4653739 | 2009-07-16 01:33:37 +0000 | [diff] [blame] | 1537 | SVal Idx = ValMgr.makeArrayIndex(i); |
Ted Kremenek | b48ad64 | 2009-12-04 00:26:31 +0000 | [diff] [blame] | 1538 | const ElementRegion *ER = MRMgr.getElementRegion(ElementTy, Idx, R, getContext()); |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 1539 | |
| 1540 | if (CAT->getElementType()->isStructureType()) |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 1541 | state = BindStruct(state, ER, *VI); |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 1542 | else |
Ted Kremenek | cf54959 | 2009-09-22 21:19:14 +0000 | [diff] [blame] | 1543 | // FIXME: Do we need special handling of nested arrays? |
Zhongxing Xu | d91ee27 | 2009-06-23 09:02:15 +0000 | [diff] [blame] | 1544 | state = Bind(state, ValMgr.makeLoc(ER), *VI); |
Zhongxing Xu | 1a12a0e | 2008-10-31 10:24:47 +0000 | [diff] [blame] | 1545 | } |
| 1546 | |
Ted Kremenek | 027e266 | 2009-11-19 20:20:24 +0000 | [diff] [blame] | 1547 | // If the init list is shorter than the array length, set the |
| 1548 | // array default value. |
| 1549 | if (i < size) |
| 1550 | state = setImplicitDefaultValue(state, R, ElementTy); |
Zhongxing Xu | 087d6c2 | 2009-06-23 05:23:38 +0000 | [diff] [blame] | 1551 | |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 1552 | return state; |
Zhongxing Xu | 1a12a0e | 2008-10-31 10:24:47 +0000 | [diff] [blame] | 1553 | } |
| 1554 | |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 1555 | const GRState * |
| 1556 | RegionStoreManager::BindStruct(const GRState *state, const TypedRegion* R, |
| 1557 | SVal V) { |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1558 | |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 1559 | if (!Features.supportsFields()) |
| 1560 | return state; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1561 | |
Zhongxing Xu | a82d8aa | 2009-05-09 03:57:34 +0000 | [diff] [blame] | 1562 | QualType T = R->getValueType(getContext()); |
Zhongxing Xu | af0a844 | 2008-10-31 10:53:01 +0000 | [diff] [blame] | 1563 | assert(T->isStructureType()); |
| 1564 | |
Ted Kremenek | 6217b80 | 2009-07-29 21:53:49 +0000 | [diff] [blame] | 1565 | const RecordType* RT = T->getAs<RecordType>(); |
Zhongxing Xu | af0a844 | 2008-10-31 10:53:01 +0000 | [diff] [blame] | 1566 | RecordDecl* RD = RT->getDecl(); |
Zhongxing Xu | c45a825 | 2009-03-11 09:07:35 +0000 | [diff] [blame] | 1567 | |
| 1568 | if (!RD->isDefinition()) |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 1569 | return state; |
Zhongxing Xu | af0a844 | 2008-10-31 10:53:01 +0000 | [diff] [blame] | 1570 | |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1571 | // Handle lazy compound values. |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1572 | if (const nonloc::LazyCompoundVal *LCV=dyn_cast<nonloc::LazyCompoundVal>(&V)) |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1573 | return CopyLazyBindings(*LCV, state, R); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1574 | |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 1575 | // We may get non-CompoundVal accidentally due to imprecise cast logic. |
| 1576 | // Ignore them and kill the field values. |
| 1577 | if (V.isUnknown() || !isa<nonloc::CompoundVal>(V)) |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1578 | return state->makeWithStore(KillStruct(state->getStore(), R)); |
Zhongxing Xu | 3f6978a | 2009-06-11 09:11:27 +0000 | [diff] [blame] | 1579 | |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 1580 | nonloc::CompoundVal& CV = cast<nonloc::CompoundVal>(V); |
Zhongxing Xu | af0a844 | 2008-10-31 10:53:01 +0000 | [diff] [blame] | 1581 | nonloc::CompoundVal::iterator VI = CV.begin(), VE = CV.end(); |
Zhongxing Xu | dbdf219 | 2009-06-23 05:43:16 +0000 | [diff] [blame] | 1582 | |
| 1583 | RecordDecl::field_iterator FI, FE; |
| 1584 | |
Argyrios Kyrtzidis | 17945a0 | 2009-06-30 02:36:12 +0000 | [diff] [blame] | 1585 | 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] | 1586 | |
Zhongxing Xu | dbdf219 | 2009-06-23 05:43:16 +0000 | [diff] [blame] | 1587 | if (VI == VE) |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 1588 | break; |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 1589 | |
Zhongxing Xu | af0a844 | 2008-10-31 10:53:01 +0000 | [diff] [blame] | 1590 | QualType FTy = (*FI)->getType(); |
Ted Kremenek | cf54959 | 2009-09-22 21:19:14 +0000 | [diff] [blame] | 1591 | const FieldRegion* FR = MRMgr.getFieldRegion(*FI, R); |
Zhongxing Xu | af0a844 | 2008-10-31 10:53:01 +0000 | [diff] [blame] | 1592 | |
Ted Kremenek | cf54959 | 2009-09-22 21:19:14 +0000 | [diff] [blame] | 1593 | if (FTy->isArrayType()) |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 1594 | state = BindArray(state, FR, *VI); |
Zhongxing Xu | 4193eca | 2008-12-20 06:32:12 +0000 | [diff] [blame] | 1595 | else if (FTy->isStructureType()) |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 1596 | state = BindStruct(state, FR, *VI); |
Ted Kremenek | cf54959 | 2009-09-22 21:19:14 +0000 | [diff] [blame] | 1597 | else |
| 1598 | state = Bind(state, ValMgr.makeLoc(FR), *VI); |
Zhongxing Xu | a82512a | 2008-10-24 08:42:28 +0000 | [diff] [blame] | 1599 | } |
| 1600 | |
Zhongxing Xu | dbdf219 | 2009-06-23 05:43:16 +0000 | [diff] [blame] | 1601 | // 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] | 1602 | if (FI != FE) { |
| 1603 | Store store = state->getStore(); |
| 1604 | RegionBindings B = GetRegionBindings(store); |
| 1605 | B = RBFactory.Add(B, R, |
| 1606 | BindingVal(ValMgr.makeIntVal(0, false), BindingVal::Default)); |
| 1607 | state = state->makeWithStore(B.getRoot()); |
| 1608 | } |
Zhongxing Xu | dbdf219 | 2009-06-23 05:43:16 +0000 | [diff] [blame] | 1609 | |
Ted Kremenek | 67f2853 | 2009-06-17 22:02:04 +0000 | [diff] [blame] | 1610 | return state; |
Zhongxing Xu | c3a0599 | 2008-11-19 11:06:24 +0000 | [diff] [blame] | 1611 | } |
| 1612 | |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1613 | Store RegionStoreManager::KillStruct(Store store, const TypedRegion* R) { |
| 1614 | RegionBindings B = GetRegionBindings(store); |
| 1615 | llvm::OwningPtr<RegionStoreSubRegionMap> |
| 1616 | SubRegions(getRegionStoreSubRegionMap(store)); |
| 1617 | RemoveSubRegionBindings(B, R, *SubRegions); |
Zhongxing Xu | 5834ed6 | 2009-01-13 01:49:57 +0000 | [diff] [blame] | 1618 | |
Zhongxing Xu | e4df9c4 | 2009-06-25 05:52:16 +0000 | [diff] [blame] | 1619 | // Set the default value of the struct region to "unknown". |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1620 | B = RBFactory.Add(B, R, BindingVal(UnknownVal(), BindingVal::Default)); |
Zhongxing Xu | 5834ed6 | 2009-01-13 01:49:57 +0000 | [diff] [blame] | 1621 | |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1622 | return B.getRoot(); |
Zhongxing Xu | 5834ed6 | 2009-01-13 01:49:57 +0000 | [diff] [blame] | 1623 | } |
| 1624 | |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1625 | const GRState* |
| 1626 | RegionStoreManager::CopyLazyBindings(nonloc::LazyCompoundVal V, |
| 1627 | const GRState *state, |
| 1628 | const TypedRegion *R) { |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1629 | |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1630 | // Nuke the old bindings stemming from R. |
Ted Kremenek | 451ac09 | 2009-08-06 04:50:20 +0000 | [diff] [blame] | 1631 | RegionBindings B = GetRegionBindings(state->getStore()); |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1632 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1633 | llvm::OwningPtr<RegionStoreSubRegionMap> |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1634 | SubRegions(getRegionStoreSubRegionMap(state->getStore())); |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1635 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1636 | // B and DVM are updated after the call to RemoveSubRegionBindings. |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1637 | RemoveSubRegionBindings(B, R, *SubRegions.get()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1638 | |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1639 | // Now copy the bindings. This amounts to just binding 'V' to 'R'. This |
| 1640 | // results in a zero-copy algorithm. |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1641 | return state->makeWithStore( |
| 1642 | RBFactory.Add(B, R, BindingVal(V, BindingVal::Direct)).getRoot()); |
Ted Kremenek | a5e81f1 | 2009-08-06 01:20:57 +0000 | [diff] [blame] | 1643 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1644 | |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1645 | //===----------------------------------------------------------------------===// |
| 1646 | // State pruning. |
| 1647 | //===----------------------------------------------------------------------===// |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1648 | |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1649 | void RegionStoreManager::RemoveDeadBindings(GRState &state, Stmt* Loc, |
Ted Kremenek | 2f26bc3 | 2009-08-02 04:45:08 +0000 | [diff] [blame] | 1650 | SymbolReaper& SymReaper, |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1651 | llvm::SmallVectorImpl<const MemRegion*>& RegionRoots) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1652 | { |
Ted Kremenek | 781115c | 2009-10-17 17:45:11 +0000 | [diff] [blame] | 1653 | typedef std::pair<const GRState*, const MemRegion *> RBDNode; |
| 1654 | |
Ted Kremenek | 2f26bc3 | 2009-08-02 04:45:08 +0000 | [diff] [blame] | 1655 | Store store = state.getStore(); |
Ted Kremenek | 451ac09 | 2009-08-06 04:50:20 +0000 | [diff] [blame] | 1656 | RegionBindings B = GetRegionBindings(store); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1657 | |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1658 | // The backmap from regions to subregions. |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1659 | llvm::OwningPtr<RegionStoreSubRegionMap> |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1660 | SubRegions(getRegionStoreSubRegionMap(store)); |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1661 | |
Ted Kremenek | a6d73af | 2009-11-26 02:35:42 +0000 | [diff] [blame] | 1662 | // Do a pass over the regions in the store. For VarRegions we check if |
| 1663 | // the variable is still live and if so add it to the list of live roots. |
| 1664 | // For other regions we populate our region backmap. |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1665 | llvm::SmallVector<const MemRegion*, 10> IntermediateRoots; |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1666 | |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1667 | // Scan the direct bindings for "intermediate" roots. |
Ted Kremenek | 451ac09 | 2009-08-06 04:50:20 +0000 | [diff] [blame] | 1668 | for (RegionBindings::iterator I = B.begin(), E = B.end(); I != E; ++I) { |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1669 | const MemRegion *R = I.getKey(); |
| 1670 | IntermediateRoots.push_back(R); |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1671 | } |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1672 | |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1673 | // Process the "intermediate" roots to find if they are referenced by |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1674 | // real roots. |
Zhongxing Xu | f77869f | 2009-10-17 08:39:24 +0000 | [diff] [blame] | 1675 | llvm::SmallVector<RBDNode, 10> WorkList; |
Ted Kremenek | 0175619 | 2009-10-29 05:14:17 +0000 | [diff] [blame] | 1676 | llvm::SmallVector<RBDNode, 10> Postponed; |
| 1677 | |
Zhongxing Xu | 6800b33 | 2009-10-18 04:15:47 +0000 | [diff] [blame] | 1678 | llvm::DenseSet<const MemRegion*> IntermediateVisited; |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1679 | |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1680 | while (!IntermediateRoots.empty()) { |
| 1681 | const MemRegion* R = IntermediateRoots.back(); |
| 1682 | IntermediateRoots.pop_back(); |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1683 | |
Zhongxing Xu | f77869f | 2009-10-17 08:39:24 +0000 | [diff] [blame] | 1684 | if (IntermediateVisited.count(R)) |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1685 | continue; |
Zhongxing Xu | f77869f | 2009-10-17 08:39:24 +0000 | [diff] [blame] | 1686 | IntermediateVisited.insert(R); |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1687 | |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1688 | if (const VarRegion* VR = dyn_cast<VarRegion>(R)) { |
Ted Kremenek | edeb5b6 | 2009-12-04 20:32:20 +0000 | [diff] [blame] | 1689 | if (SymReaper.isLive(Loc, VR)) |
Zhongxing Xu | f77869f | 2009-10-17 08:39:24 +0000 | [diff] [blame] | 1690 | WorkList.push_back(std::make_pair(&state, VR)); |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1691 | continue; |
| 1692 | } |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1693 | |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1694 | if (const SymbolicRegion* SR = dyn_cast<SymbolicRegion>(R)) { |
Ted Kremenek | 0175619 | 2009-10-29 05:14:17 +0000 | [diff] [blame] | 1695 | llvm::SmallVectorImpl<RBDNode> &Q = |
| 1696 | SymReaper.isLive(SR->getSymbol()) ? WorkList : Postponed; |
| 1697 | |
| 1698 | Q.push_back(std::make_pair(&state, SR)); |
| 1699 | |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1700 | continue; |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1701 | } |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1702 | |
| 1703 | // 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] | 1704 | if (const SubRegion* superR = |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1705 | dyn_cast<SubRegion>(cast<SubRegion>(R)->getSuperRegion())) |
Ted Kremenek | 19e1f0b | 2009-08-01 06:17:29 +0000 | [diff] [blame] | 1706 | IntermediateRoots.push_back(superR); |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1707 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1708 | |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1709 | // Enqueue the RegionRoots onto WorkList. |
| 1710 | for (llvm::SmallVectorImpl<const MemRegion*>::iterator I=RegionRoots.begin(), |
| 1711 | E=RegionRoots.end(); I!=E; ++I) { |
Zhongxing Xu | f77869f | 2009-10-17 08:39:24 +0000 | [diff] [blame] | 1712 | WorkList.push_back(std::make_pair(&state, *I)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1713 | } |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1714 | RegionRoots.clear(); |
| 1715 | |
Zhongxing Xu | 6800b33 | 2009-10-18 04:15:47 +0000 | [diff] [blame] | 1716 | llvm::DenseSet<RBDNode> Visited; |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1717 | |
Ted Kremenek | 0175619 | 2009-10-29 05:14:17 +0000 | [diff] [blame] | 1718 | tryAgain: |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1719 | while (!WorkList.empty()) { |
Zhongxing Xu | f77869f | 2009-10-17 08:39:24 +0000 | [diff] [blame] | 1720 | RBDNode N = WorkList.back(); |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1721 | WorkList.pop_back(); |
| 1722 | |
| 1723 | // Have we visited this node before? |
Zhongxing Xu | f77869f | 2009-10-17 08:39:24 +0000 | [diff] [blame] | 1724 | if (Visited.count(N)) |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1725 | continue; |
Zhongxing Xu | f77869f | 2009-10-17 08:39:24 +0000 | [diff] [blame] | 1726 | Visited.insert(N); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1727 | |
Zhongxing Xu | f77869f | 2009-10-17 08:39:24 +0000 | [diff] [blame] | 1728 | const MemRegion *R = N.second; |
| 1729 | const GRState *state_N = N.first; |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1730 | |
Zhongxing Xu | f77869f | 2009-10-17 08:39:24 +0000 | [diff] [blame] | 1731 | // Enqueue subregions. |
| 1732 | RegionStoreSubRegionMap *M; |
| 1733 | |
| 1734 | if (&state == state_N) |
| 1735 | M = SubRegions.get(); |
| 1736 | else { |
| 1737 | RegionStoreSubRegionMap *& SM = SC[state_N]; |
| 1738 | if (!SM) |
| 1739 | SM = getRegionStoreSubRegionMap(state_N->getStore()); |
| 1740 | M = SM; |
| 1741 | } |
| 1742 | |
| 1743 | RegionStoreSubRegionMap::iterator I, E; |
| 1744 | for (llvm::tie(I, E) = M->begin_end(R); I != E; ++I) |
| 1745 | WorkList.push_back(std::make_pair(state_N, *I)); |
| 1746 | |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1747 | // Enqueue the super region. |
| 1748 | if (const SubRegion *SR = dyn_cast<SubRegion>(R)) { |
| 1749 | const MemRegion *superR = SR->getSuperRegion(); |
| 1750 | if (!isa<MemSpaceRegion>(superR)) { |
| 1751 | // If 'R' is a field or an element, we want to keep the bindings |
| 1752 | // for the other fields and elements around. The reason is that |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1753 | // pointer arithmetic can get us to the other fields or elements. |
Zhongxing Xu | 8801beb | 2009-10-17 07:32:08 +0000 | [diff] [blame] | 1754 | assert(isa<FieldRegion>(R) || isa<ElementRegion>(R) |
| 1755 | || isa<ObjCIvarRegion>(R)); |
Zhongxing Xu | f77869f | 2009-10-17 08:39:24 +0000 | [diff] [blame] | 1756 | WorkList.push_back(std::make_pair(state_N, superR)); |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1757 | } |
| 1758 | } |
| 1759 | |
| 1760 | // Mark the symbol for any live SymbolicRegion as "live". This means we |
| 1761 | // should continue to track that symbol. |
Ted Kremenek | a6d73af | 2009-11-26 02:35:42 +0000 | [diff] [blame] | 1762 | if (const SymbolicRegion *SymR = dyn_cast<SymbolicRegion>(R)) |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1763 | SymReaper.markLive(SymR->getSymbol()); |
Ted Kremenek | a6d73af | 2009-11-26 02:35:42 +0000 | [diff] [blame] | 1764 | |
Ted Kremenek | a7a8dfd | 2009-12-03 17:48:05 +0000 | [diff] [blame] | 1765 | // For BlockDataRegions, enqueue the VarRegions for variables marked |
| 1766 | // with __block (passed-by-reference). |
Ted Kremenek | a6d73af | 2009-11-26 02:35:42 +0000 | [diff] [blame] | 1767 | // via BlockDeclRefExprs. |
| 1768 | if (const BlockDataRegion *BD = dyn_cast<BlockDataRegion>(R)) { |
| 1769 | for (BlockDataRegion::referenced_vars_iterator |
| 1770 | RI = BD->referenced_vars_begin(), RE = BD->referenced_vars_end(); |
Ted Kremenek | a7a8dfd | 2009-12-03 17:48:05 +0000 | [diff] [blame] | 1771 | RI != RE; ++RI) { |
| 1772 | if ((*RI)->getDecl()->getAttr<BlocksAttr>()) |
| 1773 | WorkList.push_back(std::make_pair(state_N, *RI)); |
| 1774 | } |
Ted Kremenek | a6d73af | 2009-11-26 02:35:42 +0000 | [diff] [blame] | 1775 | // No possible data bindings on a BlockDataRegion. Continue to the |
| 1776 | // next region in the worklist. |
| 1777 | continue; |
| 1778 | } |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1779 | |
| 1780 | Store store_N = state_N->getStore(); |
| 1781 | RegionBindings B_N = GetRegionBindings(store_N); |
| 1782 | |
| 1783 | // Get the data binding for R (if any). |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1784 | Optional<SVal> V = getBinding(B_N, R); |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1785 | |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1786 | if (V) { |
| 1787 | // Check for lazy bindings. |
| 1788 | if (const nonloc::LazyCompoundVal *LCV = |
| 1789 | dyn_cast<nonloc::LazyCompoundVal>(V.getPointer())) { |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1790 | |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1791 | const LazyCompoundValData *D = LCV->getCVData(); |
Zhongxing Xu | f77869f | 2009-10-17 08:39:24 +0000 | [diff] [blame] | 1792 | WorkList.push_back(std::make_pair(D->getState(), D->getRegion())); |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1793 | } |
| 1794 | else { |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1795 | // Update the set of live symbols. |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1796 | for (SVal::symbol_iterator SI=V->symbol_begin(), SE=V->symbol_end(); |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1797 | SI!=SE;++SI) |
| 1798 | SymReaper.markLive(*SI); |
| 1799 | |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1800 | // If V is a region, then add it to the worklist. |
| 1801 | if (const MemRegion *RX = V->getAsRegion()) |
Zhongxing Xu | f77869f | 2009-10-17 08:39:24 +0000 | [diff] [blame] | 1802 | WorkList.push_back(std::make_pair(state_N, RX)); |
Ted Kremenek | 9e17cc6 | 2009-09-29 06:35:00 +0000 | [diff] [blame] | 1803 | } |
| 1804 | } |
| 1805 | } |
| 1806 | |
Ted Kremenek | 0175619 | 2009-10-29 05:14:17 +0000 | [diff] [blame] | 1807 | // See if any postponed SymbolicRegions are actually live now, after |
| 1808 | // having done a scan. |
| 1809 | for (llvm::SmallVectorImpl<RBDNode>::iterator I = Postponed.begin(), |
| 1810 | E = Postponed.end() ; I != E ; ++I) { |
| 1811 | if (const SymbolicRegion *SR = cast_or_null<SymbolicRegion>(I->second)) { |
| 1812 | if (SymReaper.isLive(SR->getSymbol())) { |
| 1813 | WorkList.push_back(*I); |
| 1814 | I->second = NULL; |
| 1815 | } |
| 1816 | } |
| 1817 | } |
| 1818 | |
| 1819 | if (!WorkList.empty()) |
| 1820 | goto tryAgain; |
| 1821 | |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1822 | // We have now scanned the store, marking reachable regions and symbols |
| 1823 | // 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] | 1824 | // 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] | 1825 | for (RegionBindings::iterator I = B.begin(), E = B.end(); I != E; ++I) { |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1826 | const MemRegion* R = I.getKey(); |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1827 | // If this region live? Is so, none of its symbols are dead. |
Zhongxing Xu | f77869f | 2009-10-17 08:39:24 +0000 | [diff] [blame] | 1828 | if (Visited.count(std::make_pair(&state, R))) |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1829 | continue; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1830 | |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1831 | // Remove this dead region from the store. |
Zhongxing Xu | d91ee27 | 2009-06-23 09:02:15 +0000 | [diff] [blame] | 1832 | store = Remove(store, ValMgr.makeLoc(R)); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1833 | |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1834 | // Mark all non-live symbols that this region references as dead. |
| 1835 | if (const SymbolicRegion* SymR = dyn_cast<SymbolicRegion>(R)) |
| 1836 | SymReaper.maybeDead(SymR->getSymbol()); |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1837 | |
Zhongxing Xu | 13d5017 | 2009-10-11 08:08:02 +0000 | [diff] [blame] | 1838 | SVal X = *I.getData().getValue(); |
Ted Kremenek | 093569c | 2009-08-02 05:00:15 +0000 | [diff] [blame] | 1839 | SVal::symbol_iterator SI = X.symbol_begin(), SE = X.symbol_end(); |
| 1840 | for (; SI != SE; ++SI) |
| 1841 | SymReaper.maybeDead(*SI); |
| 1842 | } |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1843 | |
Ted Kremenek | 2f26bc3 | 2009-08-02 04:45:08 +0000 | [diff] [blame] | 1844 | // Write the store back. |
| 1845 | state.setStore(store); |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1846 | } |
| 1847 | |
Zhongxing Xu | 4e3c1f7 | 2009-10-13 02:24:55 +0000 | [diff] [blame] | 1848 | GRState const *RegionStoreManager::EnterStackFrame(GRState const *state, |
| 1849 | StackFrameContext const *frame) { |
| 1850 | FunctionDecl const *FD = cast<FunctionDecl>(frame->getDecl()); |
| 1851 | CallExpr const *CE = cast<CallExpr>(frame->getCallSite()); |
| 1852 | |
| 1853 | FunctionDecl::param_const_iterator PI = FD->param_begin(); |
| 1854 | |
| 1855 | CallExpr::const_arg_iterator AI = CE->arg_begin(), AE = CE->arg_end(); |
| 1856 | |
| 1857 | // Copy the arg expression value to the arg variables. |
| 1858 | for (; AI != AE; ++AI, ++PI) { |
| 1859 | SVal ArgVal = state->getSVal(*AI); |
Ted Kremenek | b48ad64 | 2009-12-04 00:26:31 +0000 | [diff] [blame] | 1860 | state = Bind(state, ValMgr.makeLoc(MRMgr.getVarRegion(*PI, frame)), ArgVal); |
Zhongxing Xu | 4e3c1f7 | 2009-10-13 02:24:55 +0000 | [diff] [blame] | 1861 | } |
| 1862 | |
| 1863 | return state; |
| 1864 | } |
| 1865 | |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1866 | //===----------------------------------------------------------------------===// |
| 1867 | // Utility methods. |
| 1868 | //===----------------------------------------------------------------------===// |
| 1869 | |
Ted Kremenek | 53ba0b6 | 2009-06-24 23:06:47 +0000 | [diff] [blame] | 1870 | void RegionStoreManager::print(Store store, llvm::raw_ostream& OS, |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1871 | const char* nl, const char *sep) { |
Ted Kremenek | 451ac09 | 2009-08-06 04:50:20 +0000 | [diff] [blame] | 1872 | RegionBindings B = GetRegionBindings(store); |
Ted Kremenek | ab22ee9 | 2009-10-20 01:20:57 +0000 | [diff] [blame] | 1873 | OS << "Store (direct and default bindings):" << nl; |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1874 | |
Ted Kremenek | 451ac09 | 2009-08-06 04:50:20 +0000 | [diff] [blame] | 1875 | for (RegionBindings::iterator I = B.begin(), E = B.end(); I != E; ++I) |
Mike Stump | 1eb4433 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 1876 | OS << ' ' << I.getKey() << " : " << I.getData() << nl; |
Ted Kremenek | 9af46f5 | 2009-06-16 22:36:44 +0000 | [diff] [blame] | 1877 | } |