[llvm-branch-commits] [clang] [SSAF][WPA] Add PointerFlowReachableAnalysis (PR #193097)
Jan Korous via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed Apr 29 16:01:03 PDT 2026
================
@@ -102,14 +109,125 @@ class PointerFlowAnalysis final
const PointerFlowEntitySummary &Summary) override {
auto EdgesOfEntity = getEdges(Summary);
- getResult().Edges[Id] = EdgeSet(EdgesOfEntity.begin(), EdgesOfEntity.end());
+ this->getResult().Edges[Id] =
+ EdgeSet(EdgesOfEntity.begin(), EdgesOfEntity.end());
return llvm::Error::success();
}
};
AnalysisRegistry::Add<PointerFlowAnalysis>
RegisterPointerFlowAnalysis("Whole-program pointer flow analysis");
+//===----------------------------------------------------------------------===//
+// PointerFlowReachableAnalysis---computes reachable node
+//===----------------------------------------------------------------------===//
+
+json::Object serializePointerFlowReachableAnalysisResult(
+ const UnsafeBufferReachableAnalysisResult &R,
+ JSONFormat::EntityIdToJSONFn IdToJSON) {
+ json::Object Result;
+
+ Result[UnsafeBufferReachableAnalysisResultName] =
+ entityPointerLevelMapToJSON(R.Reachables, IdToJSON);
+ return Result;
+}
+
+Expected<std::unique_ptr<AnalysisResult>>
+deserializePointerFlowReachableAnalysisResult(
+ const json::Object &Obj, JSONFormat::EntityIdFromJSONFn IdFromJSON) {
+ const json::Array *Content =
+ Obj.getArray(UnsafeBufferReachableAnalysisResultName);
+
+ if (!Content)
+ return makeSawButExpectedError(
+ Obj, "an object with a key %s",
+ UnsafeBufferReachableAnalysisResultName.data());
+
+ auto Reachables = entityPointerLevelMapFromJSON(*Content, IdFromJSON);
+
+ if (!Reachables)
+ return Reachables.takeError();
+
+ auto Ret = std::make_unique<UnsafeBufferReachableAnalysisResult>();
+
+ Ret->Reachables = std::move(*Reachables);
+ return Ret;
+}
+
+JSONFormat::AnalysisResultRegistry::Add<UnsafeBufferReachableAnalysisResult>
+ RegisterPointerFlowReachableResultForJSON(
+ serializePointerFlowReachableAnalysisResult,
+ deserializePointerFlowReachableAnalysisResult);
+
+/// Computes all the reachable "nodes" (pointers) in a pointer flow graph from a
----------------
jkorous-apple wrote:
AFAICT the only place where we specify the direction of the "flow" is the serialization format of `EdgeSet`.
https://github.com/llvm/llvm-project/pull/193089/changes#diff-1877fa0b0b0ba9a76918bda7016f7d5b9b0f9b4438ed73511cd3adee4a6aad71R22
Since the TU summary, the "no-op" aggregating analyses and this analysis and their serialization format share assumptions about the flow, I suggest we document it somewhere and link to that documentation from the doc comments. Perhaps `docs/ScalableStaticAnalysisFramework/developer-docs/analyses/PointerFlowAnalysis.rst`?
https://github.com/llvm/llvm-project/pull/193097
More information about the llvm-branch-commits
mailing list