From c4f71f223f24a67e6e98cf86dccc6ac3dedeb547 Mon Sep 17 00:00:00 2001
From: Zachary Turner <zturner@google.com>
Date: Fri, 3 Mar 2017 17:39:24 +0000
Subject: [PATCH] Don't bring in llvm/Support/thread.h in Threading.cpp

Doing so defines the type llvm::thread.  On FreeBSD, we need
to call a macro which references its own ::thread type, which
causes an ambiguity due to ADL when inside of the llvm namespace.

Since we don't even need this unless LLVM_ENABLE_THREADS == 1,
we don't even need this type anyway, as it is always equal to
std::thread, so we can just use that directly.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296891 91177308-0d34-0410-b5e6-96231b3b80d8
---
 lib/Support/Threading.cpp | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/lib/Support/Threading.cpp b/lib/Support/Threading.cpp
index a9ecf9b10bf..2feb16e5d44 100644
--- a/lib/Support/Threading.cpp
+++ b/lib/Support/Threading.cpp
@@ -15,7 +15,6 @@
 #include "llvm/Support/Threading.h"
 #include "llvm/Config/config.h"
 #include "llvm/Support/Host.h"
-#include "llvm/Support/thread.h"
 
 #include <cassert>
 #include <errno.h>
@@ -56,10 +55,17 @@ void llvm::get_thread_name(SmallVectorImpl<char> &Name) { Name.clear(); }
 
 #else
 
+#include <thread>
 unsigned llvm::heavyweight_hardware_concurrency() {
+  // Since we can't get here unless LLVM_ENABLE_THREADS == 1, it is safe to use
+  // `std::thread` directly instead of `llvm::thread` (and indeed, doing so
+  // allows us to not define `thread` in the llvm namespace, which conflicts
+  // with some platforms such as FreeBSD whose headers also define a struct
+  // called `thread` in the global namespace which can cause ambiguity due to
+  // ADL.
   int NumPhysical = sys::getHostNumPhysicalCores();
   if (NumPhysical == -1)
-    return thread::hardware_concurrency();
+    return std::thread::hardware_concurrency();
   return NumPhysical;
 }
 
-- 
2.40.0