mirror of
https://github.com/KhronosGroup/glslang
synced 2024-11-10 04:20:06 +00:00
Fix strict aliasing violation
This commit is contained in:
parent
9e78bc8108
commit
cc86f0d13f
@ -1338,7 +1338,9 @@ void TGlslangToSpvTraverser::TranslateLiterals(const glslang::TVector<const glsl
|
|||||||
for (auto constant : constants) {
|
for (auto constant : constants) {
|
||||||
if (constant->getBasicType() == glslang::EbtFloat) {
|
if (constant->getBasicType() == glslang::EbtFloat) {
|
||||||
float floatValue = static_cast<float>(constant->getConstArray()[0].getDConst());
|
float floatValue = static_cast<float>(constant->getConstArray()[0].getDConst());
|
||||||
unsigned literal = *reinterpret_cast<unsigned*>(&floatValue);
|
unsigned literal;
|
||||||
|
static_assert(sizeof(literal) == sizeof(floatValue), "sizeof(unsigned) != sizeof(float)");
|
||||||
|
memcpy(&literal, &floatValue, sizeof(literal));
|
||||||
literals.push_back(literal);
|
literals.push_back(literal);
|
||||||
} else if (constant->getBasicType() == glslang::EbtInt) {
|
} else if (constant->getBasicType() == glslang::EbtInt) {
|
||||||
unsigned literal = constant->getConstArray()[0].getIConst();
|
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->isLiteral()) {
|
||||||
if (typeParam.constant->getBasicType() == glslang::EbtFloat) {
|
if (typeParam.constant->getBasicType() == glslang::EbtFloat) {
|
||||||
float floatValue = static_cast<float>(typeParam.constant->getConstArray()[0].getDConst());
|
float floatValue = static_cast<float>(typeParam.constant->getConstArray()[0].getDConst());
|
||||||
unsigned literal = *reinterpret_cast<unsigned*>(&floatValue);
|
unsigned literal;
|
||||||
|
static_assert(sizeof(literal) == sizeof(floatValue), "sizeof(unsigned) != sizeof(float)");
|
||||||
|
memcpy(&literal, &floatValue, sizeof(literal));
|
||||||
operands.push_back({false, literal});
|
operands.push_back({false, literal});
|
||||||
} else if (typeParam.constant->getBasicType() == glslang::EbtInt) {
|
} else if (typeParam.constant->getBasicType() == glslang::EbtInt) {
|
||||||
unsigned literal = typeParam.constant->getConstArray()[0].getIConst();
|
unsigned literal = typeParam.constant->getConstArray()[0].getIConst();
|
||||||
|
Loading…
Reference in New Issue
Block a user