libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / Warray-bounds-39.c
blobcb00fa9c47d157957d492d4b035ff97bfb6c3777
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" } */
8 #define NOIPA __attribute__ ((noipa))
10 typedef __SIZE_TYPE__ size_t;
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);
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] = { };
22 char d[4];
24 NOIPA void* test_memcpy_s0_1 (void *d)
26 return memcpy (d, s0, 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
29 NOIPA void* test_memcpy_s0_2 (void *d)
31 return memcpy (d, s0, 2); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
34 NOIPA void* test_memcpy_s0_0_1 (void *d)
36 return memcpy (d, s0_0, 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
39 NOIPA void* test_memcpy_s0_0_2 (void *d)
41 return memcpy (d, s0_0, 2); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
45 NOIPA void* test_memcpy_s0_1_1 (void *d)
47 return memcpy (d, s0_1, 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
50 NOIPA void* test_memcpy_s0_1_2 (void *d)
52 return memcpy (d, s0_1, 2); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
56 NOIPA void* test_memcpy_s1_0_1 (void *d)
58 return memcpy (d, s1_0, 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
61 NOIPA void* test_memcpy_s1_0_2 (void *d)
63 return memcpy (d, s1_0, 2); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
67 NOIPA void* test_memmove_s0_1 (void *d)
69 return memmove (d, s0, 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
72 NOIPA void* test_memmove_s0_2 (void *d)
74 return memmove (d, s0, 2); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
77 NOIPA void* test_memmove_s0_0_1 (void *d)
79 return memmove (d, s0_0, 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
82 NOIPA void* test_memmove_s0_0_2 (void *d)
84 return memmove (d, s0_0, 2); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
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] = { };
95 NOIPA void* test_memcpy_e_1 (void *d)
97 return memcpy (d, &e, 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
100 NOIPA void* test_memcpy_e0_1 (void *d)
102 return memcpy (d, e0, 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
105 NOIPA void* test_memcpy_e0_0_1 (void *d)
107 return memcpy (d, e0_0, 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
110 NOIPA void* test_memcpy_e0_1_1 (void *d)
112 return memcpy (d, e0_1, 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
115 NOIPA void* test_memcpy_e1_0_1 (void *d)
117 return memcpy (d, e1_0, 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
121 NOIPA char*
122 test_strcpy_s0 (char *d) /* { dg-bogus "-Warray-bounds" "pr101679" { xfail *-*-* } } */
124 return strcpy (d, s0); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
127 NOIPA char* test_strcpy_s0_0 (char *d)
129 return strcpy (d, s0_0[0]); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
133 NOIPA char* test_strncpy_s0_1 (char *d)
135 return strncpy (d, s0, 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
138 NOIPA char* test_strncpy_s0_2 (char *d)
140 return strncpy (d, s0, 2); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
143 NOIPA char* test_strncpy_s0_0_1 (char *d)
145 return strncpy (d, s0_0[0], 1); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */
148 NOIPA char* test_strncpy_s0_0_2 (char *d)
150 return strncpy (d, s0_0[0], 2); /* { dg-warning "\\\[-Warray-bounds|-Wstringop-overread" } */