[docs] Fix build-docs.sh
[llvm-project.git] / compiler-rt / test / tsan / map32bit.cpp
blob0f8236292be7a90ac03ded0c9e6e8cdef6fda132
1 // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t 2>&1 | FileCheck %s
2 #include "test.h"
3 #include <stdint.h>
4 #include <errno.h>
5 #include <sys/mman.h>
7 // Test for issue:
8 // https://github.com/google/sanitizers/issues/412
10 // MAP_32BIT flag for mmap is supported only for x86_64.
11 // XFAIL: mips
12 // XFAIL: aarch64
13 // XFAIL: powerpc64
14 // XFAIL: s390x
16 // MAP_32BIT doesn't exist on OS X and NetBSD.
17 // UNSUPPORTED: darwin,netbsd
19 void *Thread(void *ptr) {
20 *(int*)ptr = 42;
21 barrier_wait(&barrier);
22 return 0;
25 int main() {
26 barrier_init(&barrier, 2);
27 void *ptr = mmap(0, 128 << 10, PROT_READ|PROT_WRITE,
28 MAP_32BIT|MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
29 fprintf(stderr, "ptr=%p\n", ptr);
30 if (ptr == MAP_FAILED) {
31 fprintf(stderr, "mmap failed: %d\n", errno);
32 return 1;
34 if ((uintptr_t)ptr >= (1ull << 32)) {
35 fprintf(stderr, "ptr is too high\n");
36 return 1;
38 pthread_t t;
39 pthread_create(&t, 0, Thread, ptr);
40 barrier_wait(&barrier);
41 *(int*)ptr = 42;
42 pthread_join(t, 0);
43 munmap(ptr, 128 << 10);
44 fprintf(stderr, "DONE\n");
47 // CHECK: WARNING: ThreadSanitizer: data race
48 // CHECK: DONE