Debian Codegraph @

gcc/testsuite/gcc.dg/attr-alloc_size-9.c

raw
1 /* PR c/78284 - warn on malloc with very large arguments
2 Test verifying that the built-in allocation functions are declared
3 with attribute malloc. This means that the pointer they return
4 can be assumed not to alias any other valid pointer. */
5 /* { dg-do compile } */
6 /* { dg-options "-O2 -fdump-tree-optimized" } */
7
8 void sink (void*);
9
10 extern int x;
11
12 #define TEST(call) \
13 do { \
14 p = call; \
15 x = 123; \
16 *(int*)p = 456; \
17 (x == 123) ? (void)0 : __builtin_abort (); \
18 sink (p); \
19 } while (0)
20
21 void test (void *p, unsigned n)
22 {
23 TEST (__builtin_aligned_alloc (8, n));
24 TEST (__builtin_alloca (n));
25 TEST (__builtin_calloc (4, n));
26 TEST (__builtin_malloc (n));
27 TEST (__builtin_realloc (p, n + 1));
28 }
29
30 /* { dg-final { scan-tree-dump-not "abort" "optimized" } } */