Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / asan / TestCases / Linux / mincore.cpp
blob30f450830fc257ddf98965349cc0c6bfe13e59a3
1 // RUN: %clangxx_asan -std=c++11 -O0 %s -o %t && %run %t
3 #include <assert.h>
4 #include <unistd.h>
5 #include <sys/mman.h>
7 int main(void) {
8 unsigned char vec[20];
9 int res;
10 size_t PS = sysconf(_SC_PAGESIZE);
11 void *addr = mmap(nullptr, 20 * PS, PROT_READ | PROT_WRITE,
12 MAP_NORESERVE | MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
14 res = mincore(addr, 10 * PS, vec);
15 assert(res == 0);
16 for (int i = 0; i < 10; ++i)
17 assert((vec[i] & 1) == 0);
19 for (int i = 0; i < 5; ++i)
20 ((char *)addr)[i * PS] = 1;
21 res = mincore(addr, 10 * PS, vec);
22 assert(res == 0);
23 for (int i = 0; i < 10; ++i)
24 assert((vec[i] & 1) == (i < 5));
26 for (int i = 5; i < 10; ++i)
27 ((char *)addr)[i * PS] = 1;
28 res = mincore(addr, 10 * PS, vec);
29 assert(res == 0);
30 for (int i = 0; i < 10; ++i)
31 assert((vec[i] & 1) == 1);
33 return 0;