From 147e0e78b9aa503f4604d8d36e4c536ba04bdc3e Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Tue, 2 Jul 2013 14:49:23 -0700 Subject: [PATCH] Fix for atomic aliasing in Clang or GCC builds --- .../beast/modules/beast_core/memory/beast_Atomic.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Subtrees/beast/modules/beast_core/memory/beast_Atomic.h b/Subtrees/beast/modules/beast_core/memory/beast_Atomic.h index 83d43994b2..4342dbde30 100644 --- a/Subtrees/beast/modules/beast_core/memory/beast_Atomic.h +++ b/Subtrees/beast/modules/beast_core/memory/beast_Atomic.h @@ -148,10 +148,15 @@ public: volatile Type value; private: - static inline Type castFrom32Bit (int32 value) noexcept { return *(Type*) &value; } - static inline Type castFrom64Bit (int64 value) noexcept { return *(Type*) &value; } - static inline int32 castTo32Bit (Type value) noexcept { return *(int32*) &value; } - static inline int64 castTo64Bit (Type value) noexcept { return *(int64*) &value; } + #if BEAST_CLANG || __GNUC__ >= 4 + #define BEAST_ATTRIBUTE_MAY_ALIAS __attribute__((__may_alias__)) + #else + #define BEAST_ATTRIBUTE_MAY_ALIAS + #endif + static inline Type castFrom32Bit (int32 value) noexcept { Type * BEAST_ATTRIBUTE_MAY_ALIAS tmp = (Type*)&value; return *tmp; } + static inline Type castFrom64Bit (int64 value) noexcept { Type * BEAST_ATTRIBUTE_MAY_ALIAS tmp = (Type*)&value; return *tmp; } + static inline int32 castTo32Bit (Type value) noexcept { int32 * BEAST_ATTRIBUTE_MAY_ALIAS tmp = (int32*)&value; return *tmp; } + static inline int64 castTo64Bit (Type value) noexcept { int64 * BEAST_ATTRIBUTE_MAY_ALIAS tmp = (int64*)&value; return *tmp; } Type operator++ (int); // better to just use pre-increment with atomics.. Type operator-- (int);