75 lines · c
1// RUN: %clang_cc1 -Wfree-nonheap-object -fsyntax-only -verify %s2 3void c1(int *a);4typedef __typeof__(sizeof(0)) size_t;5extern int g1 __attribute((cleanup(c1))); // expected-warning {{'cleanup' attribute only applies to local variables}}6int g2 __attribute((cleanup(c1))); // expected-warning {{'cleanup' attribute only applies to local variables}}7static int g3 __attribute((cleanup(c1))); // expected-warning {{'cleanup' attribute only applies to local variables}}8 9void t1(void)10{11 int v1 __attribute((cleanup)); // expected-error {{'cleanup' attribute takes one argument}}12 int v2 __attribute((cleanup(1, 2))); // expected-error {{'cleanup' attribute takes one argument}}13 14 static int v3 __attribute((cleanup(c1))); // expected-warning {{'cleanup' attribute only applies to local variables}}15 16 int v4 __attribute((cleanup(h))); // expected-error {{use of undeclared identifier 'h'}}17 18 int v5 __attribute((cleanup(c1)));19 int v6 __attribute((cleanup(v3))); // expected-error {{'cleanup' argument 'v3' is not a function}}20}21 22struct s {23 int a, b;24};25 26void c2(void);27void c3(struct s a);28 29void t2(void)30{31 int v1 __attribute__((cleanup(c2))); // expected-error {{'cleanup' function 'c2' must take 1 parameter}}32 int v2 __attribute__((cleanup(c3))); // expected-error {{'cleanup' function 'c3' parameter has type 'struct s' which is incompatible with type 'int *'}}33}34 35// This is a manufactured testcase, but gcc accepts it...36void c4(_Bool a);37void t4(void) {38 __attribute((cleanup(c4))) void* g;39}40 41void c5(void*) __attribute__((deprecated)); // expected-note{{'c5' has been explicitly marked deprecated here}}42void t5(void) {43 int i __attribute__((cleanup(c5))); // expected-warning {{'c5' is deprecated}}44}45 46void t6(void) {47 int i __attribute__((cleanup((void *)0))); // expected-error {{'cleanup' argument is not a function}}48}49 50void t7(__attribute__((cleanup(c4))) int a) {} // expected-warning {{'cleanup' attribute only applies to local variables}}51 52extern void free(void *);53extern void *malloc(size_t size);54void t8(void) {55 void *p56 __attribute__((57 cleanup(58 free // expected-warning{{attempt to call free on non-heap object 'p'}}59 )60 ))61 = malloc(10);62}63typedef __attribute__((aligned(2))) int Aligned2Int;64void t9(void){65 Aligned2Int __attribute__((cleanup(c1))) xwarn; // expected-warning{{passing 2-byte aligned argument to 4-byte aligned parameter 1 of 'c1' may result in an unaligned pointer access}}66}67 68__attribute__((enforce_tcb("TCB1"))) void func1(int *x) {69 *x = 5;70}71__attribute__((enforce_tcb("TCB2"))) void t10() {72 int __attribute__((cleanup(func1))) x = 5; // expected-warning{{calling 'func1' is a violation of trusted computing base 'TCB2'}}73}74 75