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
10
11#include <sanitizer/dfsan_interface.h>
12
13#include <assert.h>
14#include <pthread.h>
15#include <string.h>
16
17const int kNumThreads = 24;
18int x = 0;
19int __thread y, z;
20
21static void *ThreadFn(void *a) {
22 y = x;
23 assert(dfsan_get_label(y) == 8);
24 memcpy(dest: &z, src: &y, n: sizeof(y));
25 if ((int)a == 7)
26 dfsan_print_origin_trace(addr: &z, NULL);
27 return 0;
28}
29
30int main(void) {
31 dfsan_set_label(label: 8, addr: &x, size: sizeof(x));
32
33 pthread_t t[kNumThreads];
34 for (size_t i = 0; i < kNumThreads; ++i)
35 pthread_create(newthread: &t[i], attr: 0, start_routine: ThreadFn, arg: (void *)i);
36
37 for (size_t i = 0; i < kNumThreads; ++i)
38 pthread_join(th: t[i], thread_return: 0);
39
40 return 0;
41}
42
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]]
46
47// CHECK: Origin value: {{.*}}, Taint value was stored to memory at
48// CHECK: #0 {{.*}} in ThreadFn.dfsan {{.*}}pthread.c:[[@LINE-26]]
49
50// CHECK: Origin value: {{.*}}, Taint value was created at
51// CHECK: #0 {{.*}} in main {{.*}}pthread.c:[[@LINE-20]]
52

source code of compiler-rt/test/dfsan/pthread.c