Mesa (staging/18.2): glsl: ignore trailing whitespace when define redefined

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Oct 11 08:26:13 UTC 2018


Module: Mesa
Branch: staging/18.2
Commit: bf21df1bb532ec2eec2aa02c63290a86857bba50
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=bf21df1bb532ec2eec2aa02c63290a86857bba50

Author: Timothy Arceri <tarceri at itsqueeze.com>
Date:   Wed Oct 10 11:03:47 2018 +1100

glsl: ignore trailing whitespace when define redefined

The Nvidia/AMD binary drivers allow this, as does GCC.

This fixes shader compilation issues in the latest update of
No Mans Sky.

Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>
(cherry picked from commit 0346ad37741b11d640c1c4970b275c1f0c7f9e75)

---

 src/compiler/glsl/glcpp/glcpp-parse.y                      | 14 ++++++++++++++
 src/compiler/glsl/glcpp/tests/122-redefine-whitespace.c    |  4 ++++
 .../glsl/glcpp/tests/122-redefine-whitespace.c.expected    | 10 +++++++---
 3 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/src/compiler/glsl/glcpp/glcpp-parse.y b/src/compiler/glsl/glcpp/glcpp-parse.y
index 4be5cfa3d5..1c095cb66f 100644
--- a/src/compiler/glsl/glcpp/glcpp-parse.y
+++ b/src/compiler/glsl/glcpp/glcpp-parse.y
@@ -1077,6 +1077,20 @@ _token_list_equal_ignoring_space(token_list_t *a, token_list_t *b)
       if (node_a == NULL && node_b == NULL)
          break;
 
+      /* Ignore trailing whitespace */
+      if (node_a == NULL && node_b->token->type == SPACE) {
+         while (node_b && node_b->token->type == SPACE)
+            node_b = node_b->next;
+      }
+
+      if (node_b == NULL && node_a->token->type == SPACE) {
+         while (node_a && node_a->token->type == SPACE)
+            node_a = node_a->next;
+      }
+
+      if (node_a == NULL && node_b == NULL)
+         break;
+
       if (node_a == NULL || node_b == NULL)
          return 0;
       /* Make sure whitespace appears in the same places in both.
diff --git a/src/compiler/glsl/glcpp/tests/122-redefine-whitespace.c b/src/compiler/glsl/glcpp/tests/122-redefine-whitespace.c
index ae7ea09f67..2b084e0960 100644
--- a/src/compiler/glsl/glcpp/tests/122-redefine-whitespace.c
+++ b/src/compiler/glsl/glcpp/tests/122-redefine-whitespace.c
@@ -2,6 +2,7 @@
 #define TWO  ( 1+1 )
 #define FOUR (2 + 2)
 #define SIX  (3 + 3)
+#define EIGHT (8 + 8)
 
 /* Redefinitions with whitespace in same places, but different amounts, (so no
  * error). */
@@ -9,6 +10,9 @@
 #define FOUR    (2	+  2)
 #define SIX	(3/*comment is whitespace*/+   /* collapsed */ /* to */ /* one */ /* space */  3)
 
+/* Trailing whitespace (no error) */
+#define EIGHT (8 + 8)       
+
 /* Redefinitions with whitespace in different places. Each of these should
  * trigger an error. */
 #define TWO  (1 + 1)
diff --git a/src/compiler/glsl/glcpp/tests/122-redefine-whitespace.c.expected b/src/compiler/glsl/glcpp/tests/122-redefine-whitespace.c.expected
index 602bdef94c..766849e34a 100644
--- a/src/compiler/glsl/glcpp/tests/122-redefine-whitespace.c.expected
+++ b/src/compiler/glsl/glcpp/tests/122-redefine-whitespace.c.expected
@@ -1,14 +1,15 @@
-0:14(9): preprocessor error: Redefinition of macro TWO
+0:18(9): preprocessor error: Redefinition of macro TWO
 
-0:15(9): preprocessor error: Redefinition of macro FOUR
+0:19(9): preprocessor error: Redefinition of macro FOUR
 
-0:16(9): preprocessor error: Redefinition of macro SIX
+0:20(9): preprocessor error: Redefinition of macro SIX
 
  
 
 
 
 
+
  
 
 
@@ -18,5 +19,8 @@
  
 
 
+ 
+
+
 
 




More information about the mesa-commit mailing list