llvm-project
51 строка · 1.4 Кб
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) {22y = x;23assert(dfsan_get_label(y) == 8);24memcpy(&z, &y, sizeof(y));25if ((int)a == 7)26dfsan_print_origin_trace(&z, NULL);27return 0;28}
29
30int main(void) {31dfsan_set_label(8, &x, sizeof(x));32
33pthread_t t[kNumThreads];34for (size_t i = 0; i < kNumThreads; ++i)35pthread_create(&t[i], 0, ThreadFn, (void *)i);36
37for (size_t i = 0; i < kNumThreads; ++i)38pthread_join(t[i], 0);39
40return 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