diff --git a/compiler-rt/lib/dfsan/dfsan.cpp b/compiler-rt/lib/dfsan/dfsan.cpp index b2f474890e1ddb..0251b9d50ca0a9 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 e1ccf44ae7e0fc..7802f88f2c248c 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();