1 /* PR middle-end/84725 - enable attribute nonstring for all narrow character
3 Verify that -Wstringop-truncation is issued for uses of arrays and
4 pointers to qualified forms of characters of all three types.
6 { dg-options "-O2 -Wall -Wstringop-truncation" } */
11 char* strncpy (char*, const char*, __SIZE_TYPE__
);
22 void test_arrays (struct Arrays
*p
, const char *s
)
24 strncpy (p
->a
, s
, sizeof p
->a
); /* { dg-warning "\\\[-Wstringop-truncation" } */
25 strncpy ((char*)p
->b
, s
, sizeof p
->b
); /* { dg-warning "\\\[-Wstringop-truncation" } */
26 strncpy ((char*)p
->c
, s
, sizeof p
->c
); /* { dg-bogus "\\\[-Wstringop-truncation" } */
36 void test_pointers (struct Pointers
*p
)
38 strncpy (p
->p
, S
, sizeof S
- 1); /* { dg-warning "\\\[-Wstringop-truncation" } */
39 strncpy ((char*)p
->q
, S
, sizeof S
- 1); /* { dg-warning "\\\[-Wstringop-truncation" } */
40 strncpy ((char*)p
->r
, S
, sizeof S
- 1); /* { dg-warning "\\\[-Wstringop-truncation" } */
46 const signed char b
[4];
47 const unsigned char c
[4];
50 void test_const_arrays (struct ConstArrays
*p
, const char *s
)
52 strncpy ((char*)p
->a
, s
, sizeof p
->a
); /* { dg-warning "\\\[-Wstringop-truncation" } */
53 strncpy ((char*)p
->b
, s
, sizeof p
->b
); /* { dg-warning "\\\[-Wstringop-truncation" } */
54 strncpy ((char*)p
->c
, s
, sizeof p
->c
); /* { dg-bogus "\\\[-Wstringop-truncation" } */
61 const unsigned char *r
;
64 void test_const_pointers (struct ConstPointers
*p
)
66 strncpy ((char*)p
->p
, S
, sizeof S
- 1); /* { dg-warning "\\\[-Wstringop-truncation" } */
67 strncpy ((char*)p
->q
, S
, sizeof S
- 1); /* { dg-warning "\\\[-Wstringop-truncation" } */
68 strncpy ((char*)p
->r
, S
, sizeof S
- 1); /* { dg-warning "\\\[-Wstringop-truncation" } */
74 volatile signed char b
[4];
75 volatile unsigned char c
[4];
78 void test_volatile_arrays (struct VolatileArrays
*p
, const char *s
)
80 strncpy ((char*)p
->a
, s
, sizeof p
->a
); /* { dg-warning "\\\[-Wstringop-truncation" } */
81 strncpy ((char*)p
->b
, s
, sizeof p
->b
); /* { dg-warning "\\\[-Wstringop-truncation" } */
82 strncpy ((char*)p
->c
, s
, sizeof p
->c
); /* { dg-bogus "\\\[-Wstringop-truncation" } */
85 struct VolatilePointers
88 volatile signed char *q
;
89 volatile unsigned char *r
;
92 void test_volatile_pointers (struct VolatilePointers
*p
)
94 strncpy ((char*)p
->p
, S
, sizeof S
- 1); /* { dg-warning "\\\[-Wstringop-truncation" } */
95 strncpy ((char*)p
->q
, S
, sizeof S
- 1); /* { dg-warning "\\\[-Wstringop-truncation" } */
96 strncpy ((char*)p
->r
, S
, sizeof S
- 1); /* { dg-warning "\\\[-Wstringop-truncation" } */
99 struct ConstVolatileArrays
101 const volatile char a
[4];
102 const volatile signed char b
[4];
103 const volatile unsigned char c
[4];
106 void test_const_volatile_arrays (struct ConstVolatileArrays
*p
, const char *s
)
108 strncpy ((char*)p
->a
, s
, sizeof p
->a
); /* { dg-warning "\\\[-Wstringop-truncation" } */
109 strncpy ((char*)p
->b
, s
, sizeof p
->b
); /* { dg-warning "\\\[-Wstringop-truncation" } */
110 strncpy ((char*)p
->c
, s
, sizeof p
->c
); /* { dg-bogus "\\\[-Wstringop-truncation" } */
113 struct ConstVolatilePointers
115 const volatile char *p
;
116 const volatile signed char *q
;
117 const volatile unsigned char *r
;
120 void test_const_volatile_pointers (struct ConstVolatilePointers
*p
)
122 strncpy ((char*)p
->p
, S
, sizeof S
- 1); /* { dg-warning "\\\[-Wstringop-truncation" } */
123 strncpy ((char*)p
->q
, S
, sizeof S
- 1); /* { dg-warning "\\\[-Wstringop-truncation" } */
124 strncpy ((char*)p
->r
, S
, sizeof S
- 1); /* { dg-warning "\\\[-Wstringop-truncation" } */
127 /* { dg-prune-output "-Wdiscarded-qualifiers" } */