1// RUN: %clang_hwasan -ffixed-x10 -ffixed-x11 -ffixed-x23 -ffixed-x27 -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK
2// RUN: %clang_hwasan -ffixed-x10 -ffixed-x11 -ffixed-x23 -ffixed-x27 -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK
3// RUN: %clang_hwasan -ffixed-x10 -ffixed-x11 -ffixed-x23 -ffixed-x27 -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK
4// RUN: %clang_hwasan -ffixed-x10 -ffixed-x11 -ffixed-x23 -ffixed-x27 -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK
5// REQUIRES: aarch64-target-arch
6
7// RUN: %clang_hwasan -ffixed-x10 -ffixed-x11 -ffixed-x23 -ffixed-x27 -O2 %s -o %t && not %env_hwasan_opts=fast_unwind_on_fatal=true %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK
8// RUN: %clang_hwasan -ffixed-x10 -ffixed-x11 -ffixed-x23 -ffixed-x27 -O2 %s -o %t && not %env_hwasan_opts=fast_unwind_on_fatal=false %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK
9
10#include <stdlib.h>
11#include <stdio.h>
12#include <sanitizer/hwasan_interface.h>
13
14int main() {
15 __hwasan_enable_allocator_tagging();
16 char * volatile x = (char*) malloc(size: 10);
17 asm volatile("mov x10, #0x2222\n"
18 "mov x23, #0x3333\n"
19 "mov x27, #0x4444\n"
20 "mov x11, sp\n");
21 return x[16];
22
23 // CHECK: ERROR: HWAddressSanitizer:
24 // First frame might be __hwasan_tag_mismatch<...> so main could be frame 0 or 1.
25 // CHECK: #{{(0|1) .*}} in main {{.*}}register-dump-read.c:[[@LINE-4]]
26
27 // Developer note: FileCheck really doesn't like when you have a regex that
28 // ends with a '}' character, e.g. the regex "[0-9]{10}" will fail, because
29 // the closing '}' fails as an "unbalanced regex". We work around this by
30 // encasing the trailing space after a register, or the end-of-line specifier.
31
32 // CHECK: Registers where the failure occurred
33 // CHECK-NEXT: x0{{[ ]+[0-9a-f]{16}[ ]}}x1{{[ ]+[0-9a-f]{16}[ ]}}x2{{[ ]+[0-9a-f]{16}[ ]}}x3{{[ ]+[0-9a-f]{16}$}}
34 // CHECK-NEXT: x4{{[ ]+[0-9a-f]{16}[ ]}}x5{{[ ]+[0-9a-f]{16}[ ]}}x6{{[ ]+[0-9a-f]{16}[ ]}}x7{{[ ]+[0-9a-f]{16}$}}
35 // CHECK-NEXT: x8{{[ ]+[0-9a-f]{16}[ ]}}x9{{[ ]+[0-9a-f]{16}[ ]}}
36 // CHECK-SAME: x10 0000000000002222
37 // CHECK-SAME: x11[[STACK:[ ]+[0-9a-f]{16}$]]
38 // CHECK-NEXT: x12{{[ ]+[0-9a-f]{16}[ ]}}x13{{[ ]+[0-9a-f]{16}[ ]}}x14{{[ ]+[0-9a-f]{16}[ ]}}x15{{[ ]+[0-9a-f]{16}$}}
39 // CHECK-NEXT: x16{{[ ]+[0-9a-f]{16}[ ]}}x17{{[ ]+[0-9a-f]{16}[ ]}}x18{{[ ]+[0-9a-f]{16}[ ]}}x19{{[ ]+[0-9a-f]{16}$}}
40 // CHECK-NEXT: x20{{[ ]+[0-9a-f]{16}[ ]}}x21{{[ ]+[0-9a-f]{16}[ ]}}x22{{[ ]+[0-9a-f]{16}[ ]}}
41 // CHECK-SAME: x23 0000000000003333{{$}}
42 // CHECK-NEXT: x24{{[ ]+[0-9a-f]{16}[ ]}}x25{{[ ]+[0-9a-f]{16}[ ]}}x26{{[ ]+[0-9a-f]{16}[ ]}}
43 // CHECK-SAME: x27 0000000000004444
44 // CHECK-NEXT: x28{{[ ]+[0-9a-f]{16}[ ]}}x29{{[ ]+[0-9a-f]{16}[ ]}}x30{{[ ]+[0-9a-f]{16}[ ]}}
45 // CHECK-SAME: sp{{.*}}[[STACK]]
46}
47

source code of compiler-rt/test/hwasan/TestCases/register-dump-read.c