[llvm-branch-commits] [clang] [SSAF][Analyses] Add an AST visitor for the contribution model (PR #191933)

Ziqing Luo via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Apr 15 13:54:26 PDT 2026


https://github.com/ziqingluo-90 updated https://github.com/llvm/llvm-project/pull/191933

>From f4ab72cbf0ac61161b32f39c60766215c636da6a Mon Sep 17 00:00:00 2001
From: Ziqing Luo <ziqing_luo at apple.com>
Date: Mon, 13 Apr 2026 19:16:38 -0700
Subject: [PATCH 1/3] [SSAF][Analyses] Add an AST visitor for the contribution
 model

Add an AST visitor that respects the contribution model and will be
shared across SSAF analyses.
---
 .../EntityPointerLevel/EntityPointerLevel.h   |  11 +-
 .../Analyses/CMakeLists.txt                   |   3 +-
 .../Analyses/SSAFAnalysesCommon.cpp           | 106 ++++++++++++++++++
 .../Analyses/SSAFAnalysesCommon.h             |  12 ++
 .../UnsafeBufferUsageExtractor.cpp            | 104 +++++++----------
 5 files changed, 165 insertions(+), 71 deletions(-)
 create mode 100644 clang/lib/ScalableStaticAnalysisFramework/Analyses/SSAFAnalysesCommon.cpp

diff --git a/clang/include/clang/ScalableStaticAnalysisFramework/Analyses/EntityPointerLevel/EntityPointerLevel.h b/clang/include/clang/ScalableStaticAnalysisFramework/Analyses/EntityPointerLevel/EntityPointerLevel.h
index ed8400f65e310..0e120a40eebb8 100644
--- a/clang/include/clang/ScalableStaticAnalysisFramework/Analyses/EntityPointerLevel/EntityPointerLevel.h
+++ b/clang/include/clang/ScalableStaticAnalysisFramework/Analyses/EntityPointerLevel/EntityPointerLevel.h
@@ -22,9 +22,9 @@ namespace clang::ssaf {
 /// declared type, a EntityPointerLevel is associated with a '*' (or a '[]`) in
 /// that declaration.
 ///
-/// For example, for 'int *p[10];', there are two EntityPointerLevels. One
-/// is associated with 'int *[10]' of 'p' and the other is associated with 'int
-/// *' of 'p'.
+/// For example, for 'int *p[10];', there are two EntityPointerLevels.
+/// One is associated with 'int *[10]' of 'p' and the other is associated with
+/// 'int *' of 'p'.
 ///
 /// An EntityPointerLevel can be identified by an EntityId and an unsigned
 /// integer indicating the pointer level: '(EntityId, PointerLevel)'.
@@ -34,7 +34,7 @@ namespace clang::ssaf {
 /// For the same example 'int *p[10];', the EntityPointerLevels below are valid:
 /// - '(p, 2)' is associated with the 'int *' part of the declared type of 'p';
 /// - '(p, 1)' is associated with the 'int *[10]' part of the declared type of
-/// 'p'.
+///   'p'.
 class EntityPointerLevel {
   EntityId Entity;
   unsigned PointerLevel;
@@ -97,6 +97,8 @@ llvm::Expected<EntityPointerLevelSet> translateEntityPointerLevel(
     const Expr *E, ASTContext &Ctx,
     llvm::function_ref<EntityId(EntityName EN)> AddEntity);
 
+/// Creates a `EntityPointerLevel` from a pair of an EntityId and a pointer
+/// level:
 EntityPointerLevel buildEntityPointerLevel(EntityId, unsigned);
 
 /// Create an EntityPointerLevel (EPL) from a NamedDecl of a pointer/array type.
@@ -117,4 +119,5 @@ creatEntityPointerLevel(const NamedDecl *ND,
 /// of `E`'s associated pointer/array tyoe of the same entity.
 EntityPointerLevel incrementPointerLevel(const EntityPointerLevel &E);
 } // namespace clang::ssaf
+
 #endif // LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_ANALYSES_ENTITYPOINTERLEVEL_ENTITYPOINTERLEVEL_H
diff --git a/clang/lib/ScalableStaticAnalysisFramework/Analyses/CMakeLists.txt b/clang/lib/ScalableStaticAnalysisFramework/Analyses/CMakeLists.txt
index c15ff3b3c42e7..88dcef0c5a2fa 100644
--- a/clang/lib/ScalableStaticAnalysisFramework/Analyses/CMakeLists.txt
+++ b/clang/lib/ScalableStaticAnalysisFramework/Analyses/CMakeLists.txt
@@ -2,10 +2,11 @@ set(LLVM_LINK_COMPONENTS
   Support
   )
 
-add_clang_library(clangScalableStaticAnalysisFrameworkAnalyses 
+add_clang_library(clangScalableStaticAnalysisFrameworkAnalyses
   CallGraph/CallGraphExtractor.cpp
   CallGraph/CallGraphJSONFormat.cpp
   EntityPointerLevel/EntityPointerLevel.cpp
+  SSAFAnalysesCommon.cpp
   UnsafeBufferUsage/UnsafeBufferUsage.cpp
   UnsafeBufferUsage/UnsafeBufferUsageExtractor.cpp
 
diff --git a/clang/lib/ScalableStaticAnalysisFramework/Analyses/SSAFAnalysesCommon.cpp b/clang/lib/ScalableStaticAnalysisFramework/Analyses/SSAFAnalysesCommon.cpp
new file mode 100644
index 0000000000000..31962bdee7f92
--- /dev/null
+++ b/clang/lib/ScalableStaticAnalysisFramework/Analyses/SSAFAnalysesCommon.cpp
@@ -0,0 +1,106 @@
+//===- SSAFAnalysesCommon.cpp ---------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "SSAFAnalysesCommon.h"
+
+namespace {
+// Traverses the AST and finds contributors.
+class ContributorFinder : public DynamicRecursiveASTVisitor {
+public:
+  std::vector<const NamedDecl *> Contributors;
+
+  bool VisitFunctionDecl(FunctionDecl *D) override {
+    Contributors.push_back(D);
+    return true;
+  }
+
+  bool VisitRecordDecl(RecordDecl *D) override {
+    Contributors.push_back(D);
+    return true;
+  }
+
+  bool VisitVarDecl(VarDecl *D) override {
+    DeclContext *DC = D->getDeclContext();
+
+    if (DC->isFileContext() || DC->isNamespace())
+      Contributors.push_back(D);
+    return true;
+  }
+};
+
+// An AST visitor that skips the root node's strict-descendants that are
+// callable Decls and record Decls, because those are separate contributors.
+//
+// Clients need to implement their own `MatchAction`, which is a function that
+// takes a `DynTypedNode`, decides if it matches and performs any further
+// callback actions.
+class ContributorFactFinder : public DynamicRecursiveASTVisitor {
+  llvm::function_ref<void(const DynTypedNode &)> MatchAction;
+  const NamedDecl *RootDecl = nullptr;
+
+  template <typename NodeTy> void match(const NodeTy &Node) {
+    MatchAction(DynTypedNode::create(Node));
+  }
+
+public:
+  ContributorFactFinder(
+      llvm::function_ref<void(const DynTypedNode &)> MatchAction)
+      : MatchAction(MatchAction) {
+    ShouldVisitTemplateInstantiations = true;
+    ShouldVisitImplicitCode = false;
+  }
+
+  // The entry point:
+  void findMatches(const NamedDecl *Contributor) {
+    RootDecl = Contributor;
+    TraverseDecl(const_cast<NamedDecl *>(Contributor));
+  }
+
+  bool TraverseDecl(Decl *Node) override {
+    if (!Node)
+      return true;
+    // To skip callables:
+    if (Node != RootDecl && isa<FunctionDecl, CXXConstructorDecl, BlockDecl,
+                                ObjCMethodDecl, RecordDecl>(Node))
+      return true;
+    match(*Node);
+    return DynamicRecursiveASTVisitor::TraverseDecl(Node);
+  }
+
+  bool TraverseStmt(Stmt *Node) override {
+    if (!Node)
+      return true;
+    match(*Node);
+    return DynamicRecursiveASTVisitor::TraverseStmt(Node);
+  }
+
+  bool TraverseLambdaExpr(LambdaExpr *L) override {
+    // TODO: lambda captures of pointer variables (by copy or by reference)
+    // are currently not tracked. Each capture initializes an implicit closure
+    // field from the captured variable, which constitutes a pointer assignment
+    // edge that should be recorded here.
+    return true; // Skip lambda as it is a callable.
+  }
+};
+} // namespace
+
+namespace clang::ssaf {
+
+void findContributors(ASTContext &Ctx,
+                      std::vector<const NamedDecl *> &Contributors) {
+  ContributorFinder Finder;
+  Finder.TraverseAST(Ctx);
+  Contributors = std::move(Finder.Contributors);
+}
+
+void findMatchesIn(const NamedDecl *Contributor,
+                   llvm::function_ref<void(const DynTypedNode &)> MatchAction) {
+  ContributorFactFinder{MatchAction}.findMatches(Contributor);
+}
+
+} // namespace clang::ssaf
diff --git a/clang/lib/ScalableStaticAnalysisFramework/Analyses/SSAFAnalysesCommon.h b/clang/lib/ScalableStaticAnalysisFramework/Analyses/SSAFAnalysesCommon.h
index c14e2a98751d2..b47f03421a6cf 100644
--- a/clang/lib/ScalableStaticAnalysisFramework/Analyses/SSAFAnalysesCommon.h
+++ b/clang/lib/ScalableStaticAnalysisFramework/Analyses/SSAFAnalysesCommon.h
@@ -12,6 +12,7 @@
 #ifndef LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_ANALYSES_SSAFANALYSESCOMMON_H
 #define LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_ANALYSES_SSAFANALYSESCOMMON_H
 
+#include "clang/AST/ASTTypeTraits.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclObjC.h"
 #include "clang/AST/DynamicRecursiveASTVisitor.h"
@@ -47,4 +48,15 @@ inline llvm::Error makeEntityNameErr(ASTContext &Ctx, const NamedDecl *D) {
                        D->getNameAsString().data());
 }
 
+namespace clang::ssaf {
+
+/// Find all contributors in an AST.
+void findContributors(ASTContext &Ctx,
+                      std::vector<const NamedDecl *> &Contributors);
+/// Perform `MatchAction` on each Stmt and Decl belonging to the `Contributor`.
+void findMatchesIn(const NamedDecl *Contributor,
+                   llvm::function_ref<void(const DynTypedNode &)> MatchAction);
+
+} // namespace clang::ssaf
+
 #endif // LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_ANALYSES_SSAFANALYSESCOMMON_H
diff --git a/clang/lib/ScalableStaticAnalysisFramework/Analyses/UnsafeBufferUsage/UnsafeBufferUsageExtractor.cpp b/clang/lib/ScalableStaticAnalysisFramework/Analyses/UnsafeBufferUsage/UnsafeBufferUsageExtractor.cpp
index f79bc5c8574d6..d8b8829a19106 100644
--- a/clang/lib/ScalableStaticAnalysisFramework/Analyses/UnsafeBufferUsage/UnsafeBufferUsageExtractor.cpp
+++ b/clang/lib/ScalableStaticAnalysisFramework/Analyses/UnsafeBufferUsage/UnsafeBufferUsageExtractor.cpp
@@ -21,41 +21,17 @@
 #include "clang/ScalableStaticAnalysisFramework/Core/TUSummary/TUSummaryExtractor.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/Support/Error.h"
-#include <memory>
+#include "llvm/Support/ErrorHandling.h"
 
-namespace {
 using namespace clang;
 using namespace ssaf;
 
-Expected<EntityPointerLevelSet>
-buildEntityPointerLevels(std::set<const Expr *> &&UnsafePointers,
-                         ASTContext &Ctx,
-                         std::function<EntityId(EntityName)> AddEntity) {
-  EntityPointerLevelSet Result{};
-  llvm::Error AllErrors = llvm::ErrorSuccess();
-
-  for (const Expr *Ptr : UnsafePointers) {
-    Expected<EntityPointerLevelSet> Translation =
-        translateEntityPointerLevel(Ptr, Ctx, AddEntity);
-
-    if (Translation) {
-      // Filter out those temporary invalid EntityPointerLevels associated with
-      // `&E` pointers:
-      auto FilteredTranslation = llvm::make_filter_range(
-          *Translation, [](const EntityPointerLevel &E) -> bool {
-            return E.getPointerLevel() > 0;
-          });
-      Result.insert(FilteredTranslation.begin(), FilteredTranslation.end());
-      continue;
-    }
-    AllErrors = llvm::joinErrors(std::move(AllErrors), Translation.takeError());
-  }
-  if (AllErrors)
-    return AllErrors;
-  return Result;
-}
+static std::set<const Expr *>
+findUnsafePointersInContributor(const DynTypedNode &Node) {
+  const Decl *D = Node.get<Decl>();
 
-static std::set<const Expr *> findUnsafePointersInContributor(const Decl *D) {
+  if (!D)
+    return {};
   if (isa<FunctionDecl>(D) || isa<VarDecl>(D))
     return findUnsafePointers(D);
   if (auto *RD = dyn_cast<RecordDecl>(D)) {
@@ -68,7 +44,6 @@ static std::set<const Expr *> findUnsafePointersInContributor(const Decl *D) {
   }
   return {};
 }
-} // namespace
 
 class clang::ssaf::UnsafeBufferUsageTUSummaryExtractor
     : public TUSummaryExtractor {
@@ -79,48 +54,45 @@ class clang::ssaf::UnsafeBufferUsageTUSummaryExtractor
   EntityId addEntity(EntityName EN) { return SummaryBuilder.addEntity(EN); }
 
   Expected<std::unique_ptr<UnsafeBufferUsageEntitySummary>>
-  extractEntitySummary(const Decl *Contributor, ASTContext &Ctx) {
-    auto AddEntity = [this](EntityName EN) { return addEntity(EN); };
-    Expected<EntityPointerLevelSet> EPLs = buildEntityPointerLevels(
-        findUnsafePointersInContributor(Contributor), Ctx, AddEntity);
-
-    if (EPLs)
-      return std::make_unique<UnsafeBufferUsageEntitySummary>(
-          UnsafeBufferUsageEntitySummary(std::move(*EPLs)));
-    return EPLs.takeError();
-  }
+  extractEntitySummary(const NamedDecl *Contributor, ASTContext &Ctx) {
+    std::set<const Expr *> UnsafePointers;
 
-  void HandleTranslationUnit(ASTContext &Ctx) override {
+    auto MatchAction = [&UnsafePointers](const DynTypedNode &Node) {
+      auto Result = findUnsafePointersInContributor(Node);
+      UnsafePointers.insert(Result.begin(), Result.end());
+    };
+    findMatchesIn(Contributor, MatchAction);
 
-    // FIXME: I suppose finding contributor Decls is commonly needed by all/many
-    // extractors
-    class ContributorFinder : public DynamicRecursiveASTVisitor {
-    public:
-      std::vector<const NamedDecl *> Contributors;
+    EntityPointerLevelSet Results;
 
-      bool VisitFunctionDecl(FunctionDecl *D) override {
-        Contributors.push_back(D);
-        return true;
-      }
+    for (const Expr *Ptr : UnsafePointers) {
+      Expected<EntityPointerLevelSet> Translation =
+          translateEntityPointerLevel(Ptr, Ctx, [this](const EntityName &EN) {
+            return SummaryBuilder.addEntity(EN);
+          });
 
-      bool VisitRecordDecl(RecordDecl *D) override {
-        Contributors.push_back(D);
-        return true;
+      if (Translation) {
+        // Filter out those temporary invalid EntityPointerLevels associated
+        // with `&E` pointers. They need no transformation of entities:
+        auto FilteredTranslation = llvm::make_filter_range(
+            *Translation, [](const EntityPointerLevel &E) -> bool {
+              return E.getPointerLevel() > 0;
+            });
+        Results.insert(FilteredTranslation.begin(), FilteredTranslation.end());
+        continue;
       }
+      return Translation.takeError();
+    }
 
-      bool VisitVarDecl(VarDecl *D) override {
-        DeclContext *DC = D->getDeclContext();
-
-        if (DC->isFileContext() || DC->isNamespace())
-          Contributors.push_back(D);
-        return true;
-      }
-    } ContributorFinder;
+    return std::make_unique<UnsafeBufferUsageEntitySummary>(
+        UnsafeBufferUsageEntitySummary(std::move(Results)));
+  }
 
-    ContributorFinder.VisitTranslationUnitDecl(Ctx.getTranslationUnitDecl());
+  void HandleTranslationUnit(ASTContext &Ctx) override {
+    std::vector<const NamedDecl *> Contributors;
 
-    ContributorFinder.TraverseAST(Ctx);
-    for (auto *CD : ContributorFinder.Contributors) {
+    findContributors(Ctx, Contributors);
+    for (auto *CD : Contributors) {
       auto EntitySummary = extractEntitySummary(CD, Ctx);
 
       if (!EntitySummary)
@@ -148,4 +120,4 @@ volatile int UnsafeBufferUsageTUSummaryExtractorAnchorSource = 0;
 static clang::ssaf::TUSummaryExtractorRegistry::Add<
     ssaf::UnsafeBufferUsageTUSummaryExtractor>
     RegisterExtractor(UnsafeBufferUsageEntitySummary::Name,
-                      "The TUSummaryExtractor for unsafe buffer pointers");
\ No newline at end of file
+                      "The TUSummaryExtractor for unsafe buffer pointers");

>From bae2ead1cd034a1e7505318c5455e7565082e9ae Mon Sep 17 00:00:00 2001
From: Ziqing Luo <ziqing_luo at apple.com>
Date: Wed, 15 Apr 2026 12:34:30 -0700
Subject: [PATCH 2/3] fix merge issues

---
 .../Analyses/SSAFAnalysesCommon.cpp                          | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/lib/ScalableStaticAnalysisFramework/Analyses/SSAFAnalysesCommon.cpp b/clang/lib/ScalableStaticAnalysisFramework/Analyses/SSAFAnalysesCommon.cpp
index 31962bdee7f92..2d55511135d10 100644
--- a/clang/lib/ScalableStaticAnalysisFramework/Analyses/SSAFAnalysesCommon.cpp
+++ b/clang/lib/ScalableStaticAnalysisFramework/Analyses/SSAFAnalysesCommon.cpp
@@ -8,6 +8,8 @@
 
 #include "SSAFAnalysesCommon.h"
 
+using namespace clang;
+
 namespace {
 // Traverses the AST and finds contributors.
 class ContributorFinder : public DynamicRecursiveASTVisitor {
@@ -95,7 +97,8 @@ void findContributors(ASTContext &Ctx,
                       std::vector<const NamedDecl *> &Contributors) {
   ContributorFinder Finder;
   Finder.TraverseAST(Ctx);
-  Contributors = std::move(Finder.Contributors);
+  Contributors.insert(Contributors.end(), Finder.Contributors.begin(),
+                      Finder.Contributors.end());
 }
 
 void findMatchesIn(const NamedDecl *Contributor,

>From 47f1c1a54cd56179bf022e903b9c135c6b188389 Mon Sep 17 00:00:00 2001
From: Ziqing Luo <ziqing_luo at apple.com>
Date: Wed, 15 Apr 2026 13:53:48 -0700
Subject: [PATCH 3/3] clean up

---
 .../Analyses/EntityPointerLevel/EntityPointerLevel.h     | 2 +-
 .../Analyses/SSAFAnalysesCommon.cpp                      | 4 ++--
 .../Analyses/SSAFAnalysesCommon.h                        | 2 +-
 .../UnsafeBufferUsage/UnsafeBufferUsageExtractor.cpp     | 9 +++------
 4 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/clang/include/clang/ScalableStaticAnalysisFramework/Analyses/EntityPointerLevel/EntityPointerLevel.h b/clang/include/clang/ScalableStaticAnalysisFramework/Analyses/EntityPointerLevel/EntityPointerLevel.h
index 2642993d05842..429bb74fb417e 100644
--- a/clang/include/clang/ScalableStaticAnalysisFramework/Analyses/EntityPointerLevel/EntityPointerLevel.h
+++ b/clang/include/clang/ScalableStaticAnalysisFramework/Analyses/EntityPointerLevel/EntityPointerLevel.h
@@ -116,7 +116,7 @@ createEntityPointerLevel(const NamedDecl *ND,
 /// Creates a new EntityPointerLevel (EPL) from `E` by incrementing `E`'s
 /// pointer level.
 /// \return the EPL that is associated with the pointee (or array element) type
-/// of `E`'s associated pointer/array tyoe of the same entity.
+/// of `E`'s associated pointer/array type of the same entity.
 EntityPointerLevel incrementPointerLevel(const EntityPointerLevel &E);
 } // namespace clang::ssaf
 
diff --git a/clang/lib/ScalableStaticAnalysisFramework/Analyses/SSAFAnalysesCommon.cpp b/clang/lib/ScalableStaticAnalysisFramework/Analyses/SSAFAnalysesCommon.cpp
index 2d55511135d10..a00e7933165ef 100644
--- a/clang/lib/ScalableStaticAnalysisFramework/Analyses/SSAFAnalysesCommon.cpp
+++ b/clang/lib/ScalableStaticAnalysisFramework/Analyses/SSAFAnalysesCommon.cpp
@@ -67,8 +67,8 @@ class ContributorFactFinder : public DynamicRecursiveASTVisitor {
     if (!Node)
       return true;
     // To skip callables:
-    if (Node != RootDecl && isa<FunctionDecl, CXXConstructorDecl, BlockDecl,
-                                ObjCMethodDecl, RecordDecl>(Node))
+    if (Node != RootDecl &&
+        isa<FunctionDecl, BlockDecl, ObjCMethodDecl, RecordDecl>(Node))
       return true;
     match(*Node);
     return DynamicRecursiveASTVisitor::TraverseDecl(Node);
diff --git a/clang/lib/ScalableStaticAnalysisFramework/Analyses/SSAFAnalysesCommon.h b/clang/lib/ScalableStaticAnalysisFramework/Analyses/SSAFAnalysesCommon.h
index b9dcfcc9a7aad..e6759c1fb6e39 100644
--- a/clang/lib/ScalableStaticAnalysisFramework/Analyses/SSAFAnalysesCommon.h
+++ b/clang/lib/ScalableStaticAnalysisFramework/Analyses/SSAFAnalysesCommon.h
@@ -42,7 +42,7 @@ template <typename DeclOrExpr> bool hasPtrOrArrType(const DeclOrExpr *E) {
 inline llvm::Error makeEntityNameErr(clang::ASTContext &Ctx,
                                      const clang::NamedDecl *D) {
   return makeErrAtNode(Ctx, D, "failed to create entity name for %s",
-                       D->getNameAsString().data());
+                       D->getNameAsString().c_str());
 }
 
 namespace clang::ssaf {
diff --git a/clang/lib/ScalableStaticAnalysisFramework/Analyses/UnsafeBufferUsage/UnsafeBufferUsageExtractor.cpp b/clang/lib/ScalableStaticAnalysisFramework/Analyses/UnsafeBufferUsage/UnsafeBufferUsageExtractor.cpp
index 75137e7a5d640..770f20830c77b 100644
--- a/clang/lib/ScalableStaticAnalysisFramework/Analyses/UnsafeBufferUsage/UnsafeBufferUsageExtractor.cpp
+++ b/clang/lib/ScalableStaticAnalysisFramework/Analyses/UnsafeBufferUsage/UnsafeBufferUsageExtractor.cpp
@@ -14,7 +14,6 @@
 #include "clang/ScalableStaticAnalysisFramework/Analyses/EntityPointerLevel/EntityPointerLevel.h"
 #include "clang/ScalableStaticAnalysisFramework/Analyses/UnsafeBufferUsage/UnsafeBufferUsage.h"
 #include "clang/ScalableStaticAnalysisFramework/Core/ASTEntityMapping.h"
-#include "clang/ScalableStaticAnalysisFramework/Core/Model/EntityId.h"
 #include "clang/ScalableStaticAnalysisFramework/Core/Model/EntityName.h"
 #include "clang/ScalableStaticAnalysisFramework/Core/TUSummary/ExtractorRegistry.h"
 #include "clang/ScalableStaticAnalysisFramework/Core/TUSummary/TUSummaryBuilder.h"
@@ -27,13 +26,13 @@ using namespace clang;
 using namespace ssaf;
 
 namespace {
-static std::set<const Expr *>
+std::set<const Expr *>
 findUnsafePointersInContributor(const DynTypedNode &Node) {
   const Decl *D = Node.get<Decl>();
 
   if (!D)
     return {};
-  if (isa<FunctionDecl>(D) || isa<VarDecl>(D))
+  if (isa<FunctionDecl, VarDecl>(D))
     return findUnsafePointers(D);
   if (auto *RD = dyn_cast<RecordDecl>(D)) {
     std::set<const Expr *> Result;
@@ -53,8 +52,6 @@ class UnsafeBufferUsageTUSummaryExtractor : public TUSummaryExtractor {
   UnsafeBufferUsageTUSummaryExtractor(TUSummaryBuilder &Builder)
       : TUSummaryExtractor(Builder) {}
 
-  EntityId addEntity(EntityName EN) { return SummaryBuilder.addEntity(EN); }
-
   Expected<std::unique_ptr<UnsafeBufferUsageEntitySummary>>
   extractEntitySummary(const NamedDecl *Contributor, ASTContext &Ctx);
 
@@ -118,7 +115,7 @@ void clang::ssaf::UnsafeBufferUsageTUSummaryExtractor::HandleTranslationUnit(
       llvm::reportFatalInternalError(makeEntityNameErr(Ctx, CD));
 
     auto [Ignored, InsertionSucceeded] = SummaryBuilder.addSummary(
-        addEntity(*ContributorName), std::move(*EntitySummary));
+        SummaryBuilder.addEntity(*ContributorName), std::move(*EntitySummary));
 
     assert(InsertionSucceeded && "duplicated contributor extraction");
   }



More information about the llvm-branch-commits mailing list