• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2 // RUN: %clangxx_tsan -O2 %s -o %t && %run %t 2>&1 | FileCheck %s
3 // RUN: %clangxx_tsan -O3 %s -o %t && %run %t 2>&1 | FileCheck %s
4 //
5 // Check that load widening is not tsan-hostile.
6 #include <pthread.h>
7 #include <stdio.h>
8 #include <string.h>
9 
10 struct {
11   int i;
12   char c1, c2, c3, c4;
13 } S;
14 
15 int G;
16 
Thread1(void * x)17 void *Thread1(void *x) {
18   G = S.c1 + S.c3;
19   return NULL;
20 }
21 
Thread2(void * x)22 void *Thread2(void *x) {
23   S.c2 = 1;
24   return NULL;
25 }
26 
main()27 int main() {
28   pthread_t t[2];
29   memset(&S, 123, sizeof(S));
30   pthread_create(&t[0], NULL, Thread1, NULL);
31   pthread_create(&t[1], NULL, Thread2, NULL);
32   pthread_join(t[0], NULL);
33   pthread_join(t[1], NULL);
34   fprintf(stderr, "PASS\n");
35 }
36 
37 // CHECK-NOT: WARNING: ThreadSanitizer: data race
38 // CHECK: PASS
39