2016-04-15 20:34:00 +08:00
|
|
|
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t 2>&1 | FileCheck %s
|
2015-01-21 21:50:02 +08:00
|
|
|
#include "test.h"
|
2013-03-28 16:41:49 +08:00
|
|
|
#include <string.h>
|
|
|
|
|
2014-05-30 22:08:51 +08:00
|
|
|
int x[4], z[4];
|
2013-03-28 16:41:49 +08:00
|
|
|
|
2013-03-28 19:21:50 +08:00
|
|
|
void *MemCpyThread(void *a) {
|
|
|
|
memcpy((int*)a, z, 16);
|
2015-01-21 21:50:02 +08:00
|
|
|
barrier_wait(&barrier);
|
2013-03-28 19:21:50 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *MemSetThread(void *a) {
|
2015-01-21 21:50:02 +08:00
|
|
|
barrier_wait(&barrier);
|
2013-03-28 19:21:50 +08:00
|
|
|
memset((int*)a, 0, 16);
|
2013-03-28 16:41:49 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
2015-01-21 21:50:02 +08:00
|
|
|
barrier_init(&barrier, 2);
|
2013-03-28 16:41:49 +08:00
|
|
|
pthread_t t[2];
|
2013-03-28 19:21:50 +08:00
|
|
|
// Race on x between memcpy and memset
|
|
|
|
pthread_create(&t[0], NULL, MemCpyThread, x);
|
|
|
|
pthread_create(&t[1], NULL, MemSetThread, x);
|
|
|
|
pthread_join(t[0], NULL);
|
|
|
|
pthread_join(t[1], NULL);
|
2016-04-15 20:34:00 +08:00
|
|
|
fprintf(stderr, "PASS\n");
|
2013-03-28 16:41:49 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-28 19:21:50 +08:00
|
|
|
// CHECK: WARNING: ThreadSanitizer: data race
|
|
|
|
// CHECK: #0 memset
|
2020-04-15 07:13:25 +08:00
|
|
|
// CHECK: #{{[12]}} MemSetThread
|
2013-03-28 19:21:50 +08:00
|
|
|
// CHECK: Previous write
|
2015-11-14 04:41:37 +08:00
|
|
|
// CHECK: #0 {{(memcpy|memmove)}}
|
2020-04-15 07:13:25 +08:00
|
|
|
// CHECK: #{{[12]}} MemCpyThread
|