Satisfy C++ aliasing rules, per suggestion by Chandler.

llvm-svn: 158346
This commit is contained in:
Argyrios Kyrtzidis 2012-06-12 01:06:16 +00:00
parent f8f128606c
commit c6dc4d75fd
3 changed files with 8 additions and 3 deletions

View 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();

View 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);

View 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();