glsl/glcpp: Emit proper error for #define with a non-identifier
authorCarl Worth <cworth@cworth.org>
Tue, 17 Jun 2014 18:55:07 +0000 (11:55 -0700)
committerCarl Worth <cworth@cworth.org>
Tue, 29 Jul 2014 22:11:48 +0000 (15:11 -0700)
commitea2e9300ece89dffdc4a228dc86bea28a7cd58e2
treef6057ff1a06c9037c52cd35d486f41eba2559ba0
parent9e45fb6f5127cecd02a1420aaea59a7012e74404
glsl/glcpp: Emit proper error for #define with a non-identifier

Previously, if the preprocessor encountered a #define with a non-identifier,
such as:

#define 123 456

The lexer had no explicit rules to match non-identifiers in the <DEFINE> start
state. Because of this, flex's default rule was being invoked, (printing
characters to stdout), and all text was being discarded by the compiler until
the next identifier. As one can imagine, this led to all sorts of interesting
and surprising results.

Fix this by adding an explicit rule complementing the existing
identifier-based rules that should catch all non-identifiers after #define and
reliably give a well-formatted error message.

A new test is added to "make check" to ensure this bug stays fixed.

This commit also fixes the following Khronos GLES3 CTS test:

define_non_identifier_vertex

(The "fragment" variant was passing earlier only because the preprocessor was
behaving so randomly and causing the compilation to fail. It's lucky, in fact,
that the "vertex" version succesfully compiled so we could find and fix this
bug.)

Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
src/glsl/glcpp/glcpp-lex.l
src/glsl/glcpp/tests/129-define-non-identifier.c [new file with mode: 0644]
src/glsl/glcpp/tests/129-define-non-identifier.c.expected [new file with mode: 0644]