diff --git a/src/sksl/SkSLIRGenerator.cpp b/src/sksl/SkSLIRGenerator.cpp index 21b9c129c5..f9d26832f3 100644 --- a/src/sksl/SkSLIRGenerator.cpp +++ b/src/sksl/SkSLIRGenerator.cpp @@ -2099,11 +2099,13 @@ std::unique_ptr IRGenerator::call(int offset, if (!arguments[i]) { return nullptr; } - if (arguments[i] && (function.fParameters[i]->fModifiers.fFlags & Modifiers::kOut_Flag)) { - this->setRefKind(*arguments[i], - function.fParameters[i]->fModifiers.fFlags & Modifiers::kIn_Flag ? - VariableReference::kReadWrite_RefKind : - VariableReference::kPointer_RefKind); + const Modifiers& paramModifiers = function.fParameters[i]->fModifiers; + if (paramModifiers.fFlags & Modifiers::kOut_Flag) { + if (!this->setRefKind(*arguments[i], paramModifiers.fFlags & Modifiers::kIn_Flag + ? VariableReference::kReadWrite_RefKind + : VariableReference::kPointer_RefKind)) { + return nullptr; + } } } @@ -2359,23 +2361,23 @@ std::unique_ptr IRGenerator::convertPrefixExpression(const ASTNode& return nullptr; } return base; + case Token::Kind::TK_MINUS: - if (base->kind() == Expression::Kind::kIntLiteral) { - return std::unique_ptr(new IntLiteral(fContext, base->fOffset, - -base->as().fValue)); + if (base->is()) { + return std::make_unique(fContext, base->fOffset, + -base->as().fValue); } - if (base->kind() == Expression::Kind::kFloatLiteral) { - double value = -base->as().fValue; - return std::unique_ptr(new FloatLiteral(fContext, base->fOffset, - value)); + if (base->is()) { + return std::make_unique(fContext, base->fOffset, + -base->as().fValue); } if (!baseType.isNumber() && baseType.typeKind() != Type::TypeKind::kVector) { fErrors.error(expression.fOffset, "'-' cannot operate on '" + baseType.displayName() + "'"); return nullptr; } - return std::unique_ptr(new PrefixExpression(Token::Kind::TK_MINUS, - std::move(base))); + return std::make_unique(Token::Kind::TK_MINUS, std::move(base)); + case Token::Kind::TK_PLUSPLUS: if (!baseType.isNumber()) { fErrors.error(expression.fOffset, @@ -2383,7 +2385,9 @@ std::unique_ptr IRGenerator::convertPrefixExpression(const ASTNode& "' cannot operate on '" + baseType.displayName() + "'"); return nullptr; } - this->setRefKind(*base, VariableReference::kReadWrite_RefKind); + if (!this->setRefKind(*base, VariableReference::kReadWrite_RefKind)) { + return nullptr; + } break; case Token::Kind::TK_MINUSMINUS: if (!baseType.isNumber()) { @@ -2392,7 +2396,9 @@ std::unique_ptr IRGenerator::convertPrefixExpression(const ASTNode& "' cannot operate on '" + baseType.displayName() + "'"); return nullptr; } - this->setRefKind(*base, VariableReference::kReadWrite_RefKind); + if (!this->setRefKind(*base, VariableReference::kReadWrite_RefKind)) { + return nullptr; + } break; case Token::Kind::TK_LOGICALNOT: if (baseType != *fContext.fBool_Type) { @@ -2402,8 +2408,8 @@ std::unique_ptr IRGenerator::convertPrefixExpression(const ASTNode& return nullptr; } if (base->kind() == Expression::Kind::kBoolLiteral) { - return std::unique_ptr( - new BoolLiteral(fContext, base->fOffset, !base->as().fValue)); + return std::make_unique(fContext, base->fOffset, + !base->as().fValue); } break; case Token::Kind::TK_BITWISENOT: @@ -2417,8 +2423,7 @@ std::unique_ptr IRGenerator::convertPrefixExpression(const ASTNode& default: ABORT("unsupported prefix operator\n"); } - return std::unique_ptr(new PrefixExpression(expression.getToken().fKind, - std::move(base))); + return std::make_unique(expression.getToken().fKind, std::move(base)); } std::unique_ptr IRGenerator::convertIndex(std::unique_ptr base, @@ -2784,9 +2789,10 @@ std::unique_ptr IRGenerator::convertPostfixExpression(const ASTNode& "' cannot operate on '" + baseType.displayName() + "'"); return nullptr; } - this->setRefKind(*base, VariableReference::kReadWrite_RefKind); - return std::unique_ptr(new PostfixExpression(std::move(base), - expression.getToken().fKind)); + if (!this->setRefKind(*base, VariableReference::kReadWrite_RefKind)) { + return nullptr; + } + return std::make_unique(std::move(base), expression.getToken().fKind); } void IRGenerator::checkValid(const Expression& expr) { diff --git a/src/sksl/SkSLInliner.cpp b/src/sksl/SkSLInliner.cpp index 2eb77580a6..f17b9fe9d3 100644 --- a/src/sksl/SkSLInliner.cpp +++ b/src/sksl/SkSLInliner.cpp @@ -668,7 +668,7 @@ Inliner::InlinedCall Inliner::inlineCall(FunctionCall* call, const Variable* p = function.fDeclaration.fParameters[i]; if (p->fModifiers.fFlags & Modifiers::kOut_Flag) { SkASSERT(varMap.find(p) != varMap.end()); - if (arguments[i]->kind() == Expression::Kind::kVariableReference && + if (arguments[i]->is() && &arguments[i]->as().fVariable == varMap[p]) { // We didn't create a temporary for this parameter, so there's nothing to copy back // out. diff --git a/tests/SkSLGLSLTestbed.cpp b/tests/SkSLGLSLTestbed.cpp index baffd8bcf8..cbf40c129a 100644 --- a/tests/SkSLGLSLTestbed.cpp +++ b/tests/SkSLGLSLTestbed.cpp @@ -30,6 +30,7 @@ static void test(skiatest::Reporter* r, const SkSL::Program::Settings& settings, *inputs = program->fInputs; REPORTER_ASSERT(r, compiler.toGLSL(*program, &output)); REPORTER_ASSERT(r, output != ""); + //SkDebugf("GLSL output:\n\n%s", output.c_str()); } } diff --git a/tests/sksl/errors/golden/InvalidOutParams.glsl b/tests/sksl/errors/golden/InvalidOutParams.glsl index 9d598bb7b2..c3621d43a4 100644 --- a/tests/sksl/errors/golden/InvalidOutParams.glsl +++ b/tests/sksl/errors/golden/InvalidOutParams.glsl @@ -1,3 +1,6 @@ ### Compilation failed: - +error: 1: cannot assign to this expression +error: 5: cannot assign to this expression +error: 6: cannot assign to this expression +3 errors