================
@@ -0,0 +1,106 @@
+//===- CallGraphExtractor.cpp - Call Graph Summary Extractor 
--------------===//
+//
+// 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 "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/DeclObjC.h"
+#include "clang/Analysis/AnalysisDeclContext.h"
+#include "clang/Analysis/CallGraph.h"
+#include "clang/Basic/SourceManager.h"
+#include 
"clang/ScalableStaticAnalysisFramework/Analyses/CallGraph/CallGraphSummary.h"
+#include "clang/ScalableStaticAnalysisFramework/Core/ASTEntityMapping.h"
+#include 
"clang/ScalableStaticAnalysisFramework/Core/TUSummary/ExtractorRegistry.h"
+#include 
"clang/ScalableStaticAnalysisFramework/Core/TUSummary/TUSummaryBuilder.h"
+#include "llvm/ADT/STLExtras.h"
+#include <memory>
+
+using namespace clang;
+using namespace ssaf;
+
+namespace {
+class CallGraphExtractor final : public TUSummaryExtractor {
+public:
+  using TUSummaryExtractor::TUSummaryExtractor;
+
+private:
+  void HandleTranslationUnit(ASTContext &Ctx) override;
+
+  void handleCallGraphNode(const ASTContext &Ctx, const CallGraphNode *N);
+};
+} // namespace
+
+void CallGraphExtractor::HandleTranslationUnit(ASTContext &Ctx) {
+  CallGraph CG;
+  CG.addToCallGraph(
+      const_cast<TranslationUnitDecl *>(Ctx.getTranslationUnitDecl()));
+
+  for (const auto &N : llvm::make_second_range(CG)) {
+    if (N && N->getDecl() && N->getDefinition())
+      handleCallGraphNode(Ctx, N.get());
+  }
+}
+
+void CallGraphExtractor::handleCallGraphNode(const ASTContext &Ctx,
+                                             const CallGraphNode *N) {
+  const FunctionDecl *Definition = N->getDefinition();
+
+  // CallGraph does not work for primary templates.
----------------
steakhal wrote:

```suggestion
  // FIXME: `clang::CallGraph` does not create entries for primary templates.
```

https://github.com/llvm/llvm-project/pull/188753
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to