[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
This commit is contained in:
Matt Morehouse 2020-08-17 11:27:16 -07:00
parent 3060894bbb
commit 69721fc9d1
2 changed files with 15 additions and 0 deletions

View File

@ -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);

View File

@ -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();