Skip to content

Commit 19f2f9e

Browse files
qjia7Commit Bot
authored andcommitted
Mark variable to call 'length()' as statically used
Bug: angleproject:3008 Change-Id: I8779706c667f49fddb0a741f5bf31c4af54db3e7 Reviewed-on: https://chromium-review.googlesource.com/c/1367404 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Jamie Madill <jmadill@chromium.org> Commit-Queue: Jiajia Qin <jiajia.qin@intel.com>
1 parent 7ef0839 commit 19f2f9e

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/compiler/translator/ParseContext.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5848,6 +5848,7 @@ TIntermTyped *TParseContext::addMethod(TFunctionLookup *fnCall, const TSourceLoc
58485848
else
58495849
{
58505850
TIntermUnary *node = new TIntermUnary(EOpArrayLength, thisNode, nullptr);
5851+
markStaticReadIfSymbol(thisNode);
58515852
node->setLine(loc);
58525853
return node->fold(mDiagnostics);
58535854
}

src/tests/compiler_tests/CollectVariables_test.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2037,6 +2037,37 @@ TEST_F(CollectVertexVariablesTest, StaticallyUsedButNotActiveInstancedInterfaceB
20372037
EXPECT_FALSE(field.active);
20382038
}
20392039

2040+
// Test an interface block member variable that is statically used. The variable is used to call
2041+
// array length method.
2042+
TEST_F(CollectVertexVariablesTest, StaticallyUsedInArrayLengthOp)
2043+
{
2044+
const std::string &shaderString =
2045+
R"(#version 300 es
2046+
uniform b
2047+
{
2048+
float f[3];
2049+
};
2050+
void main() {
2051+
if (f.length() > 1)
2052+
{
2053+
gl_Position = vec4(1.0);
2054+
}
2055+
else
2056+
{
2057+
gl_Position = vec4(0.0);
2058+
}
2059+
})";
2060+
2061+
compile(shaderString);
2062+
2063+
const std::vector<InterfaceBlock> &interfaceBlocks = mTranslator->getInterfaceBlocks();
2064+
ASSERT_EQ(1u, interfaceBlocks.size());
2065+
const InterfaceBlock &interfaceBlock = interfaceBlocks[0];
2066+
2067+
EXPECT_EQ("b", interfaceBlock.name);
2068+
EXPECT_TRUE(interfaceBlock.staticUse);
2069+
}
2070+
20402071
// Test a varying that is declared invariant but not otherwise used.
20412072
TEST_F(CollectVertexVariablesTest, VaryingOnlyDeclaredInvariant)
20422073
{

0 commit comments

Comments
 (0)