brintos

brintos / llvm-project-archived public Read only

0
0
Text · 940 B · 446949d Raw
32 lines · cpp
1// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t 2>&1 | FileCheck %s2 3// Also check that atomics instrumentation can be configured by either driver or4// legacy flags:5 6// RUN: %clangxx_tsan -O1 %s -o %t -fno-sanitize-thread-atomics && not %deflake %run %t 2>&1 \7// RUN:   | FileCheck --allow-empty --check-prefix=CHECK-NO-ATOMICS %s8// RUN: %clangxx_tsan -O1 %s -o %t -mllvm -tsan-instrument-atomics=0 && not %deflake %run %t 2>&1 \9// RUN:   | FileCheck --allow-empty --check-prefix=CHECK-NO-ATOMICS %s <%t10 11#include "test.h"12 13void *Thread(void *a) {14  __atomic_fetch_add((int*)a, 1, __ATOMIC_SEQ_CST);15  barrier_wait(&barrier);16  return 0;17}18 19int main() {20  barrier_init(&barrier, 2);21  int *a = new int(0);22  pthread_t t;23  pthread_create(&t, 0, Thread, a);24  barrier_wait(&barrier);25  delete a;26  pthread_join(t, 0);27}28 29// CHECK: WARNING: ThreadSanitizer: data race30 31// CHECK-NO-ATOMICS-NOT: WARNING: ThreadSanitizer: data race32