Merge pull request #1411 from KhronosGroup/fix-literal-warnings

Build: Make literal casting have fewer warnings and be more consistent.
This commit is contained in:
John Kessenich 2018-06-20 18:54:12 -06:00 committed by GitHub
commit 16cf5a5dc2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 24 deletions

46
glslang/MachineIndependent/Constant.cpp Normal file → Executable file
View File

@ -182,66 +182,66 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, const TIntermTyped* right
newConstArray[i].setDConst(leftUnionArray[i].getDConst() / rightUnionArray[i].getDConst()); newConstArray[i].setDConst(leftUnionArray[i].getDConst() / rightUnionArray[i].getDConst());
break; break;
case EbtInt8: case EbtInt8:
if (rightUnionArray[i] == 0) if (rightUnionArray[i] == (signed char)0)
newConstArray[i].setI8Const(0x7F); newConstArray[i].setI8Const((signed char)0x7F);
else if (rightUnionArray[i].getI8Const() == -1 && leftUnionArray[i].getI8Const() == (signed char)0x80) else if (rightUnionArray[i].getI8Const() == (signed char)-1 && leftUnionArray[i].getI8Const() == (signed char)-0x80)
newConstArray[i].setI8Const((signed char)0x80); newConstArray[i].setI8Const((signed char)-0x80);
else else
newConstArray[i].setI8Const(leftUnionArray[i].getI8Const() / rightUnionArray[i].getI8Const()); newConstArray[i].setI8Const(leftUnionArray[i].getI8Const() / rightUnionArray[i].getI8Const());
break; break;
case EbtUint8: case EbtUint8:
if (rightUnionArray[i] == 0) { if (rightUnionArray[i] == (unsigned char)0u)
newConstArray[i].setU8Const(0xFF); newConstArray[i].setU8Const((unsigned char)0xFFu);
} else else
newConstArray[i].setU8Const(leftUnionArray[i].getU8Const() / rightUnionArray[i].getU8Const()); newConstArray[i].setU8Const(leftUnionArray[i].getU8Const() / rightUnionArray[i].getU8Const());
break; break;
case EbtInt16: case EbtInt16:
if (rightUnionArray[i] == 0) if (rightUnionArray[i] == (signed short)0)
newConstArray[i].setI16Const(0x7FFF); newConstArray[i].setI16Const((signed short)0x7FFF);
else if (rightUnionArray[i].getI16Const() == -1 && leftUnionArray[i].getI16Const() == (signed short)0x8000) else if (rightUnionArray[i].getI16Const() == (signed short)-1 && leftUnionArray[i].getI16Const() == (signed short)-0x8000)
newConstArray[i].setI16Const(short(0x8000)); newConstArray[i].setI16Const((signed short)-0x8000);
else else
newConstArray[i].setI16Const(leftUnionArray[i].getI16Const() / rightUnionArray[i].getI16Const()); newConstArray[i].setI16Const(leftUnionArray[i].getI16Const() / rightUnionArray[i].getI16Const());
break; break;
case EbtUint16: case EbtUint16:
if (rightUnionArray[i] == 0) { if (rightUnionArray[i] == (unsigned short)0u)
newConstArray[i].setU16Const(0xFFFF); newConstArray[i].setU16Const((unsigned short)0xFFFFu);
} else else
newConstArray[i].setU16Const(leftUnionArray[i].getU16Const() / rightUnionArray[i].getU16Const()); newConstArray[i].setU16Const(leftUnionArray[i].getU16Const() / rightUnionArray[i].getU16Const());
break; break;
case EbtInt: case EbtInt:
if (rightUnionArray[i] == 0) if (rightUnionArray[i] == 0)
newConstArray[i].setIConst(0x7FFFFFFF); newConstArray[i].setIConst(0x7FFFFFFF);
else if (rightUnionArray[i].getIConst() == -1 && leftUnionArray[i].getIConst() == (int)0x80000000) else if (rightUnionArray[i].getIConst() == -1 && leftUnionArray[i].getIConst() == -(int)0x80000000)
newConstArray[i].setIConst(0x80000000); newConstArray[i].setIConst(-(int)0x80000000);
else else
newConstArray[i].setIConst(leftUnionArray[i].getIConst() / rightUnionArray[i].getIConst()); newConstArray[i].setIConst(leftUnionArray[i].getIConst() / rightUnionArray[i].getIConst());
break; break;
case EbtUint: case EbtUint:
if (rightUnionArray[i] == 0) { if (rightUnionArray[i] == 0u)
newConstArray[i].setUConst(0xFFFFFFFFu); newConstArray[i].setUConst(0xFFFFFFFFu);
} else else
newConstArray[i].setUConst(leftUnionArray[i].getUConst() / rightUnionArray[i].getUConst()); newConstArray[i].setUConst(leftUnionArray[i].getUConst() / rightUnionArray[i].getUConst());
break; break;
case EbtInt64: case EbtInt64:
if (rightUnionArray[i] == 0) if (rightUnionArray[i] == 0ll)
newConstArray[i].setI64Const(0x7FFFFFFFFFFFFFFFll); newConstArray[i].setI64Const(0x7FFFFFFFFFFFFFFFll);
else if (rightUnionArray[i].getI64Const() == -1 && leftUnionArray[i].getI64Const() == (long long)0x8000000000000000) else if (rightUnionArray[i].getI64Const() == -1 && leftUnionArray[i].getI64Const() == -0x8000000000000000ll)
newConstArray[i].setI64Const(0x8000000000000000); newConstArray[i].setI64Const(-0x8000000000000000ll);
else else
newConstArray[i].setI64Const(leftUnionArray[i].getI64Const() / rightUnionArray[i].getI64Const()); newConstArray[i].setI64Const(leftUnionArray[i].getI64Const() / rightUnionArray[i].getI64Const());
break; break;
case EbtUint64: case EbtUint64:
if (rightUnionArray[i] == 0) { if (rightUnionArray[i] == 0ull)
newConstArray[i].setU64Const(0xFFFFFFFFFFFFFFFFull); newConstArray[i].setU64Const(0xFFFFFFFFFFFFFFFFull);
} else else
newConstArray[i].setU64Const(leftUnionArray[i].getU64Const() / rightUnionArray[i].getU64Const()); newConstArray[i].setU64Const(leftUnionArray[i].getU64Const() / rightUnionArray[i].getU64Const());
break; break;
default: default:

View File

@ -239,7 +239,7 @@ int TPpContext::TokenStream::getToken(TParseContextBase& parseContext, TPpToken
if (SaveValue(atom)) { if (SaveValue(atom)) {
char* n = reinterpret_cast<char*>(&ppToken->i64val); char* n = reinterpret_cast<char*>(&ppToken->i64val);
for (size_t i = 0; i < sizeof(ppToken->i64val); ++i) for (size_t i = 0; i < sizeof(ppToken->i64val); ++i)
*n++ = getSubtoken(); *n++ = (char)getSubtoken();
} }
return atom; return atom;