================
@@ -233,6 +236,47 @@ class UnsafeBufferReachableAnalysis
 
       updateReachablesWithOutgoings(Node, Worklist);
     }
+  }
+
+  // Filter out non-transformable pointers from `getResult().Result`, leaving
+  // only those that satisfy C3.
+  void filterTransformablePointers() {
+    assert(TypeConstrainedEntities &&
+           "The initialize(...) method should initialize "
+           "TypeConstrainedEntities to non-null");
+    auto &Result = getResult().Reachables;
+
+    for (auto &[Key, EPLs] : Result) {
+      for (auto ConstrainedEntityId : *TypeConstrainedEntities) {
+        // FIXME: optimization chance here.  Since both sets are sorted, the
+        // next 'equal_range' search can ignore everything before
+        // `NonTransEPLs.second`.
+        auto NonTransEPLs = EPLs.equal_range(ConstrainedEntityId);
+
+        EPLs.erase(NonTransEPLs.first, NonTransEPLs.second);
+      }
+    }
+  }
+
+public:
+  llvm::Error
+  initialize(const PointerFlowAnalysisResult &PtrFlowGraph,
+             const TypeConstrainedPointersAnalysisResult &TypeConstraints,
+             const UnsafeBufferUsageAnalysisResult &UnsafePtrs) override {
+    for (auto &[Id, SubGraph] : PtrFlowGraph.Edges)
+      BPG.try_emplace(Id, BoundsPropagationGraph(SubGraph));
+    TypeConstrainedEntities = &TypeConstraints.Entities;
+    assert(getResult().Reachables.empty());
+    // C1: all pointers in UnsafeBufferUsageAnalysisResult are unsafe
+    getResult().Reachables.insert(UnsafePtrs.begin(), UnsafePtrs.end());
+    return llvm::Error::success();
+  }
+
+  llvm::Expected<bool> step() override {
+    // result meets C1 & C2:
+    computeReachableUnsafePointers();
+    // result meets C1 & C2 & C3:
+    filterTransformablePointers();
----------------
ziqingluo-90 wrote:

No.  The result contains `ptr` and `foo`.
For this example, the graph is
```
(ptr, 1) -> (argv, 1) -> (foo, 1)
(ptr, 2) -> (argv, 2) -> (foo, 2)
```
with `(ptr, 1)`  and `(ptr, 2)` being known unsafe. 
The `computeReachableUnsafePointers` step will compute that all 6 
EntityPointerLevels (or simply, all three variables `ptr`, `argv` and `foo`) 
are unsafe.

The `filterTransformablePointers` will filter out `argv` only.  So the result 
is `ptr` and `foo`.  

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

Reply via email to