Satisfy C++ aliasing rules, per suggestion by Chandler.
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 12 Jun 2012 01:06:16 +0000 (01:06 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Tue, 12 Jun 2012 01:06:16 +0000 (01:06 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@158346 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/ThreadLocal.h
lib/Support/ThreadLocal.cpp
lib/Support/Windows/ThreadLocal.inc

index 1a0a00fd515fb06904078b771d48de5b0b40e86a..2957034ec74d5423d477c406f31bb4e51e64bf8b 100644 (file)
@@ -28,7 +28,12 @@ namespace llvm {
       ///
       /// This is embedded in the class and we avoid malloc'ing/free'ing it,
       /// to make this class more safe for use along with CrashRecoveryContext.
-      ThreadLocalDataTy data;
+      union {
+        char data[sizeof(ThreadLocalDataTy)];
+        struct {
+          ThreadLocalDataTy align_data;
+        };
+      };
     public:
       ThreadLocalImpl();
       virtual ~ThreadLocalImpl();
index 1030a2b97db4694b1028c6bfccb3c01f41a9fb81..17e0fe15b020f48be65d4351e3a1c7f6b4c406d6 100644 (file)
@@ -40,7 +40,7 @@ void ThreadLocalImpl::removeInstance() { data = 0; }
 namespace llvm {
 using namespace sys;
 
-ThreadLocalImpl::ThreadLocalImpl() : data(0) {
+ThreadLocalImpl::ThreadLocalImpl() : data() {
   typedef int SIZE_TOO_BIG[sizeof(pthread_key_t) <= sizeof(data) ? 1 : -1];
   pthread_key_t* key = reinterpret_cast<pthread_key_t*>(&data);
   int errorcode = pthread_key_create(key, NULL);
index 99c6f4f63b36348cf9753ac5576d7633fc11b03f..057deb325d6e8dcfbe75febcdabe531852c43ff5 100644 (file)
@@ -22,7 +22,7 @@
 namespace llvm {
 using namespace sys;
 
-ThreadLocalImpl::ThreadLocalImpl() : data(0) {
+ThreadLocalImpl::ThreadLocalImpl() : data() {
   typedef int SIZE_TOO_BIG[sizeof(DWORD) <= sizeof(data) ? 1 : -1];
   DWORD* tls = reinterpret_cast<DWORD*>(&data);
   *tls = TlsAlloc();