Commit 846fe05f by Olli Etuaho

Disable using globals as l-values in global initializers

It should not be possible to use globals as l-values in global initializers. This change was tested extensively with popular WebGL content, with no regressions found. TEST=angle_unittests BUG=angleproject:988 Change-Id: I21ab731eb1d92aeae25795856ccae280792ad1f0 Reviewed-on: https://chromium-review.googlesource.com/283910Tested-by: 's avatarOlli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org>
parent 6affeef6
...@@ -18,6 +18,8 @@ class ValidateGlobalInitializerTraverser : public TIntermTraverser ...@@ -18,6 +18,8 @@ class ValidateGlobalInitializerTraverser : public TIntermTraverser
void visitSymbol(TIntermSymbol *node) override; void visitSymbol(TIntermSymbol *node) override;
bool visitAggregate(Visit visit, TIntermAggregate *node) override; bool visitAggregate(Visit visit, TIntermAggregate *node) override;
bool visitBinary(Visit visit, TIntermBinary *node) override;
bool visitUnary(Visit visit, TIntermUnary *node) override;
bool isValid() const { return mIsValid; } bool isValid() const { return mIsValid; }
bool issueWarning() const { return mIssueWarning; } bool issueWarning() const { return mIssueWarning; }
...@@ -70,6 +72,24 @@ bool ValidateGlobalInitializerTraverser::visitAggregate(Visit visit, TIntermAggr ...@@ -70,6 +72,24 @@ bool ValidateGlobalInitializerTraverser::visitAggregate(Visit visit, TIntermAggr
return true; return true;
} }
bool ValidateGlobalInitializerTraverser::visitBinary(Visit visit, TIntermBinary *node)
{
if (node->isAssignment())
{
mIsValid = false;
}
return true;
}
bool ValidateGlobalInitializerTraverser::visitUnary(Visit visit, TIntermUnary *node)
{
if (node->isAssignment())
{
mIsValid = false;
}
return true;
}
ValidateGlobalInitializerTraverser::ValidateGlobalInitializerTraverser(const TParseContext *context) ValidateGlobalInitializerTraverser::ValidateGlobalInitializerTraverser(const TParseContext *context)
: TIntermTraverser(true, false, false), : TIntermTraverser(true, false, false),
mContext(context), mContext(context),
......
...@@ -525,6 +525,40 @@ TEST_F(MalformedShaderTest, AssignFunctionCallToGlobal) ...@@ -525,6 +525,40 @@ TEST_F(MalformedShaderTest, AssignFunctionCallToGlobal)
} }
} }
// Global variable initializers need to be constant expressions (ESSL 1.00 section 4.3)
// Initializing with an assignment to another global should be an error.
TEST_F(MalformedShaderTest, AssignAssignmentToGlobal)
{
const std::string &shaderString =
"precision mediump float;\n"
"float c = 1.0;\n"
"float b = (c = 0.0);\n"
"void main() {\n"
" gl_FragColor = vec4(b);\n"
"}\n";
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
}
}
// Global variable initializers need to be constant expressions (ESSL 1.00 section 4.3)
// Initializing with incrementing another global should be an error.
TEST_F(MalformedShaderTest, AssignIncrementToGlobal)
{
const std::string &shaderString =
"precision mediump float;\n"
"float c = 1.0;\n"
"float b = (c++);\n"
"void main() {\n"
" gl_FragColor = vec4(b);\n"
"}\n";
if (compile(shaderString))
{
FAIL() << "Shader compilation succeeded, expecting failure " << mInfoLog;
}
}
// Global variable initializers need to be constant expressions (ESSL 3.00 section 4.3) // Global variable initializers need to be constant expressions (ESSL 3.00 section 4.3)
// Initializing with a non-constant global should be an error. // Initializing with a non-constant global should be an error.
TEST_F(MalformedShaderTest, AssignNonConstGlobalToGlobal) TEST_F(MalformedShaderTest, AssignNonConstGlobalToGlobal)
......
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