| 1 |
/* PR tree-optimization/91914 - Invalid strlen folding for offset into struct |
| 2 |
{ dg-do run } |
| 3 |
{ dg-options "-O2 -Wall" } */ |
| 4 |
|
| 5 |
#define assert(expr) \ |
| 6 |
((expr) \ |
| 7 |
? (void)0 \ |
| 8 |
: (__builtin_printf ("%s:%i: assertion failed: %s\n", \ |
| 9 |
__FILE__, __LINE__, #expr), \ |
| 10 |
__builtin_abort ())) |
| 11 |
|
| 12 |
extern __SIZE_TYPE__ strlen (const char*); |
| 13 |
|
| 14 |
struct stringpool_t |
| 15 |
{ |
| 16 |
char s1[sizeof ("1")]; |
| 17 |
char s2[sizeof ("12")]; |
| 18 |
char s3[sizeof ("123")]; |
| 19 |
char s4[sizeof ("1234")]; |
| 20 |
char s5[sizeof ("12345")]; |
| 21 |
}; |
| 22 |
|
| 23 |
static const struct stringpool_t stringpool_contents = |
| 24 |
{ |
| 25 |
"1", "12", "123", "1234", "12345" |
| 26 |
}; |
| 27 |
|
| 28 |
#define stringpool ((const char *) &stringpool_contents) |
| 29 |
|
| 30 |
volatile int i0 = 0, i2 = 2, i5 = 5, i9 = 9, i14 = 14; |
| 31 |
|
| 32 |
int main (void) |
| 33 |
{ |
| 34 |
/* These shouldn't trigger warnings. */ |
| 35 |
assert (strlen (stringpool) == 1); |
| 36 |
assert (strlen (stringpool + 2) == 2); |
| 37 |
assert (strlen (stringpool + 5) == 3); |
| 38 |
assert (strlen (stringpool + 9) == 4); |
| 39 |
assert (strlen (stringpool + 14) == 5); |
| 40 |
|
| 41 |
assert (strlen (stringpool + i0) == 1); |
| 42 |
assert (strlen (stringpool + i2) == 2); |
| 43 |
assert (strlen (stringpool + i5) == 3); |
| 44 |
assert (strlen (stringpool + i9) == 4); |
| 45 |
assert (strlen (stringpool + i14) == 5); |
| 46 |
} |