Files
clang-p2996/compiler-rt/test/tsan/race_on_heap.cpp
Julian Lettner 9360f1a191 [Sanitizer] Fix sanitizer tests without reducing optimization levels
As discussed, these tests are compiled with optimization to mimic real
sanitizer usage [1].

Let's mark relevant functions with `noinline` so we can continue to
check against the stack traces in the report.

[1] https://reviews.llvm.org/D96198

This reverts commit 04af72c542.

Differential Revision: https://reviews.llvm.org/D96357
2021-02-11 15:22:20 -08:00

49 lines
1.1 KiB
C++

// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include "test.h"
void *Thread1(void *p) {
*(int*)p = 42;
return 0;
}
void *Thread2(void *p) {
*(int*)p = 44;
return 0;
}
void *alloc() __attribute__((noinline)) {
return malloc(99);
}
void *AllocThread(void* arg) {
return alloc();
}
int main() {
void *p = 0;
pthread_t t[2];
pthread_create(&t[0], 0, AllocThread, 0);
pthread_join(t[0], &p);
print_address("addr=", 1, p);
pthread_create(&t[0], 0, Thread1, (char*)p + 16);
pthread_create(&t[1], 0, Thread2, (char*)p + 16);
pthread_join(t[0], 0);
pthread_join(t[1], 0);
return 0;
}
// CHECK: addr=[[ADDR:0x[0-9,a-f]+]]
// CHECK: WARNING: ThreadSanitizer: data race
// ...
// CHECK: Location is heap block of size 99 at [[ADDR]] allocated by thread T1:
// CHECK: #0 malloc
// CHECK: #{{1|2}} alloc
// CHECK: #{{2|3}} AllocThread
// ...
// CHECK: Thread T1 (tid={{.*}}, finished) created by main thread at:
// CHECK: #0 pthread_create
// CHECK: #1 main