[clang] [clang][ssaf] Add JSONFormat support for WPASuite (PR #187403)
Balázs Benics via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 31 09:55:49 PDT 2026
================
@@ -0,0 +1,465 @@
+//===- ExamplePlugin.cpp - Example SSAF plugin ----------------------------===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+//
+// A loadable plugin that demonstrates the full SSAF analysis pipeline.
+//
+//===----------------------------------------------------------------------===//
+
+#include "clang/ScalableStaticAnalysisFramework/Core/Model/EntityId.h"
+#include "clang/ScalableStaticAnalysisFramework/Core/Model/SummaryName.h"
+#include "clang/ScalableStaticAnalysisFramework/Core/Serialization/JSONFormat.h"
+#include "clang/ScalableStaticAnalysisFramework/Core/TUSummary/EntitySummary.h"
+#include "clang/ScalableStaticAnalysisFramework/Core/WholeProgramAnalysis/AnalysisName.h"
+#include "clang/ScalableStaticAnalysisFramework/Core/WholeProgramAnalysis/AnalysisRegistry.h"
+#include "clang/ScalableStaticAnalysisFramework/Core/WholeProgramAnalysis/AnalysisResult.h"
+#include "clang/ScalableStaticAnalysisFramework/Core/WholeProgramAnalysis/DerivedAnalysis.h"
+#include "clang/ScalableStaticAnalysisFramework/Core/WholeProgramAnalysis/SummaryAnalysis.h"
+#include "llvm/Support/Error.h"
+#include "llvm/Support/JSON.h"
+#include "llvm/Support/Registry.h"
+#include <algorithm>
+#include <memory>
+#include <string>
+#include <utility>
+#include <vector>
+
+using namespace clang::ssaf;
+using namespace llvm;
+
+namespace {
+
+//===----------------------------------------------------------------------===//
+// TagsEntitySummary
+//
+// Per-entity data: a list of string tags. Stored in the LU data section
+// under summary_name "TagsEntitySummary". Serialized as:
+// { "tags": ["tag1", "tag2", ...] }
+//===----------------------------------------------------------------------===//
+
+struct TagsEntitySummary final : EntitySummary {
+ static SummaryName summaryName() { return SummaryName("TagsEntitySummary"); }
+
+ SummaryName getSummaryName() const override {
+ return SummaryName("TagsEntitySummary");
+ }
+
+ std::vector<std::string> Tags;
+};
+
+json::Object serializeTagsEntitySummary(const EntitySummary &ES,
+ JSONFormat::EntityIdToJSONFn) {
+ const auto &S = static_cast<const TagsEntitySummary &>(ES);
+ json::Array TagsArray;
+ for (const auto &Tag : S.Tags) {
+ TagsArray.push_back(Tag);
+ }
----------------
steakhal wrote:
I smell some `llvm::append_range` here.
I wish we could show a good example by reserving before appending.
https://github.com/llvm/llvm-project/pull/187403
More information about the cfe-commits
mailing list