[SLP]Reduce number of alternate instruction, where possible
[llvm-project.git] / compiler-rt / test / tsan / Linux / user_malloc.cpp
blobfbe023dda18ef93ad73f2c669138b500ffb29dae
1 // RUN: %clangxx_tsan -c -O1 -fno-sanitize=thread %s -o %t.o
2 // RUN: %clangxx_tsan -O1 %s %t.o -o %t && %run %t 2>&1 | FileCheck %s
4 #include <stdio.h>
5 #include <stdlib.h>
7 #if !__has_feature(thread_sanitizer)
9 // Defined by tsan.
10 extern "C" void *__interceptor_malloc(unsigned long size);
11 extern "C" void __interceptor_free(void *p);
12 extern "C" void *malloc(unsigned long size) {
13 static int first = 0;
14 if (__sync_lock_test_and_set(&first, 1) == 0)
15 fprintf(stderr, "user malloc\n");
16 return __interceptor_malloc(size);
19 extern "C" void free(void *p) {
20 __interceptor_free(p);
23 #else
25 int main() {
26 volatile char *p = (char*)malloc(10);
27 p[0] = 0;
28 free((void*)p);
31 #endif
33 // CHECK: user malloc
34 // CHECK-NOT: ThreadSanitizer