1 /* Exercise that -Warray-bounds is issued for out-of-bounds offsets
2 in calls to built-in functions.
4 { dg-options "-O2 -Warray-bounds=2 -Wno-stringop-overflow -ftrack-macro-expansion=0" } */
6 #include "../gcc.dg/range.h"
9 # define restrict __restrict
13 extern void* memcpy (void* restrict
, const void* restrict
, size_t);
14 extern void* mempcpy (void* restrict
, const void* restrict
, size_t);
15 extern void* memmove (void*, const void*, size_t);
17 extern char* stpcpy (char* restrict
, const char* restrict
);
19 extern char* strcat (char* restrict
, const char* restrict
);
20 extern char* strcpy (char* restrict
, const char* restrict
);
21 extern char* strncpy (char* restrict
, const char* restrict
, size_t);
27 struct MA
{ char a5
[5], a7
[7]; };
29 void sink (void*, ...);
31 void test_memcpy_bounds_memarray_range (void)
34 #define TM(mem, dst, src, n) \
37 sink (&ma); /* Initialize arrays. */ \
38 memcpy (dst, src, n); \
42 ptrdiff_t j
= SR (1, 2);
44 TM (ma
.a5
, ma
.a5
+ j
, ma
.a5
, 1);
45 TM (ma
.a5
, ma
.a5
+ j
, ma
.a5
, 3);
46 TM (ma
.a5
, ma
.a5
+ j
, ma
.a5
, 5);
47 TM (ma
.a5
, ma
.a5
+ j
, ma
.a5
, 7); /* { dg-warning "offset \\\[6, 8] from the object at .ma. is out of the bounds of referenced subobject .\(MA::\)?a5. with type .char ?\\\[5]. at offset 0" } */
48 TM (ma
.a5
, ma
.a5
+ j
, ma
.a5
, 9); /* { dg-warning "offset \\\[6, 10] from the object at .ma. is out of the bounds of referenced subobject .\(MA::\)?a5. with type .char ?\\\[5]. at offset 0" } */
51 void test_strcpy_bounds_memarray_range (void)
54 #define TM(a5init, a7init, dst, src) \
56 struct MA ma = { a5init, a7init }; \
61 ptrdiff_t i
= SR (1, 2);
63 TM ("0", "", ma
.a5
+ i
, ma
.a5
);
64 TM ("01", "", ma
.a5
+ i
, ma
.a5
);
65 TM ("012", "", ma
.a5
+ i
, ma
.a5
);
66 TM ("0123", "", ma
.a5
+ i
, ma
.a5
); /* { dg-warning "offset 6 from the object at .ma. is out of the bounds of referenced subobject .a5. with type .char\\\[5]. at offset 0" "strcpy" { xfail *-*-* } } */
68 #if __i386__ || __x86_64__
69 /* Disabled for non-x86 targets due to bug 83462. */
70 TM ("", "012345", ma
.a7
+ i
, ma
.a7
); /* { dg-warning "offset 13 from the object at .ma. is out of the bounds of referenced subobject .\(MA::\)?a7. with type .char ?\\\[7]. at offset 5" "strcpy" { xfail { ! { i?86-*-* x86_64-*-* } } } } */