From 69721fc9d1b5df9a7a32d2fee6d72c8c7c9bf644 Mon Sep 17 00:00:00 2001 From: Matt Morehouse Date: Mon, 17 Aug 2020 11:27:16 -0700 Subject: [PATCH] [DFSan] Support fast16labels mode in dfsan_union. While the instrumentation never calls dfsan_union in fast16labels mode, the custom wrappers do. We detect fast16labels mode by checking whether any labels have been created. If not, we must be using fast16labels mode. Reviewed By: vitalybuka Differential Revision: https://reviews.llvm.org/D86012 --- compiler-rt/lib/dfsan/dfsan.cpp | 5 +++++ compiler-rt/test/dfsan/custom.cpp | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/compiler-rt/lib/dfsan/dfsan.cpp b/compiler-rt/lib/dfsan/dfsan.cpp index b2f4748..0251b9d 100644 --- a/compiler-rt/lib/dfsan/dfsan.cpp +++ b/compiler-rt/lib/dfsan/dfsan.cpp @@ -170,6 +170,11 @@ dfsan_label __dfsan_union(dfsan_label l1, dfsan_label l2) { if (l2 == 0) return l1; + // If no labels have been created, yet l1 and l2 are non-zero, we are using + // fast16labels mode. + if (atomic_load(&__dfsan_last_label, memory_order_relaxed) == 0) + return l1 | l2; + if (l1 > l2) Swap(l1, l2); diff --git a/compiler-rt/test/dfsan/custom.cpp b/compiler-rt/test/dfsan/custom.cpp index e1ccf44..7802f88 100644 --- a/compiler-rt/test/dfsan/custom.cpp +++ b/compiler-rt/test/dfsan/custom.cpp @@ -1,5 +1,6 @@ // RUN: %clang_dfsan %s -o %t && DFSAN_OPTIONS="strict_data_dependencies=0" %run %t // RUN: %clang_dfsan -mllvm -dfsan-args-abi %s -o %t && DFSAN_OPTIONS="strict_data_dependencies=0" %run %t +// RUN: %clang_dfsan -DFAST_16_LABELS -mllvm -dfsan-fast-16-labels %s -o %t && DFSAN_OPTIONS="strict_data_dependencies=0" %run %t // RUN: %clang_dfsan -DSTRICT_DATA_DEPENDENCIES %s -o %t && %run %t // RUN: %clang_dfsan -DSTRICT_DATA_DEPENDENCIES -mllvm -dfsan-args-abi %s -o %t && %run %t @@ -952,10 +953,19 @@ void test_snprintf() { } int main(void) { +#ifdef FAST_16_LABELS + i_label = 1; + j_label = 2; + k_label = 4; +#else i_label = dfsan_create_label("i", 0); j_label = dfsan_create_label("j", 0); k_label = dfsan_create_label("k", 0); +#endif i_j_label = dfsan_union(i_label, j_label); + assert(i_j_label != i_label); + assert(i_j_label != j_label); + assert(i_j_label != k_label); test_calloc(); test_clock_gettime(); -- 2.7.4