Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / msan / allocator_mapping.cpp
blobe7a12da4891524879b9bf6c00efa35ac103e4430
1 // Test that a module constructor can not map memory over the MSan heap
2 // (without MAP_FIXED, of course). Current implementation ensures this by
3 // mapping the heap early, in __msan_init.
4 //
5 // RUN: %clangxx_msan -O0 %s -o %t_1
6 // RUN: %clangxx_msan -O0 -DHEAP_ADDRESS=$(%run %t_1) %s -o %t_2 && %run %t_2
7 //
8 // This test only makes sense for the 64-bit allocator. The 32-bit allocator
9 // does not have a fixed mapping. Exclude platforms that use the 32-bit
10 // allocator.
11 // UNSUPPORTED: target-is-mips64,target-is-mips64el,target=aarch64{{.*}}
13 #include <assert.h>
14 #include <stdio.h>
15 #include <sys/mman.h>
16 #include <stdlib.h>
18 #ifdef HEAP_ADDRESS
19 struct A {
20 A() {
21 void *const hint = reinterpret_cast<void *>(HEAP_ADDRESS);
22 void *p = mmap(hint, 4096, PROT_READ | PROT_WRITE,
23 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
24 // This address must be already mapped. Check that mmap() succeeds, but at a
25 // different address.
26 assert(p != reinterpret_cast<void *>(-1));
27 assert(p != hint);
29 } a;
30 #endif
32 int main() {
33 void *p = malloc(10);
34 printf("0x%zx\n", reinterpret_cast<size_t>(p) & (~0xfff));
35 free(p);