2018-11-28 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / gcc.dg / Wstringop-truncation-4.c
blobf3948637d1035c397e1f352e65cf5001f89e99b8
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" } */
6 #define NOIPA __attribute__ ((noipa))
7 #define strncat __builtin_strncat
8 #define strlen __builtin_strlen
10 extern char a4[4], b4[4], ax[];
12 NOIPA void cat_a4_s1_1 (void)
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);
20 NOIPA void cat_a4_s1_2 (void)
22 strncat (a4, "1", 2);
25 NOIPA void cat_a4_s1_3 (void)
27 strncat (a4, "1", 3);
30 NOIPA void cat_a4_s1_4 (void)
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);
38 NOIPA void cat_a4_s1_5 (void)
40 /* A bound in excess of the destination size is diagnosed by
41 -Wstringop-overflow. */
42 strncat (a4, "1", 5);
45 NOIPA void cat_a4_s1_dlen (void)
47 strncat (a4, "1", sizeof a4 - strlen (a4) - 1);
50 NOIPA void cat_a4_s2_dlen (void)
52 strncat (a4, "12", sizeof a4 - strlen (a4) - 1); /* { dg-bogus "\\\[-Wstringop-truncation]" } */
55 NOIPA void cat_a4_b4_dlen (void)
57 strncat (a4, b4, sizeof a4 - strlen (a4) - 1); /* { dg-bogus "\\\[-Wstringop-truncation]" } */
60 NOIPA void cat_ax_b4_dlen (void)
62 strncat (ax, b4, 32 - strlen (ax) - 1); /* { dg-bogus "\\\[-Wstringop-truncation]" } */