1 // RUN: %clangxx_hwasan -DSIZE=16 -O0 %s -o %t && %run %t 2>&1 | FileCheck %s
2
3 #include <assert.h>
4 #include <stdlib.h>
5 #include <sys/mman.h>
6 #include <sanitizer/hwasan_interface.h>
7
main()8 int main() {
9 char *alloc = (char *)malloc(4096);
10
11 // Simulate short granule tags.
12 alloc[15] = 0x00;
13 alloc[31] = 0xbb;
14 alloc[47] = 0xcc;
15 alloc[63] = 0xdd;
16 alloc[79] = 0xee;
17 alloc[95] = 0xff;
18
19 char *p = alloc;
20
21 // Write tags to shadow.
22 __hwasan_tag_memory(p, 1, 32);
23 __hwasan_tag_memory(p + 32, 16, 16);
24 __hwasan_tag_memory(p + 48, 0, 32);
25 __hwasan_tag_memory(p + 80, 4, 16);
26
27 char *q = (char *)__hwasan_tag_pointer(p, 7);
28 __hwasan_print_shadow(q + 5, 89 - 5);
29 // CHECK: HWASan shadow map for {{.*}}5 .. {{.*}}9 (pointer tag 7)
30 // CHECK-NEXT: {{.*}}0: 01(00)
31 // CHECK-NEXT: {{.*}}0: 01(bb)
32 // CHECK-NEXT: {{.*}}0: 10
33 // CHECK-NEXT: {{.*}}0: 00
34 // CHECK-NEXT: {{.*}}0: 00
35 // CHECK-NEXT: {{.*}}0: 04(ff)
36
37 free(alloc);
38 }
39