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
10struct {
11 int i;
12 char c1, c2, c3, c4;
13} S;
14
15int G;
16
17void *Thread1(void *x) {
18 G = S.c1 + S.c3;
19 return NULL;
20}
21
22void *Thread2(void *x) {
23 S.c2 = 1;
24 return NULL;
25}
26
27int main() {
28 pthread_t t[2];
29 memset(s: &S, c: 123, n: sizeof(S));
30 pthread_create(newthread: &t[0], NULL, start_routine: Thread1, NULL);
31 pthread_create(newthread: &t[1], NULL, start_routine: Thread2, NULL);
32 pthread_join(th: t[0], NULL);
33 pthread_join(th: t[1], NULL);
34 fprintf(stderr, format: "PASS\n");
35}
36
37// CHECK-NOT: WARNING: ThreadSanitizer: data race
38// CHECK: PASS
39

source code of compiler-rt/test/tsan/tsan-vs-gvn.cpp