[Mesa-dev] [PATCH] glsl: Properly lex extra tokens when handling # directives.

Kenneth Graunke kenneth at whitecape.org
Thu Jun 12 01:06:14 PDT 2014


On Wednesday, June 11, 2014 11:02:34 PM Matt Turner wrote:
> How did you notice this? (More specifically than semicolons being
> printed in your terminals!)
> 
> Reviewed-by: Matt Turner <mattst88 at gmail.com>

I wrote a patch that altered the Meta GLSL clear shaders, and ran Piglit.  
Basically all of tests/hiz failed, along with some other random tests.  When I 
looked at the Piglit output, I noticed that stdout was:

;;PIGLIT: {'result': 'pass' }

I then reverted my patch, and discovered the bonus semicolons were gone.  I 
checked my code for printfs - none.  I ran valgrind - nothing.  I used gdb and 
put breakpoints on printf, fprintf, and various other output functions.  
Nothing.  I grepped the Mesa source code for print statements with semicolons 
not followed by whitespace or other text.  Nothing.  I grepped the Piglit 
code.  Nothing.

I finally gave up and started over, retyping my patch from scratch, one line 
at a time, compiling and running the hiz test with each change, looking for 
semicolons.  Eventually, I got around to adding my shader source line:

"#extension GL_AMD_vertex_shader_layer : enable;\n"

and suddenly the semicolons appeared.  So I knew it was something in the GLSL 
compiler, related to extension handling.  I put breakpoints before and after 
the preprocessor ran, and did:

(gdb) call printf("\n");

to flush out the semicolons.  Nothing.  I tried before and after the main 
lexer/parser.  Semicolons.  I put a breakpoint in 
_mesa_glsl_process_extension.  Semicolons.  I noticed the parser rule 
shouldn't accept ';', but apparently was anyway.  I added it.  Suddenly, no 
semicolon output.  I looked at the lexer...and realized the normal rule for 
"." didn't apply, since non-annotated rules only happen in the initial state.

That was the strangest bug I've tracked down in a while.  You always think the 
actual executable code you add will have the bug.  But it wasn't - it was the 
(const char *) string data that tripped up an existing bug.

--Ken
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20140612/7843f62e/attachment.sig>


More information about the mesa-dev mailing list