1 /* { dg-do run } */
2 /* { dg-require-effective-target hwaddress_exec } */
3 /* { dg-options "-fno-builtin-malloc -fno-builtin-free -fno-builtin-memset" } */
4 /* { dg-shouldfail "hwasan" } */
5
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
9 void *memset (void *, int, __SIZE_TYPE__);
10 void *malloc (__SIZE_TYPE__);
11 void free (void *);
12 #ifdef __cplusplus
13 }
14 #endif
15
16 volatile int ten = 10;
main(int argc,char ** argv)17 int main(int argc, char **argv) {
18 char *x = (char*)malloc(10);
19 memset(x, 0, 10);
20 int res = x[ten]; /* BOOOM */
21 free(x);
22 return res;
23 }
24
25 /* { dg-output "HWAddressSanitizer: tag-mismatch on address 0x\[0-9a-f\]*.*" } */
26 /* { dg-output "READ of size 1 at 0x\[0-9a-f\]* tags: \[\[:xdigit:\]\]\[\[:xdigit:\]\]/\[\[:xdigit:\]\]\[\[:xdigit:\]\] \\(ptr/mem\\) in thread T0.*" } */
27 /* { dg-output "located 0 bytes to the right of 10-byte region.*" } */
28 /* { dg-output "allocated here:.*" } */
29 /* { dg-output "#1 0x\[0-9a-f\]+ +in _*main \[^\n\r]*heap-overflow.c:18" } */
30