| 1 |
/* PR middle-end/100732 - ICE on sprintf %s with integer argument |
| 2 |
{ dg-do compile } |
| 3 |
{ dg-options "-O2 -Wall -fdump-tree-optimized" } */ |
| 4 |
|
| 5 |
#define snprintf(d, n, f, ...) \ |
| 6 |
__builtin___snprintf_chk (d, n, 0, 32, f, __VA_ARGS__) |
| 7 |
|
| 8 |
int n; |
| 9 |
|
| 10 |
void gb (char *d, _Bool b) |
| 11 |
{ |
| 12 |
snprintf (d, n, "%s", b); // { dg-warning "\\\[-Wformat" } |
| 13 |
} |
| 14 |
|
| 15 |
void gi (char *d, int i) |
| 16 |
{ |
| 17 |
snprintf (d, n, "%s", i); // { dg-warning "\\\[-Wformat" } |
| 18 |
} |
| 19 |
|
| 20 |
void gd (char *d, double x) |
| 21 |
{ |
| 22 |
snprintf (d, n, "%s", x); // { dg-warning "\\\[-Wformat" } |
| 23 |
} |
| 24 |
|
| 25 |
|
| 26 |
struct X { int i; }; |
| 27 |
|
| 28 |
void gx (char *d, struct X x) |
| 29 |
{ |
| 30 |
snprintf (d, n, "%s", x); // { dg-warning "\\\[-Wformat" } |
| 31 |
} |
| 32 |
|
| 33 |
|
| 34 |
/* Also verify that the invalid sprintf call isn't folded to strcpy. |
| 35 |
{ dg-final { scan-tree-dump-times "snprintf_chk" 4 "optimized" } } |
| 36 |
{ dg-final { scan-tree-dump-not "strcpy" "optimized" } } */ |