1 /* PR middle-end/98166: bogus -Wmismatched-dealloc on user-defined allocator
2 and inlining
3 { dg-do compile }
4 { dg-options "-O2 -Wall" } */
5
6
7 void dealloc_shrt (short *p)
8 {
9 /* A positive offset would be diagnosed but a negative one must
10 not be. */
11 __builtin_free (p - 1); // { dg-bogus "-Wmismatched-dealloc" }
12 }
13
14 __attribute__ ((malloc (dealloc_shrt)))
15 short* alloc_shrt (int n) /* { return malloc (n) + 1; } */;
16
17 void test_nowarn_shrt (int n)
18 {
19 short *p = alloc_shrt (n);
20 dealloc_shrt (p);
21 }
22
23
24 void dealloc_int (int *p) /* { free (p - 1); } */;
25
26 __attribute__ ((malloc (dealloc_int, 1)))
27 int* alloc_int (int n)
28 {
29 return (int*)__builtin_malloc (n) + 1;
30 }
31
32 void test_nowarn_int (int n)
33 {
34 int *p = alloc_int (n);
35 dealloc_int (p); // { dg-bogus "-Wmismatched-dealloc" }
36 }
37
38
39 void dealloc_long (int, long *p) /* { free (p - 2); } */;
40
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;
45 }
46
47 void test_nowarn_long (int n)
48 {
49 long *p = alloc_long (n);
50 dealloc_long (0, p); // { dg-bogus "\\\[-Wmismatched-dealloc" }
51 }
52
53
54 inline void
55 dealloc_float (int, int, float *p) // { dg-message "deallocation function declared here" }
56 {
57 __builtin_free (p - 3);
58 }
59
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'" }
62
63 void test_nowarn_float (int n)
64 {
65 float *p = alloc_float (n);
66 dealloc_float (0, 1, p); // { dg-bogus "\\\[-Wmismatched-dealloc" }
67 }