summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/attr-alloc_size-9.c
blob: 0c50b0ab63cd3469196a29147cd2e0af6a64652a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* PR c/78284 - warn on malloc with very large arguments
   Test verifying that the built-in allocation functions are declared
   with attribute malloc.  This means that the pointer they return
   can be assumed not to alias any other valid pointer.  */
/* { dg-do compile } */
/* { dg-require-effective-target alloca } */
/* { dg-options "-O2 -fdump-tree-optimized" } */

void sink (void*);

extern int x;

#define TEST(call)				\
  do {						\
    p = call;					\
    x = 123;					\
    *(int*)p = 456;				\
    (x == 123) ? (void)0 : __builtin_abort ();	\
    sink (p);					\
  } while (0)

void test (void *p, unsigned n)
{
  TEST (__builtin_aligned_alloc (8, n));
  TEST (__builtin_alloca (n));
  TEST (__builtin_calloc (4, n));
  TEST (__builtin_malloc (n));
  TEST (__builtin_realloc (p, n + 1));
}

/* { dg-final { scan-tree-dump-not "abort" "optimized" } } */