summaryrefslogtreecommitdiff
path: root/lib/tsan/lit_tests/global_race.cc
blob: 0892d07da2cb7ded60b8e0df7eb3a314d95e204e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
// RUN: %clangxx_tsan -O1 %s -o %t && %t 2>&1 | FileCheck %s
#include <pthread.h>
#include <stdio.h>
#include <stddef.h>

int GlobalData[10];

void *Thread(void *a) {
  GlobalData[2] = 42;
  return 0;
}

int main() {
  fprintf(stderr, "addr=%p\n", GlobalData);
  pthread_t t;
  pthread_create(&t, 0, Thread, 0);
  GlobalData[2] = 43;
  pthread_join(t, 0);
}

// CHECK: addr=[[ADDR:0x[0-9,a-f]+]]
// CHECK: WARNING: ThreadSanitizer: data race
// Requires llvm-symbolizer, so disabled for now.
// CHECK0: Location is global 'GlobalData' of size 40 at [[ADDR]]
// CHECK0:                            (global_race.cc.exe+0x[0-9,a-f]+)