From 50d542e6b903a0e46ddff1f56a2a6adabac42967 Mon Sep 17 00:00:00 2001 From: John Kessenich Date: Wed, 7 Jan 2015 18:47:57 +0000 Subject: [PATCH] Implement ES-3.0-specific error semantics for redefining predefined macros. git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@29353 e7fa87d3-cd2b-0410-9028-fcbf551c1848 --- Test/baseResults/cppComplexExpr.vert.out | 10 +++++++++- Test/baseResults/cppSimple.vert.out | 6 +++--- Test/cppComplexExpr.vert | 9 +++++++++ glslang/MachineIndependent/ParseHelper.cpp | 13 ++++++++++--- 4 files changed, 31 insertions(+), 7 deletions(-) diff --git a/Test/baseResults/cppComplexExpr.vert.out b/Test/baseResults/cppComplexExpr.vert.out index 0cda42e7..100123ab 100644 --- a/Test/baseResults/cppComplexExpr.vert.out +++ b/Test/baseResults/cppComplexExpr.vert.out @@ -34,8 +34,16 @@ ERROR: 0:153: 'preprocessor evaluation' : undefined macro in expression not allo ERROR: 0:156: 'preprocessor evaluation' : undefined macro in expression not allowed in es profile UNDEF2 ERROR: 0:159: 'preprocessor evaluation' : undefined macro in expression not allowed in es profile UNDEF2 ERROR: 0:3000: '#error' : line of this error should be 3000 +ERROR: 0:3002: '#define' : predefined names can't be (un)defined: __LINE__ +ERROR: 0:3003: '#define' : predefined names can't be (un)defined: __FILE__ +ERROR: 0:3004: '#define' : predefined names can't be (un)defined: __VERSION__ +ERROR: 0:3005: '#define' : names beginning with "GL_" can't be (un)defined: GL_SOME_EXTENSION +ERROR: 0:3006: '#undef' : predefined names can't be (un)defined: __LINE__ +ERROR: 0:3007: '#undef' : predefined names can't be (un)defined: __FILE__ +ERROR: 0:3008: '#undef' : predefined names can't be (un)defined: __VERSION__ +ERROR: 0:3009: '#undef' : names beginning with "GL_" can't be (un)defined: GL_SOME_EXTENSION ERROR: 0:10001: '' : missing #endif -ERROR: 36 compilation errors. No code generated. +ERROR: 44 compilation errors. No code generated. Shader version: 300 diff --git a/Test/baseResults/cppSimple.vert.out b/Test/baseResults/cppSimple.vert.out index cbe3c527..2e6a9b4a 100644 --- a/Test/baseResults/cppSimple.vert.out +++ b/Test/baseResults/cppSimple.vert.out @@ -25,8 +25,8 @@ ERROR: 0:136: 'length' : no matching overloaded function found ERROR: 0:136: '=' : cannot convert from 'const float' to 'int' ERROR: 0:138: ''' : character literals not supported ERROR: 0:138: ''' : character literals not supported -ERROR: 0:141: '#define' : names beginning with "GL_" can't be defined: GL_ -ERROR: 0:142: '#define' : names beginning with "GL_" can't be defined: GL_Macro +ERROR: 0:141: '#define' : names beginning with "GL_" can't be (un)defined: GL_ +ERROR: 0:142: '#define' : names beginning with "GL_" can't be (un)defined: GL_Macro WARNING: 0:143: '#define' : names containing consecutive underscores are reserved: __M WARNING: 0:144: '#define' : names containing consecutive underscores are reserved: M__ WARNING: 0:145: '#define' : names containing consecutive underscores are reserved: ABC__DE @@ -43,7 +43,7 @@ ERROR: 0:185: '#define' : Macro redefined; different substitutions: m7 ERROR: 0:192: '#define' : Macro redefined; different substitutions: m8 ERROR: 0:196: '#define' : Macro redefined; different argument names: m9 WARNING: 0:204: '#undef' : names containing consecutive underscores are reserved: __VERSION__ -ERROR: 0:205: '#undef' : names beginning with "GL_" can't be defined: GL_ARB_texture_rectangle +ERROR: 0:205: '#undef' : names beginning with "GL_" can't be (un)defined: GL_ARB_texture_rectangle ERROR: 0:210: '#' : invalid directive ERROR: 0:211: '#' : invalid directive ERROR: 0:212: '#' : invalid directive diff --git a/Test/cppComplexExpr.vert b/Test/cppComplexExpr.vert index fe01cd59..3f15b5ef 100644 --- a/Test/cppComplexExpr.vert +++ b/Test/cppComplexExpr.vert @@ -161,6 +161,15 @@ float c = foobar(1.1, 2.2 #line 3000 #error line of this error should be 3000 + +#define __LINE__ 30 +#define __FILE__ +#define __VERSION__ +#define GL_SOME_EXTENSION +#undef __LINE__ +#undef __FILE__ +#undef __VERSION__ +#undef GL_SOME_EXTENSION #line 10000 #if 0 diff --git a/glslang/MachineIndependent/ParseHelper.cpp b/glslang/MachineIndependent/ParseHelper.cpp index 0837553a..e150c507 100644 --- a/glslang/MachineIndependent/ParseHelper.cpp +++ b/glslang/MachineIndependent/ParseHelper.cpp @@ -1783,9 +1783,16 @@ void TParseContext::reservedPpErrorCheck(TSourceLoc loc, const char* identifier, // single underscore) are also reserved, and defining such a name results in a // compile-time error." if (strncmp(identifier, "GL_", 3) == 0) - error(loc, "names beginning with \"GL_\" can't be defined:", op, identifier); - else if (strstr(identifier, "__") != 0) - warn(loc, "names containing consecutive underscores are reserved:", op, identifier); + error(loc, "names beginning with \"GL_\" can't be (un)defined:", op, identifier); + else if (strstr(identifier, "__") != 0) { + if (profile == EEsProfile && version >= 300 && + (strcmp(identifier, "__LINE__") == 0 || + strcmp(identifier, "__FILE__") == 0 || + strcmp(identifier, "__VERSION__") == 0)) + error(loc, "predefined names can't be (un)defined:", op, identifier); + else + warn(loc, "names containing consecutive underscores are reserved:", op, identifier); + } } //