[clang] 2fb29f8 - [analyzer][NFC] Modernize LivenessValues::isLive (#157800)

via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 10 03:15:00 PDT 2025


Author: Balazs Benics
Date: 2025-09-10T12:14:56+02:00
New Revision: 2fb29f8ee60305adfc2b7c8fb29a9379c1ebd184

URL: https://github.com/llvm/llvm-project/commit/2fb29f8ee60305adfc2b7c8fb29a9379c1ebd184
DIFF: https://github.com/llvm/llvm-project/commit/2fb29f8ee60305adfc2b7c8fb29a9379c1ebd184.diff

LOG: [analyzer][NFC] Modernize LivenessValues::isLive (#157800)

Removing statefullness also adds the benefit of short circuiting.

Added: 
    

Modified: 
    clang/lib/Analysis/LiveVariables.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Analysis/LiveVariables.cpp b/clang/lib/Analysis/LiveVariables.cpp
index 5e07d83c13384..74b930bf26fb6 100644
--- a/clang/lib/Analysis/LiveVariables.cpp
+++ b/clang/lib/Analysis/LiveVariables.cpp
@@ -72,15 +72,17 @@ bool LiveVariables::LivenessValues::isLive(const Expr *E) const {
 
 bool LiveVariables::LivenessValues::isLive(const VarDecl *D) const {
   if (const auto *DD = dyn_cast<DecompositionDecl>(D)) {
-    bool alive = false;
-    for (const BindingDecl *BD : DD->bindings())
-      alive |= liveBindings.contains(BD);
-
     // Note: the only known case this condition is necessary, is when a bindig
     // to a tuple-like structure is created. The HoldingVar initializers have a
     // DeclRefExpr to the DecompositionDecl.
-    alive |= liveDecls.contains(DD);
-    return alive;
+    if (liveDecls.contains(DD))
+      return true;
+
+    for (const BindingDecl *BD : DD->bindings()) {
+      if (liveBindings.contains(BD))
+        return true;
+    }
+    return false;
   }
   return liveDecls.contains(D);
 }


        


More information about the cfe-commits mailing list