[Mesa-dev] [PATCH] glsl: skip stringification in preprocessor if in unreachable branch

Ian Romanick idr at freedesktop.org
Wed Aug 29 18:05:21 UTC 2018


On 08/28/2018 06:36 PM, Timothy Arceri wrote:
> This fixes compilation of some "No Mans Sky" shaders where the stringification
> happens in branches intended for DX12.

I was going to complain that this would make things like the following
compile:

    #version 110

    #ifdef this_is_undefined
    #is_this_valid_too
    #endif

    void main() { }

This already compiles.  Looking at the C99 spec and testing with GCC,
this is intentional.  We should probably add that as another
preprocessor test.

This patch is

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

> ---
> 
>  Piglit tests: https://patchwork.freedesktop.org/series/48850/
> 
>  src/compiler/glsl/glcpp/glcpp-lex.l | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/src/compiler/glsl/glcpp/glcpp-lex.l b/src/compiler/glsl/glcpp/glcpp-lex.l
> index 9cfcc120222..fe5845acd4e 100644
> --- a/src/compiler/glsl/glcpp/glcpp-lex.l
> +++ b/src/compiler/glsl/glcpp/glcpp-lex.l
> @@ -420,8 +420,10 @@ HEXADECIMAL_INTEGER	0[xX][0-9a-fA-F]+[uU]?
>  
>  	/* This will catch any non-directive garbage after a HASH */
>  <HASH>{NONSPACE} {
> -	BEGIN INITIAL;
> -	RETURN_TOKEN (GARBAGE);
> +	if (!parser->skipping) {
> +		BEGIN INITIAL;
> +		RETURN_TOKEN (GARBAGE);
> +	}
>  }
>  
>  	/* An identifier immediately followed by '(' */


More information about the mesa-dev mailing list