Fix #1983: __ is okay starting with ES 300, rather than 310.

This commit is contained in:
John Kessenich 2019-11-23 01:29:02 -07:00
parent 86258aab80
commit 38b4db48f9
4 changed files with 18 additions and 11 deletions

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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());