Mesa (master): glsl/glcpp: Fix #pragma to not over-increment the line-number count

Ian Romanick idr at kemper.freedesktop.org
Thu Aug 7 23:08:46 UTC 2014


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

Author: Carl Worth <cworth at cworth.org>
Date:   Wed Jul  2 10:27:50 2014 -0700

glsl/glcpp: Fix #pragma to not over-increment the line-number count

Previously, the #pragma directive was swallowing an entire line, (including
the final newline). At that time it was appropriate for it to increment the
line count.

More recently, our handling of #pragma changed to not include the newline. But
the code to increment yylineno stuck around. This was causing __LINE__ to be
increased by one more than desired for every #pragma.

Remove the bogus, extra increment, and add a test for this case.

Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>

---

 src/glsl/glcpp/glcpp-lex.l                              |    2 --
 src/glsl/glcpp/tests/141-pragma-and-__LINE__.c          |    6 ++++++
 src/glsl/glcpp/tests/141-pragma-and-__LINE__.c.expected |    6 ++++++
 3 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/src/glsl/glcpp/glcpp-lex.l b/src/glsl/glcpp/glcpp-lex.l
index 2b92fd3..430abd4 100644
--- a/src/glsl/glcpp/glcpp-lex.l
+++ b/src/glsl/glcpp/glcpp-lex.l
@@ -291,8 +291,6 @@ HEXADECIMAL_INTEGER	0[xX][0-9a-fA-F]+[uU]?
 	 * Simply pass them through to the main compiler's lexer/parser. */
 <HASH>(extension|pragma)[^\r\n]* {
 	BEGIN INITIAL;
-	yylineno++;
-	yycolumn = 0;
 	RETURN_STRING_TOKEN (PRAGMA);
 }
 
diff --git a/src/glsl/glcpp/tests/141-pragma-and-__LINE__.c b/src/glsl/glcpp/tests/141-pragma-and-__LINE__.c
new file mode 100644
index 0000000..a93f3ce
--- /dev/null
+++ b/src/glsl/glcpp/tests/141-pragma-and-__LINE__.c
@@ -0,0 +1,6 @@
+Line 1 /* Test for a bug where #pragma was throwing off the __LINE__ count. */
+Line __LINE__ /* Line 2 */
+#pragma Line 3
+Line __LINE__ /* Line 4 */
+#pragma Line 5
+Line __LINE__ /* Line 6 */
diff --git a/src/glsl/glcpp/tests/141-pragma-and-__LINE__.c.expected b/src/glsl/glcpp/tests/141-pragma-and-__LINE__.c.expected
new file mode 100644
index 0000000..330731d
--- /dev/null
+++ b/src/glsl/glcpp/tests/141-pragma-and-__LINE__.c.expected
@@ -0,0 +1,6 @@
+Line 1
+Line 2
+#pragma Line 3
+Line 4
+#pragma Line 5
+Line 6




More information about the mesa-commit mailing list