Index: lib/StaticAnalyzer/Core/CallEvent.cpp =================================================================== --- lib/StaticAnalyzer/Core/CallEvent.cpp +++ lib/StaticAnalyzer/Core/CallEvent.cpp @@ -314,7 +314,7 @@ } } } - // todo: factor this out + handle the lower level const pointers. + // TODO: factor this out + handle the lower level const pointers. if (PreserveArgs.count(Idx)) ETraits.setTrait( UseBaseRegion ? MR->getBaseRegion() : MR, Index: lib/StaticAnalyzer/Core/RegionStore.cpp =================================================================== --- lib/StaticAnalyzer/Core/RegionStore.cpp +++ lib/StaticAnalyzer/Core/RegionStore.cpp @@ -654,7 +654,6 @@ template class ClusterAnalysis { protected: - typedef llvm::DenseMap ClusterMap; typedef const MemRegion * WorkListElement; typedef SmallVector WorkList; @@ -726,7 +725,8 @@ WorkListElement E = WL.pop_back_val(); const MemRegion *BaseR = E; - static_cast(this)->VisitCluster(BaseR, getCluster(BaseR)); + static_cast(this)->VisitCluster( + BaseR, getCluster(BaseR->getBaseRegion())); } } @@ -984,7 +984,7 @@ bool doNotInvalidateSuperRegion = ITraits.hasTrait( R, RegionAndSymbolInvalidationTraits::TK_DoNotInvalidateSuperRegion); const MemRegion *BaseR = doNotInvalidateSuperRegion ? R : R->getBaseRegion(); - return AddToWorkList(WorkListElement(BaseR), getCluster(BaseR)); + return AddToWorkList(WorkListElement(BaseR), getCluster(R)); } void InvalidateRegionsWorker::VisitBinding(SVal V) { @@ -1020,13 +1020,23 @@ RegionAndSymbolInvalidationTraits::TK_PreserveContents); if (C) { - for (ClusterBindings::iterator I = C->begin(), E = C->end(); I != E; ++I) - VisitBinding(I.getData()); + const MemRegion *realBase = baseR->getBaseRegion(); + if (realBase == baseR) { + for (ClusterBindings::iterator I = C->begin(), E = C->end(); I != E; ++I) + VisitBinding(I.getData()); + } else { + if (const SVal *Direct = + C->lookup(BindingKey::Make(baseR, BindingKey::Direct))) + VisitBinding(*Direct); + else if (const SVal *Default = + C->lookup(BindingKey::Make(baseR, BindingKey::Default))) + VisitBinding(*Default); + } // Invalidate regions contents. if (!PreserveRegionsContents) B = B.remove(baseR); - } + } if (const auto *TO = dyn_cast(baseR)) { if (const auto *RD = TO->getValueType()->getAsCXXRecordDecl()) {