Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / dfsan / origin_id_stack_trace.c
blobf1289f01d7b3189614596cc80029db2568a8f51c
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
4 //
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>
10 #include <stdio.h>
11 #include <string.h>
13 __attribute__((noinline)) int foo(int a, int b) { return a + b; }
15 __attribute__((noinline)) void bar(int depth, void *addr, int size) {
16 if (depth) {
17 bar(depth - 1, addr, size);
18 } else {
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[]) {
28 int a = 10;
29 int b = 20;
30 baz(8, &a, sizeof(a));
31 int c = foo(a, b);
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]]
39 char buf[3000];
40 size_t length = dfsan_sprint_origin_id_trace(c_o, buf, sizeof(buf));
42 printf("==OUTPUT==\n\n%s==EOS==\n", buf);
43 // CHECK: ==OUTPUT==
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]]
48 // CHECK: ==EOS==
50 char tinybuf[20];
51 size_t same_length =
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]]
66 buf[0] = '\0';
67 length = dfsan_sprint_origin_id_trace(c_o, buf, 0);
68 printf("Output=\"%s\"\n", buf);
69 printf("Returned length: %zu\n", length);
70 // CHECK: Output=""
71 // CHECK: Returned length: [[#LEN]]