[llvm-commits] [llvm] r158346 - in /llvm/trunk: include/llvm/Support/ThreadLocal.h lib/Support/ThreadLocal.cpp lib/Support/Windows/ThreadLocal.inc
Argyrios Kyrtzidis
akyrtzi at gmail.com
Mon Jun 11 18:06:16 PDT 2012
Author: akirtzidis
Date: Mon Jun 11 20:06:16 2012
New Revision: 158346
URL: http://llvm.org/viewvc/llvm-project?rev=158346&view=rev
Log:
Satisfy C++ aliasing rules, per suggestion by Chandler.
Modified:
llvm/trunk/include/llvm/Support/ThreadLocal.h
llvm/trunk/lib/Support/ThreadLocal.cpp
llvm/trunk/lib/Support/Windows/ThreadLocal.inc
Modified: llvm/trunk/include/llvm/Support/ThreadLocal.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/ThreadLocal.h?rev=158346&r1=158345&r2=158346&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/ThreadLocal.h (original)
+++ llvm/trunk/include/llvm/Support/ThreadLocal.h Mon Jun 11 20:06:16 2012
@@ -28,7 +28,12 @@
///
/// 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();
Modified: llvm/trunk/lib/Support/ThreadLocal.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/ThreadLocal.cpp?rev=158346&r1=158345&r2=158346&view=diff
==============================================================================
--- llvm/trunk/lib/Support/ThreadLocal.cpp (original)
+++ llvm/trunk/lib/Support/ThreadLocal.cpp Mon Jun 11 20:06:16 2012
@@ -40,7 +40,7 @@
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);
Modified: llvm/trunk/lib/Support/Windows/ThreadLocal.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/ThreadLocal.inc?rev=158346&r1=158345&r2=158346&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Windows/ThreadLocal.inc (original)
+++ llvm/trunk/lib/Support/Windows/ThreadLocal.inc Mon Jun 11 20:06:16 2012
@@ -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();
More information about the llvm-commits
mailing list