]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/testsuite/gcc.dg/Warray-bounds-39.c
PR middle-end/91631 - buffer overflow into an array member of a declared object not...
[thirdparty/gcc.git] / gcc / testsuite / gcc.dg / Warray-bounds-39.c
CommitLineData
6aa238a1
MS
1/* PR middle-end/88956 - ICE: Floating point exception on a memcpy from
2 an zero-length constant array
3 Verify both that memory and string calls with a zero-length array
4 don't cause an ICE, and also that they emit warnings.
5 { dg-do compile }
6 { dg-options "-O2 -Wall" } */
7
8typedef __SIZE_TYPE__ size_t;
9
10extern void* memcpy (void*, const void*, size_t);
11extern void* memmove (void*, const void*, size_t);
12extern char* strcpy (char*, const char*);
13extern char* strncpy (char*, const char*, size_t);
14
15const char s0[0] = { };
16const char s0_0[0][0] = { };
17const char s0_1[0][1] = { };
18const char s1_0[1][0] = { };
19
20char d[4];
21
22void* test_memcpy_s0_1 (void *d)
23{
14b7950f 24 return memcpy (d, s0, 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" } */
6aa238a1
MS
25}
26
27void* test_memcpy_s0_2 (void *d)
28{
14b7950f 29 return memcpy (d, s0, 2); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" } */
6aa238a1
MS
30}
31
32void* test_memcpy_s0_0_1 (void *d)
33{
14b7950f 34 return memcpy (d, s0_0, 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" } */
6aa238a1
MS
35}
36
37void* test_memcpy_s0_0_2 (void *d)
38{
14b7950f 39 return memcpy (d, s0_0, 2); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" } */
6aa238a1
MS
40}
41
42
43void* test_memcpy_s0_1_1 (void *d)
44{
14b7950f 45 return memcpy (d, s0_1, 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" } */
6aa238a1
MS
46}
47
48void* test_memcpy_s0_1_2 (void *d)
49{
14b7950f 50 return memcpy (d, s0_1, 2); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" } */
6aa238a1
MS
51}
52
53
54void* test_memcpy_s1_0_1 (void *d)
55{
14b7950f 56 return memcpy (d, s1_0, 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" } */
6aa238a1
MS
57}
58
59void* test_memcpy_s1_0_2 (void *d)
60{
14b7950f 61 return memcpy (d, s1_0, 2); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" } */
6aa238a1
MS
62}
63
64
65void* test_memmove_s0_1 (void *d)
66{
14b7950f 67 return memmove (d, s0, 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" } */
6aa238a1
MS
68}
69
70void* test_memmove_s0_2 (void *d)
71{
14b7950f 72 return memmove (d, s0, 2); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" } */
6aa238a1
MS
73}
74
75void* test_memmove_s0_0_1 (void *d)
76{
14b7950f 77 return memmove (d, s0_0, 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" } */
6aa238a1
MS
78}
79
80void* test_memmove_s0_0_2 (void *d)
81{
14b7950f 82 return memmove (d, s0_0, 2); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" } */
6aa238a1
MS
83}
84
85
86struct Empty { };
87const struct Empty e = { };
88const struct Empty e0[0] = { };
89const struct Empty e0_0[0][0] = { };
90const struct Empty e0_1[0][1] = { };
91const struct Empty e1_0[1][0] = { };
92
93void* test_memcpy_e_1 (void *d)
94{
14b7950f 95 return memcpy (d, &e, 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" } */
6aa238a1
MS
96}
97
98void* test_memcpy_e0_1 (void *d)
99{
14b7950f 100 return memcpy (d, e0, 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" } */
6aa238a1
MS
101}
102
103void* test_memcpy_e0_0_1 (void *d)
104{
14b7950f 105 return memcpy (d, e0_0, 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" } */
6aa238a1
MS
106}
107
108void* test_memcpy_e0_1_1 (void *d)
109{
14b7950f 110 return memcpy (d, e0_1, 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" } */
6aa238a1
MS
111}
112
113void* test_memcpy_e1_0_1 (void *d)
114{
14b7950f 115 return memcpy (d, e1_0, 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" } */
6aa238a1
MS
116}
117
118
119char* test_strcpy_s0 (char *d)
120{
14b7950f 121 return strcpy (d, s0); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" } */
6aa238a1
MS
122}
123
124char* test_strcpy_s0_0 (char *d)
125{
6889a3ac 126 return strcpy (d, s0_0[0]); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" } */
6aa238a1
MS
127}
128
129
130char* test_strncpy_s0_1 (char *d)
131{
14b7950f 132 return strncpy (d, s0, 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" } */
6aa238a1
MS
133}
134
135char* test_strncpy_s0_2 (char *d)
136{
14b7950f 137 return strncpy (d, s0, 2); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" } */
6aa238a1
MS
138}
139
140char* test_strncpy_s0_0_1 (char *d)
141{
6889a3ac 142 return strncpy (d, s0_0[0], 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" } */
6aa238a1
MS
143}
144
145char* test_strncpy_s0_0_2 (char *d)
146{
6889a3ac 147 return strncpy (d, s0_0[0], 2); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" } */
6aa238a1 148}