Debian Codegraph @

gcc/testsuite/g++.dg/ext/strncpy-chk1.C

raw
1 // PR c++/40502 - [4.5 Regression] crash in cp_diagnostic_starter
2 // { dg-do compile }
3 // { dg-options "-O2" }
4 // { dg-skip-if "packed attribute missing for struct A" { "epiphany-*-*" } }
5
6 struct A { char x[12], y[35]; };
7 struct B { char z[50]; };
8
9 inline void
10 foo (char *dest, const char *__restrict src, __SIZE_TYPE__ n)
11 {
12 // This triggers a -Wstringop-overflow warning (pruned below).
13 __builtin___strncpy_chk (dest, src, n, __builtin_object_size (dest, 0));
14 }
15
16 void bar (const char *, int);
17
18 inline void
19 baz (int i)
20 {
21 char s[128], t[32];
22 bar (s, 0);
23 bar (t, i);
24 A a;
25 B b;
26 foo (a.y, b.z, 36);
27 }
28
29 void
30 test ()
31 {
32 baz (0);
33 }
34
35 // { dg-prune-output "\\\[-Wstringop-overflow=]" }