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
8int main() {
9 char *alloc = (char *)malloc(size: 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, tag: 1, size: 32);
23 __hwasan_tag_memory(p: p + 32, tag: 16, size: 16);
24 __hwasan_tag_memory(p: p + 48, tag: 0, size: 32);
25 __hwasan_tag_memory(p: p + 80, tag: 4, size: 16);
26
27 char *q = (char *)__hwasan_tag_pointer(p, tag: 7);
28 __hwasan_print_shadow(x: q + 5, size: 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(ptr: alloc);
38}
39

source code of compiler-rt/test/hwasan/TestCases/hwasan-print-shadow.cpp