blob: f0c6f9354a5f31de2cea984b0d02aa5481465295 [file] [log] [blame]
Alexey Samsonovf4302052015-04-27 22:08:08 +00001// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
Dmitry Vyukov3ab6b232015-01-21 13:50:02 +00002#include "test.h"
Dmitry Vyukov368d97e2013-04-24 11:16:47 +00003
4_Atomic(int*) p;
5
6void *thr(void *a) {
Dmitry Vyukov3ab6b232015-01-21 13:50:02 +00007 barrier_wait(&barrier);
Dmitry Vyukov368d97e2013-04-24 11:16:47 +00008 int *pp = __c11_atomic_load(&p, __ATOMIC_RELAXED);
9 *pp = 42;
10 return 0;
11}
12
13int main() {
Dmitry Vyukov3ab6b232015-01-21 13:50:02 +000014 barrier_init(&barrier, 2);
Dmitry Vyukov368d97e2013-04-24 11:16:47 +000015 pthread_t th;
16 pthread_create(&th, 0, thr, p);
17 __c11_atomic_store(&p, new int, __ATOMIC_RELAXED);
Dmitry Vyukov3ab6b232015-01-21 13:50:02 +000018 barrier_wait(&barrier);
Dmitry Vyukov368d97e2013-04-24 11:16:47 +000019 pthread_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