libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / Wstringop-overflow-42.c
blob8527eea8e5a3a641e121dc8f5dcd3d40fd3c987f
1 /* Verify -Wstringop-overflow a with destination pointer pointing either
2 before the beginning or past the end of an object.
3 { dg-do compile }
4 { dg-options "-O -Wall -Wno-array-bounds -Wno-restrict" } */
6 typedef __SIZE_TYPE__ size_t;
8 char* strcpy (char *, const char *);
11 extern char a[1];
13 volatile char *d;
15 void cpy_si_1_max (int i, const char *s)
17 if (i < 1) i = 1;
18 d = strcpy (a + i, s); // { dg-warning "writing 1 or more bytes into a region of size 0" }
19 d = strcpy (a + i + 1, s); // { dg-warning "writing 1 or more bytes into a region of size 0" }
22 void cpy_ui_1_max (unsigned i, const char *s)
24 if (i < 1) i = 1;
25 d = strcpy (a + i, s); // { dg-warning "writing 1 or more bytes into a region of size 0" }
26 d = strcpy (a + i + 1, s); // { dg-warning "writing 1 or more bytes into a region of size 0" "" { xfail { ! lp64 } } }
29 void cpy_sl_1_max (long i, const char *s)
31 if (i < 1) i = 1;
32 d = strcpy (a + i, s); // { dg-warning "writing 1 or more bytes into a region of size 0" "" { target { ! ptr_eq_short } } }
33 d = strcpy (a + i + 1, s); // { dg-warning "writing 1 or more bytes into a region of size 0" "" { target { ! ptr_eq_short } } }
36 void cpy_ul_1_max (unsigned long i, const char *s)
38 if (i < 1) i = 1;
40 d = strcpy (a + i, s); // { dg-warning "writing 1 or more bytes into a region of size 0" "" { target { ! ptr_eq_short } } }
42 /* Because of integer wraparound the offset's range is [1, 0] so
43 the overflow isn't diagnosed (yet). */
44 d = strcpy (a + i + 1, s); // { dg-warning "writing 1 or more bytes into a region of size 0" "" { xfail *-*-* } }
48 void cpy_si_min_m1 (int i, const char *s)
50 if (i > -1) i = -1;
51 d = strcpy (a + i - 1, s); // { dg-warning "writing 1 or more bytes into a region of size 0" }
52 d = strcpy (a + i, s); // { dg-warning "writing 1 or more bytes into a region of size 0" }
53 d = strcpy (a + i + 2, s);
56 void cpy_sl_min_m1 (long i, const char *s)
58 if (i > -1) i = -1;
59 d = strcpy (a + i - 1, s); // { dg-warning "writing 1 or more bytes into a region of size 0" "" { target { ! ptr_eq_short } } }
60 d = strcpy (a + i, s); // { dg-warning "writing 1 or more bytes into a region of size 0" "" { target { ! ptr_eq_short } } }
61 d = strcpy (a + i + 2, s);