aboutsummaryrefslogtreecommitdiff
path: root/test/Analysis/null-deref-ps.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/Analysis/null-deref-ps.c')
-rw-r--r--test/Analysis/null-deref-ps.c39
1 files changed, 32 insertions, 7 deletions
diff --git a/test/Analysis/null-deref-ps.c b/test/Analysis/null-deref-ps.c
index 6e2074146c30..f37b4416f2a1 100644
--- a/test/Analysis/null-deref-ps.c
+++ b/test/Analysis/null-deref-ps.c
@@ -1,10 +1,16 @@
-// RUN: clang-cc -analyze -std=gnu99 -checker-cfref -verify %s -analyzer-constraints=basic -analyzer-store=basic &&
-// RUN: clang-cc -analyze -std=gnu99 -checker-cfref -verify %s -analyzer-constraints=range -analyzer-store=basic &&
-// RUN: clang-cc -analyze -std=gnu99 -checker-cfref -analyzer-store=region -analyzer-constraints=range -analyzer-purge-dead=false -verify %s &&
-// RUN: clang-cc -analyze -std=gnu99 -checker-cfref -analyzer-store=region -analyzer-constraints=range -verify %s
+// RUN: clang-cc -triple i386-apple-darwin10 -analyze -std=gnu99 -checker-cfref -verify %s -analyzer-constraints=basic -analyzer-store=basic &&
+// RUN: clang-cc -triple i386-apple-darwin10 -analyze -std=gnu99 -checker-cfref -verify %s -analyzer-constraints=range -analyzer-store=basic &&
+// RUN: clang-cc -triple i386-apple-darwin10 -analyze -std=gnu99 -checker-cfref -analyzer-store=region -analyzer-constraints=range -analyzer-purge-dead=false -verify %s &&
+// RUN: clang-cc -triple i386-apple-darwin10 -analyze -std=gnu99 -checker-cfref -analyzer-store=region -analyzer-constraints=range -verify %s
-#include<stdint.h>
-#include <assert.h>
+typedef unsigned uintptr_t;
+
+extern void __assert_fail (__const char *__assertion, __const char *__file,
+ unsigned int __line, __const char *__function)
+ __attribute__ ((__noreturn__));
+
+#define assert(expr) \
+ ((expr) ? (void)(0) : __assert_fail (#expr, __FILE__, __LINE__, __func__))
void f1(int *p) {
if (p) *p = 1;
@@ -72,6 +78,7 @@ int f4_b() {
else return; // expected-warning {{non-void function 'f4_b' should return a value}}
*p += 10; // expected-warning{{Dereference of null pointer}}
+ return 0;
}
@@ -102,6 +109,15 @@ int f6c(int *p, int *q) {
: bar3(p, 2, q); // no-warning
}
+void f6d(int *p) {
+ bar(p, 0);
+ // At this point, 'p' cannot be null.
+ if (!p) {
+ int *q = 0;
+ *q = 0xDEADBEEF; // no-warning
+ }
+}
+
int* qux();
int f7(int x) {
@@ -160,7 +176,7 @@ int* f7c2(int *x) {
}
-int f8(int *p, int *q) {
+void f8(int *p, int *q) {
if (!p)
if (p)
*p = 1; // no-warning
@@ -262,4 +278,13 @@ void f13() {
if (((((int) x) << 2) + 1) >> 1) *x = 1; // no-warning
}
+// PR 4759 - Attribute non-null checking by the analyzer was not correctly
+// handling pointer values that were undefined.
+void pr4759_aux(int *p) __attribute__((nonnull));
+
+void pr4759() {
+ int *p;
+ pr4759_aux(p); // expected-warning{{undefined}}
+}
+