Skip to content

Commit 9eaa69c

Browse files
authored
Preprocessor related issue fix (KhronosGroup#2378)
* Preprocessor related fix 1). Accoding to ESSL spec : All macro names containing two consecutive underscores ( __ ) are reserved for future use as predefined macro names, so just report a warning instead of error when the shader defines the macro names begining with '__'; 2. According to spec: If an implementation does not recognize the tokens following #pragma, then it will ignore that pragma, so report a compile-time warning intead of error for the following statement: #pragma debug(1.23) 3. The 'defined' macro should be allowed to expand and '__LINE__' should be allowed to be replaced with its original line number (otherwise, other expanding macros may change this value). 4. Add a flag 'indentifierSeen' in PPContext to indicate whether the any non-preprocessor tokens is existed before the extension directives, because the built-in symbols and functions are parsed before paring the user shader, so add a 'shaderSource' flag to check this error only for the user shader source; 5. Add missing type int16 and uint16. * Add test results, remove restriction of #extension. 1. Remove extension restriction in first line , as this is contraversy now. 2. The following shader is compiled failed as glslang consider the keyword 'defined' can not be undefined(in the 9th line: "#define defined BBB") The shader is as following: According to ES3.0 spec: It is an error to undefine or to redefine a built-in (pre-defined) macro name. This rule is aimed to the __LINE__, __FILE__, __VERSION__ and GL_ES, the keyword "defined" should not be restricted by this rule, so change the compile error to warning and make the following shader compile successfully. * 1. Using relaxedError to control error/warning report level. 2. remove #extension restriction. 3. Fix version related issue. 1. Using relaxedError to control error/warning report level. 2. remove #extension restriction. 3. Fix version related issue. * Add test results * Turn conditional warnings about pragma to unconditional ones.
1 parent ac2f01f commit 9eaa69c

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

glslang/MachineIndependent/ParseHelper.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,9 @@ void TParseContext::handlePragma(const TSourceLoc& loc, const TVector<TString>&
246246
else if (tokens[2].compare("off") == 0)
247247
contextPragma.optimize = false;
248248
else {
249-
error(loc, "\"on\" or \"off\" expected after '(' for 'optimize' pragma", "#pragma", "");
249+
if(relaxedErrors())
250+
// If an implementation does not recognize the tokens following #pragma, then it will ignore that pragma.
251+
warn(loc, "\"on\" or \"off\" expected after '(' for 'optimize' pragma", "#pragma", "");
250252
return;
251253
}
252254

@@ -270,7 +272,9 @@ void TParseContext::handlePragma(const TSourceLoc& loc, const TVector<TString>&
270272
else if (tokens[2].compare("off") == 0)
271273
contextPragma.debug = false;
272274
else {
273-
error(loc, "\"on\" or \"off\" expected after '(' for 'debug' pragma", "#pragma", "");
275+
if(relaxedErrors())
276+
// If an implementation does not recognize the tokens following #pragma, then it will ignore that pragma.
277+
warn(loc, "\"on\" or \"off\" expected after '(' for 'debug' pragma", "#pragma", "");
274278
return;
275279
}
276280

@@ -2798,15 +2802,18 @@ void TParseContext::reservedPpErrorCheck(const TSourceLoc& loc, const char* iden
27982802
if (strncmp(identifier, "GL_", 3) == 0)
27992803
ppError(loc, "names beginning with \"GL_\" can't be (un)defined:", op, identifier);
28002804
else if (strncmp(identifier, "defined", 8) == 0)
2801-
ppError(loc, "\"defined\" can't be (un)defined:", op, identifier);
2805+
if (relaxedErrors())
2806+
ppWarn(loc, "\"defined\" is (un)defined:", op, identifier);
2807+
else
2808+
ppError(loc, "\"defined\" can't be (un)defined:", op, identifier);
28022809
else if (strstr(identifier, "__") != 0) {
28032810
if (isEsProfile() && version >= 300 &&
28042811
(strcmp(identifier, "__LINE__") == 0 ||
28052812
strcmp(identifier, "__FILE__") == 0 ||
28062813
strcmp(identifier, "__VERSION__") == 0))
28072814
ppError(loc, "predefined names can't be (un)defined:", op, identifier);
28082815
else {
2809-
if (isEsProfile() && version < 300)
2816+
if (isEsProfile() && version < 300 && !relaxedErrors())
28102817
ppError(loc, "names containing consecutive underscores are reserved, and an error if version < 300:", op, identifier);
28112818
else
28122819
ppWarn(loc, "names containing consecutive underscores are reserved:", op, identifier);

glslang/MachineIndependent/gl_types.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@
5252
#define GL_UNSIGNED_INT64_VEC2_ARB 0x8FE5
5353
#define GL_UNSIGNED_INT64_VEC3_ARB 0x8FE6
5454
#define GL_UNSIGNED_INT64_VEC4_ARB 0x8FE7
55+
#define GL_UNSIGNED_INT16_VEC2_NV 0x8FF1
56+
#define GL_UNSIGNED_INT16_VEC3_NV 0x8FF2
57+
#define GL_UNSIGNED_INT16_VEC4_NV 0x8FF3
58+
59+
#define GL_INT16_NV 0x8FE4
60+
#define GL_INT16_VEC2_NV 0x8FE5
61+
#define GL_INT16_VEC3_NV 0x8FE6
62+
#define GL_INT16_VEC4_NV 0x8FE7
5563

5664
#define GL_BOOL 0x8B56
5765
#define GL_BOOL_VEC2 0x8B57

glslang/MachineIndependent/preprocessor/Pp.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,10 +422,10 @@ int TPpContext::eval(int token, int precedence, bool shortCircuit, int& res, boo
422422
if (! parseContext.isReadingHLSL() && isMacroInput()) {
423423
if (parseContext.relaxedErrors())
424424
parseContext.ppWarn(ppToken->loc, "nonportable when expanded from macros for preprocessor expression",
425-
"defined", "");
425+
"defined", "");
426426
else
427427
parseContext.ppError(ppToken->loc, "cannot use in preprocessor expression when expanded from macros",
428-
"defined", "");
428+
"defined", "");
429429
}
430430
bool needclose = 0;
431431
token = scanToken(ppToken);
@@ -1184,7 +1184,9 @@ MacroExpandResult TPpContext::MacroExpand(TPpToken* ppToken, bool expandUndef, b
11841184
int macroAtom = atomStrings.getAtom(ppToken->name);
11851185
switch (macroAtom) {
11861186
case PpAtomLineMacro:
1187-
ppToken->ival = parseContext.getCurrentLoc().line;
1187+
// Arguments which are macro have been replaced in the first stage.
1188+
if (ppToken->ival == 0)
1189+
ppToken->ival = parseContext.getCurrentLoc().line;
11881190
snprintf(ppToken->name, sizeof(ppToken->name), "%d", ppToken->ival);
11891191
UngetToken(PpAtomConstInt, ppToken);
11901192
return MacroExpandStarted;
@@ -1285,6 +1287,11 @@ MacroExpandResult TPpContext::MacroExpand(TPpToken* ppToken, bool expandUndef, b
12851287
nestStack.push_back('}');
12861288
else if (nestStack.size() > 0 && token == nestStack.back())
12871289
nestStack.pop_back();
1290+
1291+
//Macro replacement list is expanded in the last stage.
1292+
if (atomStrings.getAtom(ppToken->name) == PpAtomLineMacro)
1293+
ppToken->ival = parseContext.getCurrentLoc().line;
1294+
12881295
in->args[arg]->putToken(token, ppToken);
12891296
tokenRecorded = true;
12901297
}

0 commit comments

Comments
 (0)