| 1 |
#include <stdio.h> |
| 2 |
|
| 3 |
struct test { |
| 4 |
int one; |
| 5 |
int two; |
| 6 |
}; |
| 7 |
|
| 8 |
void func2(const struct test *t) |
| 9 |
{ |
| 10 |
if (t->one == 0) |
| 11 |
printf("init func2\n"); |
| 12 |
|
| 13 |
if (t->two == 0) /* { dg-warning "uninitialized" } */ |
| 14 |
printf("uninit func2\n"); |
| 15 |
} |
| 16 |
|
| 17 |
void func1(struct test *t) |
| 18 |
{ |
| 19 |
t->one = 1; |
| 20 |
func2(t); |
| 21 |
} |
| 22 |
|
| 23 |
int func3(int num) |
| 24 |
{ |
| 25 |
if (num) |
| 26 |
return num; |
| 27 |
else |
| 28 |
return 0; |
| 29 |
} |
| 30 |
|
| 31 |
void func4(int *a, int max) |
| 32 |
{ |
| 33 |
int i; |
| 34 |
// skip the first |
| 35 |
for (i=1; i<max; i++) |
| 36 |
a[i] = 0; |
| 37 |
} |
| 38 |
|
| 39 |
void func5(const int *a, int max) |
| 40 |
{ |
| 41 |
/* a[0] is uninitialized, but the rest of the array is initialized. */ |
| 42 |
int i; |
| 43 |
for (i=0; i<max; i++) { |
| 44 |
if (a[i]) /* { dg-warning "uninitialized" "" { xfail *-*-* } } */ |
| 45 |
printf("func5: %d\n", i); |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
int func6(const int *num) |
| 50 |
{ |
| 51 |
if (*num) /* { dg-warning "uninitialized" } */ |
| 52 |
return *num; |
| 53 |
else |
| 54 |
return 0; |
| 55 |
} |
| 56 |
|
| 57 |
int j; |
| 58 |
int func7(void) |
| 59 |
{ |
| 60 |
return j; /* { dg-bogus "uninitialized" } */ |
| 61 |
} |
| 62 |
|
| 63 |
void func8(const int *a, int max) |
| 64 |
{ |
| 65 |
int i; |
| 66 |
for (i=0; i<max; i++) { |
| 67 |
if (a[i]) /* { dg-warning "uninitialized" } */ |
| 68 |
printf("func8: %d\n", i); |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
enum {RED, AMBER, GREEN, BLACK}; |
| 73 |
|
| 74 |
int test_1 (void) |
| 75 |
{ |
| 76 |
struct test t; /* { dg-message "region created on stack here" } */ |
| 77 |
|
| 78 |
func1(&t); |
| 79 |
return 0; |
| 80 |
} |
| 81 |
|
| 82 |
int test_2 (void) |
| 83 |
{ |
| 84 |
int num; /* { dg-message "region created on stack here" } */ |
| 85 |
|
| 86 |
func3(num); /* { dg-warning "use of uninitialized value 'num'" } */ |
| 87 |
return 0; |
| 88 |
} |
| 89 |
|
| 90 |
int test_3 (void) |
| 91 |
{ |
| 92 |
int arry[10]; |
| 93 |
|
| 94 |
func4(arry, 10); |
| 95 |
func5(arry, 10); |
| 96 |
|
| 97 |
return 0; |
| 98 |
} |
| 99 |
|
| 100 |
int test_4 (void) |
| 101 |
{ |
| 102 |
int num; /* { dg-message "region created on stack here" } */ |
| 103 |
|
| 104 |
func6(&num); |
| 105 |
return 0; |
| 106 |
} |
| 107 |
|
| 108 |
int test_5 (void) |
| 109 |
{ |
| 110 |
int arry_2[10]; /* { dg-message "region created on stack here" } */ |
| 111 |
|
| 112 |
printf("func7: %d\n", func7()); |
| 113 |
func8(arry_2, 10); |
| 114 |
|
| 115 |
return 0; |
| 116 |
} |
| 117 |
|
| 118 |
int test_6 (void) |
| 119 |
{ |
| 120 |
int go; /* { dg-message "region created on stack here" } */ |
| 121 |
int color = BLACK; |
| 122 |
|
| 123 |
switch (color) { |
| 124 |
case RED: |
| 125 |
case AMBER: |
| 126 |
go = 0; |
| 127 |
break; |
| 128 |
case GREEN: |
| 129 |
go = 1; |
| 130 |
break; |
| 131 |
} |
| 132 |
|
| 133 |
printf("go :%d\n", go); /* { dg-warning "use of uninitialized value 'go'" } */ |
| 134 |
|
| 135 |
return 0; |
| 136 |
} |