summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target/X86/X86FloatingPoint.cpp
diff options
context:
space:
mode:
authorBob Haarman <llvm@inglorion.net>2018-04-18 23:04:09 +0000
committerBob Haarman <llvm@inglorion.net>2018-04-18 23:04:09 +0000
commitcb80a3fce0708d48f50606b0203b2dc0326270bc (patch)
tree965434cc2f2440a3398f6142037384f740a3c2bc /llvm/lib/Target/X86/X86FloatingPoint.cpp
parent8f1a28f1902806077c95ff8292192e8d6d3fa821 (diff)
downloadbcm5719-llvm-cb80a3fce0708d48f50606b0203b2dc0326270bc.tar.gz
bcm5719-llvm-cb80a3fce0708d48f50606b0203b2dc0326270bc.zip
Fix data race in X86FloatingPoint.cpp ASSERT_SORTED
Summary: 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. Reviewers: rnk Reviewed By: rnk Subscribers: llvm-commits, hiraditya Differential Revision: https://reviews.llvm.org/D45742 llvm-svn: 330301
Diffstat (limited to 'llvm/lib/Target/X86/X86FloatingPoint.cpp')
-rw-r--r--llvm/lib/Target/X86/X86FloatingPoint.cpp15
1 files changed, 8 insertions, 7 deletions
diff --git a/llvm/lib/Target/X86/X86FloatingPoint.cpp b/llvm/lib/Target/X86/X86FloatingPoint.cpp
index 9a72e7114be..39c68a6329b 100644
--- a/llvm/lib/Target/X86/X86FloatingPoint.cpp
+++ b/llvm/lib/Target/X86/X86FloatingPoint.cpp
@@ -599,13 +599,14 @@ static int Lookup(ArrayRef<TableEntry> Table, unsigned Opcode) {
#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
OpenPOWER on IntegriCloud