1 // RUN: %clang_analyze_cc1 -analyzer-store=region -analyzer-checker=core,unix.Malloc -fblocks -verify %s
2 // RUN: %clang_analyze_cc1 -analyzer-store=region -analyzer-checker=core,unix.Malloc -fblocks -verify -analyzer-config unix.Malloc:Optimistic=true %s
3 typedef __typeof(sizeof(int)) size_t;
9 free(a); // expected-warning {{Argument to free() is the address of the local variable 'a', which is not memory allocated by malloc()}}
14 free(&a); // expected-warning {{Argument to free() is the address of the local variable 'a', which is not memory allocated by malloc()}}
18 static int a[] = { 1 };
19 free(a); // expected-warning {{Argument to free() is the address of the static variable 'a', which is not memory allocated by malloc()}}
23 free(x); // no-warning
28 free(ptr()); // no-warning
32 free((void*)1000); // expected-warning {{Argument to free() is a constant address (1000), which is not memory allocated by malloc()}}
36 free(*x); // no-warning
41 free((*x)+8); // no-warning
46 free(&&label); // expected-warning {{Argument to free() is the address of the label 'label', which is not memory allocated by malloc()}}
50 free((void*)&t10); // expected-warning {{Argument to free() is the address of the function 't10', which is not memory allocated by malloc()}}
54 char *p = (char*)alloca(2);
55 free(p); // expected-warning {{Memory allocated by alloca() should not be deallocated}}
59 char *p = (char*)__builtin_alloca(2);
60 free(p); // expected-warning {{Memory allocated by alloca() should not be deallocated}}
64 free(^{return;}); // expected-warning {{Argument to free() is a block, which is not memory allocated by malloc()}}
68 free(&a); // expected-warning {{Argument to free() is the address of the parameter 'a', which is not memory allocated by malloc()}}
71 static int someGlobal[2];
73 free(someGlobal); // expected-warning {{Argument to free() is the address of the global variable 'someGlobal', which is not memory allocated by malloc()}}
76 void t16 (char **x, int offset) {
78 free(x[offset]); // no-warning