Commit 96e67388 by Olli Etuaho

Fix array.length() to return a signed integer

array.length() should return a signed integer as specified in ESSL 3.00 section 4.1.9, not unsigned. Fix this and add a simple unit test - the dEQP tests included in WebGL conformance are built in a way that they don't catch the issue. TEST=angle_unittests BUG=angleproject:972 Change-Id: I1389f51751a6a25c1681f57ac3d2d52f31ecc8fb Reviewed-on: https://chromium-review.googlesource.com/266991Reviewed-by: 's avatarOlli Etuaho <oetuaho@nvidia.com> Tested-by: 's avatarOlli Etuaho <oetuaho@nvidia.com>
parent d42f5b8c
......@@ -3148,7 +3148,7 @@ TIntermTyped *TParseContext::addFunctionCallOrMethod(TFunction *fnCall, TIntermN
if (thisNode != nullptr)
{
ConstantUnion *unionArray = new ConstantUnion[1];
unsigned int arraySize = 0;
int arraySize = 0;
TIntermTyped *typedThis = thisNode->getAsTyped();
if (fnCall->getName() != "length")
{
......@@ -3167,7 +3167,7 @@ TIntermTyped *TParseContext::addFunctionCallOrMethod(TFunction *fnCall, TIntermN
}
else
{
arraySize = static_cast<unsigned int>(typedThis->getArraySize());
arraySize = typedThis->getArraySize();
if (typedThis->hasSideEffects())
{
// This code path can be hit with an expression like this:
......@@ -3176,8 +3176,8 @@ TIntermTyped *TParseContext::addFunctionCallOrMethod(TFunction *fnCall, TIntermN
UNIMPLEMENTED();
}
}
unionArray->setUConst(arraySize);
callNode = intermediate.addConstantUnion(unionArray, TType(EbtUInt, EbpUndefined, EvqConst), loc);
unionArray->setIConst(arraySize);
callNode = intermediate.addConstantUnion(unionArray, TType(EbtInt, EbpUndefined, EvqConst), loc);
}
else if (op != EOpNull)
{
......
......@@ -422,3 +422,22 @@ TEST_F(MalformedShaderTest, TernaryOperatorOnStructs)
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
}
}
// Array length() returns a constant signed integral expression (ESSL 3.00 section 4.1.9)
// Assigning it to unsigned should result in an error.
TEST_F(MalformedShaderTest, AssignArrayLengthToUnsigned)
{
const std::string &shaderString =
"#version 300 es\n"
"precision mediump float;\n"
"out vec4 my_FragColor;\n"
"void main() {\n"
" int[1] arr;\n"
" uint l = arr.length();\n"
" my_FragColor = vec4(float(l));\n"
"}\n";
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
}
}
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