Commit 2f6ddf31 by Olli Etuaho

Allow double underscore in macro names

Double underscore is allowed according to GLSL ES 3.10, and based on Khronos discussions the intent is that this should also apply to older specs. The dEQP tests also check this, and WebGL tests that check the opposite were recently removed. The error is changed into a warning. BUG=angleproject:989 TEST=angle_unittests dEQP-GLES3.functional.shaders.preprocessor.* (2 tests start passing) dEQP-GLES2.functional.shaders.preprocessor.* (2 tests start passing) Change-Id: I582c01b4adc8fc416354351e02b776f2cc602408 Reviewed-on: https://chromium-review.googlesource.com/300965Tested-by: 's avatarOlli Etuaho <oetuaho@nvidia.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org> Tryjob-Request: Olli Etuaho <oetuaho@nvidia.com>
parent 1048ea75
...@@ -125,6 +125,8 @@ std::string Diagnostics::message(ID id) ...@@ -125,6 +125,8 @@ std::string Diagnostics::message(ID id)
return "unrecognized pragma"; return "unrecognized pragma";
case PP_NON_PP_TOKEN_BEFORE_EXTENSION_ESSL1: case PP_NON_PP_TOKEN_BEFORE_EXTENSION_ESSL1:
return "extension directive should occur before any non-preprocessor tokens"; return "extension directive should occur before any non-preprocessor tokens";
case PP_WARNING_MACRO_NAME_RESERVED:
return "macro name with a double underscore is reserved - unintented behavior is possible";
// Warnings end. // Warnings end.
default: default:
assert(false); assert(false);
......
...@@ -71,6 +71,7 @@ class Diagnostics ...@@ -71,6 +71,7 @@ class Diagnostics
PP_EOF_IN_DIRECTIVE, PP_EOF_IN_DIRECTIVE,
PP_UNRECOGNIZED_PRAGMA, PP_UNRECOGNIZED_PRAGMA,
PP_NON_PP_TOKEN_BEFORE_EXTENSION_ESSL1, PP_NON_PP_TOKEN_BEFORE_EXTENSION_ESSL1,
PP_WARNING_MACRO_NAME_RESERVED,
PP_WARNING_END PP_WARNING_END
}; };
......
...@@ -119,14 +119,12 @@ void skipUntilEOD(pp::Lexer *lexer, pp::Token *token) ...@@ -119,14 +119,12 @@ void skipUntilEOD(pp::Lexer *lexer, pp::Token *token)
bool isMacroNameReserved(const std::string &name) bool isMacroNameReserved(const std::string &name)
{ {
// Names prefixed with "GL_" are reserved. // Names prefixed with "GL_" are reserved.
if (name.substr(0, 3) == "GL_") return (name.substr(0, 3) == "GL_");
return true; }
// Names containing two consecutive underscores are reserved.
if (name.find("__") != std::string::npos)
return true;
return false; bool hasDoubleUnderscores(const std::string &name)
{
return (name.find("__") != std::string::npos);
} }
bool isMacroPredefined(const std::string &name, bool isMacroPredefined(const std::string &name,
...@@ -291,6 +289,16 @@ void DirectiveParser::parseDefine(Token *token) ...@@ -291,6 +289,16 @@ void DirectiveParser::parseDefine(Token *token)
token->location, token->text); token->location, token->text);
return; return;
} }
// Using double underscores is allowed, but may result in unintended
// behavior, so a warning is issued. At the time of writing this was
// specified in ESSL 3.10, but the intent judging from Khronos
// discussions and dEQP tests was that double underscores should be
// allowed in earlier ESSL versions too.
if (hasDoubleUnderscores(token->text))
{
mDiagnostics->report(Diagnostics::PP_WARNING_MACRO_NAME_RESERVED, token->location,
token->text);
}
Macro macro; Macro macro;
macro.type = Macro::kTypeObj; macro.type = Macro::kTypeObj;
......
...@@ -235,8 +235,6 @@ ...@@ -235,8 +235,6 @@
504 WIN LINUX : dEQP-GLES2.functional.uniform_api.value.assigned.by_value.render.nested_structs_arrays.sampler2D_samplerCube_* = FAIL 504 WIN LINUX : dEQP-GLES2.functional.uniform_api.value.assigned.by_value.render.nested_structs_arrays.sampler2D_samplerCube_* = FAIL
// Windows Linux and Mac failures // Windows Linux and Mac failures
989 WIN LINUX MAC : dEQP-GLES2.functional.shaders.preprocessor.basic.identifier_with_double_underscore_vertex = FAIL
989 WIN LINUX MAC : dEQP-GLES2.functional.shaders.preprocessor.basic.identifier_with_double_underscore_fragment = FAIL
989 WIN LINUX MAC : dEQP-GLES2.functional.shaders.preprocessor.extensions.after_non_preprocessing_tokens_vertex = FAIL 989 WIN LINUX MAC : dEQP-GLES2.functional.shaders.preprocessor.extensions.after_non_preprocessing_tokens_vertex = FAIL
989 WIN LINUX MAC : dEQP-GLES2.functional.shaders.preprocessor.extensions.after_non_preprocessing_tokens_fragment = FAIL 989 WIN LINUX MAC : dEQP-GLES2.functional.shaders.preprocessor.extensions.after_non_preprocessing_tokens_fragment = FAIL
1015 WIN LINUX MAC : dEQP-GLES2.functional.shaders.functions.invalid.return_array_in_struct_vertex = FAIL 1015 WIN LINUX MAC : dEQP-GLES2.functional.shaders.functions.invalid.return_array_in_struct_vertex = FAIL
......
...@@ -42,8 +42,6 @@ ...@@ -42,8 +42,6 @@
1087 WIN : dEQP-GLES3.functional.implementation_limits.num_compressed_texture_formats = FAIL 1087 WIN : dEQP-GLES3.functional.implementation_limits.num_compressed_texture_formats = FAIL
1087 WIN : dEQP-GLES3.functional.implementation_limits.compressed_texture_formats = FAIL 1087 WIN : dEQP-GLES3.functional.implementation_limits.compressed_texture_formats = FAIL
989 WIN : dEQP-GLES3.functional.shaders.preprocessor.basic.identifier_with_double_underscore_vertex = FAIL
989 WIN : dEQP-GLES3.functional.shaders.preprocessor.basic.identifier_with_double_underscore_fragment = FAIL
1088 WIN : dEQP-GLES3.functional.shaders.linkage.varying.rules.invalid_type_struct_array = FAIL 1088 WIN : dEQP-GLES3.functional.shaders.linkage.varying.rules.invalid_type_struct_array = FAIL
1088 WIN : dEQP-GLES3.functional.shaders.linkage.varying.rules.invalid_type_struct_struct = FAIL 1088 WIN : dEQP-GLES3.functional.shaders.linkage.varying.rules.invalid_type_struct_struct = FAIL
1088 WIN : dEQP-GLES3.functional.shaders.linkage.varying.rules.invalid_type_array_struct = FAIL 1088 WIN : dEQP-GLES3.functional.shaders.linkage.varying.rules.invalid_type_array_struct = FAIL
......
...@@ -70,12 +70,10 @@ TEST_F(DefineTest, ReservedUnderScore1) ...@@ -70,12 +70,10 @@ TEST_F(DefineTest, ReservedUnderScore1)
const char* input = "#define __foo bar\n" const char* input = "#define __foo bar\n"
"__foo\n"; "__foo\n";
const char* expected = "\n" const char* expected = "\n"
"__foo\n"; "bar\n";
EXPECT_CALL(mDiagnostics, EXPECT_CALL(mDiagnostics, print(pp::Diagnostics::PP_WARNING_MACRO_NAME_RESERVED,
print(pp::Diagnostics::PP_MACRO_NAME_RESERVED, pp::SourceLocation(0, 1), "__foo"));
pp::SourceLocation(0, 1),
"__foo"));
preprocess(input, expected); preprocess(input, expected);
} }
...@@ -85,12 +83,10 @@ TEST_F(DefineTest, ReservedUnderScore2) ...@@ -85,12 +83,10 @@ TEST_F(DefineTest, ReservedUnderScore2)
const char* input = "#define foo__bar baz\n" const char* input = "#define foo__bar baz\n"
"foo__bar\n"; "foo__bar\n";
const char* expected = "\n" const char* expected = "\n"
"foo__bar\n"; "baz\n";
EXPECT_CALL(mDiagnostics, EXPECT_CALL(mDiagnostics, print(pp::Diagnostics::PP_WARNING_MACRO_NAME_RESERVED,
print(pp::Diagnostics::PP_MACRO_NAME_RESERVED, pp::SourceLocation(0, 1), "foo__bar"));
pp::SourceLocation(0, 1),
"foo__bar"));
preprocess(input, expected); preprocess(input, expected);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment