From: Serge Pavlov Date: Fri, 12 Dec 2014 06:37:55 +0000 (+0000) Subject: Do not warn on keyword undef X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=59da7b8a685cdbc8db9da5de9beac3c8803535e9;p=platform%2Fupstream%2Fllvm.git Do not warn on keyword undef #undef a keyword is generally harmless but used often in configuration scripts. Also added tests that I forgot to include to commit in r223114. llvm-svn: 224100 --- diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td b/clang/include/clang/Basic/DiagnosticLexKinds.td index 5eb9e659..325ab0e 100644 --- a/clang/include/clang/Basic/DiagnosticLexKinds.td +++ b/clang/include/clang/Basic/DiagnosticLexKinds.td @@ -291,12 +291,10 @@ def note_pp_ambiguous_macro_chosen : Note< def note_pp_ambiguous_macro_other : Note< "other definition of %0">; def warn_pp_macro_hides_keyword : Warning< - "keyword or reserved identifier is hidden by macro definition">, + "keyword is hidden by macro definition">, InGroup; def warn_pp_macro_is_reserved_id : Warning< - "macro name is a keyword or reserved identifier">, InGroup; -def warn_pp_defundef_reserved_ident : Warning< - "reserved identifier is used as macro name">, DefaultIgnore, + "macro name is a reserved identifier">, DefaultIgnore, InGroup; def pp_invalid_string_literal : Warning< diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirectives.cpp index 16b86b7..e359ea5 100644 --- a/clang/lib/Lex/PPDirectives.cpp +++ b/clang/lib/Lex/PPDirectives.cpp @@ -104,8 +104,7 @@ void Preprocessor::DiscardUntilEndOfDirective() { enum MacroDiag { MD_NoWarn, //> Not a reserved identifier MD_KeywordDef, //> Macro hides keyword, enabled by default - MD_KeywordUndef, //> #undef keyword, enabled by default - MD_WarnStrict //> Other reserved id, disabled by default + MD_ReservedMacro //> #define of #undef reserved id, disabled by default }; /// \brief Checks if the specified identifier is reserved in the specified @@ -132,7 +131,8 @@ static MacroDiag shouldWarnOnMacroDef(Preprocessor &PP, IdentifierInfo *II) { const LangOptions &Lang = PP.getLangOpts(); StringRef Text = II->getName(); if (isReservedId(Text, Lang)) - return MD_WarnStrict; + return MD_ReservedMacro; + // Do not warn on keyword undef. It is generally harmless and widely used. if (II->isKeyword(Lang)) return MD_KeywordDef; if (Lang.CPlusPlus && (Text.equals("override") || Text.equals("final"))) @@ -142,13 +142,10 @@ static MacroDiag shouldWarnOnMacroDef(Preprocessor &PP, IdentifierInfo *II) { static MacroDiag shouldWarnOnMacroUndef(Preprocessor &PP, IdentifierInfo *II) { const LangOptions &Lang = PP.getLangOpts(); - if (II->isKeyword(Lang)) - return MD_KeywordUndef; StringRef Text = II->getName(); - if (Lang.CPlusPlus && (Text.equals("override") || Text.equals("final"))) - return MD_KeywordUndef; + // Do not warn on keyword undef. It is generally harmless and widely used. if (isReservedId(Text, Lang)) - return MD_WarnStrict; + return MD_ReservedMacro; return MD_NoWarn; } @@ -203,10 +200,8 @@ bool Preprocessor::CheckMacroName(Token &MacroNameTok, MacroUse isDefineUndef) { D = shouldWarnOnMacroUndef(*this, II); if (D == MD_KeywordDef) Diag(MacroNameTok, diag::warn_pp_macro_hides_keyword); - if (D == MD_KeywordUndef) + if (D == MD_ReservedMacro) Diag(MacroNameTok, diag::warn_pp_macro_is_reserved_id); - else if (D == MD_WarnStrict) - Diag(MacroNameTok, diag::warn_pp_defundef_reserved_ident); } // Okay, we got a good identifier. diff --git a/clang/test/PCH/single-token-macro.c b/clang/test/PCH/single-token-macro.c index b077aba..aa02f65 100644 --- a/clang/test/PCH/single-token-macro.c +++ b/clang/test/PCH/single-token-macro.c @@ -12,8 +12,6 @@ #ifndef HEADER #define HEADER -#pragma clang diagnostic ignored "-Wreserved-id-macro" - #ifdef __stdcall // __stdcall is defined as __attribute__((__stdcall__)) for targeting mingw32. #undef __stdcall diff --git a/clang/test/Preprocessor/macro-reserved.c b/clang/test/Preprocessor/macro-reserved.c new file mode 100644 index 0000000..2a0e26f --- /dev/null +++ b/clang/test/Preprocessor/macro-reserved.c @@ -0,0 +1,25 @@ +// RUN: %clang_cc1 -fsyntax-only %s -verify + +#define for 0 // expected-warning {{keyword is hidden by macro definition}} +#define final 1 +#define __HAVE_X 0 +#define _HAVE_X 0 +#define X__Y + +#undef __cplusplus +#undef _HAVE_X +#undef X__Y + +#pragma clang diagnostic warning "-Wreserved-id-macro" + +#define switch if // expected-warning {{keyword is hidden by macro definition}} +#define final 1 +#define __HAVE_X 0 // expected-warning {{macro name is a reserved identifier}} +#define _HAVE_X 0 // expected-warning {{macro name is a reserved identifier}} +#define X__Y + +#undef __cplusplus // expected-warning {{macro name is a reserved identifier}} +#undef _HAVE_X // expected-warning {{macro name is a reserved identifier}} +#undef X__Y + +int x; diff --git a/clang/test/Preprocessor/macro-reserved.cpp b/clang/test/Preprocessor/macro-reserved.cpp new file mode 100644 index 0000000..8529ddf --- /dev/null +++ b/clang/test/Preprocessor/macro-reserved.cpp @@ -0,0 +1,25 @@ +// RUN: %clang_cc1 -fsyntax-only %s -verify + +#define for 0 // expected-warning {{keyword is hidden by macro definition}} +#define final 1 // expected-warning {{keyword is hidden by macro definition}} +#define __HAVE_X 0 +#define _HAVE_X 0 +#define X__Y + +#undef __cplusplus +#undef _HAVE_X +#undef X__Y + +#pragma clang diagnostic warning "-Wreserved-id-macro" + +#define switch if // expected-warning {{keyword is hidden by macro definition}} +#define final 1 // expected-warning {{keyword is hidden by macro definition}} +#define __HAVE_X 0 // expected-warning {{macro name is a reserved identifier}} +#define _HAVE_X 0 // expected-warning {{macro name is a reserved identifier}} +#define X__Y // expected-warning {{macro name is a reserved identifier}} + +#undef __cplusplus // expected-warning {{macro name is a reserved identifier}} +#undef _HAVE_X // expected-warning {{macro name is a reserved identifier}} +#undef X__Y // expected-warning {{macro name is a reserved identifier}} + +int x; diff --git a/clang/test/Sema/thread-specifier.c b/clang/test/Sema/thread-specifier.c index 71e44c3..3968ae1 100644 --- a/clang/test/Sema/thread-specifier.c +++ b/clang/test/Sema/thread-specifier.c @@ -5,8 +5,6 @@ // RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -Wno-private-extern -verify -pedantic -x c++ %s -DCXX11 -D__thread=thread_local -std=c++11 -Wno-deprecated // RUN: %clang_cc1 -triple i686-pc-linux-gnu -fsyntax-only -Wno-private-extern -verify -pedantic -x c++ %s -DC11 -D__thread=_Thread_local -std=c++11 -Wno-deprecated -#pragma clang diagnostic ignored "-Wkeyword-macro" - #ifdef __cplusplus // In C++, we define __private_extern__ to extern. #undef __private_extern__