2015-01-28 04:19:12 +08:00
|
|
|
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
|
2013-03-26 16:31:02 +08:00
|
|
|
// Race between an aligned access and an unaligned access, which
|
|
|
|
// touches the same memory region.
|
2015-01-28 04:19:12 +08:00
|
|
|
#include "test.h"
|
2013-03-26 16:31:02 +08:00
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
uint64_t Global[2];
|
|
|
|
|
|
|
|
void *Thread1(void *x) {
|
|
|
|
Global[1]++;
|
2015-01-28 04:19:12 +08:00
|
|
|
barrier_wait(&barrier);
|
2013-03-26 16:31:02 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *Thread2(void *x) {
|
2015-01-28 04:19:12 +08:00
|
|
|
barrier_wait(&barrier);
|
2013-03-26 16:31:02 +08:00
|
|
|
char *p1 = reinterpret_cast<char *>(&Global[0]);
|
2015-01-28 04:19:12 +08:00
|
|
|
struct __attribute__((packed, aligned(1))) u_uint64_t { uint64_t val; };
|
|
|
|
u_uint64_t *p4 = reinterpret_cast<u_uint64_t *>(p1 + 1);
|
|
|
|
(*p4).val++;
|
2013-03-26 16:31:02 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
2015-01-28 04:19:12 +08:00
|
|
|
barrier_init(&barrier, 2);
|
2013-03-26 16:31:02 +08:00
|
|
|
pthread_t t[2];
|
|
|
|
pthread_create(&t[0], NULL, Thread1, NULL);
|
|
|
|
pthread_create(&t[1], NULL, Thread2, NULL);
|
|
|
|
pthread_join(t[0], NULL);
|
|
|
|
pthread_join(t[1], NULL);
|
2016-03-02 19:54:07 +08:00
|
|
|
printf("Pass\n");
|
2015-01-28 04:19:12 +08:00
|
|
|
// CHECK: ThreadSanitizer: data race
|
2013-03-27 17:25:06 +08:00
|
|
|
// CHECK: Pass
|
2013-03-27 18:22:51 +08:00
|
|
|
return 0;
|
2013-03-26 16:31:02 +08:00
|
|
|
}
|