]>
Commit | Line | Data |
---|---|---|
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 | ||
8 | typedef __SIZE_TYPE__ size_t; | |
9 | ||
10 | extern void* memcpy (void*, const void*, size_t); | |
11 | extern void* memmove (void*, const void*, size_t); | |
12 | extern char* strcpy (char*, const char*); | |
13 | extern char* strncpy (char*, const char*, size_t); | |
14 | ||
15 | const char s0[0] = { }; | |
16 | const char s0_0[0][0] = { }; | |
17 | const char s0_1[0][1] = { }; | |
18 | const char s1_0[1][0] = { }; | |
19 | ||
20 | char d[4]; | |
21 | ||
22 | void* test_memcpy_s0_1 (void *d) | |
23 | { | |
14b7950f | 24 | return memcpy (d, s0, 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" } */ |
6aa238a1 MS |
25 | } |
26 | ||
27 | void* test_memcpy_s0_2 (void *d) | |
28 | { | |
14b7950f | 29 | return memcpy (d, s0, 2); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" } */ |
6aa238a1 MS |
30 | } |
31 | ||
32 | void* 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 | ||
37 | void* 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 | ||
43 | void* 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 | ||
48 | void* 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 | ||
54 | void* 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 | ||
59 | void* 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 | ||
65 | void* test_memmove_s0_1 (void *d) | |
66 | { | |
14b7950f | 67 | return memmove (d, s0, 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" } */ |
6aa238a1 MS |
68 | } |
69 | ||
70 | void* test_memmove_s0_2 (void *d) | |
71 | { | |
14b7950f | 72 | return memmove (d, s0, 2); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" } */ |
6aa238a1 MS |
73 | } |
74 | ||
75 | void* 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 | ||
80 | void* 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 | ||
86 | struct Empty { }; | |
87 | const struct Empty e = { }; | |
88 | const struct Empty e0[0] = { }; | |
89 | const struct Empty e0_0[0][0] = { }; | |
90 | const struct Empty e0_1[0][1] = { }; | |
91 | const struct Empty e1_0[1][0] = { }; | |
92 | ||
93 | void* test_memcpy_e_1 (void *d) | |
94 | { | |
14b7950f | 95 | return memcpy (d, &e, 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" } */ |
6aa238a1 MS |
96 | } |
97 | ||
98 | void* test_memcpy_e0_1 (void *d) | |
99 | { | |
14b7950f | 100 | return memcpy (d, e0, 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" } */ |
6aa238a1 MS |
101 | } |
102 | ||
103 | void* 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 | ||
108 | void* 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 | ||
113 | void* 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 | ||
119 | char* test_strcpy_s0 (char *d) | |
120 | { | |
14b7950f | 121 | return strcpy (d, s0); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" } */ |
6aa238a1 MS |
122 | } |
123 | ||
124 | char* 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 | ||
130 | char* test_strncpy_s0_1 (char *d) | |
131 | { | |
14b7950f | 132 | return strncpy (d, s0, 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" } */ |
6aa238a1 MS |
133 | } |
134 | ||
135 | char* test_strncpy_s0_2 (char *d) | |
136 | { | |
14b7950f | 137 | return strncpy (d, s0, 2); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overflow" } */ |
6aa238a1 MS |
138 | } |
139 | ||
140 | char* 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 | ||
145 | char* 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 | } |