llvm-project
26 строк · 573.0 Байт
1// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
2#include "test.h"
3
4_Atomic(int*) p;
5
6void *thr(void *a) {
7barrier_wait(&barrier);
8int *pp = __c11_atomic_load(&p, __ATOMIC_RELAXED);
9*pp = 42;
10return 0;
11}
12
13int main() {
14barrier_init(&barrier, 2);
15pthread_t th;
16pthread_create(&th, 0, thr, p);
17__c11_atomic_store(&p, new int, __ATOMIC_RELAXED);
18barrier_wait(&barrier);
19pthread_join(th, 0);
20}
21
22// CHECK: data race
23// CHECK: Previous write
24// CHECK: #0 operator new
25// CHECK: Location is heap block
26// CHECK: #0 operator new
27