================
@@ -0,0 +1,88 @@
+//===---------- 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
+#include "llvm/Support/Error.h"
+
+namespace {
+constexpr const char *const UnsafeBuffersKey = "UnsafeBuffers";
+} // namespace
+
+namespace clang::ssaf {
+using Object = llvm::json::Object;
+using Array = llvm::json::Array;
+
+llvm::json::Object UnsafeBufferUsageEntitySummary::jsonSerializeFn(
+    const EntitySummary &ES, JSONFormat::EntityIdToJSONFn EntityIdToJSON) {
+  // 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(Array{// EntityId:
+                                      EntityIdToJSON(EPL.getEntity()),
+                                      // PointerLevel:
+                                      EPL.getPointerLevel()});
+
+  Object Data;
+
+  Data[UnsafeBuffersKey] = std::move(UnsafeBuffersData);
+  return Data;
----------------
steakhal wrote:

I think we could express this in a more compact way like this:

```suggestion
  json::Array UnsafeBuffersData;
  UnsafeBuffersData.reserve(S.UnsafeBuffers.size());
  for (const auto &[EntityID, PtrLevel] : S.UnsafeBuffers) {
    UnsafeBuffersData.push_back(Array{EntityIdToJSON(EntityID), PtrLevel});
  }
  return json::Object{{UnsafeBuffersKey, std::move(UnsafeBuffersData)}};
```

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

Reply via email to