llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-static-analyzer-1

Author: None (huang-me)

<details>
<summary>Changes</summary>

StaticAnalyzer didn't check if the variable is declared in `CompoundStmt` under 
`SwitchStmt`, which make static analyzer reach root without finding the 
declaration.

Fixes #<!-- -->68819

---
Full diff: https://github.com/llvm/llvm-project/pull/82089.diff


1 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp (+11) 


``````````diff
diff --git a/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp 
b/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
index a80352816be613..b91dfa26774aa4 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 =

``````````

</details>


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

Reply via email to