[Mesa-dev] [PATCH] glsl: glcpp: Allow "#if undefined-macro' to evaluate to false.

Carl Worth cworth at cworth.org
Sat Jun 9 00:17:15 CEST 2012


A strict reading of the GLSL specification would have this be an
error, but we've received reports from users who expect the
preprocessor to interepret undefined macros as 0. This is the standard
behavior of the rpeprocessor for C, and according to these user
reports is also the behavior of other OpenGL implementations.

So here's one of those cases where we can make our users happier by
ignoring the specification. And it's hard to imagine users who really,
really want to see an error for this case.

The two affected tests cases are updated to reflect the new behavior.
---
 src/glsl/glcpp/glcpp-parse.y                                    |    3 +++
 src/glsl/glcpp/tests/070-undefined-macro-in-expression.c        |    3 +++
 .../glcpp/tests/070-undefined-macro-in-expression.c.expected    |    6 +++++-
 src/glsl/glcpp/tests/098-elif-undefined.c                       |    4 ++++
 src/glsl/glcpp/tests/098-elif-undefined.c.expected              |    7 +++++--
 5 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/src/glsl/glcpp/glcpp-parse.y b/src/glsl/glcpp/glcpp-parse.y
index 9e8f9b2..78ff8fa 100644
--- a/src/glsl/glcpp/glcpp-parse.y
+++ b/src/glsl/glcpp/glcpp-parse.y
@@ -341,6 +341,9 @@ integer_constant:
 
 expression:
 	integer_constant
+|	IDENTIFIER {
+		$$ = 0;
+	}
 |	expression OR expression {
 		$$ = $1 || $3;
 	}
diff --git a/src/glsl/glcpp/tests/070-undefined-macro-in-expression.c b/src/glsl/glcpp/tests/070-undefined-macro-in-expression.c
index b6dc2ba..d15a484 100644
--- a/src/glsl/glcpp/tests/070-undefined-macro-in-expression.c
+++ b/src/glsl/glcpp/tests/070-undefined-macro-in-expression.c
@@ -1,2 +1,5 @@
 #if UNDEFINED_MACRO
+Failure
+#else
+Success
 #endif
diff --git a/src/glsl/glcpp/tests/070-undefined-macro-in-expression.c.expected b/src/glsl/glcpp/tests/070-undefined-macro-in-expression.c.expected
index 2bb38a1..d5a8452 100644
--- a/src/glsl/glcpp/tests/070-undefined-macro-in-expression.c.expected
+++ b/src/glsl/glcpp/tests/070-undefined-macro-in-expression.c.expected
@@ -1,2 +1,6 @@
-0:1(21): preprocessor error: syntax error, unexpected IDENTIFIER
+
+
+
+Success
+
 
diff --git a/src/glsl/glcpp/tests/098-elif-undefined.c b/src/glsl/glcpp/tests/098-elif-undefined.c
index 52a331c..1f520d4 100644
--- a/src/glsl/glcpp/tests/098-elif-undefined.c
+++ b/src/glsl/glcpp/tests/098-elif-undefined.c
@@ -1,3 +1,7 @@
 #if 0
+Not this
 #elif UNDEFINED_MACRO
+Nor this
+#else
+Yes, this.
 #endif
diff --git a/src/glsl/glcpp/tests/098-elif-undefined.c.expected b/src/glsl/glcpp/tests/098-elif-undefined.c.expected
index de967ea..2af0a12 100644
--- a/src/glsl/glcpp/tests/098-elif-undefined.c.expected
+++ b/src/glsl/glcpp/tests/098-elif-undefined.c.expected
@@ -1,5 +1,8 @@
-0:2(22): preprocessor error: syntax error, unexpected IDENTIFIER
-0:1(7): preprocessor error: Unterminated #if
 
 
 
+
+
+Yes, this.
+
+
-- 
1.7.10


-- 
carl.d.worth at intel.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20120608/962b4eb9/attachment.pgp>


More information about the mesa-dev mailing list