Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / dfsan / pthread.c
blobc5b195c76998d914dca1bd1691a4746c2c9388ff
1 // RUN: %clang_dfsan %s -o %t && %run %t
2 //
3 // RUN: %clang_dfsan -gmlt -mllvm -dfsan-track-origins=1 %s -o %t && \
4 // RUN: %run %t >%t.out 2>&1
5 // RUN: FileCheck %s < %t.out
6 //
7 // RUN: %clang_dfsan -gmlt -mllvm -dfsan-track-origins=1 -mllvm -dfsan-instrument-with-call-threshold=0 %s -o %t && \
8 // RUN: %run %t >%t.out 2>&1
9 // RUN: FileCheck %s < %t.out
11 #include <sanitizer/dfsan_interface.h>
13 #include <assert.h>
14 #include <pthread.h>
15 #include <string.h>
17 const int kNumThreads = 24;
18 int x = 0;
19 int __thread y, z;
21 static void *ThreadFn(void *a) {
22 y = x;
23 assert(dfsan_get_label(y) == 8);
24 memcpy(&z, &y, sizeof(y));
25 if ((int)a == 7)
26 dfsan_print_origin_trace(&z, NULL);
27 return 0;
30 int main(void) {
31 dfsan_set_label(8, &x, sizeof(x));
33 pthread_t t[kNumThreads];
34 for (size_t i = 0; i < kNumThreads; ++i)
35 pthread_create(&t[i], 0, ThreadFn, (void *)i);
37 for (size_t i = 0; i < kNumThreads; ++i)
38 pthread_join(t[i], 0);
40 return 0;
43 // CHECK: Taint value 0x8 {{.*}} origin tracking ()
44 // CHECK: Origin value: {{.*}}, Taint value was stored to memory at
45 // CHECK: #0 {{.*}} in ThreadFn.dfsan {{.*}}pthread.c:[[@LINE-21]]
47 // CHECK: Origin value: {{.*}}, Taint value was stored to memory at
48 // CHECK: #0 {{.*}} in ThreadFn.dfsan {{.*}}pthread.c:[[@LINE-26]]
50 // CHECK: Origin value: {{.*}}, Taint value was created at
51 // CHECK: #0 {{.*}} in main {{.*}}pthread.c:[[@LINE-20]]