Require target lra in gcc.dg/pr108095.c
[official-gcc.git] / gcc / testsuite / c-c++-common / Wmismatched-dealloc.c
blob27af2c2316b56590a7dcc264e589f41bd702aba1
1 /* PR middle-end/98166: bogus -Wmismatched-dealloc on user-defined allocator
2 and inlining
3 { dg-do compile }
4 { dg-options "-O2 -Wall" } */
7 void dealloc_shrt (short *p)
9 /* A positive offset would be diagnosed but a negative one must
10 not be. */
11 __builtin_free (p - 1); // { dg-bogus "-Wmismatched-dealloc" }
14 __attribute__ ((malloc (dealloc_shrt)))
15 short* alloc_shrt (int n) /* { return malloc (n) + 1; } */;
17 void test_nowarn_shrt (int n)
19 short *p = alloc_shrt (n);
20 dealloc_shrt (p);
24 void dealloc_int (int *p) /* { free (p - 1); } */;
26 __attribute__ ((malloc (dealloc_int, 1)))
27 int* alloc_int (int n)
29 return (int*)__builtin_malloc (n) + 1;
32 void test_nowarn_int (int n)
34 int *p = alloc_int (n);
35 dealloc_int (p); // { dg-bogus "-Wmismatched-dealloc" }
39 void dealloc_long (int, long *p) /* { free (p - 2); } */;
41 __attribute__ ((malloc (dealloc_long, 2)))
42 inline long*
43 alloc_long (int n) { // { dg-warning "'malloc \\(\[^\n\r\]*dealloc_long\[^\n\r\]*\\)' attribute ignored on functions declared 'inline'" }
44 return (long*)__builtin_malloc (n) + 2;
47 void test_nowarn_long (int n)
49 long *p = alloc_long (n);
50 dealloc_long (0, p); // { dg-bogus "\\\[-Wmismatched-dealloc" }
54 inline void
55 dealloc_float (int, int, float *p) // { dg-message "deallocation function declared here" }
57 __builtin_free (p - 3);
60 __attribute__ ((malloc (dealloc_float, 3)))
61 float* alloc_float (int n); // { dg-warning "'malloc \\(\[^\n\r\]*dealloc_float\[^\n\r\]*\\)' attribute ignored with deallocation functions declared 'inline'" }
63 void test_nowarn_float (int n)
65 float *p = alloc_float (n);
66 dealloc_float (0, 1, p); // { dg-bogus "\\\[-Wmismatched-dealloc" }