1 // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t 2>&1 | FileCheck %s
8 // https://github.com/google/sanitizers/issues/412
10 // MAP_32BIT flag for mmap is supported only for x86_64.
11 // XFAIL: target=mips{{.*}}
12 // XFAIL: target=aarch64{{.*}}
13 // XFAIL: target=powerpc64{{.*}}
14 // XFAIL: target=s390x{{.*}}
15 // XFAIL: target=loongarch64{{.*}}
16 // XFAIL: target=riscv64{{.*}}
18 // MAP_32BIT doesn't exist on OS X and NetBSD.
19 // UNSUPPORTED: darwin,target={{.*netbsd.*}}
21 void *Thread(void *ptr
) {
23 barrier_wait(&barrier
);
28 barrier_init(&barrier
, 2);
29 void *ptr
= mmap(0, 128 << 10, PROT_READ
|PROT_WRITE
,
30 MAP_32BIT
|MAP_PRIVATE
|MAP_ANONYMOUS
, -1, 0);
31 fprintf(stderr
, "ptr=%p\n", ptr
);
32 if (ptr
== MAP_FAILED
) {
33 fprintf(stderr
, "mmap failed: %d\n", errno
);
36 if ((uintptr_t)ptr
>= (1ull << 32)) {
37 fprintf(stderr
, "ptr is too high\n");
41 pthread_create(&t
, 0, Thread
, ptr
);
42 barrier_wait(&barrier
);
45 munmap(ptr
, 128 << 10);
46 fprintf(stderr
, "DONE\n");
49 // CHECK: WARNING: ThreadSanitizer: data race