[PATCH] D45742: Fix data race in X86FloatingPoint.cpp ASSERT_SORTED
Bob Haarman via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 17 15:50:39 PDT 2018
inglorion created this revision.
inglorion added a reviewer: rnk.
Herald added a subscriber: hiraditya.
ASSERT_SORTED checks if a table is sorted, and uses a boolean to
prevent the check from being run again if it was earlier determined
that the table is in fact sorted. Unsynchronized reads and writes of
that boolean triggered ThreadSanitizer's data race detection. This
change rewrites the code to use std::atomic<bool> instead.
Fixes PR36922.
https://reviews.llvm.org/D45742
Files:
llvm/lib/Target/X86/X86FloatingPoint.cpp
Index: llvm/lib/Target/X86/X86FloatingPoint.cpp
===================================================================
--- llvm/lib/Target/X86/X86FloatingPoint.cpp
+++ llvm/lib/Target/X86/X86FloatingPoint.cpp
@@ -599,13 +599,14 @@
#ifdef NDEBUG
#define ASSERT_SORTED(TABLE)
#else
-#define ASSERT_SORTED(TABLE) \
- { static bool TABLE##Checked = false; \
- if (!TABLE##Checked) { \
- assert(std::is_sorted(std::begin(TABLE), std::end(TABLE)) && \
- "All lookup tables must be sorted for efficient access!"); \
- TABLE##Checked = true; \
- } \
+#define ASSERT_SORTED(TABLE) \
+ { \
+ static std::atomic<bool> TABLE##Checked(false); \
+ if (!TABLE##Checked.load(std::memory_order_relaxed)) { \
+ assert(std::is_sorted(std::begin(TABLE), std::end(TABLE)) && \
+ "All lookup tables must be sorted for efficient access!"); \
+ TABLE##Checked.store(true, std::memory_order_relaxed); \
+ } \
}
#endif
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45742.142852.patch
Type: text/x-patch
Size: 1490 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180417/42bb7df9/attachment.bin>
More information about the llvm-commits
mailing list