1 /* Verify that Glibc <stdlib.h> declarations are handled correctly
3 { dg-options "-Wall" } */
5 #define A(...) __attribute__ ((malloc (__VA_ARGS__), noipa))
7 typedef __SIZE_TYPE__
size_t;
9 /* All functions with the same standard deallocator are associated
12 void* calloc (size_t, size_t);
13 void* malloc (size_t);
14 void* realloc (void*, size_t);
16 A (__builtin_free
) void* aligned_alloc (size_t, size_t);
18 /* Like realloc(), reallocarray() is both an allocator and a deallocator.
19 It must be associated with both free() and with itself, but nothing
21 A (__builtin_free
) void* reallocarray (void*, size_t, size_t);
22 A (reallocarray
) void* reallocarray (void*, size_t, size_t);
24 A (__builtin_free
) extern char *canonicalize_file_name (const char*);
28 A (dealloc
) void* alloc (size_t);
35 void test_builtin_aligned_alloc (void *p
)
38 void *q
= __builtin_aligned_alloc (1, 2);
44 void *q
= __builtin_aligned_alloc (1, 2);
50 void *q
= __builtin_aligned_alloc (1, 2);
51 q
= __builtin_realloc (q
, 3);
57 void *q
= __builtin_aligned_alloc (1, 2);
65 q
= __builtin_aligned_alloc (1, 2); // { dg-message "returned from '__builtin_aligned_alloc'" }
67 dealloc (q
); // { dg-warning "'dealloc' called on pointer returned from a mismatched allocation function" }
72 void test_aligned_alloc (void *p
)
75 void *q
= aligned_alloc (1, 2);
81 void *q
= aligned_alloc (1, 2);
87 void *q
= aligned_alloc (1, 2);
88 q
= __builtin_realloc (q
, 3);
94 void *q
= aligned_alloc (1, 2);
101 void *q
= aligned_alloc (1, 2); // { dg-message "returned from 'aligned_alloc'" }
103 dealloc (q
); // { dg-warning "'dealloc' called on pointer returned from a mismatched allocation function" }
108 void test_reallocarray (void *p
)
111 void *q
= __builtin_aligned_alloc (1, 2);
112 q
= reallocarray (q
, 2, 3);
118 void *q
= aligned_alloc (1, 2);
119 q
= reallocarray (q
, 2, 3);
125 void *q
= __builtin_calloc (1, 2);
126 q
= reallocarray (q
, 2, 3);
132 void *q
= calloc (1, 2);
133 q
= reallocarray (q
, 2, 3);
139 void *q
= __builtin_malloc (1);
140 q
= reallocarray (q
, 2, 3);
146 void *q
= malloc (1);
147 q
= reallocarray (q
, 2, 3);
153 void *q
= __builtin_realloc (p
, 1);
154 q
= reallocarray (q
, 2, 3);
161 void *q
= realloc (p
, 1);
162 q
= reallocarray (q
, 2, 3);
168 void *q
= __builtin_strdup ("abc");
169 q
= reallocarray (q
, 3, 4);
175 void *q
= __builtin_strndup ("abcd", 3);
176 q
= reallocarray (q
, 4, 5);
183 q
= reallocarray (q
, 5, 6);
189 void *q
= alloc (1); // { dg-message "returned from 'alloc'" }
190 q
= reallocarray (q
, 6, 7); // { dg-warning "'reallocarray' called on pointer returned from a mismatched allocation function" }
197 void *q
= reallocarray (p
, 7, 8);
198 q
= __builtin_realloc (q
, 9);
205 void *q
= reallocarray (p
, 7, 8);
213 void *q
= reallocarray (p
, 8, 9);
214 q
= reallocarray (q
, 3, 4);
221 void *q
= reallocarray (p
, 9, 10);
222 q
= reallocarray (q
, 3, 4);
224 dealloc (q
); // { dg-warning "'dealloc' called on pointer returned from a mismatched allocation function" }
229 void test_canonicalize_filename (void *p
)
232 void *q
= canonicalize_file_name ("a");
238 void *q
= canonicalize_file_name ("b");
244 void *q
= canonicalize_file_name ("c");
245 q
= __builtin_realloc (q
, 2);
251 void *q
= canonicalize_file_name ("d");
258 void *q
= canonicalize_file_name ("e");
259 q
= reallocarray (q
, 4, 5);
266 q
= canonicalize_file_name ("f"); // { dg-message "returned from 'canonicalize_file_name'" }
268 dealloc (q
); // { dg-warning "'dealloc' called on pointer returned from a mismatched allocation function" }