From cc86f0d13f9a703b38d91b8512b8fe9e7aad0d79 Mon Sep 17 00:00:00 2001 From: Harlen Date: Fri, 26 Aug 2022 13:26:56 -0300 Subject: [PATCH] Fix strict aliasing violation --- SPIRV/GlslangToSpv.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp index 75fff356..bff57bcd 100644 --- a/SPIRV/GlslangToSpv.cpp +++ b/SPIRV/GlslangToSpv.cpp @@ -1338,7 +1338,9 @@ void TGlslangToSpvTraverser::TranslateLiterals(const glslang::TVectorgetBasicType() == glslang::EbtFloat) { float floatValue = static_cast(constant->getConstArray()[0].getDConst()); - unsigned literal = *reinterpret_cast(&floatValue); + unsigned literal; + static_assert(sizeof(literal) == sizeof(floatValue), "sizeof(unsigned) != sizeof(float)"); + memcpy(&literal, &floatValue, sizeof(literal)); literals.push_back(literal); } else if (constant->getBasicType() == glslang::EbtInt) { unsigned literal = constant->getConstArray()[0].getIConst(); @@ -4247,7 +4249,9 @@ spv::Id TGlslangToSpvTraverser::convertGlslangToSpvType(const glslang::TType& ty if (typeParam.constant->isLiteral()) { if (typeParam.constant->getBasicType() == glslang::EbtFloat) { float floatValue = static_cast(typeParam.constant->getConstArray()[0].getDConst()); - unsigned literal = *reinterpret_cast(&floatValue); + unsigned literal; + static_assert(sizeof(literal) == sizeof(floatValue), "sizeof(unsigned) != sizeof(float)"); + memcpy(&literal, &floatValue, sizeof(literal)); operands.push_back({false, literal}); } else if (typeParam.constant->getBasicType() == glslang::EbtInt) { unsigned literal = typeParam.constant->getConstArray()[0].getIConst();