================
@@ -95,11 +103,136 @@ tryToFindPtrOrigin(const Expr *E, bool 
StopAtFirstRefCountedObj) {
   return {E, false};
 }
 
+bool isGuardedScopeEmbeddedInGuardianScope(const VarDecl *Guarded,
+                                           const VarDecl *MaybeGuardian) {
+  assert(Guarded);
+  assert(MaybeGuardian);
+
+  if (!MaybeGuardian->isLocalVarDecl())
+    return false;
+
+  const CompoundStmt *guardiansClosestCompStmtAncestor = nullptr;
+
+  ASTContext &ctx = MaybeGuardian->getASTContext();
+
+  for (DynTypedNodeList guardianAncestors = ctx.getParents(*MaybeGuardian);
----------------
haoNoQ wrote:

I haven't spent nearly enough time in such code but I suspect that instead of 
dealing with `Stmt`s, you should be dealing with `DeclContext`s. Decl contexts 
represent all the places where something can potentially be declared. Unlike 
statements, decl contexts naturally have parent pointers (so you don't have to 
invoke the Parent Map), and they should get you straight to the point without 
figuring out how many statements of which kind do you need to skip.

https://github.com/llvm/llvm-project/pull/82305
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to