Check that #version 300 es directive is on the first line

ESSL3.00 and 3.10 specs don't allow even newlines before the version
directive.

BUG=angleproject:1009
TEST=WebGL 2 conformance tests, angle_unittests

Change-Id: Id7967829077e35e03572c724e0eafffbed0c975b
Reviewed-on: https://chromium-review.googlesource.com/272719
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Tested-by: Olli Etuaho <oetuaho@nvidia.com>
Reviewed-by: Zhenyao Mo <zmo@chromium.org>
diff --git a/src/compiler/preprocessor/DiagnosticsBase.cpp b/src/compiler/preprocessor/DiagnosticsBase.cpp
index 2e9ba6b..5a1c390 100644
--- a/src/compiler/preprocessor/DiagnosticsBase.cpp
+++ b/src/compiler/preprocessor/DiagnosticsBase.cpp
@@ -105,6 +105,8 @@
       case PP_VERSION_NOT_FIRST_STATEMENT:
         return "#version directive must occur before anything else, "
                "except for comments and white space";
+      case PP_VERSION_NOT_FIRST_LINE_ESSL3:
+        return "#version directive must occur on the first line of the shader";
       case PP_INVALID_LINE_NUMBER:
         return "invalid line number";
       case PP_INVALID_FILE_NUMBER:
diff --git a/src/compiler/preprocessor/DiagnosticsBase.h b/src/compiler/preprocessor/DiagnosticsBase.h
index f2f16d5..7aaadb4 100644
--- a/src/compiler/preprocessor/DiagnosticsBase.h
+++ b/src/compiler/preprocessor/DiagnosticsBase.h
@@ -60,6 +60,7 @@
         PP_INVALID_VERSION_NUMBER,
         PP_INVALID_VERSION_DIRECTIVE,
         PP_VERSION_NOT_FIRST_STATEMENT,
+        PP_VERSION_NOT_FIRST_LINE_ESSL3,
         PP_INVALID_LINE_NUMBER,
         PP_INVALID_FILE_NUMBER,
         PP_INVALID_LINE_DIRECTIVE,
diff --git a/src/compiler/preprocessor/DirectiveParser.cpp b/src/compiler/preprocessor/DirectiveParser.cpp
index 1fdece2..e94f1db 100644
--- a/src/compiler/preprocessor/DirectiveParser.cpp
+++ b/src/compiler/preprocessor/DirectiveParser.cpp
@@ -801,6 +801,13 @@
         valid = false;
     }
 
+    if (valid && version >= 300 && token->location.line > 1)
+    {
+        mDiagnostics->report(Diagnostics::PP_VERSION_NOT_FIRST_LINE_ESSL3,
+                             token->location, token->text);
+        valid = false;
+    }
+
     if (valid)
     {
         mDirectiveHandler->handleVersion(token->location, version);