[OptTable] Fix typo VALUE => VALUES (NFCI) (#121523)
[llvm-project.git] / compiler-rt / test / hwasan / TestCases / test_shadow.c
blob693ba255a030ea60fc1de8ad6f0fbaa9e75a117d
1 // RUN: %clang_hwasan %s -o %t && %run %t
3 #include <assert.h>
4 #include <sanitizer/hwasan_interface.h>
5 #include <stdio.h>
6 #include <stdlib.h>
8 int main() {
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);
13 do {
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)
21 break;
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);
27 // Inbound ranges.
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));
37 } while (0);
38 free(x);
40 return 0;