Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / msan / Linux / mincore.cpp
blob35f5713d43125199aadb8e41b4352540375f9e7d
1 // RUN: %clangxx_msan -std=c++11 -O0 %s -o %t && %run %t
3 #include <assert.h>
4 #include <unistd.h>
5 #include <sys/mman.h>
6 #include <sanitizer/msan_interface.h>
8 int main(void) {
9 unsigned char vec[20];
10 int res;
11 size_t PS = sysconf(_SC_PAGESIZE);
12 void *addr = mmap(nullptr, 20 * PS, PROT_READ | PROT_WRITE,
13 MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
15 __msan_poison(&vec, sizeof(vec));
16 res = mincore(addr, 10 * PS, vec);
17 assert(res == 0);
18 assert(__msan_test_shadow(vec, sizeof(vec)) == 10);
20 __msan_poison(&vec, sizeof(vec));
21 res = mincore(addr, 10 * PS + 42, vec);
22 assert(res == 0);
23 assert(__msan_test_shadow(vec, sizeof(vec)) == 11);
25 __msan_poison(&vec, sizeof(vec));
26 res = mincore(addr, 10 * PS - 1, vec);
27 assert(res == 0);
28 assert(__msan_test_shadow(vec, sizeof(vec)) == 10);
30 __msan_poison(&vec, sizeof(vec));
31 res = mincore(addr, 1, vec);
32 assert(res == 0);
33 assert(__msan_test_shadow(vec, sizeof(vec)) == 1);
35 return 0;