|
@@ -1903,6 +1903,24 @@ SpirvEvalInfo SPIRVEmitter::doCastExpr(const CastExpr *expr) {
|
|
|
const QualType subExprType = subExpr->getType();
|
|
|
const QualType toType = expr->getType();
|
|
|
|
|
|
+ // Unfortunately the front-end fails to deduce some types in certain cases.
|
|
|
+ // Provide a hint about literal type usage if possible.
|
|
|
+ TypeTranslator::LiteralTypeHint hint(typeTranslator);
|
|
|
+
|
|
|
+ // 'literal int' to 'float' conversion. If a literal integer is to be used as
|
|
|
+ // a 32-bit float, the hint is a 32-bit integer.
|
|
|
+ if (toType->isFloatingType() &&
|
|
|
+ subExprType->isSpecificBuiltinType(BuiltinType::LitInt) &&
|
|
|
+ llvm::APFloat::getSizeInBits(astContext.getFloatTypeSemantics(toType)) ==
|
|
|
+ 32)
|
|
|
+ hint.setHint(astContext.IntTy);
|
|
|
+ // TODO: We could provide other useful hints. For instance:
|
|
|
+ // For the case of toType being a boolean, if the fromType is a literal float,
|
|
|
+ // we could provide a FloatTy hint and if the fromType is a literal integer,
|
|
|
+ // we could provide an IntTy hint. The front-end, however, seems to deduce the
|
|
|
+ // correct type in these cases; therefore we currently don't provide any
|
|
|
+ // additional hints.
|
|
|
+
|
|
|
switch (expr->getCastKind()) {
|
|
|
case CastKind::CK_LValueToRValue:
|
|
|
return loadIfGLValue(subExpr);
|