1 // RUN: %clang_hwasan %s -o %t && %run %t
4 #include <sanitizer/hwasan_interface.h>
9 __hwasan_enable_allocator_tagging();
10 for (int sz
= 0; sz
< 64; ++sz
) {
11 fprintf(stderr
, "sz: %d\n", sz
);
12 char *x
= (char *)malloc(sz
);
14 // Empty range is always OK.
15 for (int b
= -16; b
< sz
+ 32; ++b
)
16 assert(__hwasan_test_shadow(x
+ b
, 0) == -1);
18 int real_sz
= sz
? sz
: 1;
19 // Unlucky case when we cant distinguish between tag and short granule size.
20 if (__hwasan_tag_pointer(x
, real_sz
% 16) == x
)
23 // Underflow - the first byte is bad.
24 for (int b
= -16; b
< 0; ++b
)
25 assert(__hwasan_test_shadow(x
+ b
, real_sz
) == 0);
28 for (int b
= 0; b
< real_sz
; ++b
)
29 for (int e
= b
; e
<= real_sz
; ++e
)
30 assert(__hwasan_test_shadow(x
+ b
, e
- b
) == -1);
32 // Overflow - the first byte after the buffer is bad.
33 for (int b
= 0; b
<= real_sz
; ++b
)
34 for (int e
= real_sz
+ 1; e
<= real_sz
+ 64; ++e
)
35 assert(__hwasan_test_shadow(x
+ b
, e
- b
) == (real_sz
- b
));