From 38b4db48f98c4e3a9cc405de3a76547b857e1c37 Mon Sep 17 00:00:00 2001 From: John Kessenich Date: Sat, 23 Nov 2019 01:29:02 -0700 Subject: [PATCH] Fix #1983: __ is okay starting with ES 300, rather than 310. --- Test/100.frag | 3 +++ Test/baseResults/100.frag.out | 6 +++++- Test/baseResults/300BuiltIns.frag.out | 6 +++--- glslang/MachineIndependent/ParseHelper.cpp | 14 +++++++------- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/Test/100.frag b/Test/100.frag index 4f0c69b5..0508ea99 100644 --- a/Test/100.frag +++ b/Test/100.frag @@ -219,6 +219,9 @@ int init1 = gl_FrontFacing ? 1 : 2; // ERROR, non-const initializer int init2 = gl_FrontFacing ? 1 : 2; +#define A__B // error +int a__b; // error + #pragma STDGL invariant(all) #line 3000 diff --git a/Test/baseResults/100.frag.out b/Test/baseResults/100.frag.out index 5e702e87..8dd31e32 100644 --- a/Test/baseResults/100.frag.out +++ b/Test/baseResults/100.frag.out @@ -83,9 +83,11 @@ ERROR: 0:193: '.length' : not supported for this version or the enabled extensio ERROR: 0:194: '.' : cannot apply to an array: method ERROR: 0:194: 'a' : can't use function syntax on variable ERROR: 0:214: 'non-constant global initializer (needs GL_EXT_shader_non_constant_global_initializers)' : not supported for this version or the enabled extensions +ERROR: 0:222: '#define' : names containing consecutive underscores are reserved, and an error if version < 300: A__B +ERROR: 0:223: 'a__b' : identifiers containing consecutive underscores ("__") are reserved, and an error if version < 300 ERROR: 0:3000: '#error' : line of this error should be 3000 ERROR: 0:3002: '' : syntax error, unexpected IDENTIFIER, expecting LEFT_BRACE or COMMA or SEMICOLON -ERROR: 77 compilation errors. No code generated. +ERROR: 79 compilation errors. No code generated. Shader version: 100 @@ -421,6 +423,7 @@ ERROR: node is still EOpNull! 0:? 5.000000 0:? 'init1' ( global mediump int) 0:? 'init2' ( global mediump int) +0:? 'a__b' ( global mediump int) Linked fragment stage: @@ -573,4 +576,5 @@ ERROR: node is still EOpNull! 0:? 5.000000 0:? 'init1' ( global mediump int) 0:? 'init2' ( global mediump int) +0:? 'a__b' ( global mediump int) diff --git a/Test/baseResults/300BuiltIns.frag.out b/Test/baseResults/300BuiltIns.frag.out index 84d4d086..54ecfa5f 100644 --- a/Test/baseResults/300BuiltIns.frag.out +++ b/Test/baseResults/300BuiltIns.frag.out @@ -1,9 +1,9 @@ 300BuiltIns.frag ERROR: 0:6: 'float' : type requires declaration of default precision qualifier ERROR: 0:70: 'noise2' : no matching overloaded function found -ERROR: 0:72: 't__' : identifiers containing consecutive underscores ("__") are reserved, and an error if version <= 300 -ERROR: 0:75: '#define' : names containing consecutive underscores are reserved, and an error if version <= 300: __D -ERROR: 4 compilation errors. No code generated. +WARNING: 0:72: 't__' : identifiers containing consecutive underscores ("__") are reserved +WARNING: 0:75: '#define' : names containing consecutive underscores are reserved: __D +ERROR: 2 compilation errors. No code generated. Shader version: 300 diff --git a/glslang/MachineIndependent/ParseHelper.cpp b/glslang/MachineIndependent/ParseHelper.cpp index c5831302..9c46d57c 100644 --- a/glslang/MachineIndependent/ParseHelper.cpp +++ b/glslang/MachineIndependent/ParseHelper.cpp @@ -2669,14 +2669,14 @@ void TParseContext::reservedErrorCheck(const TSourceLoc& loc, const TString& ide if (builtInName(identifier)) error(loc, "identifiers starting with \"gl_\" are reserved", identifier.c_str(), ""); - // "__" are not supposed to be an error. ES 310 (and desktop) added the clarification: + // "__" are not supposed to be an error. ES 300 (and desktop) added the clarification: // "In addition, all identifiers containing two consecutive underscores (__) are // reserved; using such a name does not itself result in an error, but may result // in undefined behavior." // however, before that, ES tests required an error. if (identifier.find("__") != TString::npos) { - if (isEsProfile() && version <= 300) - error(loc, "identifiers containing consecutive underscores (\"__\") are reserved, and an error if version <= 300", identifier.c_str(), ""); + if (isEsProfile() && version < 300) + error(loc, "identifiers containing consecutive underscores (\"__\") are reserved, and an error if version < 300", identifier.c_str(), ""); else warn(loc, "identifiers containing consecutive underscores (\"__\") are reserved", identifier.c_str(), ""); } @@ -2688,7 +2688,7 @@ void TParseContext::reservedErrorCheck(const TSourceLoc& loc, const TString& ide // void TParseContext::reservedPpErrorCheck(const TSourceLoc& loc, const char* identifier, const char* op) { - // "__" are not supposed to be an error. ES 310 (and desktop) added the clarification: + // "__" are not supposed to be an error. ES 300 (and desktop) added the clarification: // "All macro names containing two consecutive underscores ( __ ) are reserved; // defining such a name does not itself result in an error, but may result in // undefined behavior. All macro names prefixed with "GL_" ("GL" followed by a @@ -2706,8 +2706,8 @@ void TParseContext::reservedPpErrorCheck(const TSourceLoc& loc, const char* iden strcmp(identifier, "__VERSION__") == 0)) ppError(loc, "predefined names can't be (un)defined:", op, identifier); else { - if (isEsProfile() && version <= 300) - ppError(loc, "names containing consecutive underscores are reserved, and an error if version <= 300:", op, identifier); + if (isEsProfile() && version < 300) + ppError(loc, "names containing consecutive underscores are reserved, and an error if version < 300:", op, identifier); else ppWarn(loc, "names containing consecutive underscores are reserved:", op, identifier); } @@ -6922,7 +6922,7 @@ TIntermTyped* TParseContext::constructBuiltIn(const TType& type, TOperator op, T // This avoids requesting a matrix of a new type that is going to be discarded anyway. // TODO: This could be generalized to more type combinations, but that would require // more extensive testing and full algorithm rework. For now, the need to do two changes makes - // the recursive call work, and avoids the most aggregious case of creating integer matrices. + // the recursive call work, and avoids the most egregious case of creating integer matrices. if (node->getType().isMatrix() && (type.isScalar() || type.isVector()) && type.isFloatingDomain() != node->getType().isFloatingDomain()) { TType transitionType(node->getBasicType(), glslang::EvqTemporary, type.getVectorSize(), 0, 0, node->isVector());