PR tree-optimization/86401
[official-gcc.git] / gcc / testsuite / c-c++-common / attr-nonstring-5.c
blobf9b4fd92732bd07effef9d6859f214fed2aeb3ef
1 /* PR middle-end/84725 - enable attribute nonstring for all narrow character
2 types
3 Verify that using attribute nonstring with all three narrow character
4 types is accepted and using arrays and pointers to characters of all
5 three types (including their qualified forms) declared with the
6 attributes doesn't trigger -Wstringop-truncation warnings.
7 { dg-do compile }
8 { dg-options "-O -Wall -Wstringop-truncation" } */
10 #if __cplusplus
11 extern "C"
12 #endif
13 char* strncpy (char*, const char*, __SIZE_TYPE__);
15 #define NONSTR __attribute__ ((nonstring))
17 #define S "1234"
19 struct Arrays
21 char NONSTR a[4];
22 signed char NONSTR b[4];
23 unsigned char NONSTR c[4];
26 void test_arrays (struct Arrays *p, const char *s)
28 strncpy (p->a, s, sizeof p->a);
29 strncpy ((char*)p->b, s, sizeof p->b);
30 strncpy ((char*)p->c, s, sizeof p->c);
33 struct Pointers
35 char NONSTR *p;
36 signed char NONSTR *q;
37 unsigned char NONSTR *r;
40 void test_pointers (struct Pointers *p)
42 strncpy (p->p, S, sizeof S - 1);
43 strncpy ((char*)p->q, S, sizeof S - 1);
44 strncpy ((char*)p->r, S, sizeof S - 1);
47 struct ConstArrays
49 const char NONSTR a[4];
50 const signed char NONSTR b[4];
51 const unsigned char NONSTR c[4];
54 void test_const_arrays (struct ConstArrays *p, const char *s)
56 strncpy ((char*)p->a, s, sizeof p->a);
57 strncpy ((char*)p->b, s, sizeof p->b);
58 strncpy ((char*)p->c, s, sizeof p->c);
61 struct ConstPointers
63 const char NONSTR *p;
64 const signed char NONSTR *q;
65 const unsigned char NONSTR *r;
68 void test_const_pointers (struct ConstPointers *p)
70 strncpy ((char*)p->p, S, sizeof S - 1);
71 strncpy ((char*)p->q, S, sizeof S - 1);
72 strncpy ((char*)p->r, S, sizeof S - 1);
75 struct VolatileArrays
77 volatile char NONSTR a[4];
78 volatile signed char NONSTR b[4];
79 volatile unsigned char NONSTR c[4];
82 void test_volatile_arrays (struct VolatileArrays *p, const char *s)
84 strncpy ((char*)p->a, s, sizeof p->a);
85 strncpy ((char*)p->b, s, sizeof p->b);
86 strncpy ((char*)p->c, s, sizeof p->c);
89 struct VolatilePointers
91 volatile char NONSTR *p;
92 volatile signed char NONSTR *q;
93 volatile unsigned char NONSTR *r;
96 void test_volatile_pointers (struct VolatilePointers *p)
98 strncpy ((char*)p->p, S, sizeof S - 1);
99 strncpy ((char*)p->q, S, sizeof S - 1);
100 strncpy ((char*)p->r, S, sizeof S - 1);
103 struct ConstVolatileArrays
105 const volatile char NONSTR a[4];
106 const volatile signed char NONSTR b[4];
107 const volatile unsigned char NONSTR c[4];
110 void test_const_volatile_arrays (struct ConstVolatileArrays *p, const char *s)
112 strncpy ((char*)p->a, s, sizeof p->a);
113 strncpy ((char*)p->b, s, sizeof p->b);
114 strncpy ((char*)p->c, s, sizeof p->c);
117 struct ConstVolatilePointers
119 const volatile char NONSTR *p;
120 const volatile signed char NONSTR *q;
121 const volatile unsigned char NONSTR *r;
124 void test_const_volatile_pointers (struct ConstVolatilePointers *p)
126 strncpy ((char*)p->p, S, sizeof S - 1);
127 strncpy ((char*)p->q, S, sizeof S - 1);
128 strncpy ((char*)p->r, S, sizeof S - 1);
131 /* { dg-prune-output "-Wdiscarded-qualifiers" } */