[clang-tools-extra] [clang-tidy] In C++17, callee is guaranteed to be sequenced before arguments. (PR #93623)

Julian Schmidt via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 7 16:18:35 PDT 2024


================
@@ -69,6 +73,30 @@ class UseAfterMoveFinder {
   llvm::SmallPtrSet<const CFGBlock *, 8> Visited;
 };
 
+/// Returns whether the `Before` block can reach the `After` block.
+bool reaches(const CFGBlock *Before, const CFGBlock *After) {
+  llvm::SmallVector<const CFGBlock *> Stack;
+  llvm::SmallPtrSet<const CFGBlock *, 1> Visited;
+
+  Stack.push_back(Before);
+  while (!Stack.empty()) {
+    const CFGBlock *Current = Stack.back();
+    Stack.pop_back();
+
+    if (Current == After)
+      return true;
+
+    Visited.insert(Current);
+
+    for (const CFGBlock *Succ : Current->succs()) {
+      if (Succ && !Visited.contains(Succ))
+        Stack.push_back(Succ);
+    }
+  }
+
+  return false;
+}
+
----------------
5chmidti wrote:

What do you think about using https://github.com/llvm/llvm-project/blob/main/clang/include/clang/Analysis/Analyses/CFGReachabilityAnalysis.h?

We are rebuilding the CFG a lot of times and don't cache anything, so the caching in `CFGReverseBlockReachabilityAnalysis` won't have any worth until we do, but it is an existing implementation of what you are doing here, so we should at least consider it.

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


More information about the cfe-commits mailing list