[clang] [alpha.webkit.UncountedCallArgsChecker] Don't assume local variables are safe & treat guarded local variable as safe function arguments (PR #82305)

Artem Dergachev via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 7 20:42:55 PST 2024


================
@@ -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


More information about the cfe-commits mailing list