1 // RUN: %clang_dfsan -gmlt -mllvm -dfsan-track-origins=1 %s -o %t && \
2 // RUN: %run %t >%t.out 2>&1
3 // RUN: FileCheck %s < %t.out
5 // RUN: %clang_dfsan -gmlt -mllvm -dfsan-track-origins=1 -mllvm -dfsan-instrument-with-call-threshold=0 %s -o %t && \
6 // RUN: %run %t >%t.out 2>&1
7 // RUN: FileCheck %s < %t.out
9 #include <sanitizer/dfsan_interface.h>
13 __attribute__((noinline
)) int foo(int a
, int b
) { return a
+ b
; }
15 __attribute__((noinline
)) void bar(int depth
, void *addr
, int size
) {
17 bar(depth
- 1, addr
, size
);
19 dfsan_set_label(1, addr
, size
);
23 __attribute__((noinline
)) void baz(int depth
, void *addr
, int size
) {
24 bar(depth
, addr
, size
);
27 int main(int argc
, char *argv
[]) {
30 baz(8, &a
, sizeof(a
));
32 dfsan_origin c_o
= dfsan_get_origin(c
);
33 dfsan_print_origin_id_trace(c_o
);
34 // CHECK: Origin value: {{.*}}, Taint value was created at
35 // CHECK: #0 {{.*}} in bar.dfsan {{.*}}origin_id_stack_trace.c:[[@LINE-16]]
36 // CHECK-COUNT-8: #{{[0-9]+}} {{.*}} in bar.dfsan {{.*}}origin_id_stack_trace.c:[[@LINE-19]]
37 // CHECK: #9 {{.*}} in baz.dfsan {{.*}}origin_id_stack_trace.c:[[@LINE-13]]
40 size_t length
= dfsan_sprint_origin_id_trace(c_o
, buf
, sizeof(buf
));
42 printf("==OUTPUT==\n\n%s==EOS==\n", buf
);
44 // CHECK: Origin value: {{.*}}, Taint value was created at
45 // CHECK: #0 {{.*}} in bar.dfsan {{.*}}origin_id_stack_trace.c:[[@LINE-26]]
46 // CHECK-COUNT-8: #{{[0-9]+}} {{.*}} in bar.dfsan {{.*}}origin_id_stack_trace.c:[[@LINE-29]]
47 // CHECK: #9 {{.*}} in baz.dfsan {{.*}}origin_id_stack_trace.c:[[@LINE-23]]
52 dfsan_sprint_origin_id_trace(c_o
, tinybuf
, sizeof(tinybuf
));
54 printf("==TRUNCATED OUTPUT==\n\n%s==EOS==\n", tinybuf
);
55 // CHECK: ==TRUNCATED OUTPUT==
56 // CHECK: Origin value: 0x1==EOS==
58 printf("Returned length: %zu\n", length
);
59 printf("Actual length: %zu\n", strlen(buf
));
60 printf("Returned length with truncation: %zu\n", same_length
);
62 // CHECK: Returned length: [[#LEN:]]
63 // CHECK: Actual length: [[#LEN]]
64 // CHECK: Returned length with truncation: [[#LEN]]
67 length
= dfsan_sprint_origin_id_trace(c_o
, buf
, 0);
68 printf("Output=\"%s\"\n", buf
);
69 printf("Returned length: %zu\n", length
);
71 // CHECK: Returned length: [[#LEN]]