| 1 |
/* Tests of brace-enclosed initializers |
| 2 |
Some of these use the CONSTRUCTOR tree code, but it appears |
| 3 |
only for a full zero-init; it appears that by the time the analyzer |
| 4 |
runs that this initialization has been converted into field-wise |
| 5 |
gimple assign stmts, with just "zero-init everything" CONSTRUCTORs |
| 6 |
and "clobber" CONSTRUCTORs. */ |
| 7 |
|
| 8 |
#include "../../gcc.dg/analyzer/analyzer-decls.h" |
| 9 |
|
| 10 |
struct coord |
| 11 |
{ |
| 12 |
int x; |
| 13 |
int y; |
| 14 |
}; |
| 15 |
|
| 16 |
struct tri |
| 17 |
{ |
| 18 |
struct coord v[3]; |
| 19 |
}; |
| 20 |
|
| 21 |
union iap |
| 22 |
{ |
| 23 |
int i; |
| 24 |
void *p; |
| 25 |
}; |
| 26 |
|
| 27 |
void test_1 (void) |
| 28 |
{ |
| 29 |
struct coord c = {3, 4}; |
| 30 |
__analyzer_eval (c.x == 3); /* { dg-warning "TRUE" } */ |
| 31 |
__analyzer_eval (c.y == 4); /* { dg-warning "TRUE" } */ |
| 32 |
} |
| 33 |
|
| 34 |
void test_2 (void) |
| 35 |
{ |
| 36 |
struct coord c = {3}; |
| 37 |
__analyzer_eval (c.x == 3); /* { dg-warning "TRUE" } */ |
| 38 |
__analyzer_eval (c.y == 0); /* { dg-warning "TRUE" } */ |
| 39 |
} |
| 40 |
|
| 41 |
void test_3 (void) |
| 42 |
{ |
| 43 |
struct coord c = {}; |
| 44 |
__analyzer_eval (c.x == 0); /* { dg-warning "TRUE" } */ |
| 45 |
__analyzer_eval (c.y == 0); /* { dg-warning "TRUE" } */ |
| 46 |
} |
| 47 |
|
| 48 |
void test_4 (void) |
| 49 |
{ |
| 50 |
int c[2] = {3, 4}; |
| 51 |
__analyzer_eval (c[0] == 3); /* { dg-warning "TRUE" } */ |
| 52 |
__analyzer_eval (c[1] == 4); /* { dg-warning "TRUE" } */ |
| 53 |
} |
| 54 |
|
| 55 |
void test_5 (void) |
| 56 |
{ |
| 57 |
int c[2] = {3}; |
| 58 |
__analyzer_eval (c[0] == 3); /* { dg-warning "TRUE" } */ |
| 59 |
__analyzer_eval (c[1] == 0); /* { dg-warning "TRUE" } */ |
| 60 |
} |
| 61 |
|
| 62 |
void test_6 (void) |
| 63 |
{ |
| 64 |
int c[2] = {}; |
| 65 |
__analyzer_eval (c[0] == 0); /* { dg-warning "TRUE" } */ |
| 66 |
__analyzer_eval (c[1] == 0); /* { dg-warning "TRUE" } */ |
| 67 |
} |
| 68 |
|
| 69 |
void test_7 (void) |
| 70 |
{ |
| 71 |
struct coord c[2] = {{3, 4}, {5, 6}}; |
| 72 |
__analyzer_eval (c[0].x == 3); /* { dg-warning "TRUE" } */ |
| 73 |
__analyzer_eval (c[0].y == 4); /* { dg-warning "TRUE" } */ |
| 74 |
__analyzer_eval (c[1].x == 5); /* { dg-warning "TRUE" } */ |
| 75 |
__analyzer_eval (c[1].y == 6); /* { dg-warning "TRUE" } */ |
| 76 |
} |
| 77 |
|
| 78 |
void test_8 (void) |
| 79 |
{ |
| 80 |
struct coord c[2] = {{3}, {5}}; |
| 81 |
__analyzer_eval (c[0].x == 3); /* { dg-warning "TRUE" } */ |
| 82 |
__analyzer_eval (c[0].y == 0); /* { dg-warning "TRUE" } */ |
| 83 |
__analyzer_eval (c[1].x == 5); /* { dg-warning "TRUE" } */ |
| 84 |
__analyzer_eval (c[1].y == 0); /* { dg-warning "TRUE" } */ |
| 85 |
} |
| 86 |
|
| 87 |
void test_9 (void) |
| 88 |
{ |
| 89 |
struct coord c[2] = {{}, {}}; |
| 90 |
__analyzer_eval (c[0].x == 0); /* { dg-warning "TRUE" } */ |
| 91 |
__analyzer_eval (c[0].y == 0); /* { dg-warning "TRUE" } */ |
| 92 |
__analyzer_eval (c[1].x == 0); /* { dg-warning "TRUE" } */ |
| 93 |
__analyzer_eval (c[1].y == 0); /* { dg-warning "TRUE" } */ |
| 94 |
} |
| 95 |
|
| 96 |
void test_10 (void) |
| 97 |
{ |
| 98 |
struct coord c[2] = {{.x = 3, .y = 4}, {5, 6}}; |
| 99 |
__analyzer_eval (c[0].x == 3); /* { dg-warning "TRUE" } */ |
| 100 |
__analyzer_eval (c[0].y == 4); /* { dg-warning "TRUE" } */ |
| 101 |
__analyzer_eval (c[1].x == 5); /* { dg-warning "TRUE" } */ |
| 102 |
__analyzer_eval (c[1].y == 6); /* { dg-warning "TRUE" } */ |
| 103 |
} |
| 104 |
|
| 105 |
void test_11 (void) |
| 106 |
{ |
| 107 |
struct coord c[2] = {{.y = 4}, {5, 6}}; |
| 108 |
__analyzer_eval (c[0].x == 0); /* { dg-warning "TRUE" } */ |
| 109 |
__analyzer_eval (c[0].y == 4); /* { dg-warning "TRUE" } */ |
| 110 |
__analyzer_eval (c[1].x == 5); /* { dg-warning "TRUE" } */ |
| 111 |
__analyzer_eval (c[1].y == 6); /* { dg-warning "TRUE" } */ |
| 112 |
} |
| 113 |
|
| 114 |
void test_12 (void) |
| 115 |
{ |
| 116 |
struct tri t = {}; |
| 117 |
__analyzer_eval (t.v[0].x == 0); /* { dg-warning "TRUE" } */ |
| 118 |
__analyzer_eval (t.v[2].y == 0); /* { dg-warning "TRUE" } */ |
| 119 |
} |
| 120 |
|
| 121 |
void test_13 (void) |
| 122 |
{ |
| 123 |
struct tri t = {3, 4, 5, 6, 7, 8}; |
| 124 |
__analyzer_eval (t.v[0].x == 3); /* { dg-warning "TRUE" } */ |
| 125 |
__analyzer_eval (t.v[0].y == 4); /* { dg-warning "TRUE" } */ |
| 126 |
__analyzer_eval (t.v[1].x == 5); /* { dg-warning "TRUE" } */ |
| 127 |
__analyzer_eval (t.v[1].y == 6); /* { dg-warning "TRUE" } */ |
| 128 |
__analyzer_eval (t.v[2].x == 7); /* { dg-warning "TRUE" } */ |
| 129 |
__analyzer_eval (t.v[2].y == 8); /* { dg-warning "TRUE" } */ |
| 130 |
} |
| 131 |
|
| 132 |
void test_14 (void) |
| 133 |
{ |
| 134 |
union iap u = {}; |
| 135 |
__analyzer_eval (u.i == 0); /* { dg-warning "TRUE" } */ |
| 136 |
} |