Validate global initializer qualifiers
Allow only constants, other globals, temporaries, and uniforms to be used
in global variable initialization for now. The spec limits global
variable initialization further to only constant expressions, but fully
implementing this has a too large compatibility cost for ESSL 1.00, so
implement it only partially. In the case of ESSL 3.00 we can use stricter
validation, since there's no legacy to worry about.
Resubmitting the change, since the previous version neglected to remove
incorrect GLSL tests.
TEST=angle_unittests, WebGL conformance tests, angle_end2end_tests
BUG=angleproject:988
Change-Id: I1bb3b8dc305689a90eadfe8cc7705e5ac3829e03
Reviewed-on: https://chromium-review.googlesource.com/270651
Tested-by: Olli Etuaho <oetuaho@nvidia.com>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/compiler/translator/ParseContext.cpp b/src/compiler/translator/ParseContext.cpp
index e2541ad..a764a76 100644
--- a/src/compiler/translator/ParseContext.cpp
+++ b/src/compiler/translator/ParseContext.cpp
@@ -12,6 +12,7 @@
#include "compiler/preprocessor/SourceLocation.h"
#include "compiler/translator/glslang.h"
#include "compiler/translator/ValidateSwitch.h"
+#include "compiler/translator/ValidateGlobalInitializer.h"
#include "compiler/translator/util.h"
///////////////////////////////////////////////////////////////////////
@@ -1110,6 +1111,20 @@
return true;
}
+ bool globalInitWarning = false;
+ if (symbolTable.atGlobalLevel() && !ValidateGlobalInitializer(initializer, this, &globalInitWarning))
+ {
+ // Error message does not completely match behavior with ESSL 1.00, but
+ // we want to steer developers towards only using constant expressions.
+ error(line, "global variable initializers must be constant expressions", "=");
+ return true;
+ }
+ if (globalInitWarning)
+ {
+ warning(line, "global variable initializers should be constant expressions "
+ "(uniforms and globals are allowed in global initializers for legacy compatibility)", "=");
+ }
+
//
// identifier must be of type constant, a global, or a temporary
//