xref: /llvm-project/compiler-rt/test/tsan/munmap_invalid.cpp (revision 4a5086dce35834bb7143a6b468718974570f0c32)
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 
main()15 int main() {
16   // These bogus munmap's must not crash tsan runtime.
17   munmap(0, 1);
18   munmap(0, -1);
19   munmap((void *)main, -1);
20   void *p =
21       mmap(0, 4096, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
22   munmap(p, (1ull << 60));
23   munmap(p, -10000);
24   munmap(p, 0);
25   fprintf(stderr, "DONE\n");
26   return 0;
27 }
28 
29 // CHECK: DONE
30