[LVI] Add trunc to i1 handling. (#124480)
[llvm-project.git] / compiler-rt / test / asan / TestCases / Posix / high-address-dereference.c
blob37a7b1702e982e503844b41fbc5c01634f5673cc
1 // On x86_64, the kernel does not provide the faulting address for dereferences
2 // of addresses greater than the 48-bit hardware addressable range, i.e.,
3 // `siginfo.si_addr` is zero in ASan's SEGV signal handler. This test checks
4 // that ASan does not misrepresent such cases as "NULL dereferences".
6 // REQUIRES: x86_64-target-arch
7 // RUN: %clang_asan %s -o %t
8 // RUN: %env_asan_opts=print_scariness=1 not %run %t 0x0000000000000000 2>&1 | FileCheck %s --check-prefixes=ZERO,HINT-PAGE0
9 // RUN: %env_asan_opts=print_scariness=1 not %run %t 0x0000000000000FFF 2>&1 | FileCheck %s --check-prefixes=LOW1,HINT-PAGE0
10 // RUN: %env_asan_opts=print_scariness=1 not %run %t 0x0000000000001000 2>&1 | FileCheck %s --check-prefixes=LOW2,HINT-NONE
11 // RUN: %env_asan_opts=print_scariness=1 not %run %t 0x4141414141414141 2>&1 | FileCheck %s --check-prefixes=HIGH,HINT-HIGHADDR
12 // RUN: %env_asan_opts=print_scariness=1 not %run %t 0xFFFFFFFFFFFFFFFF 2>&1 | FileCheck %s --check-prefixes=MAX,HINT-HIGHADDR
14 #include <stdint.h>
15 #include <stdlib.h>
17 int main(int argc, const char *argv[]) {
18 const char *hex = argv[1];
19 uint64_t *addr = (uint64_t *)strtoull(hex, NULL, 16);
20 uint64_t x = *addr; // segmentation fault
21 return x;
24 // ZERO: SEGV on unknown address 0x000000000000 (pc
25 // LOW1: SEGV on unknown address 0x000000000fff (pc
26 // LOW2: SEGV on unknown address 0x000000001000 (pc
27 // HIGH: {{BUS|SEGV}} on unknown address (pc
28 // MAX: {{BUS|SEGV}} on unknown address (pc
30 // HINT-PAGE0-NOT: Hint: this fault was caused by a dereference of a high value address
31 // HINT-PAGE0: Hint: address points to the zero page.
33 // HINT-NONE-NOT: Hint: this fault was caused by a dereference of a high value address
34 // HINT-NONE-NOT: Hint: address points to the zero page.
36 // HINT-HIGHADDR: Hint: this fault was caused by a dereference of a high value address
37 // HINT-HIGHADDR-NOT: Hint: address points to the zero page.
39 // ZERO: SCARINESS: 10 (null-deref)
40 // LOW1: SCARINESS: 10 (null-deref)
41 // LOW2: SCARINESS: 20 (wild-addr-read)
42 // HIGH: SCARINESS: {{(20 \(wild-addr-read\))|(60 \(wild-jump\))}}
43 // MAX: SCARINESS: {{(20 \(wild-addr-read\))|(60 \(wild-jump\))}}
45 // TODO: Currently, register values are only printed on Mac. Once this changes,
46 // remove the 'TODO_' prefix in the following lines.
47 // TODO_HIGH,TODO_MAX: Register values:
48 // TODO_HIGH: = 0x4141414141414141
49 // TODO_MAX: = 0xffffffffffffffff