145
|
1 /* PR middle-end/93646 - confusing -Wstringop-truncation on strncat where
|
|
2 -Wstringop-overflow is expected
|
|
3 { dg-do compile }
|
|
4 { dg-options "-O2 -Wall" } */
|
|
5
|
|
6 extern __SIZE_TYPE__ strlen (const char*);
|
|
7 extern char* strncat (char*, const char*, __SIZE_TYPE__);
|
|
8
|
|
9
|
|
10 char a[4];
|
|
11
|
|
12
|
|
13 void f0 (char *d, const char *s)
|
|
14 {
|
|
15 strncat (d, s, strlen (s)); // { dg-warning "specified bound depends on the length of the source argument" }
|
|
16 /* { dg-message "function 'f0'.*inlined from 'f1'" "inlining stack" { target *-*-* } 0 } */
|
|
17
|
|
18 // Prevent f0 from being replaced by g0.
|
|
19 *d = 'f';
|
|
20 }
|
|
21
|
|
22 void f1 (const char *s)
|
|
23 {
|
|
24 f0 (a, s);
|
|
25 }
|
|
26
|
|
27
|
|
28 static void g0 (char *d, const char *s)
|
|
29 {
|
|
30 strncat (d, s, strlen (s)); // { dg-warning "specified bound 3 equals source length" }
|
|
31 /* { dg-message "function 'g0'.*inlined from 'g1'" "inlining stack" { target *-*-* } 0 } */
|
|
32
|
|
33 // Prevent g0 from being replaced by f0.
|
|
34 *d = 'g';
|
|
35 }
|
|
36
|
|
37 void g1 (void)
|
|
38 {
|
|
39 g0 (a, "123");
|
|
40 }
|