Commit 2aafa18b by Olli Etuaho

Fix null check after addUnaryMath is called for a built-in function

The intermTypedNode pointer null check should be done before the pointer is used, not after. In practice the pointer should never be null if IntermUnary::promote() is consistent with the built-in function table, but it's useful to have the null check as a fail-safe when developing. Change-Id: I24e0d7399ef9d628f474e99fbca08dbd67fdd8c3 Reviewed-on: https://chromium-review.googlesource.com/240411Tested-by: 's avatarOlli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 433c85d3
...@@ -353,6 +353,13 @@ function_call ...@@ -353,6 +353,13 @@ function_call
// Treat it like a built-in unary operator. // Treat it like a built-in unary operator.
// //
$$ = context->intermediate.addUnaryMath(op, $1.intermNode, @1); $$ = context->intermediate.addUnaryMath(op, $1.intermNode, @1);
if ($$ == 0) {
std::stringstream extraInfoStream;
extraInfoStream << "built in unary operator function. Type: " << static_cast<TIntermTyped*>($1.intermNode)->getCompleteString();
std::string extraInfo = extraInfoStream.str();
context->error($1.intermNode->getLine(), " wrong operand type", "Internal Error", extraInfo.c_str());
YYERROR;
}
const TType& returnType = fnCandidate->getReturnType(); const TType& returnType = fnCandidate->getReturnType();
if (returnType.getBasicType() == EbtBool) { if (returnType.getBasicType() == EbtBool) {
// Bool types should not have precision, so we'll override any precision // Bool types should not have precision, so we'll override any precision
...@@ -362,13 +369,6 @@ function_call ...@@ -362,13 +369,6 @@ function_call
// addUnaryMath has set the precision of the node based on the operand. // addUnaryMath has set the precision of the node based on the operand.
$$->setTypePreservePrecision(returnType); $$->setTypePreservePrecision(returnType);
} }
if ($$ == 0) {
std::stringstream extraInfoStream;
extraInfoStream << "built in unary operator function. Type: " << static_cast<TIntermTyped*>($1.intermNode)->getCompleteString();
std::string extraInfo = extraInfoStream.str();
context->error($1.intermNode->getLine(), " wrong operand type", "Internal Error", extraInfo.c_str());
YYERROR;
}
} else { } else {
TIntermAggregate *aggregate = context->intermediate.setAggregateOperator($1.intermAggregate, op, @1); TIntermAggregate *aggregate = context->intermediate.setAggregateOperator($1.intermAggregate, op, @1);
aggregate->setType(fnCandidate->getReturnType()); aggregate->setType(fnCandidate->getReturnType());
......
...@@ -2505,6 +2505,13 @@ yyreduce: ...@@ -2505,6 +2505,13 @@ yyreduce:
// Treat it like a built-in unary operator. // Treat it like a built-in unary operator.
// //
(yyval.interm.intermTypedNode) = context->intermediate.addUnaryMath(op, (yyvsp[0].interm).intermNode, (yylsp[0])); (yyval.interm.intermTypedNode) = context->intermediate.addUnaryMath(op, (yyvsp[0].interm).intermNode, (yylsp[0]));
if ((yyval.interm.intermTypedNode) == 0) {
std::stringstream extraInfoStream;
extraInfoStream << "built in unary operator function. Type: " << static_cast<TIntermTyped*>((yyvsp[0].interm).intermNode)->getCompleteString();
std::string extraInfo = extraInfoStream.str();
context->error((yyvsp[0].interm).intermNode->getLine(), " wrong operand type", "Internal Error", extraInfo.c_str());
YYERROR;
}
const TType& returnType = fnCandidate->getReturnType(); const TType& returnType = fnCandidate->getReturnType();
if (returnType.getBasicType() == EbtBool) { if (returnType.getBasicType() == EbtBool) {
// Bool types should not have precision, so we'll override any precision // Bool types should not have precision, so we'll override any precision
...@@ -2514,13 +2521,6 @@ yyreduce: ...@@ -2514,13 +2521,6 @@ yyreduce:
// addUnaryMath has set the precision of the node based on the operand. // addUnaryMath has set the precision of the node based on the operand.
(yyval.interm.intermTypedNode)->setTypePreservePrecision(returnType); (yyval.interm.intermTypedNode)->setTypePreservePrecision(returnType);
} }
if ((yyval.interm.intermTypedNode) == 0) {
std::stringstream extraInfoStream;
extraInfoStream << "built in unary operator function. Type: " << static_cast<TIntermTyped*>((yyvsp[0].interm).intermNode)->getCompleteString();
std::string extraInfo = extraInfoStream.str();
context->error((yyvsp[0].interm).intermNode->getLine(), " wrong operand type", "Internal Error", extraInfo.c_str());
YYERROR;
}
} else { } else {
TIntermAggregate *aggregate = context->intermediate.setAggregateOperator((yyvsp[0].interm).intermAggregate, op, (yylsp[0])); TIntermAggregate *aggregate = context->intermediate.setAggregateOperator((yyvsp[0].interm).intermAggregate, op, (yylsp[0]));
aggregate->setType(fnCandidate->getReturnType()); aggregate->setType(fnCandidate->getReturnType());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment