[Heikki Kultala] This patch contains the ABI changes for the TCE target.
[clang.git] / test / Analysis / free.c
blob60bb3f2eb5a650a8ca4882df4733975f1121182b
1 // RUN: %clang_cc1 -analyze -analyzer-experimental-internal-checks -analyzer-check-objc-mem -analyzer-store=region -analyzer-experimental-checks -fblocks -verify %s
2 void free(void *);
4 void t1 () {
5 int a[] = { 1 };
6 free(a); // expected-warning {{Argument to free() is the address of the local variable 'a', which is not memory allocated by malloc()}}
9 void t2 () {
10 int a = 1;
11 free(&a); // expected-warning {{Argument to free() is the address of the local variable 'a', which is not memory allocated by malloc()}}
14 void t3 () {
15 static int a[] = { 1 };
16 free(a); // expected-warning {{Argument to free() is the address of the static variable 'a', which is not memory allocated by malloc()}}
19 void t4 (char *x) {
20 free(x); // no-warning
23 void t5 () {
24 extern char *ptr();
25 free(ptr()); // no-warning
28 void t6 () {
29 free((void*)1000); // expected-warning {{Argument to free() is a constant address (1000), which is not memory allocated by malloc()}}
32 void t7 (char **x) {
33 free(*x); // no-warning
36 void t8 (char **x) {
37 // ugh
38 free((*x)+8); // no-warning
41 void t9 () {
42 label:
43 free(&&label); // expected-warning {{Argument to free() is the address of the label 'label', which is not memory allocated by malloc()}}
46 void t10 () {
47 free((void*)&t10); // expected-warning {{Argument to free() is the address of the function 't10', which is not memory allocated by malloc()}}
50 void t11 () {
51 char *p = (char*)__builtin_alloca(2);
52 free(p); // expected-warning {{Argument to free() was allocated by alloca(), not malloc()}}
55 void t12 () {
56 free(^{return;}); // expected-warning {{Argument to free() is a block, which is not memory allocated by malloc()}}
59 void t13 (char a) {
60 free(&a); // expected-warning {{Argument to free() is the address of the parameter 'a', which is not memory allocated by malloc()}}
63 static int someGlobal[2];
64 void t14 () {
65 free(someGlobal); // expected-warning {{Argument to free() is the address of the global variable 'someGlobal', which is not memory allocated by malloc()}}
68 void t15 (char **x, int offset) {
69 // Unknown value
70 free(x[offset]); // no-warning