aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/Walloca-3.c
blob: b8000ff1249becc2c87506246963f60d502ba7fa (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
32
33
34
/* { dg-do compile } */
/* { dg-require-effective-target alloca } */
/* { dg-options "-Walloca-larger-than=2000 -O2" } */

void f (void *);

__SIZE_TYPE__ LIMIT;

// Warn when there is an alloca bound, but it is an unknown bound.

void
g1 (__SIZE_TYPE__ n)
{
  void *p;
  if (n < LIMIT)
    p = __builtin_alloca (n); // { dg-warning "may be too large" }
  else
    p = __builtin_malloc (n);
  f (p);
}

// Similar to the above, but do not get confused by the upcast.

unsigned short SHORT_LIMIT;
void
g2 (unsigned short n)
{
  void *p;
  if (n < SHORT_LIMIT)
    p = __builtin_alloca (n); // { dg-warning "may be too large" }
  else
    p = __builtin_malloc (n);
  f (p);
}