1919#include " clang/ASTMatchers/ASTMatchFinder.h"
2020#include " clang/Analysis/Analyses/LiveVariables.h"
2121#include " clang/Analysis/AnalysisDeclContext.h"
22+ #include " clang/Analysis/CFG.h"
2223#include " clang/Basic/JsonSupport.h"
2324#include " clang/Basic/TargetInfo.h"
2425#include " clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
@@ -473,11 +474,11 @@ class RegionStoreManager : public StoreManager {
473474 // ===-------------------------------------------------------------------===//
474475 // Binding values to regions.
475476 // ===-------------------------------------------------------------------===//
476- RegionBindingsRef invalidateGlobalRegion (MemRegion::Kind K, const Stmt *S,
477- unsigned Count ,
478- const LocationContext *LCtx ,
479- RegionBindingsRef B ,
480- InvalidatedRegions *Invalidated);
477+ RegionBindingsRef
478+ invalidateGlobalRegion (MemRegion::Kind K ,
479+ const CFGBlock::ConstCFGElementRef elemRef ,
480+ unsigned Count, const LocationContext *LCtx ,
481+ RegionBindingsRef B, InvalidatedRegions *Invalidated);
481482
482483 StoreRef invalidateRegions (Store store, ArrayRef<SVal> Values, const Stmt *S,
483484 unsigned Count, const LocationContext *LCtx,
@@ -1044,7 +1045,7 @@ RegionStoreManager::removeSubRegionBindings(RegionBindingsConstRef B,
10441045namespace {
10451046class InvalidateRegionsWorker : public ClusterAnalysis <InvalidateRegionsWorker>
10461047{
1047- const Stmt *S ;
1048+ const CFGBlock::ConstCFGElementRef ElemRef ;
10481049 unsigned Count;
10491050 const LocationContext *LCtx;
10501051 InvalidatedSymbols &IS;
@@ -1053,14 +1054,16 @@ class InvalidateRegionsWorker : public ClusterAnalysis<InvalidateRegionsWorker>
10531054 GlobalsFilterKind GlobalsFilter;
10541055public:
10551056 InvalidateRegionsWorker (RegionStoreManager &rm, ProgramStateManager &stateMgr,
1056- RegionBindingsRef b, const Stmt *S, unsigned count,
1057- const LocationContext *lctx, InvalidatedSymbols &is,
1057+ RegionBindingsRef b,
1058+ const CFGBlock::ConstCFGElementRef elemRef,
1059+ unsigned count, const LocationContext *lctx,
1060+ InvalidatedSymbols &is,
10581061 RegionAndSymbolInvalidationTraits &ITraitsIn,
10591062 StoreManager::InvalidatedRegions *r,
10601063 GlobalsFilterKind GFK)
1061- : ClusterAnalysis<InvalidateRegionsWorker>(rm, stateMgr, b), S(S),
1062- Count (count), LCtx(lctx), IS(is), ITraits(ITraitsIn), Regions(r ),
1063- GlobalsFilter (GFK) {}
1064+ : ClusterAnalysis<InvalidateRegionsWorker>(rm, stateMgr, b),
1065+ ElemRef (elemRef), Count(count), LCtx(lctx), IS(is), ITraits(ITraitsIn),
1066+ Regions (r), GlobalsFilter(GFK) {}
10641067
10651068 void VisitCluster (const MemRegion *baseR, const ClusterBindings *C);
10661069 void VisitBinding (SVal V);
@@ -1193,7 +1196,7 @@ void InvalidateRegionsWorker::VisitCluster(const MemRegion *baseR,
11931196 // Invalidate the region by setting its default value to
11941197 // conjured symbol. The type of the symbol is irrelevant.
11951198 DefinedOrUnknownSVal V =
1196- svalBuilder.conjureSymbolVal (baseR, S , LCtx, Ctx.IntTy , Count);
1199+ svalBuilder.conjureSymbolVal (baseR, ElemRef , LCtx, Ctx.IntTy , Count);
11971200 B = B.addBinding (baseR, BindingKey::Default, V);
11981201 return ;
11991202 }
@@ -1215,7 +1218,7 @@ void InvalidateRegionsWorker::VisitCluster(const MemRegion *baseR,
12151218 // Invalidate the region by setting its default value to
12161219 // conjured symbol. The type of the symbol is irrelevant.
12171220 DefinedOrUnknownSVal V =
1218- svalBuilder.conjureSymbolVal (baseR, S , LCtx, Ctx.IntTy , Count);
1221+ svalBuilder.conjureSymbolVal (baseR, ElemRef , LCtx, Ctx.IntTy , Count);
12191222 B = B.addBinding (baseR, BindingKey::Default, V);
12201223 return ;
12211224 }
@@ -1283,13 +1286,13 @@ void InvalidateRegionsWorker::VisitCluster(const MemRegion *baseR,
12831286 conjure_default:
12841287 // Set the default value of the array to conjured symbol.
12851288 DefinedOrUnknownSVal V = svalBuilder.conjureSymbolVal (
1286- baseR, S , LCtx, AT->getElementType (), Count);
1289+ baseR, ElemRef , LCtx, AT->getElementType (), Count);
12871290 B = B.addBinding (baseR, BindingKey::Default, V);
12881291 return ;
12891292 }
12901293
12911294 DefinedOrUnknownSVal V =
1292- svalBuilder.conjureSymbolVal (baseR, S , LCtx, T, Count);
1295+ svalBuilder.conjureSymbolVal (baseR, ElemRef , LCtx, T, Count);
12931296 assert (SymbolManager::canSymbolicate (T) || V.isUnknown ());
12941297 B = B.addBinding (baseR, BindingKey::Direct, V);
12951298}
@@ -1318,15 +1321,15 @@ bool InvalidateRegionsWorker::includeEntireMemorySpace(const MemRegion *Base) {
13181321}
13191322
13201323RegionBindingsRef RegionStoreManager::invalidateGlobalRegion (
1321- MemRegion::Kind K, const Stmt *S, unsigned Count ,
1322- const LocationContext *LCtx, RegionBindingsRef B,
1324+ MemRegion::Kind K, const CFGBlock::ConstCFGElementRef elemRef ,
1325+ unsigned Count, const LocationContext *LCtx, RegionBindingsRef B,
13231326 InvalidatedRegions *Invalidated) {
13241327 // Bind the globals memory space to a new symbol that we will use to derive
13251328 // the bindings for all globals.
13261329 const GlobalsSpaceRegion *GS = MRMgr.getGlobalsRegion (K);
1327- SVal V =
1328- svalBuilder. conjureSymbolVal ( /* symbolTag = */ (const void *)GS, S , LCtx,
1329- /* type does not matter */ Ctx.IntTy , Count);
1330+ SVal V = svalBuilder. conjureSymbolVal (
1331+ /* symbolTag = */ (const void *)GS, elemRef , LCtx,
1332+ /* type does not matter */ Ctx.IntTy , Count);
13301333
13311334 B = B.removeBinding (GS)
13321335 .addBinding (BindingKey::Make (GS, BindingKey::Default), V);
@@ -1376,8 +1379,8 @@ StoreRef RegionStoreManager::invalidateRegions(
13761379 }
13771380
13781381 RegionBindingsRef B = getRegionBindings (store);
1379- InvalidateRegionsWorker W (*this , StateMgr, B, S , Count, LCtx, IS, ITraits ,
1380- Invalidated, GlobalsFilter);
1382+ InvalidateRegionsWorker W (*this , StateMgr, B, Call-> getCFGElementRef () , Count,
1383+ LCtx, IS, ITraits, Invalidated, GlobalsFilter);
13811384
13821385 // Scan the bindings and generate the clusters.
13831386 W.GenerateClusters ();
@@ -1396,12 +1399,14 @@ StoreRef RegionStoreManager::invalidateRegions(
13961399 // TODO: This could possibly be more precise with modules.
13971400 switch (GlobalsFilter) {
13981401 case GFK_All:
1399- B = invalidateGlobalRegion (MemRegion::GlobalInternalSpaceRegionKind, S,
1400- Count, LCtx, B, Invalidated);
1402+ B = invalidateGlobalRegion (MemRegion::GlobalInternalSpaceRegionKind,
1403+ Call->getCFGElementRef (), Count, LCtx, B,
1404+ Invalidated);
14011405 [[fallthrough]];
14021406 case GFK_SystemOnly:
1403- B = invalidateGlobalRegion (MemRegion::GlobalSystemSpaceRegionKind, S, Count,
1404- LCtx, B, Invalidated);
1407+ B = invalidateGlobalRegion (MemRegion::GlobalSystemSpaceRegionKind,
1408+ Call->getCFGElementRef (), Count, LCtx, B,
1409+ Invalidated);
14051410 [[fallthrough]];
14061411 case GFK_None:
14071412 break ;
0 commit comments