[Mesa-dev] [PATCH] glcpp: Check version_resolved in the proper place.

Matt Turner mattst88 at gmail.com
Sat Jan 25 12:07:59 PST 2014


The check was in the wrong place, such that if a shader incorrectly put
a preprocessor token before the #version declaration, the version would
be resolved twice, leading to a segmentation fault when attempting to
redefine the __VERSION__ macro.

 #define GL_ARB_sample_shading
 #version 130
 void main() {}
---
 src/glsl/glcpp/glcpp-parse.y | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/glsl/glcpp/glcpp-parse.y b/src/glsl/glcpp/glcpp-parse.y
index 184e5c2..3737001 100644
--- a/src/glsl/glcpp/glcpp-parse.y
+++ b/src/glsl/glcpp/glcpp-parse.y
@@ -2024,6 +2024,9 @@ _glcpp_parser_handle_version_declaration(glcpp_parser_t *parser, intmax_t versio
 {
 	const struct gl_extensions *extensions = parser->extensions;
 
+	if (parser->version_resolved)
+		return;
+
 	parser->version_resolved = true;
 
 	add_builtin_define (parser, "__VERSION__", version);
@@ -2146,9 +2149,6 @@ _glcpp_parser_handle_version_declaration(glcpp_parser_t *parser, intmax_t versio
 void
 glcpp_parser_resolve_version(glcpp_parser_t *parser)
 {
-	if (parser->version_resolved)
-		return;
-
 	_glcpp_parser_handle_version_declaration(parser, IMPLICIT_GLSL_VERSION,
 						 NULL, false);
 }
-- 
1.8.3.2



More information about the mesa-dev mailing list