[clang] [alpha.webkit.UncountedLocalVarsChecker] Ignore a VarDecl in "if" with trivial "then" (PR #171764)

Balázs Benics via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 11 08:04:57 PST 2025


================
@@ -492,4 +492,42 @@ namespace virtual_function {
     auto* baz = &*obj;
     // expected-warning at -1{{Local variable 'baz' is uncounted and unsafe [alpha.webkit.UncountedLocalVarsChecker]}}
   }
-}
\ No newline at end of file
+}
+
+namespace vardecl_in_if_condition {
+  RefCountable* provide();
+
+  RefCountable* get() {
+    if (auto* obj = provide())
+      return obj; // no warning
+    return nullptr;
+  }
+
+  RefCountable* get_non_trivial_then() {
+    if (auto* obj = provide()) // expected-warning{{Local variable 'obj' is uncounted and unsafe [alpha.webkit.UncountedLocalVarsChecker]}}
+      return obj->next();
+    return nullptr;
+  }
+
+  RefCountable* get_non_trivial_else() {
+    if (auto* obj = provide())
+      return obj;
+    else
+      return provide()->next();
+    return nullptr;
+  }
----------------
steakhal wrote:

I think `getConditionVariable()` should return the decl to the variable declared. and that variable is accessible from both the true and also from the false branches of the IfStmt. I'd insist of at least adding a test case.

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


More information about the cfe-commits mailing list