[compiler-rt] r362859 - Experimantal dfsan mode "fast16labels=1"

Kostya Serebryany via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 7 17:22:23 PDT 2019


Author: kcc
Date: Fri Jun  7 17:22:23 2019
New Revision: 362859

URL: http://llvm.org/viewvc/llvm-project?rev=362859&view=rev
Log:
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

Added:
    compiler-rt/trunk/test/dfsan/fast16labels.c
Modified:
    compiler-rt/trunk/lib/dfsan/dfsan.cc
    compiler-rt/trunk/lib/dfsan/dfsan_flags.inc

Modified: compiler-rt/trunk/lib/dfsan/dfsan.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/dfsan/dfsan.cc?rev=362859&r1=362858&r2=362859&view=diff
==============================================================================
--- compiler-rt/trunk/lib/dfsan/dfsan.cc (original)
+++ compiler-rt/trunk/lib/dfsan/dfsan.cc Fri Jun  7 17:22:23 2019
@@ -162,6 +162,8 @@ static void dfsan_check_label(dfsan_labe
 // 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)

Modified: compiler-rt/trunk/lib/dfsan/dfsan_flags.inc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/dfsan/dfsan_flags.inc?rev=362859&r1=362858&r2=362859&view=diff
==============================================================================
--- compiler-rt/trunk/lib/dfsan/dfsan_flags.inc (original)
+++ compiler-rt/trunk/lib/dfsan/dfsan_flags.inc Fri Jun  7 17:22:23 2019
@@ -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."
+)

Added: compiler-rt/trunk/test/dfsan/fast16labels.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/dfsan/fast16labels.c?rev=362859&view=auto
==============================================================================
--- compiler-rt/trunk/test/dfsan/fast16labels.c (added)
+++ compiler-rt/trunk/test/dfsan/fast16labels.c Fri Jun  7 17:22:23 2019
@@ -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.
+}




More information about the llvm-commits mailing list