summaryrefslogtreecommitdiffstats
path: root/test/Analysis/global-region-invalidation.c
diff options
context:
space:
mode:
authordim <dim@FreeBSD.org>2013-04-08 18:45:10 +0000
committerdim <dim@FreeBSD.org>2013-04-08 18:45:10 +0000
commitc72c57c9e9b69944e3e009cd5e209634839581d3 (patch)
tree4fc2f184c499d106f29a386c452b49e5197bf63d /test/Analysis/global-region-invalidation.c
parent5b20025c30d23d521e12c1f33ec8fa6b821952cd (diff)
downloadFreeBSD-src-c72c57c9e9b69944e3e009cd5e209634839581d3.zip
FreeBSD-src-c72c57c9e9b69944e3e009cd5e209634839581d3.tar.gz
Vendor import of clang trunk r178860:
http://llvm.org/svn/llvm-project/cfe/trunk@178860
Diffstat (limited to 'test/Analysis/global-region-invalidation.c')
-rw-r--r--test/Analysis/global-region-invalidation.c44
1 files changed, 41 insertions, 3 deletions
diff --git a/test/Analysis/global-region-invalidation.c b/test/Analysis/global-region-invalidation.c
index 2d64b49..77de9dd 100644
--- a/test/Analysis/global-region-invalidation.c
+++ b/test/Analysis/global-region-invalidation.c
@@ -67,15 +67,29 @@ int constIntGlob() {
return 3 / *m; // expected-warning {{Division by zero}}
}
-extern const int x;
+extern const int y;
int constIntGlobExtern() {
- if (x == 0) {
+ if (y == 0) {
foo();
- return 5 / x; // expected-warning {{Division by zero}}
+ return 5 / y; // expected-warning {{Division by zero}}
}
return 0;
}
+static void * const ptr = 0;
+void constPtrGlob() {
+ clang_analyzer_eval(ptr == 0); // expected-warning{{TRUE}}
+ foo();
+ clang_analyzer_eval(ptr == 0); // expected-warning{{TRUE}}
+}
+
+static const int x2 = x;
+void constIntGlob2() {
+ clang_analyzer_eval(x2 == 0); // expected-warning{{TRUE}}
+ foo();
+ clang_analyzer_eval(x2 == 0); // expected-warning{{TRUE}}
+}
+
void testAnalyzerEvalIsPure() {
extern int someGlobal;
if (someGlobal == 0) {
@@ -84,3 +98,27 @@ void testAnalyzerEvalIsPure() {
}
}
+// Test that static variables with initializers do not get reinitialized on
+// recursive calls.
+void Function2(void);
+int *getPtr();
+void Function1(void) {
+ static unsigned flag;
+ static int *p = 0;
+ if (!flag) {
+ flag = 1;
+ p = getPtr();
+ }
+ int m = *p; // no-warning: p is never null.
+ m++;
+ Function2();
+}
+void Function2(void) {
+ Function1();
+}
+
+void SetToNonZero(void) {
+ static int g = 5;
+ clang_analyzer_eval(g == 5); // expected-warning{{TRUE}}
+}
+
OpenPOWER on IntegriCloud