Commit 081c3f2e by Arun Patole Committed by Olli Etuaho

Report warning whenever constant folding results are undefined

With recent constant folding changes, we are reporting warnings whenever constant folding results are undefined for values passed in, this change adds that warning at all the places where it was missing. BUG=angleproject:913 TEST=dEQP Tests, angle_unittests Change-Id: Ief8380488e2a4807c91ddac06d342cb172433b9d Reviewed-on: https://chromium-review.googlesource.com/272879Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarOlli Etuaho <oetuaho@nvidia.com> Tested-by: 's avatarOlli Etuaho <oetuaho@nvidia.com>
parent b2b6dfaf
...@@ -1289,7 +1289,7 @@ TIntermTyped *TIntermConstantUnion::fold( ...@@ -1289,7 +1289,7 @@ TIntermTyped *TIntermConstantUnion::fold(
case EOpAsin: case EOpAsin:
// For asin(x), results are undefined if |x| > 1, we are choosing to set result to 0. // For asin(x), results are undefined if |x| > 1, we are choosing to set result to 0.
if (getType().getBasicType() == EbtFloat && fabsf(unionArray[i].getFConst()) > 1.0f) if (getType().getBasicType() == EbtFloat && fabsf(unionArray[i].getFConst()) > 1.0f)
tempConstArray[i].setFConst(0.0f); UndefinedConstantFoldingError(getLine(), op, getType().getBasicType(), infoSink, &tempConstArray[i]);
else if (!foldFloatTypeUnary(unionArray[i], &asinf, infoSink, &tempConstArray[i])) else if (!foldFloatTypeUnary(unionArray[i], &asinf, infoSink, &tempConstArray[i]))
return nullptr; return nullptr;
break; break;
...@@ -1297,7 +1297,7 @@ TIntermTyped *TIntermConstantUnion::fold( ...@@ -1297,7 +1297,7 @@ TIntermTyped *TIntermConstantUnion::fold(
case EOpAcos: case EOpAcos:
// For acos(x), results are undefined if |x| > 1, we are choosing to set result to 0. // For acos(x), results are undefined if |x| > 1, we are choosing to set result to 0.
if (getType().getBasicType() == EbtFloat && fabsf(unionArray[i].getFConst()) > 1.0f) if (getType().getBasicType() == EbtFloat && fabsf(unionArray[i].getFConst()) > 1.0f)
tempConstArray[i].setFConst(0.0f); UndefinedConstantFoldingError(getLine(), op, getType().getBasicType(), infoSink, &tempConstArray[i]);
else if (!foldFloatTypeUnary(unionArray[i], &acosf, infoSink, &tempConstArray[i])) else if (!foldFloatTypeUnary(unionArray[i], &acosf, infoSink, &tempConstArray[i]))
return nullptr; return nullptr;
break; break;
...@@ -1330,7 +1330,7 @@ TIntermTyped *TIntermConstantUnion::fold( ...@@ -1330,7 +1330,7 @@ TIntermTyped *TIntermConstantUnion::fold(
case EOpAcosh: case EOpAcosh:
// For acosh(x), results are undefined if x < 1, we are choosing to set result to 0. // For acosh(x), results are undefined if x < 1, we are choosing to set result to 0.
if (getType().getBasicType() == EbtFloat && unionArray[i].getFConst() < 1.0f) if (getType().getBasicType() == EbtFloat && unionArray[i].getFConst() < 1.0f)
tempConstArray[i].setFConst(0.0f); UndefinedConstantFoldingError(getLine(), op, getType().getBasicType(), infoSink, &tempConstArray[i]);
else if (!foldFloatTypeUnary(unionArray[i], &acoshf, infoSink, &tempConstArray[i])) else if (!foldFloatTypeUnary(unionArray[i], &acoshf, infoSink, &tempConstArray[i]))
return nullptr; return nullptr;
break; break;
...@@ -1338,7 +1338,7 @@ TIntermTyped *TIntermConstantUnion::fold( ...@@ -1338,7 +1338,7 @@ TIntermTyped *TIntermConstantUnion::fold(
case EOpAtanh: case EOpAtanh:
// For atanh(x), results are undefined if |x| >= 1, we are choosing to set result to 0. // For atanh(x), results are undefined if |x| >= 1, we are choosing to set result to 0.
if (getType().getBasicType() == EbtFloat && fabsf(unionArray[i].getFConst()) >= 1.0f) if (getType().getBasicType() == EbtFloat && fabsf(unionArray[i].getFConst()) >= 1.0f)
tempConstArray[i].setFConst(0.0f); UndefinedConstantFoldingError(getLine(), op, getType().getBasicType(), infoSink, &tempConstArray[i]);
else if (!foldFloatTypeUnary(unionArray[i], &atanhf, infoSink, &tempConstArray[i])) else if (!foldFloatTypeUnary(unionArray[i], &atanhf, infoSink, &tempConstArray[i]))
return nullptr; return nullptr;
break; break;
...@@ -1451,7 +1451,7 @@ TIntermTyped *TIntermConstantUnion::fold( ...@@ -1451,7 +1451,7 @@ TIntermTyped *TIntermConstantUnion::fold(
case EOpLog: case EOpLog:
// For log(x), results are undefined if x <= 0, we are choosing to set result to 0. // For log(x), results are undefined if x <= 0, we are choosing to set result to 0.
if (getType().getBasicType() == EbtFloat && unionArray[i].getFConst() <= 0.0f) if (getType().getBasicType() == EbtFloat && unionArray[i].getFConst() <= 0.0f)
tempConstArray[i].setFConst(0.0f); UndefinedConstantFoldingError(getLine(), op, getType().getBasicType(), infoSink, &tempConstArray[i]);
else if (!foldFloatTypeUnary(unionArray[i], &logf, infoSink, &tempConstArray[i])) else if (!foldFloatTypeUnary(unionArray[i], &logf, infoSink, &tempConstArray[i]))
return nullptr; return nullptr;
break; break;
...@@ -1465,7 +1465,7 @@ TIntermTyped *TIntermConstantUnion::fold( ...@@ -1465,7 +1465,7 @@ TIntermTyped *TIntermConstantUnion::fold(
// For log2(x), results are undefined if x <= 0, we are choosing to set result to 0. // For log2(x), results are undefined if x <= 0, we are choosing to set result to 0.
// And log2f is not available on some plarforms like old android, so just using log(x)/log(2) here. // And log2f is not available on some plarforms like old android, so just using log(x)/log(2) here.
if (getType().getBasicType() == EbtFloat && unionArray[i].getFConst() <= 0.0f) if (getType().getBasicType() == EbtFloat && unionArray[i].getFConst() <= 0.0f)
tempConstArray[i].setFConst(0.0f); UndefinedConstantFoldingError(getLine(), op, getType().getBasicType(), infoSink, &tempConstArray[i]);
else if (!foldFloatTypeUnary(unionArray[i], &logf, infoSink, &tempConstArray[i])) else if (!foldFloatTypeUnary(unionArray[i], &logf, infoSink, &tempConstArray[i]))
return nullptr; return nullptr;
else else
...@@ -1475,7 +1475,7 @@ TIntermTyped *TIntermConstantUnion::fold( ...@@ -1475,7 +1475,7 @@ TIntermTyped *TIntermConstantUnion::fold(
case EOpSqrt: case EOpSqrt:
// For sqrt(x), results are undefined if x < 0, we are choosing to set result to 0. // For sqrt(x), results are undefined if x < 0, we are choosing to set result to 0.
if (getType().getBasicType() == EbtFloat && unionArray[i].getFConst() < 0.0f) if (getType().getBasicType() == EbtFloat && unionArray[i].getFConst() < 0.0f)
tempConstArray[i].setFConst(0.0f); UndefinedConstantFoldingError(getLine(), op, getType().getBasicType(), infoSink, &tempConstArray[i]);
else if (!foldFloatTypeUnary(unionArray[i], &sqrtf, infoSink, &tempConstArray[i])) else if (!foldFloatTypeUnary(unionArray[i], &sqrtf, infoSink, &tempConstArray[i]))
return nullptr; return nullptr;
break; break;
...@@ -1485,7 +1485,7 @@ TIntermTyped *TIntermConstantUnion::fold( ...@@ -1485,7 +1485,7 @@ TIntermTyped *TIntermConstantUnion::fold(
// so getting the square root first using builtin function sqrt() and then taking its inverse. // so getting the square root first using builtin function sqrt() and then taking its inverse.
// Also, for inversesqrt(x), results are undefined if x <= 0, we are choosing to set result to 0. // Also, for inversesqrt(x), results are undefined if x <= 0, we are choosing to set result to 0.
if (getType().getBasicType() == EbtFloat && unionArray[i].getFConst() <= 0.0f) if (getType().getBasicType() == EbtFloat && unionArray[i].getFConst() <= 0.0f)
tempConstArray[i].setFConst(0.0f); UndefinedConstantFoldingError(getLine(), op, getType().getBasicType(), infoSink, &tempConstArray[i]);
else if (!foldFloatTypeUnary(unionArray[i], &sqrtf, infoSink, &tempConstArray[i])) else if (!foldFloatTypeUnary(unionArray[i], &sqrtf, infoSink, &tempConstArray[i]))
return nullptr; return nullptr;
else else
...@@ -1712,7 +1712,7 @@ TIntermTyped *TIntermConstantUnion::FoldAggregateBuiltIn(TOperator op, TIntermAg ...@@ -1712,7 +1712,7 @@ TIntermTyped *TIntermConstantUnion::FoldAggregateBuiltIn(TOperator op, TIntermAg
float max = unionArrays[2][i].getFConst(); float max = unionArrays[2][i].getFConst();
// Results are undefined if min > max. // Results are undefined if min > max.
if (min > max) if (min > max)
tempConstArray[i].setFConst(0.0f); UndefinedConstantFoldingError(loc, op, basicType, infoSink, &tempConstArray[i]);
else else
tempConstArray[i].setFConst(gl::clamp(x, min, max)); tempConstArray[i].setFConst(gl::clamp(x, min, max));
} }
...@@ -1724,7 +1724,7 @@ TIntermTyped *TIntermConstantUnion::FoldAggregateBuiltIn(TOperator op, TIntermAg ...@@ -1724,7 +1724,7 @@ TIntermTyped *TIntermConstantUnion::FoldAggregateBuiltIn(TOperator op, TIntermAg
int max = unionArrays[2][i].getIConst(); int max = unionArrays[2][i].getIConst();
// Results are undefined if min > max. // Results are undefined if min > max.
if (min > max) if (min > max)
tempConstArray[i].setIConst(0); UndefinedConstantFoldingError(loc, op, basicType, infoSink, &tempConstArray[i]);
else else
tempConstArray[i].setIConst(gl::clamp(x, min, max)); tempConstArray[i].setIConst(gl::clamp(x, min, max));
} }
...@@ -1736,7 +1736,7 @@ TIntermTyped *TIntermConstantUnion::FoldAggregateBuiltIn(TOperator op, TIntermAg ...@@ -1736,7 +1736,7 @@ TIntermTyped *TIntermConstantUnion::FoldAggregateBuiltIn(TOperator op, TIntermAg
unsigned int max = unionArrays[2][i].getUConst(); unsigned int max = unionArrays[2][i].getUConst();
// Results are undefined if min > max. // Results are undefined if min > max.
if (min > max) if (min > max)
tempConstArray[i].setUConst(0u); UndefinedConstantFoldingError(loc, op, basicType, infoSink, &tempConstArray[i]);
else else
tempConstArray[i].setUConst(gl::clamp(x, min, max)); tempConstArray[i].setUConst(gl::clamp(x, min, max));
} }
......
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