1 /* PR 85643 - attribute nonstring fails to squash -Wstringop-truncation
4 { dg-options "-O2 -Wall -ftrack-macro-expansion=0" } */
6 #define strncpy __builtin_strncpy
13 char a
[16] __attribute__ ((__nonstring__
));
17 test_memarray (const struct A
*s
)
20 strncpy (b
.a
, s
->a
, sizeof b
.a
);
25 test_array (const char *s
)
27 static char a
[80] __attribute__ ((__nonstring__
));
28 strncpy (a
, s
, sizeof a
);
33 test_array_idx (const char *s
)
35 static char a
[80] __attribute__ ((__nonstring__
));
36 char *p
__attribute__ ((__nonstring__
)) = &a
[20];
37 strncpy (p
, s
, 60); /* { dg-bogus "-Wstringop-truncation" } */
42 test_array_off (const char *s
)
44 static char a
[80] __attribute__ ((__nonstring__
));
45 char *p
__attribute__ ((__nonstring__
)) = a
+ 20;
46 strncpy (p
, s
, 60); /* { dg-bogus "-Wstringop-truncation" } */
51 test_memarray_cstidx_idx (const char *s
)
54 char *p
__attribute__ ((__nonstring__
)) = &b
[1].a
[4];
56 /* The destination below is represented as &MEM[(void *)&a + 20B] and
57 which (in general) doesn't make it possible to determine what member
59 strncpy (p
, s
, sizeof b
[1].a
- 4); /* { dg-bogus "-Wstringop-truncation" "" { xfail *-*-*} } */
64 test_memarray_cstidx_off (const char *s
)
67 char *p
__attribute__ ((__nonstring__
)) = b
[1].a
+ 4;
70 strncpy (p
, s
, sizeof b
[1].a
- 4); /* { dg-bogus "-Wstringop-truncation" "" { xfail *-*-*} } */
75 test_memarray_varidx_idx (const char *s
, int i
)
78 char *p
__attribute__ ((__nonstring__
)) = &b
[i
].a
[4];
79 strncpy (p
, s
, sizeof b
[i
].a
- 4);
84 test_memarray_varidx_off (const char *s
, int i
)
87 char *p
__attribute__ ((__nonstring__
)) = b
[i
].a
+ 4;
88 strncpy (p
, s
, sizeof b
[i
].a
- 4);