diff options
author | Kostya Serebryany <kcc@google.com> | 2019-06-08 00:22:23 +0000 |
---|---|---|
committer | Kostya Serebryany <kcc@google.com> | 2019-06-08 00:22:23 +0000 |
commit | 6257d18824e35884f884963c806872f0e05f93dd (patch) | |
tree | b617fb216935a61fccb8eac972862f17566b94fb | |
parent | 3b4c2648f1c9e70b7b22084e524cb899aa69896e (diff) | |
download | compiler-rt-6257d18824e35884f884963c806872f0e05f93dd.tar.gz |
Experimantal dfsan mode "fast16labels=1"
Summary:
dfsan mode "fast16labels=1".
In this mode the labels are treated as 16-bit bit masks.
Reviewers: pcc
Reviewed By: pcc
Subscribers: delcypher, #sanitizers, llvm-commits
Tags: #llvm, #sanitizers
Differential Revision: https://reviews.llvm.org/D62870
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@362859 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/dfsan/dfsan.cc | 2 | ||||
-rw-r--r-- | lib/dfsan/dfsan_flags.inc | 4 | ||||
-rw-r--r-- | test/dfsan/fast16labels.c | 25 |
3 files changed, 31 insertions, 0 deletions
diff --git a/lib/dfsan/dfsan.cc b/lib/dfsan/dfsan.cc index 7f585a8b1..b206908a5 100644 --- a/lib/dfsan/dfsan.cc +++ b/lib/dfsan/dfsan.cc @@ -162,6 +162,8 @@ static void dfsan_check_label(dfsan_label label) { // this function (the instrumentation pass inlines the equality test). extern "C" SANITIZER_INTERFACE_ATTRIBUTE dfsan_label __dfsan_union(dfsan_label l1, dfsan_label l2) { + if (flags().fast16labels) + return l1 | l2; DCHECK_NE(l1, l2); if (l1 == 0) diff --git a/lib/dfsan/dfsan_flags.inc b/lib/dfsan/dfsan_flags.inc index cdd0035c9..29db73b98 100644 --- a/lib/dfsan/dfsan_flags.inc +++ b/lib/dfsan/dfsan_flags.inc @@ -29,3 +29,7 @@ DFSAN_FLAG( DFSAN_FLAG(const char *, dump_labels_at_exit, "", "The path of the file where " "to dump the labels when the " "program terminates.") +DFSAN_FLAG(bool, fast16labels, false, + "Enables experimental mode where DFSan supports only 16 power-of-2 labels " + "(1, 2, 4, 8, ... 32768) and the label union is computed as a bit-wise OR." +) diff --git a/test/dfsan/fast16labels.c b/test/dfsan/fast16labels.c new file mode 100644 index 000000000..a9b716039 --- /dev/null +++ b/test/dfsan/fast16labels.c @@ -0,0 +1,25 @@ +// RUN: %clang_dfsan %s -o %t && DFSAN_OPTIONS=fast16labels=1 %run %t +// +// Tests DFSAN_OPTIONS=fast16labels=1 +// +#include <sanitizer/dfsan_interface.h> + +#include <assert.h> +#include <stdio.h> + +int foo(int a, int b) { + return a + b; +} + +int main() { + int a = 10; + int b = 20; + dfsan_set_label(8, &a, sizeof(a)); + dfsan_set_label(512, &b, sizeof(b)); + int c = foo(a, b); + printf("A: 0x%x\n", dfsan_get_label(a)); + printf("B: 0x%x\n", dfsan_get_label(b)); + dfsan_label l = dfsan_get_label(c); + printf("C: 0x%x\n", l); + assert(l == 520); // OR of the other two labels. +} |