|
@@ -4465,7 +4465,7 @@ uint32_t SPIRVEmitter::castToInt(const uint32_t fromVal, QualType fromType,
|
|
|
if (isSameScalarOrVecType(fromType, toIntType))
|
|
|
return fromVal;
|
|
|
|
|
|
- const uint32_t intType = typeTranslator.translateType(toIntType);
|
|
|
+ uint32_t intType = typeTranslator.translateType(toIntType);
|
|
|
|
|
|
// AST may include a 'literal int' to 'int' conversion. No-op.
|
|
|
if (fromType->isLiteralType(astContext) && fromType->isIntegerType() &&
|
|
@@ -4475,6 +4475,15 @@ uint32_t SPIRVEmitter::castToInt(const uint32_t fromVal, QualType fromType,
|
|
|
if (isBoolOrVecOfBoolType(fromType)) {
|
|
|
const uint32_t one = getValueOne(toIntType);
|
|
|
const uint32_t zero = getValueZero(toIntType);
|
|
|
+ if (toIntType->isScalarType() && toIntType->isLiteralType(astContext)) {
|
|
|
+ // Special case for handling casting from boolean values to literal ints.
|
|
|
+ // For source code like (a == b) != 5, an IntegralCast will be inserted
|
|
|
+ // for (a == b), whose return type will be 64-bit integer if following the
|
|
|
+ // normal path.
|
|
|
+ // TODO: This is not beautiful. But other ways are even worse.
|
|
|
+ intType = toIntType->isSignedIntegerType() ? theBuilder.getInt32Type()
|
|
|
+ : theBuilder.getUint32Type();
|
|
|
+ }
|
|
|
return theBuilder.createSelect(intType, fromVal, one, zero);
|
|
|
}
|
|
|
|