Mesa (glsl2): glcpp: Fix function-like macros with an argument used multiple times.

Carl Worth cworth at kemper.freedesktop.org
Thu Jul 22 23:38:17 UTC 2010


Module: Mesa
Branch: glsl2
Commit: fbe4240626bfe102a9c4c889ee18cb9ea27bddec
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=fbe4240626bfe102a9c4c889ee18cb9ea27bddec

Author: Carl Worth <cworth at cworth.org>
Date:   Thu Jul 22 16:36:04 2010 -0700

glcpp: Fix function-like macros with an argument used multiple times.

It's really hard to believe that this case has been broken, but apparently
no test previously exercised it. So this commit adds such a test and fixes
it by making a copy of the argument token-list before expanding it.

This fix causes the following glean tests to now pass:

	glsl1-Preprocessor test 6 (#if 0, #define macro)
	glsl1-Preprocessor test 7 (multi-line #define)

---

 src/glsl/glcpp/glcpp-parse.y                 |   10 +++++++---
 src/glsl/glcpp/tests/069-repeated-argument.c |    2 ++
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/glsl/glcpp/glcpp-parse.y b/src/glsl/glcpp/glcpp-parse.y
index e4dcc76..5b74678 100644
--- a/src/glsl/glcpp/glcpp-parse.y
+++ b/src/glsl/glcpp/glcpp-parse.y
@@ -1075,7 +1075,7 @@ _token_list_create_with_one_space (void *ctx)
  *
  * Returns the token list that results from the expansion and sets
  * *last to the last node in the list that was consumed by the
- * expansion. Specificallty, *last will be set as follows: as the
+ * expansion. Specifically, *last will be set as follows: as the
  * token of the closing right parenthesis.
  */
 static token_list_t *
@@ -1147,9 +1147,13 @@ _glcpp_parser_expand_function (glcpp_parser_t *parser,
 			 * tokens, or append a placeholder token for
 			 * an empty argument. */
 			if (argument->head) {
+				token_list_t *expanded_argument;
+				expanded_argument = _token_list_copy (parser,
+								      argument);
 				_glcpp_parser_expand_token_list (parser,
-								 argument);
-				_token_list_append_list (substituted, argument);
+								 expanded_argument);
+				_token_list_append_list (substituted,
+							 expanded_argument);
 			} else {
 				token_t *new_token;
 
diff --git a/src/glsl/glcpp/tests/069-repeated-argument.c b/src/glsl/glcpp/tests/069-repeated-argument.c
new file mode 100644
index 0000000..2b46ead
--- /dev/null
+++ b/src/glsl/glcpp/tests/069-repeated-argument.c
@@ -0,0 +1,2 @@
+#define double(x) x x
+double(1)




More information about the mesa-commit mailing list