Skip to content

[analyzer][NFC] Trivial refactoring of region invalidation #102456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 12, 2024

Conversation

NagyDonat
Copy link
Contributor

This commit removes invalidateRegionsImpl(), moving its body to invalidateRegions(ValueList Values, ...), because it was a completely useless layer of indirection.

Moreover I'm fixing some strange indentation within this function body and renaming two variables to the proper UpperCamelCase format.

This commit removes `invalidateRegionsImpl()`, moving its body to
`invalidateRegions(ValueList Values, ...)`, because it was a completely
useless layer of indirection.

Moreover I'm fixing some strange indentation within this function body
and renaming two variables to the proper `UpperCamelCase` format.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:static analyzer labels Aug 8, 2024
@llvmbot
Copy link
Member

llvmbot commented Aug 8, 2024

@llvm/pr-subscribers-clang

Author: Donát Nagy (NagyDonat)

Changes

This commit removes invalidateRegionsImpl(), moving its body to invalidateRegions(ValueList Values, ...), because it was a completely useless layer of indirection.

Moreover I'm fixing some strange indentation within this function body and renaming two variables to the proper UpperCamelCase format.


Full diff: https://github.com/llvm/llvm-project/pull/102456.diff

2 Files Affected:

  • (modified) clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h (-11)
  • (modified) clang/lib/StaticAnalyzer/Core/ProgramState.cpp (+9-24)
diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
index 51d76dc257ee9..9889d2604a890 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
@@ -484,17 +484,6 @@ class ProgramState : public llvm::FoldingSetNode {
   friend void ProgramStateRetain(const ProgramState *state);
   friend void ProgramStateRelease(const ProgramState *state);
 
-  /// \sa invalidateValues()
-  /// \sa invalidateRegions()
-  ProgramStateRef
-  invalidateRegionsImpl(ArrayRef<SVal> Values,
-                        const Expr *E, unsigned BlockCount,
-                        const LocationContext *LCtx,
-                        bool ResultsInSymbolEscape,
-                        InvalidatedSymbols *IS,
-                        RegionAndSymbolInvalidationTraits *HTraits,
-                        const CallEvent *Call) const;
-
   SVal wrapSymbolicRegion(SVal Base) const;
 };
 
diff --git a/clang/lib/StaticAnalyzer/Core/ProgramState.cpp b/clang/lib/StaticAnalyzer/Core/ProgramState.cpp
index f82cd944750a3..e6d3399a21942 100644
--- a/clang/lib/StaticAnalyzer/Core/ProgramState.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ProgramState.cpp
@@ -159,8 +159,8 @@ ProgramState::invalidateRegions(RegionList Regions,
   for (const MemRegion *Reg : Regions)
     Values.push_back(loc::MemRegionVal(Reg));
 
-  return invalidateRegionsImpl(Values, E, Count, LCtx, CausedByPointerEscape,
-                               IS, ITraits, Call);
+  return invalidateRegions(Values, E, Count, LCtx, CausedByPointerEscape, IS,
+                           Call, ITraits);
 }
 
 ProgramStateRef
