Safely promote uninitialized constants.

TRAC #22676 Signed-off-by: Geoff Lang Signed-off-by: Shannon Woods Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/trunk@1998 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent 88de0c74
...@@ -1378,7 +1378,6 @@ TIntermTyped* TIntermConstantUnion::fold(TOperator op, TIntermTyped* constantNod ...@@ -1378,7 +1378,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];
...@@ -1389,13 +1388,13 @@ TIntermTyped* TIntermediate::promoteConstantUnion(TBasicType promoteTo, TIntermC ...@@ -1389,13 +1388,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());
...@@ -1405,13 +1404,13 @@ TIntermTyped* TIntermediate::promoteConstantUnion(TBasicType promoteTo, TIntermC ...@@ -1405,13 +1404,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());
...@@ -1421,13 +1420,13 @@ TIntermTyped* TIntermediate::promoteConstantUnion(TBasicType promoteTo, TIntermC ...@@ -1421,13 +1420,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());
......
...@@ -1313,7 +1313,6 @@ TIntermTyped* TParseContext::addConstVectorNode(TVectorFields& fields, TIntermTy ...@@ -1313,7 +1313,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