[PATCH] D80171: [analyzer] LoopUnrolling: fix crash when a parameter is a loop counter

Abbas Sabra via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 18 16:50:11 PDT 2020


AbbasSabra created this revision.
AbbasSabra added a reviewer: szepet.
Herald added subscribers: ASDenysPetrov, martong, Charusso, dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, zzheng, rnkovacs, baloghadamsoftware, xazax.hun.
Herald added a project: clang.

When loop counter is a function parameter "isPossiblyEscaped" will not find the variable declaration "VD" which lead to "llvm_unreachable". Parameters should be escaped like global variables to avoid a crash.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80171

Files:
  clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
  clang/test/Analysis/loop-unrolling.cpp


Index: clang/test/Analysis/loop-unrolling.cpp
===================================================================
--- clang/test/Analysis/loop-unrolling.cpp
+++ clang/test/Analysis/loop-unrolling.cpp
@@ -499,3 +499,9 @@
     clang_analyzer_numTimesReached(); // expected-warning {{6}}
   }
 }
+
+void arg_as_loop_counter(int i) {
+  for (i = 0; i < 10; ++i) {
+    (void)i;
+  }
+}
Index: clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
+++ clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp
@@ -160,8 +160,8 @@
 }
 
 static bool isPossiblyEscaped(const VarDecl *VD, ExplodedNode *N) {
-  // Global variables assumed as escaped variables.
-  if (VD->hasGlobalStorage())
+  // Global variables and parameters assumed as escaped variables.
+  if (VD->hasGlobalStorage() || VD->getKind() == Decl::ParmVar)
     return true;
 
   while (!N->pred_empty()) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80171.264751.patch
Type: text/x-patch
Size: 970 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200518/4d27d563/attachment.bin>


More information about the cfe-commits mailing list