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