================
@@ -40,6 +42,29 @@ static bool isChangedBefore(const Stmt *S, const Stmt 
*NextS, const Stmt *PrevS,
          SM.isBeforeInTranslationUnit(MutS->getEndLoc(), NextS->getBeginLoc());
 }
 
+/// Returns the outermost loop that encloses `S` and is itself enclosed by
+/// `Outer`, or null if there is no such loop. The walk passes through
+/// declarations, such as a variable initialized by a lambda, but stops at the
+/// enclosing function.
+static const Stmt *getOutermostLoopBetween(const Stmt *S, const Stmt *Outer,
+                                           ASTContext *Context) {
+  const Stmt *Loop = nullptr;
+  DynTypedNodeList Parents = Context->getParents(*S);
+  while (!Parents.empty()) {
+    const DynTypedNode Parent = Parents[0];
+    if (Parent.get<FunctionDecl>())
+      break;
+    if (const auto *ParentStmt = Parent.get<Stmt>()) {
+      if (ParentStmt == Outer)
+        break;
+      if (isa<ForStmt, WhileStmt, DoStmt, CXXForRangeStmt>(ParentStmt))
+        Loop = ParentStmt;
+    }
+    Parents = Context->getParents(Parent);
----------------
mamadou-wane wrote:

Added the comment in c19d0254d.

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

Reply via email to