| 1 |
struct st |
| 2 |
{ |
| 3 |
int a, b, c, d, e; |
| 4 |
}; |
| 5 |
|
| 6 |
int |
| 7 |
test_1 (int flag, struct st *p) |
| 8 |
{ |
| 9 |
struct st *q; |
| 10 |
int result = 0; |
| 11 |
if (flag) |
| 12 |
q = p; |
| 13 |
/* We should only warn about the first use of uninit for 'q': */ |
| 14 |
result += q->a; /* { dg-warning "use of uninitialized value 'q'" } */ |
| 15 |
/* ...and not for these: */ |
| 16 |
result += q->b; /* { dg-bogus "use of uninitialized value 'q'" } */ |
| 17 |
result += q->c; /* { dg-bogus "use of uninitialized value 'q'" } */ |
| 18 |
result += q->d; /* { dg-bogus "use of uninitialized value 'q'" } */ |
| 19 |
result += q->e; /* { dg-bogus "use of uninitialized value 'q'" } */ |
| 20 |
return result; |
| 21 |
} |
| 22 |
|
| 23 |
int |
| 24 |
test_2 (int flag, struct st *p, struct st *r) |
| 25 |
{ |
| 26 |
struct st *q; |
| 27 |
int result = 0; |
| 28 |
if (flag) |
| 29 |
q = p; |
| 30 |
/* We should only warn about the first use of uninit for 'q': */ |
| 31 |
if (q == r) /* { dg-warning "use of uninitialized value 'q'" } */ |
| 32 |
result += 1; |
| 33 |
/* ...and not for these, after a conditional: */ |
| 34 |
result += q->b; /* { dg-bogus "use of uninitialized value 'q'" } */ |
| 35 |
result += q->c; /* { dg-bogus "use of uninitialized value 'q'" } */ |
| 36 |
result += q->d; /* { dg-bogus "use of uninitialized value 'q'" } */ |
| 37 |
result += q->e; /* { dg-bogus "use of uninitialized value 'q'" } */ |
| 38 |
return result; |
| 39 |
} |
| 40 |
|
| 41 |
int |
| 42 |
test_3 (int flag, int val) |
| 43 |
{ |
| 44 |
int result = 0; |
| 45 |
int idx; |
| 46 |
if (flag) |
| 47 |
idx = val; |
| 48 |
switch (idx) /* { dg-warning "use of uninitialized value 'idx'" } */ |
| 49 |
{ |
| 50 |
case 0: |
| 51 |
result = 3; |
| 52 |
break; |
| 53 |
case 1: |
| 54 |
result = 4; |
| 55 |
break; |
| 56 |
default: |
| 57 |
result = 5; |
| 58 |
break; |
| 59 |
} |
| 60 |
switch (idx) /* { dg-bogus "use of uninitialized value 'idx'" } */ |
| 61 |
{ |
| 62 |
case 0: |
| 63 |
result += 3; |
| 64 |
break; |
| 65 |
case 1: |
| 66 |
result += 4; |
| 67 |
break; |
| 68 |
default: |
| 69 |
result += 5; |
| 70 |
break; |
| 71 |
} |
| 72 |
return result; |
| 73 |
} |