@@ -172,18 +172,6 @@ ProgramState::invalidateRegions(ValueList Values,
                              const CallEvent *Call,
                              RegionAndSymbolInvalidationTraits *ITraits) const {
 
-  return invalidateRegionsImpl(Values, E, Count, LCtx, CausedByPointerEscape,
-                               IS, ITraits, Call);
-}
-
-ProgramStateRef
-ProgramState::invalidateRegionsImpl(ValueList Values,
-                                    const Expr *E, unsigned Count,
-                                    const LocationContext *LCtx,
-                                    bool CausedByPointerEscape,
-                                    InvalidatedSymbols *IS,
-                                    RegionAndSymbolInvalidationTraits *ITraits,
-                                    const CallEvent *Call) const {
   ProgramStateManager &Mgr = getStateManager();
   ExprEngine &Eng = Mgr.getOwningEngine();
 
@@ -197,21 +185,18 @@ ProgramState::invalidateRegionsImpl(ValueList Values,
 
   StoreManager::InvalidatedRegions TopLevelInvalidated;
   StoreManager::InvalidatedRegions Invalidated;
-  const StoreRef &newStore
-  = Mgr.StoreMgr->invalidateRegions(getStore(), Values, E, Count, LCtx, Call,
-                                    *IS, *ITraits, &TopLevelInvalidated,
-                                    &Invalidated);
+  const StoreRef &NewStore = Mgr.StoreMgr->invalidateRegions(
+      getStore(), Values, E, Count, LCtx, Call, *IS, *ITraits,
+      &TopLevelInvalidated, &Invalidated);
 
-  ProgramStateRef newState = makeWithStore(newStore);
+  ProgramStateRef NewState = makeWithStore(NewStore);
 
   if (CausedByPointerEscape) {
-    newState = Eng.notifyCheckersOfPointerEscape(newState, IS,
-                                                 TopLevelInvalidated,
-                                                 Call,
-                                                 *ITraits);
+    NewState = Eng.notifyCheckersOfPointerEscape(
+        NewState, IS, TopLevelInvalidated, Call, *ITraits);
   }
 
-  return Eng.processRegionChanges(newState, IS, TopLevelInvalidated,
+  return Eng.processRegionChanges(NewState, IS, TopLevelInvalidated,
                                   Invalidated, LCtx, Call);
 }
 

@llvmbot
Copy link
Member

llvmbot commented Aug 8, 2024

@llvm/pr-subscribers-clang-static-analyzer-1

Author: Donát Nagy (NagyDonat)

Changes

This commit removes invalidateRegionsImpl(), moving its body to invalidateRegions(ValueList Values, ...), because it was a completely useless layer of indirection.

Moreover I'm fixing some strange indentation within this function body and renaming two variables to the proper UpperCamelCase format.


Full diff: https://github.com/llvm/llvm-project/pull/102456.diff

2 Files Affected:

  • (modified) clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h (-11)
  • (modified) clang/lib/StaticAnalyzer/Core/ProgramState.cpp (+9-24)
diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
index 51d76dc257ee94..9889d2604a890e 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h
@@ -484,17 +484,6 @@ class ProgramState : public llvm::FoldingSetNode {
   friend void ProgramStateRetain(const ProgramState *state);
   friend void ProgramStateRelease(const ProgramState *state);
 
-  /// \sa invalidateValues()
-  /// \sa invalidateRegions()
-  ProgramStateRef
-  invalidateRegionsImpl(ArrayRef<SVal> Values,
-                        const Expr *E, unsigned BlockCount,
-                        const LocationContext *LCtx,
-                        bool ResultsInSymbolEscape,
-                        InvalidatedSymbols *IS,
-                        RegionAndSymbolInvalidationTraits *HTraits,
-                        const CallEvent *Call) const;
-
   SVal wrapSymbolicRegion(SVal Base) const;
 };
 
diff --git a/clang/lib/StaticAnalyzer/Core/ProgramState.cpp b/clang/lib/StaticAnalyzer/Core/ProgramState.cpp
index f82cd944750a3c..e6d3399a219424 100644
--- a/clang/lib/StaticAnalyzer/Core/ProgramState.cpp
+++ b/clang/lib/StaticAnalyzer/Core/ProgramState.cpp
@@ -159,8 +159,8 @@ ProgramState::invalidateRegions(RegionList Regions,
   for (const MemRegion *Reg : Regions)
     Values.push_back(loc::MemRegionVal(Reg));
 
-  return invalidateRegionsImpl(Values, E, Count, LCtx, CausedByPointerEscape,
-                               IS, ITraits, Call);
+  return invalidateRegions(Values, E, Count, LCtx, CausedByPointerEscape, IS,
+                           Call, ITraits);
 }
 
 ProgramStateRef
@@ -172,18 +172,6 @@ ProgramState::invalidateRegions(ValueList Values,
                              const CallEvent *Call,
                              RegionAndSymbolInvalidationTraits *ITraits) const {
 
-  return invalidateRegionsImpl(Values, E, Count, LCtx, CausedByPointerEscape,
-                               IS, ITraits, Call);
-}
-
-ProgramStateRef
-ProgramState::invalidateRegionsImpl(ValueList Values,
-                                    const Expr *E, unsigned Count,
-                                    const LocationContext *LCtx,
-                                    bool CausedByPointerEscape,
-                                    InvalidatedSymbols *IS,
-                                    RegionAndSymbolInvalidationTraits *ITraits,
-                                    const CallEvent *Call) const {
   ProgramStateManager &Mgr = getStateManager();
   ExprEngine &Eng = Mgr.getOwningEngine();
 
@@ -197,21 +185,18 @@ ProgramState::invalidateRegionsImpl(ValueList Values,
 
   StoreManager::InvalidatedRegions TopLevelInvalidated;
   StoreManager::InvalidatedRegions Invalidated;
-  const StoreRef &newStore
-  = Mgr.StoreMgr->invalidateRegions(getStore(), Values, E, Count, LCtx, Call,
-                                    *IS, *ITraits, &TopLevelInvalidated,
-                                    &Invalidated);
+  const StoreRef &NewStore = Mgr.StoreMgr->invalidateRegions(
+      getStore(), Values, E, Count, LCtx, Call, *IS, *ITraits,
+      &TopLevelInvalidated, &Invalidated);
 
-  ProgramStateRef newState = makeWithStore(newStore);
+  ProgramStateRef NewState = makeWithStore(NewStore);
 
   if (CausedByPointerEscape) {
-    newState = Eng.notifyCheckersOfPointerEscape(newState, IS,
-                                                 TopLevelInvalidated,
-                                                 Call,
-                                                 *ITraits);
+    NewState = Eng.notifyCheckersOfPointerEscape(
+        NewState, IS, TopLevelInvalidated, Call, *ITraits);
   }
 
-  return Eng.processRegionChanges(newState, IS, TopLevelInvalidated,
+  return Eng.processRegionChanges(NewState, IS, TopLevelInvalidated,
                                   Invalidated, LCtx, Call);
 }
 

Copy link
Contributor

@steakhal steakhal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@NagyDonat NagyDonat merged commit b680862 into llvm:main Aug 12, 2024
11 checks passed
@NagyDonat NagyDonat deleted the invalidateRegions-nfc branch August 12, 2024 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:static analyzer clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants