[clang] [ssaf][UnsafeBufferUsage] Add JSON serialization for UnsafeBufferUsage (PR #187156)

Ziqing Luo via cfe-commits cfe-commits at lists.llvm.org
Sun Mar 29 16:04:18 PDT 2026


================
@@ -91,15 +93,35 @@ class UnsafeBufferUsageEntitySummary final : public EntitySummary {
       : EntitySummary(), UnsafeBuffers(std::move(UnsafeBuffers)) {}
 
 public:
-  SummaryName getSummaryName() const override {
-    return SummaryName{"UnsafeBufferUsage"};
-  };
+  SummaryName getSummaryName() const override { return summaryName(); };
 
   bool operator==(const EntityPointerLevelSet &Other) const {
     return UnsafeBuffers == Other;
   }
 
+  bool operator==(const UnsafeBufferUsageEntitySummary &Other) const {
+    return UnsafeBuffers == Other.UnsafeBuffers;
+  }
+
   bool empty() const { return UnsafeBuffers.empty(); }
+
+  static llvm::json::Object
+  jsonSerializeFn(const EntitySummary &ES,
+                  JSONFormat::EntityIdToJSONFn EntityId2JSON);
+
+  static llvm::Expected<std::unique_ptr<EntitySummary>>
+  jsonDeserializeFn(const llvm::json::Object &Data, EntityIdTable &,
+                    JSONFormat::EntityIdFromJSONFn EntityIdFromJSON);
----------------
ziqingluo-90 wrote:

I think we could borrow `json`'s API:  each summary serialization code just operates Object, Array, Value, etc..   The JSON format implementation uses `json::Object, json::Array, ...` while other formats need to implement their own `Object, Array, Value ...`.    I changed my code to show this idea. Consequently, the serialization test becomes format-independent with a Mock implementation of the API.

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


More information about the cfe-commits mailing list