This patch splits the handling of racy address and racy stack into separate functions. If a race was already reported for the address, we can avoid the cost for collecting the involved stacks.
This patch also removes the race condition in storing the racy address / racy stack. This race allows all threads to report the race. Because all threads get the read lock first, it is quite probable that they all finish the lookup before one thread gets the chance to aquire the write lock.
For certain data race patterns in OpenMP programs, this patch significantly reduces the execution time. As an example the execution times for below code:
master (report_bugs=1): real 0m24s
master (report_bugs=0): real 0m0.2s
patch (report_bugs=1): real 0m0.5s
patch (report_bugs=0): real 0m0.2s
// RUN: clang -fopenmp -fsanitize=thread %s -o %t; env TSAN_OPTIONS="ignore_noninstrumented_modules=1" %t #include <stdio.h> int main(void) { long sum=0; #pragma omp parallel num_threads(4) //reduction(+:sum) for(int i=0; i<1000000; i++) { sum++; } printf("Sum: %ld\n",sum); }
Please add a helper function for this check b/c it's now duplicated twice.
The same for the address check.