https://github.com/pskrgag updated https://github.com/llvm/llvm-project/pull/109792
>From 16034884baf76bf60394423884e6c6b6cb6ae3f1 Mon Sep 17 00:00:00 2001 From: Pavel Skripkin <paskrip...@gmail.com> Date: Tue, 24 Sep 2024 15:31:11 +0300 Subject: [PATCH 1/3] clang/csa: change Expr to Stmt in invalidateRegions --- .../Core/PathSensitive/ProgramState.h | 4 +-- .../Core/PathSensitive/SValBuilder.h | 2 +- .../StaticAnalyzer/Core/PathSensitive/Store.h | 4 +-- .../lib/StaticAnalyzer/Core/ProgramState.cpp | 8 ++--- clang/lib/StaticAnalyzer/Core/RegionStore.cpp | 30 +++++++++---------- clang/lib/StaticAnalyzer/Core/SValBuilder.cpp | 4 +-- 6 files changed, 26 insertions(+), 26 deletions(-) diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h index 2f6cd481fd6362..eef7a54f03bf11 100644 --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h @@ -326,14 +326,14 @@ class ProgramState : public llvm::FoldingSetNode { /// \param ITraits information about special handling for particular regions /// or symbols. [[nodiscard]] ProgramStateRef - invalidateRegions(ArrayRef<const MemRegion *> Regions, const Expr *E, + invalidateRegions(ArrayRef<const MemRegion *> Regions, const Stmt *S, unsigned BlockCount, const LocationContext *LCtx, bool CausesPointerEscape, InvalidatedSymbols *IS = nullptr, const CallEvent *Call = nullptr, RegionAndSymbolInvalidationTraits *ITraits = nullptr) const; [[nodiscard]] ProgramStateRef - invalidateRegions(ArrayRef<SVal> Values, const Expr *E, unsigned BlockCount, + invalidateRegions(ArrayRef<SVal> Values, const Stmt *S, unsigned BlockCount, const LocationContext *LCtx, bool CausesPointerEscape, InvalidatedSymbols *IS = nullptr, const CallEvent *Call = nullptr, diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h index 6eedaf0544559b..0fc4e5cda81777 100644 --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h @@ -203,7 +203,7 @@ class SValBuilder { const LocationContext *LCtx, unsigned count); DefinedOrUnknownSVal conjureSymbolVal(const void *symbolTag, - const Expr *expr, + const Stmt *S, const LocationContext *LCtx, QualType type, unsigned count); diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/Store.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/Store.h index e08d5e104e9c0a..332855a3c9c45e 100644 --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/Store.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/Store.h @@ -215,7 +215,7 @@ class StoreManager { /// /// \param[in] store The initial store. /// \param[in] Values The values to invalidate. - /// \param[in] E The current statement being evaluated. Used to conjure + /// \param[in] S The current statement being evaluated. Used to conjure /// symbols to mark the values of invalidated regions. /// \param[in] Count The current block count. Used to conjure /// symbols to mark the values of invalidated regions. @@ -233,7 +233,7 @@ class StoreManager { /// even if they do not currently have bindings. Pass \c NULL if this /// information will not be used. virtual StoreRef invalidateRegions( - Store store, ArrayRef<SVal> Values, const Expr *Ex, unsigned Count, + Store store, ArrayRef<SVal> Values, const Stmt *S, unsigned Count, const LocationContext *LCtx, const CallEvent *Call, InvalidatedSymbols &IS, RegionAndSymbolInvalidationTraits &ITraits, InvalidatedRegions *TopLevelRegions, InvalidatedRegions *Invalidated) = 0; diff --git a/clang/lib/StaticAnalyzer/Core/ProgramState.cpp b/clang/lib/StaticAnalyzer/Core/ProgramState.cpp index e6d3399a219424..64243cbec410c9 100644 --- a/clang/lib/StaticAnalyzer/Core/ProgramState.cpp +++ b/clang/lib/StaticAnalyzer/Core/ProgramState.cpp @@ -149,7 +149,7 @@ typedef ArrayRef<SVal> ValueList; ProgramStateRef ProgramState::invalidateRegions(RegionList Regions, - const Expr *E, unsigned Count, + const Stmt *S, unsigned Count, const LocationContext *LCtx, bool CausedByPointerEscape, InvalidatedSymbols *IS, @@ -159,13 +159,13 @@ ProgramState::invalidateRegions(RegionList Regions, for (const MemRegion *Reg : Regions) Values.push_back(loc::MemRegionVal(Reg)); - return invalidateRegions(Values, E, Count, LCtx, CausedByPointerEscape, IS, + return invalidateRegions(Values, S, Count, LCtx, CausedByPointerEscape, IS, Call, ITraits); } ProgramStateRef ProgramState::invalidateRegions(ValueList Values, - const Expr *E, unsigned Count, + const Stmt *S, unsigned Count, const LocationContext *LCtx, bool CausedByPointerEscape, InvalidatedSymbols *IS, @@ -186,7 +186,7 @@ ProgramState::invalidateRegions(ValueList Values, StoreManager::InvalidatedRegions TopLevelInvalidated; StoreManager::InvalidatedRegions Invalidated; const StoreRef &NewStore = Mgr.StoreMgr->invalidateRegions( - getStore(), Values, E, Count, LCtx, Call, *IS, *ITraits, + getStore(), Values, S, Count, LCtx, Call, *IS, *ITraits, &TopLevelInvalidated, &Invalidated); ProgramStateRef NewState = makeWithStore(NewStore); diff --git a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp index c257a87dff385b..6da2886598b9d6 100644 --- a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp +++ b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp @@ -406,7 +406,7 @@ class RegionStoreManager : public StoreManager { // Binding values to regions. //===-------------------------------------------------------------------===// RegionBindingsRef invalidateGlobalRegion(MemRegion::Kind K, - const Expr *Ex, + const Stmt *S, unsigned Count, const LocationContext *LCtx, RegionBindingsRef B, @@ -414,7 +414,7 @@ class RegionStoreManager : public StoreManager { StoreRef invalidateRegions(Store store, ArrayRef<SVal> Values, - const Expr *E, unsigned Count, + const Stmt *S, unsigned Count, const LocationContext *LCtx, const CallEvent *Call, InvalidatedSymbols &IS, @@ -975,7 +975,7 @@ RegionStoreManager::removeSubRegionBindings(RegionBindingsConstRef B, namespace { class InvalidateRegionsWorker : public ClusterAnalysis<InvalidateRegionsWorker> { - const Expr *Ex; + const Stmt *S; unsigned Count; const LocationContext *LCtx; InvalidatedSymbols &IS; @@ -986,14 +986,14 @@ class InvalidateRegionsWorker : public ClusterAnalysis<InvalidateRegionsWorker> InvalidateRegionsWorker(RegionStoreManager &rm, ProgramStateManager &stateMgr, RegionBindingsRef b, - const Expr *ex, unsigned count, + const Stmt *S, unsigned count, const LocationContext *lctx, InvalidatedSymbols &is, RegionAndSymbolInvalidationTraits &ITraitsIn, StoreManager::InvalidatedRegions *r, GlobalsFilterKind GFK) : ClusterAnalysis<InvalidateRegionsWorker>(rm, stateMgr, b), - Ex(ex), Count(count), LCtx(lctx), IS(is), ITraits(ITraitsIn), Regions(r), + S(S), Count(count), LCtx(lctx), IS(is), ITraits(ITraitsIn), Regions(r), GlobalsFilter(GFK) {} void VisitCluster(const MemRegion *baseR, const ClusterBindings *C); @@ -1127,7 +1127,7 @@ void InvalidateRegionsWorker::VisitCluster(const MemRegion *baseR, // Invalidate the region by setting its default value to // conjured symbol. The type of the symbol is irrelevant. DefinedOrUnknownSVal V = - svalBuilder.conjureSymbolVal(baseR, Ex, LCtx, Ctx.IntTy, Count); + svalBuilder.conjureSymbolVal(baseR, S, LCtx, Ctx.IntTy, Count); B = B.addBinding(baseR, BindingKey::Default, V); return; } @@ -1148,7 +1148,7 @@ void InvalidateRegionsWorker::VisitCluster(const MemRegion *baseR, if (T->isRecordType()) { // Invalidate the region by setting its default value to // conjured symbol. The type of the symbol is irrelevant. - DefinedOrUnknownSVal V = svalBuilder.conjureSymbolVal(baseR, Ex, LCtx, + DefinedOrUnknownSVal V = svalBuilder.conjureSymbolVal(baseR, S, LCtx, Ctx.IntTy, Count); B = B.addBinding(baseR, BindingKey::Default, V); return; @@ -1217,13 +1217,13 @@ void InvalidateRegionsWorker::VisitCluster(const MemRegion *baseR, conjure_default: // Set the default value of the array to conjured symbol. DefinedOrUnknownSVal V = - svalBuilder.conjureSymbolVal(baseR, Ex, LCtx, + svalBuilder.conjureSymbolVal(baseR, S, LCtx, AT->getElementType(), Count); B = B.addBinding(baseR, BindingKey::Default, V); return; } - DefinedOrUnknownSVal V = svalBuilder.conjureSymbolVal(baseR, Ex, LCtx, + DefinedOrUnknownSVal V = svalBuilder.conjureSymbolVal(baseR, S, LCtx, T,Count); assert(SymbolManager::canSymbolicate(T) || V.isUnknown()); B = B.addBinding(baseR, BindingKey::Direct, V); @@ -1254,7 +1254,7 @@ bool InvalidateRegionsWorker::includeEntireMemorySpace(const MemRegion *Base) { RegionBindingsRef RegionStoreManager::invalidateGlobalRegion(MemRegion::Kind K, - const Expr *Ex, + const Stmt *S, unsigned Count, const LocationContext *LCtx, RegionBindingsRef B, @@ -1262,7 +1262,7 @@ RegionStoreManager::invalidateGlobalRegion(MemRegion::Kind K, // Bind the globals memory space to a new symbol that we will use to derive // the bindings for all globals. const GlobalsSpaceRegion *GS = MRMgr.getGlobalsRegion(K); - SVal V = svalBuilder.conjureSymbolVal(/* symbolTag = */ (const void*) GS, Ex, LCtx, + SVal V = svalBuilder.conjureSymbolVal(/* symbolTag = */ (const void*) GS, S, LCtx, /* type does not matter */ Ctx.IntTy, Count); @@ -1301,7 +1301,7 @@ void RegionStoreManager::populateWorkList(InvalidateRegionsWorker &W, StoreRef RegionStoreManager::invalidateRegions(Store store, ArrayRef<SVal> Values, - const Expr *Ex, unsigned Count, + const Stmt *S, unsigned Count, const LocationContext *LCtx, const CallEvent *Call, InvalidatedSymbols &IS, @@ -1319,7 +1319,7 @@ RegionStoreManager::invalidateRegions(Store store, } RegionBindingsRef B = getRegionBindings(store); - InvalidateRegionsWorker W(*this, StateMgr, B, Ex, Count, LCtx, IS, ITraits, + InvalidateRegionsWorker W(*this, StateMgr, B, S, Count, LCtx, IS, ITraits, Invalidated, GlobalsFilter); // Scan the bindings and generate the clusters. @@ -1340,11 +1340,11 @@ RegionStoreManager::invalidateRegions(Store store, switch (GlobalsFilter) { case GFK_All: B = invalidateGlobalRegion(MemRegion::GlobalInternalSpaceRegionKind, - Ex, Count, LCtx, B, Invalidated); + S, Count, LCtx, B, Invalidated); [[fallthrough]]; case GFK_SystemOnly: B = invalidateGlobalRegion(MemRegion::GlobalSystemSpaceRegionKind, - Ex, Count, LCtx, B, Invalidated); + S, Count, LCtx, B, Invalidated); [[fallthrough]]; case GFK_None: break; diff --git a/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp b/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp index 7eca0579143f44..cb5fcbade2cfc2 100644 --- a/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp +++ b/clang/lib/StaticAnalyzer/Core/SValBuilder.cpp @@ -174,7 +174,7 @@ DefinedOrUnknownSVal SValBuilder::conjureSymbolVal(const void *SymbolTag, } DefinedOrUnknownSVal SValBuilder::conjureSymbolVal(const void *symbolTag, - const Expr *expr, + const Stmt *St, const LocationContext *LCtx, QualType type, unsigned count) { @@ -184,7 +184,7 @@ DefinedOrUnknownSVal SValBuilder::conjureSymbolVal(const void *symbolTag, if (!SymbolManager::canSymbolicate(type)) return UnknownVal(); - SymbolRef sym = SymMgr.conjureSymbol(expr, LCtx, type, count, symbolTag); + SymbolRef sym = SymMgr.conjureSymbol(St, LCtx, type, count, symbolTag); if (Loc::isLocType(type)) return loc::MemRegionVal(MemMgr.getSymbolicRegion(sym)); >From 9257c258ad4b1db0bc2a366409870ef05572d815 Mon Sep 17 00:00:00 2001 From: Pavel Skripkin <paskrip...@gmail.com> Date: Tue, 24 Sep 2024 15:49:41 +0300 Subject: [PATCH 2/3] fix formatting --- .../clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h index 0fc4e5cda81777..ec2b2b24569480 100644 --- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h +++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h @@ -202,11 +202,9 @@ class SValBuilder { const Expr *expr, const LocationContext *LCtx, unsigned count); - DefinedOrUnknownSVal conjureSymbolVal(const void *symbolTag, - const Stmt *S, + DefinedOrUnknownSVal conjureSymbolVal(const void *symbolTag, const Stmt *S, const LocationContext *LCtx, - QualType type, - unsigned count); + QualType type, unsigned count); DefinedOrUnknownSVal conjureSymbolVal(const Stmt *stmt, const LocationContext *LCtx, QualType type, >From b461cf20d543a08c5da51652b0694683c30cf171 Mon Sep 17 00:00:00 2001 From: Pavel Skripkin <paskrip...@gmail.com> Date: Tue, 24 Sep 2024 15:54:10 +0300 Subject: [PATCH 3/3] fix formatting v2 --- .../lib/StaticAnalyzer/Core/ProgramState.cpp | 26 +++++++------------ 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Core/ProgramState.cpp b/clang/lib/StaticAnalyzer/Core/ProgramState.cpp index 64243cbec410c9..0be2709f0907d8 100644 --- a/clang/lib/StaticAnalyzer/Core/ProgramState.cpp +++ b/clang/lib/StaticAnalyzer/Core/ProgramState.cpp @@ -147,14 +147,11 @@ ProgramState::bindDefaultZero(SVal loc, const LocationContext *LCtx) const { typedef ArrayRef<const MemRegion *> RegionList; typedef ArrayRef<SVal> ValueList; -ProgramStateRef -ProgramState::invalidateRegions(RegionList Regions, - const Stmt *S, unsigned Count, - const LocationContext *LCtx, - bool CausedByPointerEscape, - InvalidatedSymbols *IS, - const CallEvent *Call, - RegionAndSymbolInvalidationTraits *ITraits) const { +ProgramStateRef ProgramState::invalidateRegions( + RegionList Regions, const Stmt *S, unsigned Count, + const LocationContext *LCtx, bool CausedByPointerEscape, + InvalidatedSymbols *IS, const CallEvent *Call, + RegionAndSymbolInvalidationTraits *ITraits) const { SmallVector<SVal, 8> Values; for (const MemRegion *Reg : Regions) Values.push_back(loc::MemRegionVal(Reg)); @@ -163,14 +160,11 @@ ProgramState::invalidateRegions(RegionList Regions, Call, ITraits); } -ProgramStateRef -ProgramState::invalidateRegions(ValueList Values, - const Stmt *S, unsigned Count, - const LocationContext *LCtx, - bool CausedByPointerEscape, - InvalidatedSymbols *IS, - const CallEvent *Call, - RegionAndSymbolInvalidationTraits *ITraits) const { +ProgramStateRef ProgramState::invalidateRegions( + ValueList Values, const Stmt *S, unsigned Count, + const LocationContext *LCtx, bool CausedByPointerEscape, + InvalidatedSymbols *IS, const CallEvent *Call, + RegionAndSymbolInvalidationTraits *ITraits) const { ProgramStateManager &Mgr = getStateManager(); ExprEngine &Eng = Mgr.getOwningEngine(); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits