1 /* PR c/78668 - aligned_alloc, realloc, et al. missing attribute alloc_size
2 Test to verify that memory allocation built-ins are decorated with
3 attribute alloc_size that __builtin_object_size can make use of (or
4 are treated as if they were for that purpose)..
6 { dg-additional-options "-O2 -fdump-tree-optimized" } */
10 unsigned size (unsigned n
)
15 void test_aligned_alloc (unsigned a
)
17 unsigned n
= size (7);
19 void *p
= __builtin_aligned_alloc (n
, a
);
20 if (__builtin_object_size (p
, 0) != n
)
25 void test_alloca (void)
27 unsigned n
= size (13);
29 void *p
= __builtin_alloca (n
);
31 /* Also verify that alloca is declared with attribute returns_nonnull
32 (or treated as it were as the case may be). */
36 if (__builtin_object_size (p
, 0) != n
)
41 void test_calloc (void)
43 unsigned m
= size (19);
44 unsigned n
= size (23);
46 void *p
= __builtin_calloc (m
, n
);
47 if (__builtin_object_size (p
, 0) != m
* n
)
52 void test_malloc (void)
54 unsigned n
= size (17);
56 void *p
= __builtin_malloc (n
);
57 if (__builtin_object_size (p
, 0) != n
)
62 void test_realloc (void *p
)
64 unsigned n
= size (31);
66 p
= __builtin_realloc (p
, n
);
67 if (__builtin_object_size (p
, 0) != n
)
72 /* { dg-final { scan-tree-dump-not "abort" "optimized" } } */