aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/gnu2x-empty-init-1.c
blob: e7dc9dfde23297ca935bb6421f08eaf0a6f9d5f4 (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
/* Test C2X support for empty initializers: valid use cases with GNU
   extensions.  */
/* { dg-do run } */
/* { dg-options "-std=gnu2x" } */

extern void exit (int);
extern void abort (void);

void
f (int a)
{
  struct s { volatile int x[a]; };
  struct s b = {};
  for (int i = 0; i < a; i++)
    if (b.x[i] != 0)
      abort ();
  /* Overwrite contents of b.x before second call to make it more likely stack
     contents are nonzero if proper initialization did not occur.  */
  for (int i = 0; i < a; i++)
    b.x[i] = -1;
}

int
main (void)
{
  f (100);
  f (100);
  exit (0);
}