@@ -2941,6 +2941,7 @@ Expr* SemanticsExprVisitor::convertToLogicOperatorExpr(InvokeExpr* expr)
2941
2941
bool shortCircuitSupport = true ;
2942
2942
for (auto & arg : expr->arguments )
2943
2943
{
2944
+ arg = maybeCoerceExprToProperIntType (arg);
2944
2945
if (!as<BasicExpressionType>(arg->type .type ))
2945
2946
{
2946
2947
shortCircuitSupport = false ;
@@ -3020,13 +3021,15 @@ Expr* SemanticsExprVisitor::visitInvokeExpr(InvokeExpr* expr)
3020
3021
{
3021
3022
arg = CheckExpr (arg);
3022
3023
}
3023
- if (auto result = tryFoldLiteralNegateExpr (expr))
3024
- return result;
3024
+
3025
3025
// if the expression is '&&' or '||', we will convert it
3026
3026
// to use short-circuit evaluation.
3027
3027
if (auto newExpr = convertToLogicOperatorExpr (expr))
3028
3028
return newExpr;
3029
3029
3030
+ if (auto result = tryFoldLiteralNegateExpr (expr))
3031
+ return result;
3032
+
3030
3033
expr->functionExpr = CheckTerm (expr->functionExpr );
3031
3034
3032
3035
if (auto baseType = as<DeclRefType>(expr->functionExpr ->type ))
@@ -4955,6 +4958,20 @@ Expr* SemanticsVisitor::checkGeneralMemberLookupExpr(MemberExpr* expr, Type* bas
4955
4958
return createLookupResultExpr (expr->name , lookupResult, expr->baseExpression , expr->loc , expr);
4956
4959
}
4957
4960
4961
+ bool isValidVectorSwizzleName (Name* name)
4962
+ {
4963
+ if (!name)
4964
+ return false ;
4965
+ if (name->text .getLength () > 4 || name->text .getLength () == 0 )
4966
+ return false ;
4967
+ for (auto ch : name->text )
4968
+ {
4969
+ if (ch < ' w' || ch > ' z' )
4970
+ return false ;
4971
+ }
4972
+ return true ;
4973
+ }
4974
+
4958
4975
Expr* SemanticsExprVisitor::visitMemberExpr (MemberExpr* expr)
4959
4976
{
4960
4977
bool needDeref = false ;
@@ -4996,15 +5013,21 @@ Expr* SemanticsExprVisitor::visitMemberExpr(MemberExpr* expr)
4996
5013
}
4997
5014
if (auto baseVecType = as<VectorExpressionType>(baseType))
4998
5015
{
4999
- return CheckSwizzleExpr (
5000
- expr,
5001
- baseVecType->getElementType (),
5002
- baseVecType->getElementCount ());
5016
+ if (isValidVectorSwizzleName (expr->name ))
5017
+ {
5018
+ return CheckSwizzleExpr (
5019
+ expr,
5020
+ baseVecType->getElementType (),
5021
+ baseVecType->getElementCount ());
5022
+ }
5003
5023
}
5004
- else if (auto baseScalarType = as<BasicExpressionType>(baseType))
5024
+ if (auto baseScalarType = as<BasicExpressionType>(baseType))
5005
5025
{
5006
- // Treat scalar like a 1-element vector when swizzling
5007
- return CheckSwizzleExpr (expr, baseScalarType, 1 );
5026
+ if (isValidVectorSwizzleName (expr->name ))
5027
+ {
5028
+ // Treat scalar like a 1-element vector when swizzling
5029
+ return CheckSwizzleExpr (expr, baseScalarType, 1 );
5030
+ }
5008
5031
}
5009
5032
else if (as<NamespaceType>(baseType))
5010
5033
{
0 commit comments