1 /* PR middle-end/98166: bogus -Wmismatched-dealloc on user-defined allocator
3 Verify that the allocator can be declared inline without a warning when
4 it's associated with a standard deallocator. Associating an inline
5 deallocator with an allocator would cause false positives when the former
6 calls a deallocation function the allocator isn't associated with, so
7 that triggers a warning on declaration.
9 { dg-options "-O2 -Wall" } */
11 __attribute__ ((malloc (__builtin_free
)))
15 return (int*)__builtin_malloc (n
+ sizeof (int));
18 void test_nowarn_int (int n
)
21 int *p
= alloc_int (n
);
26 int *p
= alloc_int (n
);
27 __builtin_free (p
+ 1); // { dg-warning "\\\[-Wfree-nonheap-object" }
33 dealloc_long (long *p
)
35 __builtin_free (p
); // { dg-warning "'__builtin_free|void __builtin_free\\(void\\*\\)' called on pointer 'p|<unknown>' with nonzero offset" }
38 __attribute__ ((malloc (dealloc_long
)))
39 long* alloc_long (int); // { dg-warning "'malloc \\\(dealloc_long\\\)' attribute ignored with deallocation functions declared 'inline'" }
41 void test_nowarn_long (int n
)
44 long *p
= alloc_long (n
);
49 long *p
= alloc_long (n
);