[clang] [clang][ssaf] Add whole-program analysis execution layer (PR #186813)

Aviral Goel via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 16 21:53:13 PDT 2026


================
@@ -0,0 +1,144 @@
+//===- DerivedAnalysis.h --------------------------------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+//
+// Defines DerivedAnalysisBase (type-erased base known to AnalysisDriver) and
+// the typed intermediate DerivedAnalysis<ResultT, DepResultTs...> that
+// concrete analyses inherit from.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_CORE_ANALYSIS_DERIVEDANALYSIS_H
+#define LLVM_CLANG_SCALABLESTATICANALYSISFRAMEWORK_CORE_ANALYSIS_DERIVEDANALYSIS_H
+
+#include "clang/ScalableStaticAnalysisFramework/Core/Analysis/AnalysisBase.h"
+#include "clang/ScalableStaticAnalysisFramework/Core/Analysis/AnalysisName.h"
+#include "clang/ScalableStaticAnalysisFramework/Core/Analysis/AnalysisResult.h"
+#include "clang/ScalableStaticAnalysisFramework/Core/Analysis/AnalysisTraits.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/ErrorHandling.h"
+#include <map>
+#include <memory>
+#include <vector>
+
+namespace clang::ssaf {
+
+class AnalysisDriver;
+class AnalysisRegistry;
+
+/// Type-erased base for derived analyses. Known to AnalysisDriver.
+///
+/// Not subclassed directly -- use DerivedAnalysis<ResultT, DepResultTs...>.
+/// A derived analysis consumes previously produced AnalysisResult objects
+/// and computes a new one via an initialize/step/finalize lifecycle.
+class DerivedAnalysisBase : public AnalysisBase {
+  friend class AnalysisDriver;
+
+protected:
+  DerivedAnalysisBase() : AnalysisBase(AnalysisBase::Kind::Derived) {}
+
+private:
+  /// Called once with the dependency results before the step() loop.
+  ///
+  /// \param DepResults  Immutable results of all declared dependencies, keyed
+  ///                    by AnalysisName. Guaranteed to contain every name
+  ///                    returned by dependencyNames().
+  virtual llvm::Error initialize(
----------------
aviralg wrote:

I thought of passing these arguments directly to step. But step is called in a loop and passing arguments repeatedly would suggest that the arguments are changing on every call, which they are not. So I prefer an explicit initialize method for feeding the dependencies.

https://github.com/llvm/llvm-project/pull/186813


More information about the cfe-commits mailing list