blob: b470e6c543f87e20ff34adff88c64a35760eb6b0 [file] [log] [blame]
Greg Fitzgeraldb8aae542014-04-30 21:34:17 +00001// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
Vitaly Buka28901052017-09-12 20:03:39 +00002
Bill Seurerf2611ac2017-02-02 21:32:07 +00003// UNSUPPORTED: powerpc64le
Vitaly Buka28901052017-09-12 20:03:39 +00004
5// FIXME: Remove the test or find how to fix this.
6// On some distributions, probably with newer glibc, tsan initialization calls
7// dlsym which then calls malloc and crashes because of tsan is not initialized.
8// UNSUPPORTED: linux
9
Dmitry Vyukovb4ede782013-01-09 08:22:06 +000010#include <stdio.h>
11
Viktor Kutuzov348758b2014-10-10 07:01:52 +000012// Defined by tsan.
Dmitry Vyukovb4ede782013-01-09 08:22:06 +000013extern "C" void *__interceptor_malloc(unsigned long size);
14extern "C" void __interceptor_free(void *p);
15
16extern "C" void *malloc(unsigned long size) {
17 static int first = 0;
18 if (__sync_lock_test_and_set(&first, 1) == 0)
Renato Golin1f422862016-04-15 12:34:00 +000019 fprintf(stderr, "user malloc\n");
Dmitry Vyukovb4ede782013-01-09 08:22:06 +000020 return __interceptor_malloc(size);
21}
22
23extern "C" void free(void *p) {
24 __interceptor_free(p);
25}
26
27int main() {
28 volatile char *p = (char*)malloc(10);
29 p[0] = 0;
30 free((void*)p);
31}
32
33// CHECK: user malloc
34// CHECK-NOT: ThreadSanitizer
35