Validate that all preprocessor function arguments are unique.

Fixes:
dEQP-GLES2.functional.shaders.preprocessor.invalid_function_definitions.unique_param_name_vertex
dEQP-GLES2.functional.shaders.preprocessor.invalid_function_definitions.unique_param_name_fragment

BUG=angleproject:989

Change-Id: I32198f1c9036c371b46e7ad2986a44e42fd38e20
Reviewed-on: https://chromium-review.googlesource.com/267396
Reviewed-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Zhenyao Mo <zmo@chromium.org>
Tested-by: Geoff Lang <geofflang@chromium.org>
diff --git a/src/compiler/preprocessor/DiagnosticsBase.cpp b/src/compiler/preprocessor/DiagnosticsBase.cpp
index 6868e1f..4bcdfec 100644
--- a/src/compiler/preprocessor/DiagnosticsBase.cpp
+++ b/src/compiler/preprocessor/DiagnosticsBase.cpp
@@ -78,6 +78,8 @@
         return "Not enough arguments for macro";
       case PP_MACRO_TOO_MANY_ARGS:
         return "Too many arguments for macro";
+      case PP_MACRO_DUPLICATE_PARAMETER_NAMES:
+        return "duplicate macro parameter name";
       case PP_CONDITIONAL_ENDIF_WITHOUT_IF:
         return "unexpected #endif found without a matching #if";
       case PP_CONDITIONAL_ELSE_WITHOUT_IF:
diff --git a/src/compiler/preprocessor/DiagnosticsBase.h b/src/compiler/preprocessor/DiagnosticsBase.h
index 9fd48be..a76ccb3 100644
--- a/src/compiler/preprocessor/DiagnosticsBase.h
+++ b/src/compiler/preprocessor/DiagnosticsBase.h
@@ -46,6 +46,7 @@
         PP_MACRO_UNTERMINATED_INVOCATION,
         PP_MACRO_TOO_FEW_ARGS,
         PP_MACRO_TOO_MANY_ARGS,
+        PP_MACRO_DUPLICATE_PARAMETER_NAMES,
         PP_CONDITIONAL_ENDIF_WITHOUT_IF,
         PP_CONDITIONAL_ELSE_WITHOUT_IF,
         PP_CONDITIONAL_ELSE_AFTER_ELSE,
diff --git a/src/compiler/preprocessor/DirectiveParser.cpp b/src/compiler/preprocessor/DirectiveParser.cpp
index cbc6ce0..b38f332 100644
--- a/src/compiler/preprocessor/DirectiveParser.cpp
+++ b/src/compiler/preprocessor/DirectiveParser.cpp
@@ -6,6 +6,7 @@
 
 #include "DirectiveParser.h"
 
+#include <algorithm>
 #include <cassert>
 #include <cstdlib>
 #include <sstream>
@@ -364,6 +365,14 @@
             mTokenizer->lex(token);
             if (token->type != Token::IDENTIFIER)
                 break;
+
+            if (std::find(macro.parameters.begin(), macro.parameters.end(), token->text) != macro.parameters.end())
+            {
+                mDiagnostics->report(Diagnostics::PP_MACRO_DUPLICATE_PARAMETER_NAMES,
+                                     token->location, token->text);
+                return;
+            }
+
             macro.parameters.push_back(token->text);
 
             mTokenizer->lex(token);  // Get ','.