(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
Walloca-1.c
       1  /* { dg-do compile } */
       2  /* { dg-require-effective-target alloca } */
       3  /* { dg-options "-Walloca-larger-than=2000 -O2 -ftrack-macro-expansion=0" } */
       4  
       5  #define alloca __builtin_alloca
       6  
       7  typedef __SIZE_TYPE__ size_t;
       8  extern size_t strlen(const char *);
       9  
      10  extern void useit (char *);
      11  
      12  int num;
      13  
      14  void foo1 (size_t len, size_t len2, size_t len3)
      15  {
      16    int i;
      17  
      18    for (i=0; i < 123; ++i)
      19      {
      20        char *s = alloca (566);	/* { dg-warning "'alloca' within a loop" } */
      21        useit (s);
      22      }
      23  
      24    char *s = alloca (123);
      25    useit (s);			// OK, constant argument to alloca
      26  
      27    s = alloca (num);		// { dg-warning "\(may be too large|unbounded use\)" }
      28    useit (s);
      29  
      30    s = alloca (30000);		/* { dg-warning "is too large" } */
      31    useit (s);
      32  
      33    if (len < 2000)
      34      {
      35        s = alloca(len);		// OK, bounded
      36        useit (s);
      37      }
      38  
      39    if (len + len2 < 2000)	// OK, bounded
      40      {
      41        s = alloca(len + len2);
      42        useit (s);
      43      }
      44  
      45    if (len3 <= 2001)
      46      {
      47        s = alloca(len3);		/* { dg-warning "may be too large" } */
      48        useit(s);
      49      }
      50  }
      51  
      52  void foo2 (__SIZE_TYPE__ len)
      53  {
      54    // Test that a direct call to __builtin_alloca_with_align is not confused
      55    // with a VLA.
      56    void *p = __builtin_alloca_with_align (len, 8); // { dg-warning "unbounded use of 'alloca'" }
      57    useit (p);
      58  }
      59  
      60  void foo3 (unsigned char a)
      61  {
      62    if (a == 0)
      63      useit (__builtin_alloca (a)); // { dg-warning "argument to 'alloca' is zero" }
      64  }