Clean up switch/case pruning code
There was some duplicate switch/case pruning in the code in
PruneEmptyCases and RemoveNoOpStatementsFromTheEndOfSwitchStatements.
Combine the functionality of both AST transformations into
PruneEmptyCases and remove the other transformation.
The tests are improved to better cover the full functionality.
BUG=angleproject:2402
TEST=angle_unittests, angle_end2end_tests --gtest_filter=*Switch*
Change-Id: Ib74b6b9b455769ea15650e9653a9c53635342c49
Reviewed-on: https://chromium-review.googlesource.com/964081
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
diff --git a/src/compiler/translator/Compiler.cpp b/src/compiler/translator/Compiler.cpp
index df13869..8a352c1 100644
--- a/src/compiler/translator/Compiler.cpp
+++ b/src/compiler/translator/Compiler.cpp
@@ -31,7 +31,6 @@
#include "compiler/translator/RegenerateStructNames.h"
#include "compiler/translator/RemoveArrayLengthMethod.h"
#include "compiler/translator/RemoveInvariantDeclaration.h"
-#include "compiler/translator/RemoveNoOpCasesFromEndOfSwitchStatements.h"
#include "compiler/translator/RemovePow.h"
#include "compiler/translator/RemoveUnreferencedVariables.h"
#include "compiler/translator/RewriteDoWhile.h"
@@ -466,13 +465,6 @@
// After this empty declarations are not allowed in the AST.
PruneNoOps(root, &symbolTable);
- // In case the last case inside a switch statement is a certain type of no-op, GLSL
- // compilers in drivers may not accept it. In this case we clean up the dead code from the
- // end of switch statements. This is also required because PruneNoOps may have left switch
- // statements that only contained an empty declaration inside the final case in an invalid
- // state. Relies on that PruneNoOps has already been run.
- RemoveNoOpCasesFromEndOfSwitchStatements(root, &symbolTable);
-
// Create the function DAG and check there is no recursion
if (!initCallDag(root))
{
@@ -585,6 +577,12 @@
RemoveUnreferencedVariables(root, &symbolTable);
+ // In case the last case inside a switch statement is a certain type of no-op, GLSL compilers in
+ // drivers may not accept it. In this case we clean up the dead code from the end of switch
+ // statements. This is also required because PruneNoOps or RemoveUnreferencedVariables may have
+ // left switch statements that only contained an empty declaration inside the final case in an
+ // invalid state. Relies on that PruneNoOps and RemoveUnreferencedVariables have already been
+ // run.
PruneEmptyCases(root);
// Built-in function emulation needs to happen after validateLimitations pass.