Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:Leap:42.2:Ports
glm
aliasing.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File aliasing.patch of Package glm
Index: glm/glm/detail/func_common.inl =================================================================== --- glm.orig/glm/detail/func_common.inl +++ glm/glm/detail/func_common.inl @@ -850,7 +850,9 @@ namespace detail GLM_FUNC_QUALIFIER int floatBitsToInt(float const & v) { - return reinterpret_cast<int&>(const_cast<float&>(v)); + int Bits; + std::memcpy(&Bits, &v, sizeof(Bits)); + return Bits; } template <template <typename, precision> class vecType, precision P> @@ -861,7 +863,9 @@ namespace detail GLM_FUNC_QUALIFIER uint floatBitsToUint(float const & v) { - return reinterpret_cast<uint&>(const_cast<float&>(v)); + uint Bits; + std::memcpy(&Bits, &v, sizeof(Bits)); + return Bits; } template <template <typename, precision> class vecType, precision P> @@ -872,7 +876,9 @@ namespace detail GLM_FUNC_QUALIFIER float intBitsToFloat(int const & v) { - return reinterpret_cast<float&>(const_cast<int&>(v)); + float Float; + std::memcpy(&Float, &v, sizeof(Float)); + return Float; } template <template <typename, precision> class vecType, precision P> @@ -883,7 +889,9 @@ namespace detail GLM_FUNC_QUALIFIER float uintBitsToFloat(uint const & v) { - return reinterpret_cast<float&>(const_cast<uint&>(v)); + float Float; + std::memcpy(&Float, &v, sizeof(Float)); + return Float; } template <template <typename, precision> class vecType, precision P> Index: glm/glm/detail/func_integer.inl =================================================================== --- glm.orig/glm/detail/func_integer.inl +++ glm/glm/detail/func_integer.inl @@ -171,10 +171,8 @@ namespace glm GLM_STATIC_ASSERT(sizeof(uint) == sizeof(uint32), "uint and uint32 size mismatch"); uint64 Value64 = static_cast<uint64>(x) * static_cast<uint64>(y); - uint32* PointerMSB = (reinterpret_cast<uint32*>(&Value64) + 1); - msb = *PointerMSB; - uint32* PointerLSB = (reinterpret_cast<uint32*>(&Value64) + 0); - lsb = *PointerLSB; + msb = Value64 >> 32; + lsb = Value64; } template <> @@ -232,10 +230,8 @@ namespace glm GLM_STATIC_ASSERT(sizeof(int) == sizeof(int32), "int and int32 size mismatch"); int64 Value64 = static_cast<int64>(x) * static_cast<int64>(y); - int32* PointerMSB = (reinterpret_cast<int32*>(&Value64) + 1); - msb = *PointerMSB; - int32* PointerLSB = (reinterpret_cast<int32*>(&Value64)); - lsb = *PointerLSB; + msb = Value64 >> 32; + lsb = Value64; } template <> Index: glm/glm/detail/func_packing.inl =================================================================== --- glm.orig/glm/detail/func_packing.inl +++ glm/glm/detail/func_packing.inl @@ -35,24 +35,32 @@ namespace glm GLM_FUNC_QUALIFIER uint packUnorm2x16(vec2 const & v) { u16vec2 Topack(round(clamp(v, 0.0f, 1.0f) * 65535.0f)); - return reinterpret_cast<uint&>(Topack); + uint Packed; + std::memcpy(&Packed, &Topack, sizeof(Packed)); + return Packed; } GLM_FUNC_QUALIFIER vec2 unpackUnorm2x16(uint const & p) { - vec2 Unpack(reinterpret_cast<u16vec2 const &>(p)); + u16vec2 Packed; + std::memcpy(&Packed, &p, sizeof(Packed)); + vec2 Unpack(Packed); return Unpack * float(1.5259021896696421759365224689097e-5); // 1.0 / 65535.0 } GLM_FUNC_QUALIFIER uint packSnorm2x16(vec2 const & v) { i16vec2 Topack(round(clamp(v ,-1.0f, 1.0f) * 32767.0f)); - return reinterpret_cast<uint32&>(Topack); + uint32 Packed; + std::memcpy(&Packed, &Topack, sizeof(Packed)); + return Packed; } GLM_FUNC_QUALIFIER vec2 unpackSnorm2x16(uint const & p) { - vec2 Unpack(reinterpret_cast<i16vec2 const &>(p)); + i16vec2 Packed; + std::memcpy(&Packed, &p, sizeof(Packed)); + vec2 Unpack(Packed); return clamp( Unpack * 3.0518509475997192297128208258309e-5f, //1.0f / 32767.0f, -1.0f, 1.0f); @@ -61,24 +69,32 @@ namespace glm GLM_FUNC_QUALIFIER uint packUnorm4x8(vec4 const & v) { u8vec4 Topack(round(clamp(v, 0.0f, 1.0f) * 255.0f)); - return reinterpret_cast<uint&>(Topack); + uint Packed; + std::memcpy(&Packed, &Topack, sizeof(Packed)); + return Packed; } GLM_FUNC_QUALIFIER vec4 unpackUnorm4x8(uint const & p) { - vec4 Unpack(reinterpret_cast<u8vec4 const&>(p)); + u8vec4 Packed; + std::memcpy(&Packed, &p, sizeof(Packed)); + vec4 Unpack(Packed); return Unpack * float(0.0039215686274509803921568627451); // 1 / 255 } GLM_FUNC_QUALIFIER uint packSnorm4x8(vec4 const & v) { i8vec4 Topack(round(clamp(v ,-1.0f, 1.0f) * 127.0f)); - return reinterpret_cast<uint&>(Topack); + uint Packed; + std::memcpy(&Packed, &Topack, sizeof(Packed)); + return Packed; } GLM_FUNC_QUALIFIER glm::vec4 unpackSnorm4x8(uint const & p) { - vec4 Unpack(reinterpret_cast<i8vec4 const &>(p)); + i8vec4 Packed; + std::memcpy(&Packed, &p, sizeof(Packed)); + vec4 Unpack(Packed); return clamp( Unpack * 0.0078740157480315f, // 1.0f / 127.0f -1.0f, 1.0f); @@ -86,12 +102,16 @@ namespace glm GLM_FUNC_QUALIFIER double packDouble2x32(uvec2 const & v) { - return reinterpret_cast<double const &>(v); + double Packed; + std::memcpy(&Packed, &v, sizeof(Packed)); + return Packed; } GLM_FUNC_QUALIFIER uvec2 unpackDouble2x32(double const & v) { - return reinterpret_cast<uvec2 const &>(v); + uvec2 Unpack; + std::memcpy(&Unpack, &v, sizeof(Unpack)); + return Unpack; } GLM_FUNC_QUALIFIER uint packHalf2x16(vec2 const & v) @@ -100,13 +120,15 @@ namespace glm detail::toFloat16(v.x), detail::toFloat16(v.y)); - uint * Result = reinterpret_cast<uint*>(&Unpack); - return *Result; + uint Packed; + std::memcpy(&Packed, &Unpack, sizeof(Packed)); + return Packed; } GLM_FUNC_QUALIFIER vec2 unpackHalf2x16(uint const & v) { - i16vec2 Unpack(reinterpret_cast<i16vec2 const &>(v)); + i16vec2 Unpack; + std::memcpy(&Unpack, &v, sizeof(Unpack)); return vec2( detail::toFloat32(Unpack.x), Index: glm/glm/detail/setup.hpp =================================================================== --- glm.orig/glm/detail/setup.hpp +++ glm/glm/detail/setup.hpp @@ -30,6 +30,7 @@ #define GLM_SETUP_INCLUDED #include <cassert> +#include <cstring> /////////////////////////////////////////////////////////////////////////////////////////////////// // Version Index: glm/glm/gtc/packing.inl =================================================================== --- glm.orig/glm/gtc/packing.inl +++ glm/glm/gtc/packing.inl @@ -145,7 +145,9 @@ namespace detail else if(glm::isinf(x)) return 0x1f << 6; - return float2packed11(reinterpret_cast<uint&>(x)); + uint Topack; + std::memcpy(&Topack, &x, sizeof(Topack)); + return float2packed11(Topack); } GLM_FUNC_QUALIFIER float packed11bitToFloat(glm::uint x) @@ -158,7 +160,9 @@ namespace detail return ~0;//Inf uint result = packed11ToFloat(x); - return reinterpret_cast<float&>(result); + float Unpack; + std::memcpy(&Unpack, &result, sizeof(Unpack)); + return Unpack; } GLM_FUNC_QUALIFIER glm::uint floatTo10bit(float x) @@ -170,7 +174,9 @@ namespace detail else if(glm::isinf(x)) return 0x1f << 5; - return float2packed10(reinterpret_cast<uint&>(x)); + uint Topack; + std::memcpy(&Topack, &x, sizeof(Topack)); + return float2packed10(Topack); } GLM_FUNC_QUALIFIER float packed10bitToFloat(glm::uint x) @@ -183,7 +189,9 @@ namespace detail return ~0;//Inf uint result = packed10ToFloat(x); - return reinterpret_cast<float&>(result); + float Unpack; + std::memcpy(&Unpack, &result, sizeof(Unpack)); + return Unpack; } // GLM_FUNC_QUALIFIER glm::uint f11_f11_f10(float x, float y, float z) @@ -231,21 +239,24 @@ namespace detail GLM_FUNC_QUALIFIER uint16 packUnorm2x8(vec2 const & v) { u8vec2 Topack(round(clamp(v, 0.0f, 1.0f) * 255.0f)); - uint16* Packed = reinterpret_cast<uint16*>(&Topack); - return *Packed; + uint16 Packed; + std::memcpy(&Packed, &Topack, sizeof(Packed)); + return Packed; } GLM_FUNC_QUALIFIER vec2 unpackUnorm2x8(uint16 const & p) { - u8vec2* Unpacked = reinterpret_cast<u8vec2*>(const_cast<uint16*>(&p)); - return vec2(*Unpacked) * float(0.0039215686274509803921568627451); // 1 / 255 + u8vec2 Unpack; + std::memcpy(&Unpack, &p, sizeof(Unpack)); + return vec2(Unpack) * float(0.0039215686274509803921568627451); // 1 / 255 } GLM_FUNC_QUALIFIER uint8 packSnorm1x8(float const & v) { int8 Topack(static_cast<int8>(round(clamp(v ,-1.0f, 1.0f) * 127.0f))); - uint8* Packed = reinterpret_cast<uint8*>(&Topack); - return *Packed; + uint8 Packed; + std::memcpy(&Packed, &Topack, sizeof(Packed)); + return Packed; } GLM_FUNC_QUALIFIER float unpackSnorm1x8(uint8 const & p) @@ -259,15 +270,17 @@ namespace detail GLM_FUNC_QUALIFIER uint16 packSnorm2x8(vec2 const & v) { i8vec2 Topack(round(clamp(v ,-1.0f, 1.0f) * 127.0f)); - uint16* Packed = reinterpret_cast<uint16*>(&Topack); - return *Packed; + uint16 Packed; + std::memcpy(&Packed, &Topack, sizeof(Packed)); + return Packed; } GLM_FUNC_QUALIFIER vec2 unpackSnorm2x8(uint16 const & p) { - i8vec2* Unpack = reinterpret_cast<i8vec2*>(const_cast<uint16*>(&p)); + i8vec2 Unpack; + std::memcpy(&Unpack, &p, sizeof(Unpack)); return clamp( - vec2(*Unpack) * 0.00787401574803149606299212598425f, // 1.0f / 127.0f + vec2(Unpack) * 0.00787401574803149606299212598425f, // 1.0f / 127.0f -1.0f, 1.0f); } @@ -285,21 +298,24 @@ namespace detail GLM_FUNC_QUALIFIER uint64 packUnorm4x16(vec4 const & v) { u16vec4 Topack(round(clamp(v , 0.0f, 1.0f) * 65535.0f)); - uint64* Packed = reinterpret_cast<uint64*>(&Topack); - return *Packed; + uint64 Packed; + std::memcpy(&Packed, &Topack, sizeof(Packed)); + return Packed; } GLM_FUNC_QUALIFIER vec4 unpackUnorm4x16(uint64 const & p) { - u16vec4* Unpack = reinterpret_cast<u16vec4*>(const_cast<uint64*>(&p)); - return vec4(*Unpack) * 1.5259021896696421759365224689097e-5f; // 1.0 / 65535.0 + u16vec4 Unpack; + std::memcpy(&Unpack, &p, sizeof(Unpack)); + return vec4(Unpack) * 1.5259021896696421759365224689097e-5f; // 1.0 / 65535.0 } GLM_FUNC_QUALIFIER uint16 packSnorm1x16(float const & v) { int16 Topack = static_cast<int16>(round(clamp(v ,-1.0f, 1.0f) * 32767.0f)); - uint16* Packed = reinterpret_cast<uint16*>(&Topack); - return *Packed; + uint16 Packed; + std::memcpy(&Packed, &Topack, sizeof(Packed)); + return Packed; } GLM_FUNC_QUALIFIER float unpackSnorm1x16(uint16 const & p) @@ -313,29 +329,33 @@ namespace detail GLM_FUNC_QUALIFIER uint64 packSnorm4x16(vec4 const & v) { i16vec4 Topack = static_cast<i16vec4>(round(clamp(v ,-1.0f, 1.0f) * 32767.0f)); - uint64* Packed = reinterpret_cast<uint64*>(&Topack); - return *Packed; + uint64 Packed; + std::memcpy(&Packed, &Topack, sizeof(Packed)); + return Packed; } GLM_FUNC_QUALIFIER vec4 unpackSnorm4x16(uint64 const & p) { - i16vec4* Unpack(reinterpret_cast<i16vec4*>(const_cast<uint64*>(&p))); + i16vec4 Unpack; + std::memcpy(&Unpack, &p, sizeof(Unpack)); return clamp( - vec4(*Unpack) * 3.0518509475997192297128208258309e-5f, //1.0f / 32767.0f, + vec4(Unpack) * 3.0518509475997192297128208258309e-5f, //1.0f / 32767.0f, -1.0f, 1.0f); } GLM_FUNC_QUALIFIER uint16 packHalf1x16(float const & v) { int16 Topack = detail::toFloat16(v); - uint16* Packed = reinterpret_cast<uint16*>(&Topack); - return *Packed; + uint16 Packed; + std::memcpy(&Packed, &Topack, sizeof(Packed)); + return Packed; } GLM_FUNC_QUALIFIER float unpackHalf1x16(uint16 const & v) { - int16* Unpack = reinterpret_cast<int16*>(const_cast<uint16*>(&v)); - return detail::toFloat32(*Unpack); + int16 Unpack; + std::memcpy(&Unpack, &v, sizeof(Unpack)); + return detail::toFloat32(Unpack); } GLM_FUNC_QUALIFIER uint64 packHalf4x16(glm::vec4 const & v) @@ -346,14 +366,15 @@ namespace detail detail::toFloat16(v.z), detail::toFloat16(v.w)); - uint64* Packed = reinterpret_cast<uint64*>(&Unpack); - return *Packed; + uint64 Packed; + std::memcpy(&Packed, &Unpack, sizeof(Packed)); + return Packed; } GLM_FUNC_QUALIFIER glm::vec4 unpackHalf4x16(uint64 const & v) { - i16vec4* p = reinterpret_cast<i16vec4*>(const_cast<uint64*>(&v)); - i16vec4 Unpack(*p); + i16vec4 Unpack; + std::memcpy(&Unpack, &v, sizeof(Unpack)); return vec4( detail::toFloat32(Unpack.x), Index: glm/test/core/core_func_common.cpp =================================================================== --- glm.orig/test/core/core_func_common.cpp +++ glm/test/core/core_func_common.cpp @@ -67,7 +67,8 @@ int test_floatBitsToInt() float A = 1.0f; int B = glm::floatBitsToInt(A); float C = glm::intBitsToFloat(B); - int D = *(int*)&A; + int D; + std::memcpy(&D, &A, sizeof(D)); Error += B == D ? 0 : 1; Error += A == C ? 0 : 1; } @@ -76,8 +77,11 @@ int test_floatBitsToInt() glm::vec2 A(1.0f, 2.0f); glm::ivec2 B = glm::floatBitsToInt(A); glm::vec2 C = glm::intBitsToFloat(B); - Error += B.x == *(int*)&(A.x) ? 0 : 1; - Error += B.y == *(int*)&(A.y) ? 0 : 1; + int D; + std::memcpy(&D, &A.x, sizeof(D)); + Error += B.x == D ? 0 : 1; + std::memcpy(&D, &A.y, sizeof(D)); + Error += B.y == D ? 0 : 1; Error += A == C? 0 : 1; } @@ -85,9 +89,13 @@ int test_floatBitsToInt() glm::vec3 A(1.0f, 2.0f, 3.0f); glm::ivec3 B = glm::floatBitsToInt(A); glm::vec3 C = glm::intBitsToFloat(B); - Error += B.x == *(int*)&(A.x) ? 0 : 1; - Error += B.y == *(int*)&(A.y) ? 0 : 1; - Error += B.z == *(int*)&(A.z) ? 0 : 1; + int D; + std::memcpy(&D, &A.x, sizeof(D)); + Error += B.x == D ? 0 : 1; + std::memcpy(&D, &A.y, sizeof(D)); + Error += B.y == D ? 0 : 1; + std::memcpy(&D, &A.z, sizeof(D)); + Error += B.z == D ? 0 : 1; Error += A == C? 0 : 1; } @@ -95,10 +103,15 @@ int test_floatBitsToInt() glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f); glm::ivec4 B = glm::floatBitsToInt(A); glm::vec4 C = glm::intBitsToFloat(B); - Error += B.x == *(int*)&(A.x) ? 0 : 1; - Error += B.y == *(int*)&(A.y) ? 0 : 1; - Error += B.z == *(int*)&(A.z) ? 0 : 1; - Error += B.w == *(int*)&(A.w) ? 0 : 1; + int D; + std::memcpy(&D, &A.x, sizeof(D)); + Error += B.x == D ? 0 : 1; + std::memcpy(&D, &A.y, sizeof(D)); + Error += B.y == D ? 0 : 1; + std::memcpy(&D, &A.z, sizeof(D)); + Error += B.z == D ? 0 : 1; + std::memcpy(&D, &A.w, sizeof(D)); + Error += B.w == D ? 0 : 1; Error += A == C? 0 : 1; } @@ -113,7 +126,9 @@ int test_floatBitsToUint() float A = 1.0f; glm::uint B = glm::floatBitsToUint(A); float C = glm::intBitsToFloat(B); - Error += B == *(glm::uint*)&A ? 0 : 1; + glm::uint D; + std::memcpy(&D, &A, sizeof(D)); + Error += B == D ? 0 : 1; Error += A == C? 0 : 1; } @@ -121,8 +136,11 @@ int test_floatBitsToUint() glm::vec2 A(1.0f, 2.0f); glm::uvec2 B = glm::floatBitsToUint(A); glm::vec2 C = glm::uintBitsToFloat(B); - Error += B.x == *(glm::uint*)&(A.x) ? 0 : 1; - Error += B.y == *(glm::uint*)&(A.y) ? 0 : 1; + glm::uint D; + std::memcpy(&D, &A.x, sizeof(D)); + Error += B.x == D ? 0 : 1; + std::memcpy(&D, &A.y, sizeof(D)); + Error += B.y == D ? 0 : 1; Error += A == C ? 0 : 1; } @@ -130,9 +148,13 @@ int test_floatBitsToUint() glm::vec3 A(1.0f, 2.0f, 3.0f); glm::uvec3 B = glm::floatBitsToUint(A); glm::vec3 C = glm::uintBitsToFloat(B); - Error += B.x == *(glm::uint*)&(A.x) ? 0 : 1; - Error += B.y == *(glm::uint*)&(A.y) ? 0 : 1; - Error += B.z == *(glm::uint*)&(A.z) ? 0 : 1; + glm::uint D; + std::memcpy(&D, &A.x, sizeof(D)); + Error += B.x == D ? 0 : 1; + std::memcpy(&D, &A.y, sizeof(D)); + Error += B.y == D ? 0 : 1; + std::memcpy(&D, &A.z, sizeof(D)); + Error += B.z == D ? 0 : 1; Error += A == C? 0 : 1; } @@ -140,10 +162,15 @@ int test_floatBitsToUint() glm::vec4 A(1.0f, 2.0f, 3.0f, 4.0f); glm::uvec4 B = glm::floatBitsToUint(A); glm::vec4 C = glm::uintBitsToFloat(B); - Error += B.x == *(glm::uint*)&(A.x) ? 0 : 1; - Error += B.y == *(glm::uint*)&(A.y) ? 0 : 1; - Error += B.z == *(glm::uint*)&(A.z) ? 0 : 1; - Error += B.w == *(glm::uint*)&(A.w) ? 0 : 1; + glm::uint D; + std::memcpy(&D, &A.x, sizeof(D)); + Error += B.x == D ? 0 : 1; + std::memcpy(&D, &A.y, sizeof(D)); + Error += B.y == D ? 0 : 1; + std::memcpy(&D, &A.z, sizeof(D)); + Error += B.z == D ? 0 : 1; + std::memcpy(&D, &A.w, sizeof(D)); + Error += B.w == D ? 0 : 1; Error += A == C? 0 : 1; }
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor