[llvm-branch-commits] [clang] [ssaf][UnsafeBufferUsage] Add JSON serialization for UnsafeBufferUsage (PR #187156)
Aviral Goel via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Mar 18 10:07:16 PDT 2026
================
@@ -0,0 +1,89 @@
+//===---------- UnsafeBufferUsage.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 "clang/ScalableStaticAnalysisFramework/Analyses/UnsafeBufferUsage/UnsafeBufferUsage.h"
+#include "clang/ScalableStaticAnalysisFramework/SSAFForceLinker.h" // IWYU pragma: keep
+
+namespace {
+constexpr const char *const UnsafeBuffersKey = "UnsafeBuffers";
+} // namespace
+
+namespace clang::ssaf {
+using Object = llvm::json::Object;
+using Array = llvm::json::Array;
+using Value = llvm::json::Value;
+
+llvm::json::Object UnsafeBufferUsageEntitySummary::jsonSerializeFn(
+ const EntitySummary &ES, JSONFormat::EntityIdToJSONFn EntityId2JSON) {
+ // Writes a EntityPointerLevel as
+ // Array {
+ // Object {
+ // "@" : [entity-id]
+ // },
+ // [pointer-level]
+ // }
+ Array UnsafeBuffersData;
+
+ for (const auto &EPL :
+ static_cast<const UnsafeBufferUsageEntitySummary &>(ES).UnsafeBuffers)
+ UnsafeBuffersData.push_back(
+ Value(Array{// EntityId:
+ Value(EntityId2JSON(EPL.getEntity())),
+ // PointerLevel:
+ Value(EPL.getPointerLevel())}));
+
+ Object Data;
+
+ Data[UnsafeBuffersKey] = Value(std::move(UnsafeBuffersData));
+ return Data;
+}
+
+llvm::Expected<std::unique_ptr<EntitySummary>>
+UnsafeBufferUsageEntitySummary::jsonDeserializeFn(
+ const llvm::json::Object &Data, EntityIdTable &,
+ JSONFormat::EntityIdFromJSONFn EntityIdFromJSON) {
----------------
aviralg wrote:
If you want shorter name, it could be FromJSON. But this is up to you.
https://github.com/llvm/llvm-project/pull/187156
More information about the llvm-branch-commits
mailing list