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-require-effective-target alloca }
7 { dg-additional-options "-O2 -fdump-tree-optimized" } */
11 unsigned size (unsigned n
)
16 void test_aligned_alloc (unsigned a
)
18 unsigned n
= size (7);
20 void *p
= __builtin_aligned_alloc (a
, n
);
21 if (__builtin_object_size (p
, 0) != n
)
26 void test_alloca (void)
28 unsigned n
= size (13);
30 void *p
= __builtin_alloca (n
);
32 /* Also verify that alloca is declared with attribute returns_nonnull
33 (or treated as it were as the case may be). */
37 if (__builtin_object_size (p
, 0) != n
)
42 void test_calloc (void)
44 unsigned m
= size (19);
45 unsigned n
= size (23);
47 void *p
= __builtin_calloc (m
, n
);
48 if (__builtin_object_size (p
, 0) != m
* n
)
53 void test_malloc (void)
55 unsigned n
= size (17);
57 void *p
= __builtin_malloc (n
);
58 if (__builtin_object_size (p
, 0) != n
)
63 void test_realloc (void *p
)
65 unsigned n
= size (31);
67 p
= __builtin_realloc (p
, n
);
68 if (__builtin_object_size (p
, 0) != n
)
73 /* { dg-final { scan-tree-dump-not "abort" "optimized" } } */