This will emit an error for something like:

        #define FOO(x,x) ...

Obviously, it's not a legal thing to do, and it's easy to check.

Add a "make check" test for this as well.

This fixes the following Khronos GLES3 CTS tests:

        invalid_function_definitions.unique_param_name_vertex
        invalid_function_definitions.unique_param_name_fragment
---
 src/glsl/glcpp/glcpp-parse.y                       | 29 ++++++++++++++++++++++
 src/glsl/glcpp/tests/134-duplicate-parameter.c     |  2 ++
 .../glcpp/tests/134-duplicate-parameter.c.expected |  4 +++
 3 files changed, 35 insertions(+)
 create mode 100644 src/glsl/glcpp/tests/134-duplicate-parameter.c
 create mode 100644 src/glsl/glcpp/tests/134-duplicate-parameter.c.expected

diff --git a/src/glsl/glcpp/glcpp-parse.y b/src/glsl/glcpp/glcpp-parse.y
index 1e816ab..4af3bc3 100644
--- a/src/glsl/glcpp/glcpp-parse.y
+++ b/src/glsl/glcpp/glcpp-parse.y
@@ -57,6 +57,9 @@ _string_list_append_item (string_list_t *list, const char 
*str);
 static int
 _string_list_contains (string_list_t *list, const char *member, int *index);
 
+static const char *
+_string_list_has_duplicate (string_list_t *list);
+
 static int
 _string_list_length (string_list_t *list);
 
@@ -793,6 +796,25 @@ _string_list_contains (string_list_t *list, const char 
*member, int *index)
        return 0;
 }
 
+/* Return duplicate string in list (if any), NULL otherwise. */
+const char *
+_string_list_has_duplicate (string_list_t *list)
+{
+       string_node_t *node, *dup;
+
+       if (list == NULL)
+               return NULL;
+
+       for (node = list->head; node; node = node->next) {
+               for (dup = node->next; dup; dup = dup->next) {
+                       if (strcmp (node->str, dup->str) == 0)
+                               return node->str;
+               }
+       }
+
+       return NULL;
+}
+
 int
 _string_list_length (string_list_t *list)
 {
@@ -1979,9 +2001,16 @@ _define_function_macro (glcpp_parser_t *parser,
                        token_list_t *replacements)
 {
        macro_t *macro, *previous;
+       const char *dup;
 
        _check_for_reserved_macro_name(parser, loc, identifier);
 
+        /* Check for any duplicate parameter names. */
+       if ((dup = _string_list_has_duplicate (parameters)) != NULL) {
+               glcpp_error (loc, parser, "Duplicate macro parameter \"%s\"",
+                            dup);
+       }
+
        macro = ralloc (parser, macro_t);
        ralloc_steal (macro, parameters);
        ralloc_steal (macro, replacements);
diff --git a/src/glsl/glcpp/tests/134-duplicate-parameter.c 
b/src/glsl/glcpp/tests/134-duplicate-parameter.c
new file mode 100644
index 0000000..fd96bd6
--- /dev/null
+++ b/src/glsl/glcpp/tests/134-duplicate-parameter.c
@@ -0,0 +1,2 @@
+#define FOO(a,a) which a?
+#define BAR(x,y,z,x) so very x
diff --git a/src/glsl/glcpp/tests/134-duplicate-parameter.c.expected 
b/src/glsl/glcpp/tests/134-duplicate-parameter.c.expected
new file mode 100644
index 0000000..bc1a334
--- /dev/null
+++ b/src/glsl/glcpp/tests/134-duplicate-parameter.c.expected
@@ -0,0 +1,4 @@
+0:1(9): preprocessor error: Duplicate macro parameter "a"
+0:2(9): preprocessor error: Duplicate macro parameter "x"
+
+
-- 
2.0.0

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to