1 /* PR middle-end/92942 - missing -Wstringop-overflow for allocations with
2 a negative lower bound size
4 { dg-options "-O2 -Wall" }
5 { dg-require-effective-target alloca } */
7 #define SIZE_MAX __SIZE_MAX__
8 #define UINT8_MAX __UINT8_MAX__
9 #define UINT16_MAX __UINT16_MAX__
11 typedef __SIZE_TYPE__
size_t;
12 typedef __UINT8_TYPE__
uint8_t;
13 typedef __UINT16_TYPE__
uint16_t;
15 void* usr_alloc1 (size_t) __attribute__ ((alloc_size (1)));
16 void* usr_alloc2 (size_t, size_t) __attribute__ ((alloc_size (1, 2)));
18 void* malloc (size_t);
19 void* memcpy (void*, const void*, size_t);
20 void* memset (void*, int, size_t);
21 char* strcpy (char*, const char*);
25 void malloc_uint_range_strcpy (unsigned n
)
27 void *p
= malloc (5 < n
? 5 : n
);
29 strcpy (p
, "01234"); // { dg-warning "\\\[-Wstringop-overflow" }
36 void malloc_uint16_anti_range_memset (uint16_t n
)
38 if (5 <= n
&& n
<= 9) return;
41 if (UINT16_MAX
< SIZE_MAX
)
43 size_t sz
= (uint16_t)-1 + (size_t)1;
44 memset (p
, 0, sz
); // { dg-warning "\\\[-Wstringop-overflow" }
54 memset (p
, 0, UINT16_MAX
- 1);
56 memset (p
, 0, UINT16_MAX
);
60 void malloc_int_strcpy (int n
)
62 void *p
= malloc (7 < n
? 7 : n
);
64 strcpy (p
, "0123456"); // { dg-warning "\\\[-Wstringop-overflow" }
71 void vla_int_strcpy (int n
)
73 char a
[9 < n
? 9 : n
];
75 strcpy (a
, "012345678"); // { dg-warning "\\\[-Wstringop-overflow" }
78 strcpy (a
, "01234567");
82 void usr_alloc1_int_strcpy (int n
)
84 void *p
= usr_alloc1 (7 < n
? 7 : n
);
86 strcpy (p
, "0123456"); // { dg-warning "\\\[-Wstringop-overflow" }
93 void usr_alloc2_cst_ir_strcpy (int n
)
95 void *p
= usr_alloc2 (1, 5 < n
? 5 : n
);
97 strcpy (p
, "01234"); // { dg-warning "\\\[-Wstringop-overflow" }
104 void usr_alloc2_ir_ir_strcpy (int m
, int n
)
106 void *p
= usr_alloc2 (3 < n
? 3 : n
, 5 < n
? 5 : n
);
108 strcpy (p
, "0123456789abcde"); // { dg-warning "\\\[-Wstringop-overflow" }
111 strcpy (p
, "0123456789abcd");
115 void usr_alloc2_uint8_memset (uint8_t m
, uint8_t n
)
117 if (3 <= m
&& m
<= 7) return;
118 if (5 <= n
&& n
<= 9) return;
119 void *p
= usr_alloc2 (m
, n
);
121 size_t sz
= UINT8_MAX
* UINT8_MAX
+ 1;
122 memset (p
, 0, sz
); // { dg-warning "\\\[-Wstringop-overflow" "" { xfail *-*-* } }
123 // { dg-warning "\\\[-Warray-bounds" "pr?????" { target *-*-* } .-1 }
126 memset (p
, 0, sz
- 1);
144 void malloc_int_memset (int n
)
146 void *p
= malloc (11 < n
? 11 : n
);
148 memset (p
, 0, 12); // { dg-warning "\\\[-Wstringop-overflow" }
155 void vla_int_memset (int n
)
157 char a
[13 < n
? 13 : n
];
159 memset (a
, 0, 14); // { dg-warning "\\\[-Wstringop-overflow" }