Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / asan / TestCases / Darwin / segv_read_write.c
blob127365d2f09cea1e1d89f7885269bf3a1985a2df
1 // RUN: %clangxx_asan -std=c++11 -O0 %s -o %t
2 // RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=READ
3 // RUN: not %run %t write 2>&1 | FileCheck %s --check-prefix=WRITE
4 // REQUIRES: x86-target-arch
6 #include <sys/mman.h>
8 static volatile int sink;
9 __attribute__((noinline)) void Read(int *ptr) { sink = *ptr; }
10 __attribute__((noinline)) void Write(int *ptr) { *ptr = 0; }
11 int main(int argc, char **argv) {
12 void *volatile p =
13 mmap(nullptr, 4096, PROT_READ, MAP_PRIVATE | MAP_ANON, -1, 0);
14 munmap(p, 4096);
15 if (argc == 1)
16 Read((int *)p);
17 else
18 Write((int *)p);
20 // READ: AddressSanitizer: SEGV on unknown address
21 // READ: The signal is caused by a READ memory access.
22 // WRITE: AddressSanitizer: SEGV on unknown address
23 // WRITE: The signal is caused by a WRITE memory access.