[compiler-rt] b2b59f6 - [dfsan] Add test for origin tracking stack traces

George Balatsouras via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 15 16:23:35 PDT 2021


Author: George Balatsouras
Date: 2021-04-15T16:22:47-07:00
New Revision: b2b59f622ee5ca1d5c979a88464ea3fb59e292a3

URL: https://github.com/llvm/llvm-project/commit/b2b59f622ee5ca1d5c979a88464ea3fb59e292a3
DIFF: https://github.com/llvm/llvm-project/commit/b2b59f622ee5ca1d5c979a88464ea3fb59e292a3.diff

LOG: [dfsan] Add test for origin tracking stack traces

Reviewed By: stephan.yichao.zhao

Differential Revision: https://reviews.llvm.org/D100518

Added: 
    compiler-rt/test/dfsan/origin_stack_trace.c

Modified: 
    

Removed: 
    


################################################################################
diff  --git a/compiler-rt/test/dfsan/origin_stack_trace.c b/compiler-rt/test/dfsan/origin_stack_trace.c
new file mode 100644
index 000000000000..40a51e374fd1
--- /dev/null
+++ b/compiler-rt/test/dfsan/origin_stack_trace.c
@@ -0,0 +1,44 @@
+// RUN: %clang_dfsan -gmlt -mllvm -dfsan-track-origins=1 -mllvm -dfsan-fast-16-labels=true %s -o %t && \
+// RUN:     %run %t >%t.out 2>&1
+// RUN: FileCheck %s --check-prefix=CHECK < %t.out
+//
+// RUN: %clang_dfsan -gmlt -mllvm -dfsan-track-origins=1 -mllvm -dfsan-fast-16-labels=true -mllvm -dfsan-instrument-with-call-threshold=0 %s -o %t && \
+// RUN:     %run %t >%t.out 2>&1
+// RUN: FileCheck %s --check-prefix=CHECK < %t.out
+//
+// REQUIRES: x86_64-target-arch
+
+#include <sanitizer/dfsan_interface.h>
+
+#define NOINLINE __attribute__((noinline))
+
+NOINLINE int foo(int a, int b) { return a + b; }
+
+NOINLINE void bar(int depth, void *addr, int size) {
+  if (depth) {
+    bar(depth - 1, addr, size);
+  } else {
+    dfsan_set_label(1, addr, size);
+  }
+}
+
+NOINLINE void baz(int depth, void *addr, int size) {
+  bar(depth, addr, size);
+}
+
+int main(int argc, char *argv[]) {
+  int a = 10;
+  int b = 20;
+  baz(8, &a, sizeof(a));
+  int c = foo(a, b);
+  dfsan_print_origin_trace(&c, NULL);
+}
+
+// CHECK: Taint value 0x1 {{.*}} origin tracking ()
+// CHECK: Origin value: {{.*}}, Taint value was stored to memory at
+// CHECK: #0 {{.*}} in main {{.*}}origin_stack_trace.c:[[@LINE-6]]
+
+// CHECK: Origin value: {{.*}}, Taint value was created at
+// CHECK: #0 {{.*}} in dfs$bar {{.*}}origin_stack_trace.c:[[@LINE-21]]
+// CHECK-COUNT-8: #{{[0-9]+}} {{.*}} in dfs$bar {{.*}}origin_stack_trace.c:[[@LINE-24]]
+// CHECK: #9 {{.*}} in dfs$baz {{.*}}origin_stack_trace.c:[[@LINE-18]]


        


More information about the llvm-commits mailing list