From 7bd3d3953acd883867522213c88907ff69195e3a Mon Sep 17 00:00:00 2001 From: Nicolas Capens Date: Tue, 29 Mar 2016 17:27:04 -0400 Subject: [PATCH] Fix treating undefined preprocessor identifiers as error. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Change-Id: Ifa9db4ab541d9421dddfe6b09571d8b5d38a479d Reviewed-on: https://swiftshader-review.googlesource.com/5011 Tested-by: Nicolas Capens Reviewed-by: Alexis Hétu Reviewed-by: Nicolas Capens --- src/OpenGL/compiler/preprocessor/Diagnostics.cpp | 2 ++ src/OpenGL/compiler/preprocessor/Diagnostics.h | 1 + src/OpenGL/compiler/preprocessor/ExpressionParser.cpp | 10 ++++++++++ src/OpenGL/compiler/preprocessor/ExpressionParser.y | 10 ++++++++++ 4 files changed, 23 insertions(+) diff --git a/src/OpenGL/compiler/preprocessor/Diagnostics.cpp b/src/OpenGL/compiler/preprocessor/Diagnostics.cpp index 06d1d8018..c6e675832 100644 --- a/src/OpenGL/compiler/preprocessor/Diagnostics.cpp +++ b/src/OpenGL/compiler/preprocessor/Diagnostics.cpp @@ -109,6 +109,8 @@ std::string Diagnostics::message(ID id) return "invalid file number"; case INVALID_LINE_DIRECTIVE: return "invalid line directive"; + case UNDEFINED_IDENTIFIER: + return "undefined identifier"; // Errors end. // Warnings begin. case EOF_IN_DIRECTIVE: diff --git a/src/OpenGL/compiler/preprocessor/Diagnostics.h b/src/OpenGL/compiler/preprocessor/Diagnostics.h index 4db9c3012..cb8710121 100644 --- a/src/OpenGL/compiler/preprocessor/Diagnostics.h +++ b/src/OpenGL/compiler/preprocessor/Diagnostics.h @@ -61,6 +61,7 @@ class Diagnostics INVALID_LINE_NUMBER, INVALID_FILE_NUMBER, INVALID_LINE_DIRECTIVE, + UNDEFINED_IDENTIFIER, ERROR_END, WARNING_BEGIN, diff --git a/src/OpenGL/compiler/preprocessor/ExpressionParser.cpp b/src/OpenGL/compiler/preprocessor/ExpressionParser.cpp index 2b561dfab..94f460ccc 100644 --- a/src/OpenGL/compiler/preprocessor/ExpressionParser.cpp +++ b/src/OpenGL/compiler/preprocessor/ExpressionParser.cpp @@ -1762,6 +1762,16 @@ int yylex(YYSTYPE* lvalp, Context* context) type = TOK_CONST_INT; break; } + case pp::Token::IDENTIFIER: + // Defined identifiers should have been expanded already. + // Unlike the C/C++ preprocessor, it does not default to 0. + // Use of such identifiers causes an error. + context->diagnostics->report(pp::Diagnostics::UNDEFINED_IDENTIFIER, + token->location, token->text); + + *lvalp = 0; + type = TOK_CONST_INT; + break; case pp::Token::OP_OR: type = TOK_OP_OR; break; case pp::Token::OP_AND: type = TOK_OP_AND; break; case pp::Token::OP_NE: type = TOK_OP_NE; break; diff --git a/src/OpenGL/compiler/preprocessor/ExpressionParser.y b/src/OpenGL/compiler/preprocessor/ExpressionParser.y index 2856c14b6..9a4dcfa5c 100644 --- a/src/OpenGL/compiler/preprocessor/ExpressionParser.y +++ b/src/OpenGL/compiler/preprocessor/ExpressionParser.y @@ -194,6 +194,16 @@ int yylex(YYSTYPE* lvalp, Context* context) type = TOK_CONST_INT; break; } + case pp::Token::IDENTIFIER: + // Defined identifiers should have been expanded already. + // Unlike the C/C++ preprocessor, it does not default to 0. + // Use of such identifiers causes an error. + context->diagnostics->report(pp::Diagnostics::UNDEFINED_IDENTIFIER, + token->location, token->text); + + *lvalp = 0; + type = TOK_CONST_INT; + break; case pp::Token::OP_OR: type = TOK_OP_OR; break; case pp::Token::OP_AND: type = TOK_OP_AND; break; case pp::Token::OP_NE: type = TOK_OP_NE; break; -- 2.11.0