[clang] [clang][StaticAnalyzer] Crash on loop unrolling mode (PR #82089)

via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 16 19:03:17 PST 2024


https://github.com/huang-me updated https://github.com/llvm/llvm-project/pull/82089

>From 4ebdf475b79d059c97881ad83aeecf677fb32631 Mon Sep 17 00:00:00 2001
From: huang-me <amos0107 at gmail.com>
Date: Sat, 17 Feb 2024 10:43:48 +0800
Subject: [PATCH] Fix crash on StaticAnalyzer loop unrolling

---
 clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp b/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
index a80352816be613..205f13fdcb81e3 100644
--- a/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
+++ b/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
@@ -226,6 +226,17 @@ static bool isPossiblyEscaped(ExplodedNode *N, const DeclRefExpr *DR) {
           return false;
       }
     }
+
+    if (const SwitchStmt *SS = dyn_cast<SwitchStmt>(S)) {
+      for(const Stmt *CB : dyn_cast<CompoundStmt>(SS->getBody())->body()) {
+        for (const Decl *D : dyn_cast<DeclStmt>(CB)->decls()) {
+          // Once we reach the declaration of the VD we can return.
+          if (D->getCanonicalDecl() == VD)
+            return false;
+        }
+      }
+    }
+
     // Check the usage of the pass-by-ref function calls and adress-of operator
     // on VD and reference initialized by VD.
     ASTContext &ASTCtx =



More information about the cfe-commits mailing list