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 #define NOIPA __attribute__ ((noipa))
9
10 typedef __SIZE_TYPE__ size_t;
11
12 extern void* memcpy (void*, const void*, size_t);
13 extern void* memmove (void*, const void*, size_t);
14 extern char* strcpy (char*, const char*);
15 extern char* strncpy (char*, const char*, size_t);
16
17 const char s0[0] = { };
18 const char s0_0[0][0] = { };
19 const char s0_1[0][1] = { };
20 const char s1_0[1][0] = { };
21
22 char d[4];
23
24 NOIPA void* test_memcpy_s0_1 (void *d)
25 {
26 return memcpy (d, s0, 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
27 }
28
29 NOIPA void* test_memcpy_s0_2 (void *d)
30 {
31 return memcpy (d, s0, 2); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
32 }
33
34 NOIPA void* test_memcpy_s0_0_1 (void *d)
35 {
36 return memcpy (d, s0_0, 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
37 }
38
39 NOIPA void* test_memcpy_s0_0_2 (void *d)
40 {
41 return memcpy (d, s0_0, 2); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
42 }
43
44
45 NOIPA void* test_memcpy_s0_1_1 (void *d)
46 {
47 return memcpy (d, s0_1, 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
48 }
49
50 NOIPA void* test_memcpy_s0_1_2 (void *d)
51 {
52 return memcpy (d, s0_1, 2); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
53 }
54
55
56 NOIPA void* test_memcpy_s1_0_1 (void *d)
57 {
58 return memcpy (d, s1_0, 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
59 }
60
61 NOIPA void* test_memcpy_s1_0_2 (void *d)
62 {
63 return memcpy (d, s1_0, 2); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
64 }
65
66
67 NOIPA void* test_memmove_s0_1 (void *d)
68 {
69 return memmove (d, s0, 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
70 }
71
72 NOIPA void* test_memmove_s0_2 (void *d)
73 {
74 return memmove (d, s0, 2); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
75 }
76
77 NOIPA void* test_memmove_s0_0_1 (void *d)
78 {
79 return memmove (d, s0_0, 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
80 }
81
82 NOIPA void* test_memmove_s0_0_2 (void *d)
83 {
84 return memmove (d, s0_0, 2); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
85 }
86
87
88 struct Empty { };
89 const struct Empty e = { };
90 const struct Empty e0[0] = { };
91 const struct Empty e0_0[0][0] = { };
92 const struct Empty e0_1[0][1] = { };
93 const struct Empty e1_0[1][0] = { };
94
95 NOIPA void* test_memcpy_e_1 (void *d)
96 {
97 return memcpy (d, &e, 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
98 }
99
100 NOIPA void* test_memcpy_e0_1 (void *d)
101 {
102 return memcpy (d, e0, 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
103 }
104
105 NOIPA void* test_memcpy_e0_0_1 (void *d)
106 {
107 return memcpy (d, e0_0, 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
108 }
109
110 NOIPA void* test_memcpy_e0_1_1 (void *d)
111 {
112 return memcpy (d, e0_1, 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
113 }
114
115 NOIPA void* test_memcpy_e1_0_1 (void *d)
116 {
117 return memcpy (d, e1_0, 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
118 }
119
120
121 NOIPA char*
122 test_strcpy_s0 (char *d) /* { dg-bogus "-Warray-bounds" "pr101679" { xfail *-*-* } } */
123 {
124 return strcpy (d, s0); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
125 }
126
127 NOIPA char* test_strcpy_s0_0 (char *d)
128 {
129 return strcpy (d, s0_0[0]); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
130 }
131
132
133 NOIPA char* test_strncpy_s0_1 (char *d)
134 {
135 return strncpy (d, s0, 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
136 }
137
138 NOIPA char* test_strncpy_s0_2 (char *d)
139 {
140 return strncpy (d, s0, 2); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
141 }
142
143 NOIPA char* test_strncpy_s0_0_1 (char *d)
144 {
145 return strncpy (d, s0_0[0], 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
146 }
147
148 NOIPA char* test_strncpy_s0_0_2 (char *d)
149 {
150 return strncpy (d, s0_0[0], 2); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
151 }