summaryrefslogtreecommitdiffstats
path: root/clang/test/Analysis
diff options
context:
space:
mode:
authorJordan Rose <jordan_rose@apple.com>2012-07-26 20:04:25 +0000
committerJordan Rose <jordan_rose@apple.com>2012-07-26 20:04:25 +0000
commit20edae8749c7967718d2f2bfca76b1a6d39eca8f (patch)
treee12266cca834b1c4ea7c42f0bc42a01643898ac2 /clang/test/Analysis
parent54529a347e13c789ebb544fdae75a2651085b95f (diff)
downloadbcm5719-llvm-20edae8749c7967718d2f2bfca76b1a6d39eca8f.tar.gz
bcm5719-llvm-20edae8749c7967718d2f2bfca76b1a6d39eca8f.zip
[analyzer] Don't crash on array constructors and destructors.
This workaround is fairly lame: we simulate the first element's constructor and destructor and rely on the region invalidation to "initialize" the rest of the elements. llvm-svn: 160809
Diffstat (limited to 'clang/test/Analysis')
-rw-r--r--clang/test/Analysis/dtor.cpp37
1 files changed, 35 insertions, 2 deletions
diff --git a/clang/test/Analysis/dtor.cpp b/clang/test/Analysis/dtor.cpp
index f5837539cb7..4e3c0017f4a 100644
--- a/clang/test/Analysis/dtor.cpp
+++ b/clang/test/Analysis/dtor.cpp
@@ -1,4 +1,6 @@
-// RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.Malloc -analyzer-store region -analyzer-ipa=inlining -cfg-add-implicit-dtors -cfg-add-initializers -verify %s
+// RUN: %clang_cc1 -analyze -analyzer-checker=core,unix.Malloc,debug.ExprInspection -analyzer-store region -analyzer-ipa=inlining -cfg-add-implicit-dtors -cfg-add-initializers -verify %s
+
+void clang_analyzer_eval(bool);
class A {
public:
@@ -100,7 +102,7 @@ void testMultipleInheritance3() {
// Remove dead bindings...
doSomething();
// destructor called here
- // expected-warning@25 {{Attempt to free released memory}}
+ // expected-warning@27 {{Attempt to free released memory}}
}
}
@@ -121,3 +123,34 @@ void testSmartPointerMember() {
}
*mem = 0; // expected-warning{{Use of memory after it is freed}}
}
+
+
+struct IntWrapper {
+ IntWrapper() : x(0) {}
+ ~IntWrapper();
+ int *x;
+};
+
+void testArrayInvalidation() {
+ int i = 42;
+ int j = 42;
+
+ {
+ IntWrapper arr[2];
+
+ // There should be no undefined value warnings here.
+ // Eventually these should be TRUE as well, but right now
+ // we can't handle array constructors.
+ clang_analyzer_eval(arr[0].x == 0); // expected-warning{{UNKNOWN}}
+ clang_analyzer_eval(arr[1].x == 0); // expected-warning{{UNKNOWN}}
+
+ arr[0].x = &i;
+ arr[1].x = &j;
+ clang_analyzer_eval(*arr[0].x == 42); // expected-warning{{TRUE}}
+ clang_analyzer_eval(*arr[1].x == 42); // expected-warning{{TRUE}}
+ }
+
+ // The destructors should have invalidated i and j.
+ clang_analyzer_eval(i == 42); // expected-warning{{UNKNOWN}}
+ clang_analyzer_eval(j == 42); // expected-warning{{UNKNOWN}}
+}
OpenPOWER on IntegriCloud