Ensure that all functions have a body node in the AST

Some traversers that insert code to main() assume that the main()
function has a non-null body node in place. This assumption was
previously wrong, since functions could be missing the body node
in case the function body was empty.

Fix possible invalid dereferencing of missing function body nodes by
always adding an empty sequence node to represent the body of
functions that have an empty body in the ESSL source. This also
enables simplifying some tree traversers that used to take the
possibility of missing function body nodes into account.

Also fix AddDefaultReturnStatements to check the last statement inside
the function body for a return statement, instead of checking the
first statement.

BUG=angleproject:1539
TEST=angle_unittests, angle_end2end_tests

Change-Id: I2fbd18c78653fa2f1a96dbd9a619accc4874030d
Reviewed-on: https://chromium-review.googlesource.com/392046
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
diff --git a/src/compiler/translator/OutputHLSL.cpp b/src/compiler/translator/OutputHLSL.cpp
index e2a0550..5762a29 100644
--- a/src/compiler/translator/OutputHLSL.cpp
+++ b/src/compiler/translator/OutputHLSL.cpp
@@ -1618,19 +1618,13 @@
 
             out << ")\n";
 
-            if (sequence->size() > 1)
-            {
-                mInsideFunction = true;
-                TIntermNode *body = (*sequence)[1];
-                // The function body node will output braces.
-                ASSERT(IsSequence(body));
-                body->traverse(this);
-                mInsideFunction = false;
-            }
-            else
-            {
-                out << "{}\n";
-            }
+            mInsideFunction = true;
+            ASSERT(sequence->size() == 2);
+            TIntermNode *body = (*sequence)[1];
+            // The function body node will output braces.
+            ASSERT(IsSequence(body));
+            body->traverse(this);
+            mInsideFunction = false;
 
             mCurrentFunctionMetadata = nullptr;