(root)/
gcc-13.2.0/
gcc/
testsuite/
gcc.dg/
vla-stexp-4.c
       1  /* PR29970, PR91038 */
       2  /* { dg-do run } */
       3  /* { dg-options "-O0 -Wunused-variable" } */
       4  /* { dg-require-effective-target alloca } */
       5  
       6  int foo3b(void)   // should not return 0
       7  {
       8          int n = 0;
       9          return sizeof *({ n = 10; int x[n]; &x; });
      10  }
      11  
      12  int foo4(void)   // should not ICE
      13  {
      14          return (*({
      15                          int n = 20;
      16                          char (*x)[n][n] = __builtin_malloc(n * n);
      17                          (*x)[12][1] = 1;
      18                          x;
      19                  }))[12][1];
      20  }
      21  
      22  int foo5(void)   // should return 1, returns 0
      23  {
      24          int n = 0;
      25          return (*({
      26                          n = 20;
      27                          char (*x)[n][n] = __builtin_malloc(n * n);
      28                          (*x)[12][1] = 1;
      29                          (*x)[0][1] = 0;
      30                          x;
      31                  }))[12][1];
      32  }
      33  
      34  int foo5c(void)   // should return 400 
      35  {
      36          int n = 0;
      37          return sizeof(*({
      38                          n = 20;
      39                          char (*x)[n][n] = __builtin_malloc(n * n);
      40                          (*x)[12][1] = 1;
      41                          (*x)[0][1] = 0;
      42                          x;
      43                  }));
      44  }
      45  
      46  int foo5b(void)   // should return 1, returns 0
      47  {
      48  	int n = 0;			/* { dg-warning "unused variable" } */
      49          return (*({
      50                          int n = 20;
      51                          char (*x)[n][n] = __builtin_malloc(n * n);
      52                          (*x)[12][1] = 1;
      53                          (*x)[0][1] = 0;
      54                          x;
      55                  }))[12][1];
      56  }
      57  
      58  int foo5a(void)   // should return 1, returns 0
      59  {
      60          return (*({
      61                          int n = 20;
      62                          char (*x)[n][n] = __builtin_malloc(n * n);
      63                          (*x)[12][1] = 1;
      64                          (*x)[0][1] = 0;
      65                          x;
      66                  }))[12][1];
      67  }
      68  
      69  
      70  
      71  
      72  int main()
      73  {
      74  	if (sizeof(int[10]) != foo3b())
      75  		__builtin_abort();
      76  
      77  	if (1 != foo4())
      78  		__builtin_abort();
      79  
      80  	if (400 != foo5c())
      81  		__builtin_abort();
      82  
      83  	if (1 != foo5a())
      84  		__builtin_abort();
      85  
      86  	if (1 != foo5b()) // -O0
      87  		__builtin_abort();
      88  
      89  	if (1 != foo5())
      90  		__builtin_abort();
      91  
      92  	return 0;
      93  }
      94  
      95