| 1 |
/* PR tree-optimization/85700 - Spurious -Wstringop-truncation warning |
| 2 |
with strncat |
| 3 |
{ dg-do compile } |
| 4 |
{ dg-options "-O2 -Wno-stringop-overflow -Wstringop-truncation -ftrack-macro-expansion=0" } */ |
| 5 |
|
| 6 |
#define NOIPA __attribute__ ((noipa)) |
| 7 |
#define strncat __builtin_strncat |
| 8 |
#define strlen __builtin_strlen |
| 9 |
|
| 10 |
extern char a4[4], b4[4], ax[]; |
| 11 |
|
| 12 |
NOIPA void cat_a4_s1_1 (void) |
| 13 |
{ |
| 14 |
/* There is no truncation here but since the bound of 1 equals |
| 15 |
the length of the source string it's likely a mistake that |
| 16 |
could cause overflow so it's diagnosed by -Wstringop-overflow */ |
| 17 |
strncat (a4, "1", 1); |
| 18 |
} |
| 19 |
|
| 20 |
NOIPA void cat_a4_s1_2 (void) |
| 21 |
{ |
| 22 |
strncat (a4, "1", 2); |
| 23 |
} |
| 24 |
|
| 25 |
NOIPA void cat_a4_s1_3 (void) |
| 26 |
{ |
| 27 |
strncat (a4, "1", 3); |
| 28 |
} |
| 29 |
|
| 30 |
NOIPA void cat_a4_s1_4 (void) |
| 31 |
{ |
| 32 |
/* There is no truncation here but since the bound of 1 equals |
| 33 |
the length of the source string it's likely a mistake that |
| 34 |
could cause overflow so it's diagnosed by -Wstringop-overflow */ |
| 35 |
strncat (a4, "1", 4); |
| 36 |
} |
| 37 |
|
| 38 |
NOIPA void cat_a4_s1_5 (void) |
| 39 |
{ |
| 40 |
/* A bound in excess of the destination size is diagnosed by |
| 41 |
-Wstringop-overflow. */ |
| 42 |
strncat (a4, "1", 5); |
| 43 |
} |
| 44 |
|
| 45 |
NOIPA void cat_a4_s1_dlen (void) |
| 46 |
{ |
| 47 |
strncat (a4, "1", sizeof a4 - strlen (a4) - 1); |
| 48 |
} |
| 49 |
|
| 50 |
NOIPA void cat_a4_s2_dlen (void) |
| 51 |
{ |
| 52 |
strncat (a4, "12", sizeof a4 - strlen (a4) - 1); /* { dg-bogus "\\\[-Wstringop-truncation]" } */ |
| 53 |
} |
| 54 |
|
| 55 |
NOIPA void cat_a4_b4_dlen (void) |
| 56 |
{ |
| 57 |
strncat (a4, b4, sizeof a4 - strlen (a4) - 1); /* { dg-bogus "\\\[-Wstringop-truncation]" } */ |
| 58 |
} |
| 59 |
|
| 60 |
NOIPA void cat_ax_b4_dlen (void) |
| 61 |
{ |
| 62 |
strncat (ax, b4, 32 - strlen (ax) - 1); /* { dg-bogus "\\\[-Wstringop-truncation]" } */ |
| 63 |
} |