Index: clang/lib/StaticAnalyzer/Core/RegionStore.cpp =================================================================== --- clang/lib/StaticAnalyzer/Core/RegionStore.cpp +++ clang/lib/StaticAnalyzer/Core/RegionStore.cpp @@ -36,6 +36,8 @@ using namespace clang; using namespace ento; +#define DEBUG_TYPE "RegionStore" + //===----------------------------------------------------------------------===// // Representation of binding keys. //===----------------------------------------------------------------------===// @@ -273,6 +275,8 @@ RegionBindingsRef RegionBindingsRef::addBinding(BindingKey K, SVal V) const { const MemRegion *Base = K.getBaseRegion(); + LLVM_DEBUG(llvm::dbgs() << "addBinding: MR: '" << Base << "', V: '" << V + << "'\n"); const ClusterBindings *ExistingCluster = lookup(Base); ClusterBindings Cluster = @@ -307,6 +311,8 @@ if (!Cluster) return *this; + LLVM_DEBUG(llvm::dbgs() << "removeBinding: MR: '" << Base << "'\n"); + ClusterBindings NewCluster = CBFactory->remove(*Cluster, K); if (NewCluster.isEmpty()) return remove(Base); @@ -451,6 +457,9 @@ // a default value. StoreRef BindDefaultInitial(Store store, const MemRegion *R, SVal V) override { + LLVM_DEBUG(llvm::dbgs() + << "BindDefaultInitial: MR: '" << R << "', V: '" << V << "'\n"); + RegionBindingsRef B = getRegionBindings(store); // Use other APIs when you have to wipe the region that was initialized // earlier. @@ -463,6 +472,8 @@ // BindDefaultZero is used for zeroing constructors that may accidentally // overwrite existing bindings. StoreRef BindDefaultZero(Store store, const MemRegion *R) override { + LLVM_DEBUG(llvm::dbgs() << "BindDefaultZero: MR: '" << R << "'\n"); + // FIXME: The offsets of empty bases can be tricky because of // of the so called "empty base class optimization". // If a base class has been optimized out @@ -1389,6 +1400,8 @@ /// the array). This is called by ExprEngine when evaluating casts /// from arrays to pointers. SVal RegionStoreManager::ArrayToPointer(Loc Array, QualType T) { + LLVM_DEBUG(llvm::dbgs() << "ArrayToPointer: '" << Array << "'\n"); + if (Array.getAs()) return Array; @@ -1406,6 +1419,8 @@ //===----------------------------------------------------------------------===// SVal RegionStoreManager::getBinding(RegionBindingsConstRef B, Loc L, QualType T) { + LLVM_DEBUG(llvm::dbgs() << "getBinding: '" << L << "'\n"); + assert(!L.getAs() && "location unknown"); assert(!L.getAs() && "location undefined"); @@ -1513,8 +1528,10 @@ const SVal *V = B.lookup(R, BindingKey::Direct); // Check if the region has a binding. - if (V) + if (V) { + LLVM_DEBUG(llvm::dbgs() << "getBinding for raw lookup: '" << R << "'\n"); return *V; + } // The location does not have a bound value. This means that it has // the value it had upon its creation and/or entry to the analyzed @@ -1552,6 +1569,8 @@ static Optional getExistingLazyBinding(SValBuilder &SVB, RegionBindingsConstRef B, const SubRegion *R, bool AllowSubregionBindings) { + LLVM_DEBUG(llvm::dbgs() << "getExistingLazyBinding: '" << R << "'\n"); + Optional V = B.getDefaultBinding(R); if (!V) return None; @@ -1588,6 +1607,8 @@ RegionStoreManager::findLazyBinding(RegionBindingsConstRef B, const SubRegion *R, const SubRegion *originalRegion) { + LLVM_DEBUG(llvm::dbgs() << "findLazyBinding: '" << R << "'\n"); + if (originalRegion != R) { if (Optional V = getExistingLazyBinding(svalBuilder, B, R, true)) @@ -1628,6 +1649,8 @@ SVal RegionStoreManager::getBindingForElement(RegionBindingsConstRef B, const ElementRegion* R) { + LLVM_DEBUG(llvm::dbgs() << "getBindingForElement: '" << R << "'\n"); + // We do not currently model bindings of the CompoundLiteralregion. if (isa(R->getBaseRegion())) return UnknownVal(); @@ -1738,6 +1761,7 @@ SVal RegionStoreManager::getBindingForField(RegionBindingsConstRef B, const FieldRegion* R) { + LLVM_DEBUG(llvm::dbgs() << "getBindingForField: '" << R << "'\n"); // Check if the region has a binding. if (const Optional &V = B.getDirectBinding(R)) @@ -1782,6 +1806,8 @@ const MemRegion *superR, const TypedValueRegion *R, QualType Ty) { + LLVM_DEBUG(llvm::dbgs() << "getBindingForDerivedDefaultValue: '" << R + << "'\n"); if (const Optional &D = B.getDefaultBinding(superR)) { const SVal &val = D.getValue(); @@ -1808,6 +1834,8 @@ SVal RegionStoreManager::getLazyBinding(const SubRegion *LazyBindingRegion, RegionBindingsRef LazyBinding) { + LLVM_DEBUG(llvm::dbgs() << "getLazyBinding: '" << LazyBindingRegion << "'\n"); + SVal Result; if (const ElementRegion *ER = dyn_cast(LazyBindingRegion)) Result = getBindingForElement(LazyBinding, ER); @@ -1839,6 +1867,8 @@ RegionStoreManager::getBindingForFieldOrElementCommon(RegionBindingsConstRef B, const TypedValueRegion *R, QualType Ty) { + LLVM_DEBUG(llvm::dbgs() << "getBindingForFieldOrElementCommon: '" << R + << "'\n"); // At this point we have already checked in either getBindingForElement or // getBindingForField if 'R' has a direct binding. @@ -1923,6 +1953,8 @@ SVal RegionStoreManager::getBindingForObjCIvar(RegionBindingsConstRef B, const ObjCIvarRegion* R) { + LLVM_DEBUG(llvm::dbgs() << "getBindingForObjCIvar: '" << R << "'\n"); + // Check if the region has a binding. if (const Optional &V = B.getDirectBinding(R)) return *V; @@ -1943,6 +1975,7 @@ SVal RegionStoreManager::getBindingForVar(RegionBindingsConstRef B, const VarRegion *R) { + LLVM_DEBUG(llvm::dbgs() << "getBindingForVar: '" << R << "'\n"); // Check if the region has a binding. if (Optional V = B.getDirectBinding(R)) @@ -2005,12 +2038,16 @@ } SVal RegionStoreManager::getBindingForLazySymbol(const TypedValueRegion *R) { + LLVM_DEBUG(llvm::dbgs() << "getBindingForLazySymbol: '" << R << "'\n"); + // All other values are symbolic. return svalBuilder.getRegionValueSymbolVal(R); } const RegionStoreManager::SValListTy & RegionStoreManager::getInterestingValues(nonloc::LazyCompoundVal LCV) { + LLVM_DEBUG(llvm::dbgs() << "getInterestingValues: '" << LCV << "'\n"); + // First, check the cache. LazyBindingsMapTy::iterator I = LazyBindingsMap.find(LCV.getCVData()); if (I != LazyBindingsMap.end()) @@ -2053,6 +2090,8 @@ NonLoc RegionStoreManager::createLazyBinding(RegionBindingsConstRef B, const TypedValueRegion *R) { + LLVM_DEBUG(llvm::dbgs() << "createLazyBinding: '" << R << "'\n"); + if (Optional V = getExistingLazyBinding(svalBuilder, B, R, false)) return *V; @@ -2070,6 +2109,8 @@ SVal RegionStoreManager::getBindingForStruct(RegionBindingsConstRef B, const TypedValueRegion *R) { + LLVM_DEBUG(llvm::dbgs() << "getBindingForStruct: '" << R << "'\n"); + const RecordDecl *RD = R->getValueType()->castAs()->getDecl(); if (!RD->getDefinition() || isRecordEmpty(RD)) return UnknownVal(); @@ -2114,6 +2155,8 @@ //===----------------------------------------------------------------------===// StoreRef RegionStoreManager::killBinding(Store ST, Loc L) { + LLVM_DEBUG(llvm::dbgs() << "killBinding: L: '" << L << "'\n"); + if (Optional LV = L.getAs()) if (const MemRegion* R = LV->getRegion()) return StoreRef(getRegionBindings(ST).removeBinding(R) @@ -2126,6 +2169,8 @@ RegionBindingsRef RegionStoreManager::bind(RegionBindingsConstRef B, Loc L, SVal V) { + LLVM_DEBUG(llvm::dbgs() << "bind: L: '" << L << "', V: '" << V << "'\n"); + if (L.getAs()) return B; @@ -2160,6 +2205,8 @@ // Clear out bindings that may overlap with this binding. RegionBindingsRef NewB = removeSubRegionBindings(B, cast(R)); + + LLVM_DEBUG(llvm::dbgs() << "bind raw V: '" << V << "'\n"); return NewB.addBinding(BindingKey::Make(R, BindingKey::Direct), V); } @@ -2167,6 +2214,8 @@ RegionStoreManager::setImplicitDefaultValue(RegionBindingsConstRef B, const MemRegion *R, QualType T) { + LLVM_DEBUG(llvm::dbgs() << "setImplicitDefaultValue: '" << R << "'\n"); + SVal V; if (Loc::isLocType(T)) @@ -2194,6 +2243,8 @@ RegionStoreManager::bindArray(RegionBindingsConstRef B, const TypedValueRegion* R, SVal Init) { + LLVM_DEBUG(llvm::dbgs() << "bindArray: MR: '" << R << "', V: '" << Init + << "'\n"); const ArrayType *AT =cast(Ctx.getCanonicalType(R->getValueType())); QualType ElementTy = AT->getElementType(); @@ -2252,6 +2303,9 @@ RegionBindingsRef RegionStoreManager::bindVector(RegionBindingsConstRef B, const TypedValueRegion* R, SVal V) { + LLVM_DEBUG(llvm::dbgs() << "bindVector: MR: '" << R << "', V: '" << V + << "'\n"); + QualType T = R->getValueType(); const VectorType *VT = T->castAs(); // Use castAs for typedefs. @@ -2294,6 +2348,9 @@ const TypedValueRegion *R, const RecordDecl *RD, nonloc::LazyCompoundVal LCV) { + LLVM_DEBUG(llvm::dbgs() << "tryBindSmallStruct: MR: '" << R << "', V: '" + << LCV << "'\n"); + FieldVector Fields; if (const CXXRecordDecl *Class = dyn_cast(RD)) @@ -2332,6 +2389,9 @@ RegionBindingsRef RegionStoreManager::bindStruct(RegionBindingsConstRef B, const TypedValueRegion* R, SVal V) { + LLVM_DEBUG(llvm::dbgs() << "bindStruct: MR: '" << R << "', V: '" << V + << "'\n"); + if (!Features.supportsFields()) return B; @@ -2452,6 +2512,9 @@ RegionStoreManager::bindAggregate(RegionBindingsConstRef B, const TypedRegion *R, SVal Val) { + LLVM_DEBUG(llvm::dbgs() << "bindAggregate: MR: '" << R << "', V: '" << Val + << "'\n"); + // Remove the old bindings, using 'R' as the root of all regions // we will invalidate. Then add the new binding. return removeSubRegionBindings(B, R).addBinding(R, BindingKey::Default, Val);