Disallow user-defined function calls in global variable init
Generate an error message when an user-defined function call is found in
a global variable initializer.
Even before this patch, the call graph already marked functions that were
only called from the global scope as unused.
This change was tested extensively with popular WebGL content, with no
regressions found.
TEST=angle_unittests
BUG=angleproject:988
Change-Id: Iec1b16d2af386f1e5c383f86926d80cef553b694
Reviewed-on: https://chromium-review.googlesource.com/283291
Tested-by: Olli Etuaho <oetuaho@nvidia.com>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Zhenyao Mo <zmo@chromium.org>
diff --git a/src/compiler/translator/ValidateGlobalInitializer.cpp b/src/compiler/translator/ValidateGlobalInitializer.cpp
index 71cb76c..7b84b13 100644
--- a/src/compiler/translator/ValidateGlobalInitializer.cpp
+++ b/src/compiler/translator/ValidateGlobalInitializer.cpp
@@ -17,6 +17,7 @@
ValidateGlobalInitializerTraverser(const TParseContext *context);
void visitSymbol(TIntermSymbol *node) override;
+ bool visitAggregate(Visit visit, TIntermAggregate *node) override;
bool isValid() const { return mIsValid; }
bool issueWarning() const { return mIssueWarning; }
@@ -59,6 +60,16 @@
}
}
+bool ValidateGlobalInitializerTraverser::visitAggregate(Visit visit, TIntermAggregate *node)
+{
+ // Disallow calls to user-defined functions in global variable initializers.
+ if (node->getOp() == EOpFunctionCall && node->isUserDefined())
+ {
+ mIsValid = false;
+ }
+ return true;
+}
+
ValidateGlobalInitializerTraverser::ValidateGlobalInitializerTraverser(const TParseContext *context)
: TIntermTraverser(true, false, false),
mContext(context),