aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/uninit-pr89230-2.c
blob: 473d2da5d3d2fbf30c43b1a5dcadb4fef9f18fe2 (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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* PR middle-end/89230 - Bogus uninited usage warning with printf
   { dg-do compile }
   { dg-options "-O2 -Wall" } */

typedef __SIZE_TYPE__ size_t;

extern void* memset (void*, int, size_t);
extern int printf (const char*, ...);
extern int rand (void);

struct S
{
  int a;
  int b;
};

struct H
{
  int c;
  int d;
};

void getblk (void* blk)
{
  struct S* s = (struct S*) blk;
  memset (blk, 0, 512);
  s->a = rand () & 1;
}

struct H* gethdr (void* blk)
{
  memset (blk, 0, 512);
  return rand () & 1 ? (struct H*) blk : 0;
}

int main (void)
{
  char blk[512], tmp[512];
  struct S *s = (struct S*) blk;
  struct H *h;

  getblk (blk);

  if (s->a  ||  !(h = gethdr (tmp))  ||  s->a != h->d) {

    printf ("%d\n", s->b);
    if (s->a)
      printf ("s->a = %d\n", s->a);
    else if (!h)
      printf ("!h\n");
    else
      printf ("h->d = %d\n", h->d);
  }
}