Ensure that if-else branches are always sequence nodes

This mainly affects RewriteElseBlocks, which was the only piece of
code still adding TIntermIfElse nodes directly as children of other
TIntermIfElse nodes.

BUG=angleproject:1490
TEST=angle_unittests

Change-Id: I5b25c2fb9c642424417cd6c29e37c20482c6ffaf
Reviewed-on: https://chromium-review.googlesource.com/392847
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/RewriteElseBlocks.cpp b/src/compiler/translator/RewriteElseBlocks.cpp
index bbffc79..13d71c7 100644
--- a/src/compiler/translator/RewriteElseBlocks.cpp
+++ b/src/compiler/translator/RewriteElseBlocks.cpp
@@ -8,6 +8,8 @@
 //
 
 #include "compiler/translator/RewriteElseBlocks.h"
+
+#include "compiler/translator/Intermediate.h"
 #include "compiler/translator/NodeSearch.h"
 #include "compiler/translator/SymbolTable.h"
 
@@ -49,16 +51,7 @@
                 TIntermIfElse *ifElse  = statement->getAsIfElseNode();
                 if (ifElse && ifElse->getFalseBlock() != nullptr)
                 {
-                    // Check for if / else if
-                    TIntermIfElse *elseIfBranch = ifElse->getFalseBlock()->getAsIfElseNode();
-                    if (elseIfBranch)
-                    {
-                        ifElse->replaceChildNode(elseIfBranch, rewriteIfElse(elseIfBranch));
-                        delete elseIfBranch;
-                    }
-
                     (*node->getSequence())[statementIndex] = rewriteIfElse(ifElse);
-                    delete ifElse;
                 }
             }
         }
@@ -84,7 +77,7 @@
     TIntermTyped *typedCondition     = ifElse->getCondition()->getAsTyped();
     TIntermAggregate *storeCondition = createTempInitDeclaration(typedCondition);
 
-    TIntermIfElse *falseBlock = nullptr;
+    TIntermAggregate *falseBlock = nullptr;
 
     TType boolType(EbtBool, EbpUndefined, EvqTemporary);
 
@@ -107,7 +100,9 @@
 
         TIntermSymbol *conditionSymbolElse = createTempSymbol(boolType);
         TIntermUnary *negatedCondition     = new TIntermUnary(EOpLogicalNot, conditionSymbolElse);
-        falseBlock = new TIntermIfElse(negatedCondition, ifElse->getFalseBlock(), negatedElse);
+        TIntermIfElse *falseIfElse =
+            new TIntermIfElse(negatedCondition, ifElse->getFalseBlock(), negatedElse);
+        falseBlock = TIntermediate::EnsureSequence(falseIfElse);
     }
 
     TIntermSymbol *conditionSymbolSel = createTempSymbol(boolType);