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