]> granicus.if.org Git - clang/commitdiff
[analyzer] Return an UnknownVal when we try to get the binding for a VLA.
authorJordan Rose <jordan_rose@apple.com>
Sat, 16 Jun 2012 01:28:00 +0000 (01:28 +0000)
committerJordan Rose <jordan_rose@apple.com>
Sat, 16 Jun 2012 01:28:00 +0000 (01:28 +0000)
This happens in C++ mode right at the declaration of a struct VLA;
MallocChecker sees a bind and tries to get see if it's an escaping bind.
It's likely that our handling of this is still incomplete, but it fixes a
crash on valid without disturbing anything else for now.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158587 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Core/RegionStore.cpp
test/Analysis/cxx-crashes.cpp

index 9c00d963432b180bbaa3b81d4dcfedbf1ff8ec9e..7f6aa9f935a8395ae12532b46953b9f423fe0b4d 100644 (file)
@@ -1055,8 +1055,12 @@ SVal RegionStoreManager::getBinding(Store store, Loc L, QualType T) {
   if (RTy->isUnionType())
     return UnknownVal();
 
-  if (RTy->isArrayType())
-    return getBindingForArray(store, R);
+  if (RTy->isArrayType()) {
+    if (RTy->isConstantArrayType())
+      return getBindingForArray(store, R);
+    else
+      return UnknownVal();
+  }
 
   // FIXME: handle Vector types.
   if (RTy->isVectorType())
index 17fc74d06f4611023f54a772b788b4120b1ccdb1..1ee81a20235e6fe74bbfb046316124bd43d7da4a 100644 (file)
@@ -1,4 +1,6 @@
-// RUN: %clang_cc1 -analyze -analyzer-checker=core -verify %s
+// RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.Malloc,debug.ExprInspection -verify %s
+
+void clang_analyzer_eval(bool);
 
 int f1(char *dst) {
   char *p = dst + 4;
@@ -54,3 +56,17 @@ struct C {
 void C::f() { }
 
 }
+
+
+void vla(int n) {
+  int nums[n];
+  nums[0] = 1;
+  clang_analyzer_eval(nums[0] == 1); // expected-warning{{TRUE}}
+  
+  // This used to fail with MallocChecker on, and /only/ in C++ mode.
+  // This struct is POD, though, so it should be fine to put it in a VLA.
+  struct { int x; } structs[n];
+  structs[0].x = 1;
+  clang_analyzer_eval(structs[0].x == 1); // expected-warning{{TRUE}}
+}
+