Debian Codegraph @

gcc/testsuite/gcc.dg/uninit-pr89230-2.c

raw
1 /* PR middle-end/89230 - Bogus uninited usage warning with printf
2 { dg-do compile }
3 { dg-options "-O2 -Wall" } */
4
5 typedef __SIZE_TYPE__ size_t;
6
7 extern void* memset (void*, int, size_t);
8 extern int printf (const char*, ...);
9 extern int rand (void);
10
11 struct S
12 {
13 int a;
14 int b;
15 };
16
17 struct H
18 {
19 int c;
20 int d;
21 };
22
23 void getblk (void* blk)
24 {
25 struct S* s = (struct S*) blk;
26 memset (blk, 0, 512);
27 s->a = rand () & 1;
28 }
29
30 struct H* gethdr (void* blk)
31 {
32 memset (blk, 0, 512);
33 return rand () & 1 ? (struct H*) blk : 0;
34 }
35
36 int main (void)
37 {
38 char blk[512], tmp[512];
39 struct S *s = (struct S*) blk;
40 struct H *h;
41
42 getblk (blk);
43
44 if (s->a || !(h = gethdr (tmp)) || s->a != h->d) {
45
46 printf ("%d\n", s->b);
47 if (s->a)
48 printf ("s->a = %d\n", s->a);
49 else if (!h)
50 printf ("!h\n");
51 else
52 printf ("h->d = %d\n", h->d);
53 }
54 }