aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/Wstringop-truncation-4.c
blob: f3948637d1035c397e1f352e65cf5001f89e99b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* PR tree-optimization/85700 - Spurious -Wstringop-truncation warning
   with strncat
   { dg-do compile }
   { dg-options "-O2 -Wno-stringop-overflow -Wstringop-truncation -ftrack-macro-expansion=0" } */

#define NOIPA __attribute__ ((noipa))
#define strncat __builtin_strncat
#define strlen __builtin_strlen

extern char a4[4], b4[4], ax[];

NOIPA void cat_a4_s1_1 (void)
{
  /* There is no truncation here but since the bound of 1 equals
     the length of the source string it's likely a mistake that
     could cause overflow so it's diagnosed by -Wstringop-overflow */
  strncat (a4, "1", 1);
}

NOIPA void cat_a4_s1_2 (void)
{
  strncat (a4, "1", 2);
}

NOIPA void cat_a4_s1_3 (void)
{
  strncat (a4, "1", 3);
}

NOIPA void cat_a4_s1_4 (void)
{
  /* There is no truncation here but since the bound of 1 equals
     the length of the source string it's likely a mistake that
     could cause overflow so it's diagnosed by -Wstringop-overflow */
  strncat (a4, "1", 4);
}

NOIPA void cat_a4_s1_5 (void)
{
  /* A bound in excess of the destination size is diagnosed by
     -Wstringop-overflow.  */
  strncat (a4, "1", 5);
}

NOIPA void cat_a4_s1_dlen (void)
{
  strncat (a4, "1", sizeof a4 - strlen (a4) - 1);
}

NOIPA void cat_a4_s2_dlen (void)
{
  strncat (a4, "12", sizeof a4 - strlen (a4) - 1);  /* { dg-bogus "\\\[-Wstringop-truncation]" } */
}

NOIPA void cat_a4_b4_dlen (void)
{
  strncat (a4, b4, sizeof a4 - strlen (a4) - 1);  /* { dg-bogus "\\\[-Wstringop-truncation]" } */
}

NOIPA void cat_ax_b4_dlen (void)
{
  strncat (ax, b4, 32 - strlen (ax) - 1);  /* { dg-bogus "\\\[-Wstringop-truncation]" } */
}