Commit 55b22d6e by Nicolas Capens

Safely promote uninitialized constants.

Bug 19331817 Change-Id: Ia0e032301f360b7d866c3d64ee6cf41c2e481bf3 Reviewed-on: https://swiftshader-review.googlesource.com/2120Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com>
parent 2e2ba8dd
...@@ -1184,7 +1184,6 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod ...@@ -1184,7 +1184,6 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod
TIntermTyped* TIntermediate::promoteConstantUnion(TBasicType promoteTo, TIntermConstantUnion* node) TIntermTyped* TIntermediate::promoteConstantUnion(TBasicType promoteTo, TIntermConstantUnion* node)
{ {
ConstantUnion *rightUnionArray = node->getUnionArrayPointer();
int size = node->getType().getObjectSize(); int size = node->getType().getObjectSize();
ConstantUnion *leftUnionArray = new ConstantUnion[size]; ConstantUnion *leftUnionArray = new ConstantUnion[size];
...@@ -1195,13 +1194,13 @@ TIntermTyped* TIntermediate::promoteConstantUnion(TBasicType promoteTo, TIntermC ...@@ -1195,13 +1194,13 @@ TIntermTyped* TIntermediate::promoteConstantUnion(TBasicType promoteTo, TIntermC
case EbtFloat: case EbtFloat:
switch (node->getType().getBasicType()) { switch (node->getType().getBasicType()) {
case EbtInt: case EbtInt:
leftUnionArray[i].setFConst(static_cast<float>(rightUnionArray[i].getIConst())); leftUnionArray[i].setFConst(static_cast<float>(node->getIConst(i)));
break; break;
case EbtBool: case EbtBool:
leftUnionArray[i].setFConst(static_cast<float>(rightUnionArray[i].getBConst())); leftUnionArray[i].setFConst(static_cast<float>(node->getBConst(i)));
break; break;
case EbtFloat: case EbtFloat:
leftUnionArray[i] = rightUnionArray[i]; leftUnionArray[i].setFConst(static_cast<float>(node->getFConst(i)));
break; break;
default: default:
infoSink.info.message(EPrefixInternalError, "Cannot promote", node->getLine()); infoSink.info.message(EPrefixInternalError, "Cannot promote", node->getLine());
...@@ -1211,13 +1210,13 @@ TIntermTyped* TIntermediate::promoteConstantUnion(TBasicType promoteTo, TIntermC ...@@ -1211,13 +1210,13 @@ TIntermTyped* TIntermediate::promoteConstantUnion(TBasicType promoteTo, TIntermC
case EbtInt: case EbtInt:
switch (node->getType().getBasicType()) { switch (node->getType().getBasicType()) {
case EbtInt: case EbtInt:
leftUnionArray[i] = rightUnionArray[i]; leftUnionArray[i].setIConst(static_cast<int>(node->getIConst(i)));
break; break;
case EbtBool: case EbtBool:
leftUnionArray[i].setIConst(static_cast<int>(rightUnionArray[i].getBConst())); leftUnionArray[i].setIConst(static_cast<int>(node->getBConst(i)));
break; break;
case EbtFloat: case EbtFloat:
leftUnionArray[i].setIConst(static_cast<int>(rightUnionArray[i].getFConst())); leftUnionArray[i].setIConst(static_cast<int>(node->getFConst(i)));
break; break;
default: default:
infoSink.info.message(EPrefixInternalError, "Cannot promote", node->getLine()); infoSink.info.message(EPrefixInternalError, "Cannot promote", node->getLine());
...@@ -1227,13 +1226,13 @@ TIntermTyped* TIntermediate::promoteConstantUnion(TBasicType promoteTo, TIntermC ...@@ -1227,13 +1226,13 @@ TIntermTyped* TIntermediate::promoteConstantUnion(TBasicType promoteTo, TIntermC
case EbtBool: case EbtBool:
switch (node->getType().getBasicType()) { switch (node->getType().getBasicType()) {
case EbtInt: case EbtInt:
leftUnionArray[i].setBConst(rightUnionArray[i].getIConst() != 0); leftUnionArray[i].setBConst(node->getIConst(i) != 0);
break; break;
case EbtBool: case EbtBool:
leftUnionArray[i] = rightUnionArray[i]; leftUnionArray[i].setBConst(node->getBConst(i));
break; break;
case EbtFloat: case EbtFloat:
leftUnionArray[i].setBConst(rightUnionArray[i].getFConst() != 0.0f); leftUnionArray[i].setBConst(node->getFConst(i) != 0.0f);
break; break;
default: default:
infoSink.info.message(EPrefixInternalError, "Cannot promote", node->getLine()); infoSink.info.message(EPrefixInternalError, "Cannot promote", node->getLine());
......
...@@ -1175,7 +1175,6 @@ TIntermTyped* TParseContext::addConstVectorNode(TVectorFields& fields, TIntermTy ...@@ -1175,7 +1175,6 @@ TIntermTyped* TParseContext::addConstVectorNode(TVectorFields& fields, TIntermTy
ConstantUnion *unionArray; ConstantUnion *unionArray;
if (tempConstantNode) { if (tempConstantNode) {
unionArray = tempConstantNode->getUnionArrayPointer(); unionArray = tempConstantNode->getUnionArrayPointer();
ASSERT(unionArray);
if (!unionArray) { if (!unionArray) {
return node; return node;
......
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