(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
pr85388-3.c
       1  /* This test needs to use setrlimit to set the stack size, so it can
       2     only run on Unix.  */
       3  /* { dg-do run { target { i?86-*-linux* i?86-*-gnu* x86_64-*-linux* } } } */
       4  /* { dg-require-effective-target cet } */
       5  /* { dg-require-effective-target split_stack } */
       6  /* { dg-options "-fsplit-stack -fcf-protection" } */
       7  
       8  #include <stdarg.h>
       9  #include <stdlib.h>
      10  #include <sys/types.h>
      11  #include <sys/resource.h>
      12  
      13  /* Use a noinline function to ensure that the buffer is not removed
      14     from the stack.  */
      15  static void use_buffer (char *buf) __attribute__ ((noinline));
      16  static void
      17  use_buffer (char *buf)
      18  {
      19    buf[0] = '\0';
      20  }
      21  
      22  /* Each recursive call uses 10,000 bytes.  We call it 1000 times,
      23     using a total of 10,000,000 bytes.  If -fsplit-stack is not
      24     working, that will overflow our stack limit.  */
      25  
      26  static void
      27  down (int i, ...)
      28  {
      29    char buf[10000];
      30    va_list ap;
      31  
      32    va_start (ap, i);
      33    if (va_arg (ap, int) != 1
      34        || va_arg (ap, int) != 2
      35        || va_arg (ap, int) != 3
      36        || va_arg (ap, int) != 4
      37        || va_arg (ap, int) != 5
      38        || va_arg (ap, int) != 6
      39        || va_arg (ap, int) != 7
      40        || va_arg (ap, int) != 8
      41        || va_arg (ap, int) != 9
      42        || va_arg (ap, int) != 10)
      43      abort ();
      44  
      45    if (i > 0)
      46      {
      47        use_buffer (buf);
      48        down (i - 1, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
      49      }
      50  }
      51  
      52  int
      53  main (void)
      54  {
      55    struct rlimit r;
      56  
      57    /* We set a stack limit because we are usually invoked via make, and
      58       make sets the stack limit to be as large as possible.  */
      59    r.rlim_cur = 8192 * 1024;
      60    r.rlim_max = 8192 * 1024;
      61    if (setrlimit (RLIMIT_STACK, &r) != 0)
      62      abort ();
      63    down (1000, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
      64    return 0;
      65  }