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 04af72c5423eb5ff7c0deba2d08cb46d583bb9d4.

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

33 lines
687 B
C++

// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include "test.h"
int X = 0;
void MySleep() __attribute__((noinline)) {
sleep(1); // the sleep that must appear in the report
}
void *Thread(void *p) {
barrier_wait(&barrier);
MySleep(); // Assume the main thread has done the write.
X = 42;
return 0;
}
int main() {
barrier_init(&barrier, 2);
pthread_t t;
pthread_create(&t, 0, Thread, 0);
X = 43;
barrier_wait(&barrier);
pthread_join(t, 0);
return 0;
}
// CHECK: WARNING: ThreadSanitizer: data race
// ...
// CHECK: As if synchronized via sleep:
// CHECK-NEXT: #0 sleep
// CHECK-NEXT: #1 MySleep
// CHECK-NEXT: #2 Thread