| 1 |
/* PR tree-optimization/79352 - -fprintf-return-value doesn't handle |
| 2 |
flexible-like array members properly |
| 3 |
{ dg-do compile } |
| 4 |
{ dg-options "-O2 -fdump-tree-optimized -fno-ipa-icf" } */ |
| 5 |
|
| 6 |
struct A { int i; char a1[1]; }; |
| 7 |
struct B { int i; char a3[3]; }; |
| 8 |
struct C { int i; char ax[]; }; |
| 9 |
|
| 10 |
int test_array_1 (int i, struct A *a) |
| 11 |
{ |
| 12 |
return __builtin_snprintf (0, 0, "%-s", a->a1); |
| 13 |
} |
| 14 |
|
| 15 |
int test_array_3 (int i, struct B *b) |
| 16 |
{ |
| 17 |
return __builtin_snprintf (0, 0, "%-s", b->a3); |
| 18 |
} |
| 19 |
|
| 20 |
int test_array_1_3 (int i, struct A *a, struct B *b) |
| 21 |
{ |
| 22 |
return __builtin_snprintf (0, 0, "%-s", i ? a->a1 : b->a3); |
| 23 |
} |
| 24 |
|
| 25 |
int test_string_and_array_3 (int i, struct B *b) |
| 26 |
{ |
| 27 |
return __builtin_snprintf (0, 0, "%-s", i ? "123" : b->a3); |
| 28 |
} |
| 29 |
|
| 30 |
int test_flexarray (struct C *c) |
| 31 |
{ |
| 32 |
return __builtin_snprintf (0, 0, "%-s", c->ax); |
| 33 |
} |
| 34 |
|
| 35 |
int test_array_and_flexarray (int i, struct B *b, struct C *c) |
| 36 |
{ |
| 37 |
return __builtin_snprintf (0, 0, "%-s", i ? b->a3 : c->ax); |
| 38 |
} |
| 39 |
|
| 40 |
int test_string_and_flexarray (int i, struct C *c) |
| 41 |
{ |
| 42 |
return __builtin_snprintf (0, 0, "%-s", i ? "123" : c->ax); |
| 43 |
} |
| 44 |
|
| 45 |
/* { dg-final { scan-tree-dump-times "snprintf" 7 "optimized"} } */ |