Author: Martin Braenne
Date: 2023-08-29T06:53:48Z
New Revision: aef05a12329cf83c0a6fe46b464ab6ac08ee3439

URL: 
https://github.com/llvm/llvm-project/commit/aef05a12329cf83c0a6fe46b464ab6ac08ee3439
DIFF: 
https://github.com/llvm/llvm-project/commit/aef05a12329cf83c0a6fe46b464ab6ac08ee3439.diff

LOG: [clang][dataflow][NFC] Eliminate `getStorageLocation()` / 
`setStorageLocation()` in `DataflowAnalysisContext`.

Instead, inline them into the `getStableStorageLocation()` overloads, which is 
the only place they were called from (and should be called from).

`getStorageLocation()` / `setStorageLocation()` were confusing because neither 
their name nor their documentation made reference to the fact that the storage 
location is stable.

It didn't make sense to keep these as private member functions either. The code 
for the two `getStableStorageLocation()` overloads has become only marginally 
more complex by inlining these functions, and the `Expr` version is actually 
more efficient because we only call `ignoreCFGOmittedNodes()` once instead of 
twice.

Reviewed By: ymandel, xazax.hun

Differential Revision: https://reviews.llvm.org/D158981

Added: 
    

Modified: 
    clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
    clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp

Removed: 
    


################################################################################
diff  --git 
a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
index e5c325b876bd7a..685bbe486b54e1 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowAnalysisContext.h
@@ -103,39 +103,6 @@ class DataflowAnalysisContext {
   /// Returns a stable storage location for `E`.
   StorageLocation &getStableStorageLocation(const Expr &E);
 
-  /// Assigns `Loc` as the storage location of `D`.
-  ///
-  /// Requirements:
-  ///
-  ///  `D` must not be assigned a storage location.
-  void setStorageLocation(const ValueDecl &D, StorageLocation &Loc) {
-    assert(!DeclToLoc.contains(&D));
-    DeclToLoc[&D] = &Loc;
-  }
-
-  /// Returns the storage location assigned to `D` or null if `D` has no
-  /// assigned storage location.
-  StorageLocation *getStorageLocation(const ValueDecl &D) const {
-    return DeclToLoc.lookup(&D);
-  }
-
-  /// Assigns `Loc` as the storage location of `E`.
-  ///
-  /// Requirements:
-  ///
-  ///  `E` must not be assigned a storage location.
-  void setStorageLocation(const Expr &E, StorageLocation &Loc) {
-    const Expr &CanonE = ignoreCFGOmittedNodes(E);
-    assert(!ExprToLoc.contains(&CanonE));
-    ExprToLoc[&CanonE] = &Loc;
-  }
-
-  /// Returns the storage location assigned to `E` or null if `E` has no
-  /// assigned storage location.
-  StorageLocation *getStorageLocation(const Expr &E) const {
-    return ExprToLoc.lookup(&ignoreCFGOmittedNodes(E));
-  }
-
   /// Returns a pointer value that represents a null pointer. Calls with
   /// `PointeeType` that are canonically equivalent will return the same 
result.
   /// A null `PointeeType` can be used for the pointee of `std::nullptr_t`.

diff  --git a/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
index 0a6d7792208258..47a994f4bbdb6a 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowAnalysisContext.cpp
@@ -74,19 +74,21 @@ StorageLocation 
&DataflowAnalysisContext::createStorageLocation(QualType Type) {
 
 StorageLocation &
 DataflowAnalysisContext::getStableStorageLocation(const VarDecl &D) {
-  if (auto *Loc = getStorageLocation(D))
+  if (auto *Loc = DeclToLoc.lookup(&D))
     return *Loc;
   auto &Loc = createStorageLocation(D.getType().getNonReferenceType());
-  setStorageLocation(D, Loc);
+  DeclToLoc[&D] = &Loc;
   return Loc;
 }
 
 StorageLocation &
 DataflowAnalysisContext::getStableStorageLocation(const Expr &E) {
-  if (auto *Loc = getStorageLocation(E))
+  const Expr &CanonE = ignoreCFGOmittedNodes(E);
+
+  if (auto *Loc = ExprToLoc.lookup(&CanonE))
     return *Loc;
-  auto &Loc = createStorageLocation(E.getType());
-  setStorageLocation(E, Loc);
+  auto &Loc = createStorageLocation(CanonE.getType());
+  ExprToLoc[&CanonE] = &Loc;
   return Loc;
 }
 


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to