| 1 |
/* PR tree-optimization/79691 - -Wformat-truncation suppressed by |
| 2 |
(and only by) -Og |
| 3 |
|
| 4 |
{ dg-do compile } |
| 5 |
{ dg-options "-Og -Wall -fdump-tree-optimized" } */ |
| 6 |
|
| 7 |
char d[2]; |
| 8 |
|
| 9 |
/* Verify -Wformat-overflow works. */ |
| 10 |
void f1 (void) |
| 11 |
{ |
| 12 |
__builtin_sprintf (d, "%i", 123); /* { dg-warning "directive writing 3 bytes" } */ |
| 13 |
} |
| 14 |
|
| 15 |
/* Verify -Wformat-truncation works. */ |
| 16 |
void f2 (void) |
| 17 |
{ |
| 18 |
__builtin_snprintf (d, sizeof d, "%i", 1234); /* { dg-warning "output truncated writing 4 bytes" } */ |
| 19 |
} |
| 20 |
|
| 21 |
/* Verify -fprintf-return-value works. */ |
| 22 |
int f3 (void) |
| 23 |
{ |
| 24 |
return __builtin_snprintf (0, 0, "%i", 12345); |
| 25 |
} |
| 26 |
|
| 27 |
/* Verify -fprintf-return-value results used for constant propagation. */ |
| 28 |
int f4 (int i) |
| 29 |
{ |
| 30 |
int n1 = __builtin_snprintf (0, 0, "%i", 1234); |
| 31 |
int n2 = __builtin_snprintf (0, 0, "%i", 12345); |
| 32 |
return n1 + n2; |
| 33 |
} |
| 34 |
|
| 35 |
/* { dg-final { scan-tree-dump-times "sprintf" 1 "optimized" } } |
| 36 |
{ dg-final { scan-tree-dump-times "snprintf" 1 "optimized" } } |
| 37 |
{ dg-final { scan-tree-dump " = 9;" "optimized" } } */ |