Add unittests to verify invariant doesn't leak
This is a followup CL of
https://chromium-review.googlesource.com/366720. Unittests is added to
check invariant status does not leak across shaders.
This CL also moves mInvariantVaryings and mGlobalInvariant from
TSymbolTable to TSymbolTableLevel. So at the end of a compilation, the
levels pop, and the settings will be cleared and will not affect the
next compilation.
Change-Id: I1199fade7a637276ab149ab9a599621b9977298b
Reviewed-on: https://chromium-review.googlesource.com/370844
Commit-Queue: Zhenyao Mo <zmo@chromium.org>
Reviewed-by: Zhenyao Mo <zmo@chromium.org>
Reviewed-by: Kenneth Russell <kbr@chromium.org>
diff --git a/src/compiler/translator/ParseContext.cpp b/src/compiler/translator/ParseContext.cpp
index 1561382..eac0702 100644
--- a/src/compiler/translator/ParseContext.cpp
+++ b/src/compiler/translator/ParseContext.cpp
@@ -410,12 +410,14 @@
// Both test, and if necessary spit out an error, to see if we are currently
// globally scoped.
-void TParseContext::checkIsAtGlobalLevel(const TSourceLoc &line, const char *token)
+bool TParseContext::checkIsAtGlobalLevel(const TSourceLoc &line, const char *token)
{
if (!symbolTable.atGlobalLevel())
{
error(line, "only allowed at global scope", token);
+ return false;
}
+ return true;
}
// For now, keep it simple: if it starts "gl_", it's reserved, independent
@@ -1672,7 +1674,8 @@
const TSymbol *symbol)
{
// invariant declaration
- checkIsAtGlobalLevel(invariantLoc, "invariant varying");
+ if (!checkIsAtGlobalLevel(invariantLoc, "invariant varying"))
+ return nullptr;
if (!symbol)
{