diff options
| author | Roman Divacky <rdivacky@FreeBSD.org> | 2010-07-13 17:21:42 +0000 |
|---|---|---|
| committer | Roman Divacky <rdivacky@FreeBSD.org> | 2010-07-13 17:21:42 +0000 |
| commit | 4ba675006b5a8edfc48b6a9bd3dcf54a70cc08f2 (patch) | |
| tree | 48b44512b5db8ced345df4a1a56b5065cf2a14d9 /test/Analysis/free.c | |
| parent | d7279c4c177bca357ef96ff1379fd9bc420bfe83 (diff) | |
Diffstat (limited to 'test/Analysis/free.c')
| -rw-r--r-- | test/Analysis/free.c | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/test/Analysis/free.c b/test/Analysis/free.c new file mode 100644 index 0000000000000..60bb3f2eb5a65 --- /dev/null +++ b/test/Analysis/free.c @@ -0,0 +1,71 @@ +// RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-experimental-checks -fblocks -verify %s +void free(void *); + +void t1 () { + int a[] = { 1 }; + free(a); // expected-warning {{Argument to free() is the address of the local variable 'a', which is not memory allocated by malloc()}} +} + +void t2 () { + int a = 1; + free(&a); // expected-warning {{Argument to free() is the address of the local variable 'a', which is not memory allocated by malloc()}} +} + +void t3 () { + static int a[] = { 1 }; + free(a); // expected-warning {{Argument to free() is the address of the static variable 'a', which is not memory allocated by malloc()}} +} + +void t4 (char *x) { + free(x); // no-warning +} + +void t5 () { + extern char *ptr(); + free(ptr()); // no-warning +} + +void t6 () { + free((void*)1000); // expected-warning {{Argument to free() is a constant address (1000), which is not memory allocated by malloc()}} +} + +void t7 (char **x) { + free(*x); // no-warning +} + +void t8 (char **x) { + // ugh + free((*x)+8); // no-warning +} + +void t9 () { +label: + free(&&label); // expected-warning {{Argument to free() is the address of the label 'label', which is not memory allocated by malloc()}} +} + +void t10 () { + free((void*)&t10); // expected-warning {{Argument to free() is the address of the function 't10', which is not memory allocated by malloc()}} +} + +void t11 () { + char *p = (char*)__builtin_alloca(2); + free(p); // expected-warning {{Argument to free() was allocated by alloca(), not malloc()}} +} + +void t12 () { + free(^{return;}); // expected-warning {{Argument to free() is a block, which is not memory allocated by malloc()}} +} + +void t13 (char a) { + free(&a); // expected-warning {{Argument to free() is the address of the parameter 'a', which is not memory allocated by malloc()}} +} + +static int someGlobal[2]; +void t14 () { + free(someGlobal); // expected-warning {{Argument to free() is the address of the global variable 'someGlobal', which is not memory allocated by malloc()}} +} + +void t15 (char **x, int offset) { + // Unknown value + free(x[offset]); // no-warning +} |
