Fix building ThreadLocal.cpp with --disable-threads.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 13 Jun 2012 16:30:06 +0000 (16:30 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Wed, 13 Jun 2012 16:30:06 +0000 (16:30 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158405 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/ThreadLocal.cpp

index 17e0fe15b020f48be65d4351e3a1c7f6b4c406d6..109580478deeb6003cc615cb246503813a428ed2 100644 (file)
@@ -25,9 +25,16 @@ namespace llvm {
 using namespace sys;
 ThreadLocalImpl::ThreadLocalImpl() { }
 ThreadLocalImpl::~ThreadLocalImpl() { }
-void ThreadLocalImpl::setInstance(const void* d) { data = const_cast<void*>(d);}
+void ThreadLocalImpl::setInstance(const void* d) {
+  typedef int SIZE_TOO_BIG[sizeof(d) <= sizeof(data) ? 1 : -1];
+  void **pd = reinterpret_cast<void**>(&data);
+  *pd = const_cast<void*>(d);
+}
 const void* ThreadLocalImpl::getInstance() { return data; }
-void ThreadLocalImpl::removeInstance() { data = 0; }
+void ThreadLocalImpl::removeInstance() {
+  void **pd = reinterpret_cast<void**>(&data);
+  *pd = 0;
+}
 }
 #else