1 // RUN: %clangxx_hwasan -DSIZE=16 -O0 %s -o %t && %run %t 2>&1 | FileCheck %s
2
3 // REQUIRES: stable-runtime
4
5 #include <assert.h>
6 #include <stdlib.h>
7 #include <sys/mman.h>
8 #include <sanitizer/hwasan_interface.h>
9
main()10 int main() {
11 void *alloc = malloc(4096);
12
13 // __hwasan_tag_memory expects untagged pointers.
14 char *p = (char *)__hwasan_tag_pointer(alloc, 0);
15 assert(p);
16
17 __hwasan_tag_memory(p, 1, 32);
18 __hwasan_tag_memory(p + 32, 3, 16);
19 __hwasan_tag_memory(p + 48, 0, 32);
20 __hwasan_tag_memory(p + 80, 4, 16);
21
22 char *q = (char *)__hwasan_tag_pointer(p, 7);
23 __hwasan_print_shadow(q + 5, 89 - 5);
24 // CHECK: HWASan shadow map for {{.*}}5 .. {{.*}}9 (pointer tag 7)
25 // CHECK-NEXT: {{.*}}0: 1
26 // CHECK-NEXT: {{.*}}0: 1
27 // CHECK-NEXT: {{.*}}0: 3
28 // CHECK-NEXT: {{.*}}0: 0
29 // CHECK-NEXT: {{.*}}0: 0
30 // CHECK-NEXT: {{.*}}0: 4
31
32 free(alloc);
33 }
34