diff options
author | Kenneth Graunke <[email protected]> | 2016-03-04 18:26:00 -0800 |
---|---|---|
committer | Kenneth Graunke <[email protected]> | 2016-03-07 23:01:43 -0800 |
commit | 07ec67d85ca652b76fb91abd68b6ad98e56a49df (patch) | |
tree | dc4005bdbd1674e5dca342dc89c881fab2bb550a /src/compiler/glsl/glcpp/tests | |
parent | 90f9df3210b5b66585007ec4836bfca498fd45f0 (diff) |
glcpp: Implicitly resolve version after the first non-space/hash token.
We resolved the implicit version directive when processing control lines,
such as #ifdef, to ensure any built-in macros exist. However, we failed
to resolve it when handling ordinary text.
For example,
int x = __VERSION__;
should resolve __VERSION__ to 110, but since we never resolved the implicit
version, none of the built-in macros exist, so it was left as is.
This also meant we allowed the following shader to slop through:
123
#version 120
Nothing would cause the implicit version to take effect, so when we saw
the #version directive, we thought everything was peachy.
This patch makes the lexer's per-token action resolve the implicit
version on the first non-space/newline/hash token that isn't part of
a #version directive, fulfilling the GLSL language spec:
"The #version directive must occur in a shader before anything else,
except for comments and white space."
Because we emit #version as HASH_TOKEN then VERSION_TOKEN, we have to
allow HASH_TOKEN to slop through as well, so we don't resolve the
implicit version as soon as we see the # character. However, this is
fine, because the parser's HASH_TOKEN NEWLINE rule does resolve the
version, disallowing cases like:
#
#version 120
This patch also adds the above shaders as new glcpp tests.
Fixes dEQP-GLES2.functional.shaders.preprocessor.predefined_macros.
{gl_es_1_vertex,gl_es_1_fragment}.
Signed-off-by: Kenneth Graunke <[email protected]>
Reviewed-by: Ian Romanick <[email protected]>
Diffstat (limited to 'src/compiler/glsl/glcpp/tests')
6 files changed, 12 insertions, 0 deletions
diff --git a/src/compiler/glsl/glcpp/tests/144-implicit-version.c b/src/compiler/glsl/glcpp/tests/144-implicit-version.c new file mode 100644 index 00000000000..7bf72fc19e9 --- /dev/null +++ b/src/compiler/glsl/glcpp/tests/144-implicit-version.c @@ -0,0 +1 @@ +int x = __VERSION__; diff --git a/src/compiler/glsl/glcpp/tests/144-implicit-version.c.expected b/src/compiler/glsl/glcpp/tests/144-implicit-version.c.expected new file mode 100644 index 00000000000..8c2dfd9ce30 --- /dev/null +++ b/src/compiler/glsl/glcpp/tests/144-implicit-version.c.expected @@ -0,0 +1 @@ +int x = 110; diff --git a/src/compiler/glsl/glcpp/tests/145-version-first.c b/src/compiler/glsl/glcpp/tests/145-version-first.c new file mode 100644 index 00000000000..f9fcfb08246 --- /dev/null +++ b/src/compiler/glsl/glcpp/tests/145-version-first.c @@ -0,0 +1,2 @@ +123 +#version 120 diff --git a/src/compiler/glsl/glcpp/tests/145-version-first.c.expected b/src/compiler/glsl/glcpp/tests/145-version-first.c.expected new file mode 100644 index 00000000000..f4092b04af7 --- /dev/null +++ b/src/compiler/glsl/glcpp/tests/145-version-first.c.expected @@ -0,0 +1,3 @@ +0:2(1): preprocessor error: #version must appear on the first line +123 + diff --git a/src/compiler/glsl/glcpp/tests/146-version-first-hash.c b/src/compiler/glsl/glcpp/tests/146-version-first-hash.c new file mode 100644 index 00000000000..14dbe964bd6 --- /dev/null +++ b/src/compiler/glsl/glcpp/tests/146-version-first-hash.c @@ -0,0 +1,2 @@ +# +#version 120 diff --git a/src/compiler/glsl/glcpp/tests/146-version-first-hash.c.expected b/src/compiler/glsl/glcpp/tests/146-version-first-hash.c.expected new file mode 100644 index 00000000000..2872090333d --- /dev/null +++ b/src/compiler/glsl/glcpp/tests/146-version-first-hash.c.expected @@ -0,0 +1,3 @@ +0:1(3): preprocessor error: #version must appear on the first line + + |