1 // RUN: %clang_dfsan -gmlt %s -o %t && %run %t >%t.out 2>&1
2 // RUN: FileCheck %s < %t.out
5 #include <sanitizer/dfsan_interface.h>
9 #define NOINLINE __attribute__((noinline))
11 NOINLINE
size_t bar(int depth
, char *buf
, size_t len
) {
13 return dfsan_sprint_stack_trace(buf
, len
);
16 return bar(depth
- 1, buf
, len
);
19 NOINLINE
size_t baz(int depth
, char *buf
, size_t len
) {
20 return bar(depth
, buf
, len
);
23 int main(int argc
, char *argv
[]) {
25 size_t length
= dfsan_sprint_stack_trace(buf
, sizeof(buf
));
26 assert(length
< sizeof(buf
));
27 printf("==OUTPUT==\n%s==EOS==\n", buf
);
30 // CHECK: #0 {{.*}} in main [[FILEPATH:.*]]/stack_trace.c:[[# @LINE - 5 ]]
33 length
= baz(8, buf
, sizeof(buf
));
34 printf("==OUTPUT==\n%s==EOS==\n", buf
);
37 // CHECK: #0 {{.*}} in bar.dfsan [[FILEPATH]]/stack_trace.c:13
38 // CHECK-COUNT-8: #{{[1-9]+}} {{.*}} in bar.dfsan [[FILEPATH]]/stack_trace.c:16
39 // CHECK: #9 {{.*}} in baz.dfsan [[FILEPATH]]/stack_trace.c:20
40 // CHECK: #10 {{.*}} in main [[FILEPATH]]/stack_trace.c:[[# @LINE - 7 ]]
44 size_t same_length
= baz(8, tinybuf
, sizeof(tinybuf
));
46 printf("==TRUNCATED OUTPUT==\n%s==EOS==\n", tinybuf
);
47 // CHECK: ==TRUNCATED OUTPUT==
50 printf("Returned length: %zu\n", length
);
51 printf("Actual length: %zu\n", strlen(buf
));
52 printf("Returned length with truncation: %zu\n", same_length
);
54 // CHECK: Returned length: [[#LEN:]]
55 // CHECK: Actual length: [[#LEN]]
56 // CHECK: Returned length with truncation: [[#LEN]]
59 length
= baz(8, buf
, 0);
60 printf("Output=\"%s\"\n", buf
);
61 printf("Returned length: %zu\n", length
);
63 // CHECK: Returned length: [[#LEN]]