1// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2
3// Fails on Darwin bots:
4// https://green.lab.llvm.org/green//job/clang-stage1-RA/25954/consoleFull
5// and on clang-s390x-linux-lnt:
6// https://lab.llvm.org/buildbot#builders/45/builds/5224
7// Presumably the test is not 100% legal and kernel is allowed
8// to unmap part of the range (e.g. .text) and then fail.
9// So let's be conservative:
10// REQUIRES: linux, x86_64-target-arch
11
12#include "test.h"
13#include <sys/mman.h>
14
15int main() {
16 // These bogus munmap's must not crash tsan runtime.
17 munmap(addr: 0, len: 1);
18 munmap(addr: 0, len: -1);
19 munmap(addr: (void *)main, len: -1);
20 void *p =
21 mmap(addr: 0, len: 4096, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, fd: -1, offset: 0);
22 munmap(addr: p, len: (1ull << 60));
23 munmap(addr: p, len: -10000);
24 munmap(addr: p, len: 0);
25 fprintf(stderr, format: "DONE\n");
26 return 0;
27}
28
29// CHECK: DONE
30

source code of compiler-rt/test/tsan/munmap_invalid.cpp