<div dir="ltr">Change r224100 should have fixed the build on ninja-clang-x64-mingw64-RA, however there is other problem. It looks like unrelated to my fix, if you think it is, please let me know.<div class="gmail_extra"><br clear="all"><div><div class="gmail_signature">Thanks,<br>--Serge<br></div></div>
<br><div class="gmail_quote">2014-12-12 0:36 GMT+06:00 Aaron Ballman <span dir="ltr"><<a href="mailto:aaron@aaronballman.com" target="_blank">aaron@aaronballman.com</a>></span>:<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This appears to have broken at least one bot:<br>
<a href="http://bb.pgr.jp/builders/ninja-clang-x64-mingw64-RA/builds/5534" target="_blank">http://bb.pgr.jp/builders/ninja-clang-x64-mingw64-RA/builds/5534</a><br>
<br>
I'm not certain whether the correct fix is to expect your new<br>
diagnostic, or to simply turn the diagnostic off for this test.<br>
<span class="HOEnZb"><font color="#888888"><br>
~Aaron<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
On Thu, Dec 11, 2014 at 7:18 AM, Serge Pavlov <<a href="mailto:sepavloff@gmail.com">sepavloff@gmail.com</a>> wrote:<br>
> Author: sepavloff<br>
> Date: Thu Dec 11 06:18:08 2014<br>
> New Revision: 224012<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=224012&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=224012&view=rev</a><br>
> Log:<br>
> Emit warning if define or undef reserved identifier or keyword.<br>
><br>
> Recommit of r223114, reverted in r223120.<br>
><br>
><br>
> Modified:<br>
>     cfe/trunk/include/clang/Basic/DiagnosticGroups.td<br>
>     cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td<br>
>     cfe/trunk/include/clang/Basic/IdentifierTable.h<br>
>     cfe/trunk/lib/Basic/IdentifierTable.cpp<br>
>     cfe/trunk/lib/Lex/PPDirectives.cpp<br>
>     cfe/trunk/test/PCH/single-token-macro.c<br>
>     cfe/trunk/test/Preprocessor/cxx_oper_keyword_ms_compat.cpp<br>
>     cfe/trunk/test/Sema/thread-specifier.c<br>
><br>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=224012&r1=224011&r2=224012&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=224012&r1=224011&r2=224012&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)<br>
> +++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Thu Dec 11 06:18:08 2014<br>
> @@ -337,6 +337,8 @@ def : DiagGroup<"sequence-point", [Unseq<br>
><br>
>  // Preprocessor warnings.<br>
>  def AmbiguousMacro : DiagGroup<"ambiguous-macro">;<br>
> +def KeywordAsMacro : DiagGroup<"keyword-macro">;<br>
> +def ReservedIdAsMacro : DiagGroup<"reserved-id-macro">;<br>
><br>
>  // Just silence warnings about -Wstrict-aliasing for now.<br>
>  def : DiagGroup<"strict-aliasing=0">;<br>
><br>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=224012&r1=224011&r2=224012&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=224012&r1=224011&r2=224012&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td (original)<br>
> +++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td Thu Dec 11 06:18:08 2014<br>
> @@ -290,6 +290,14 @@ def note_pp_ambiguous_macro_chosen : Not<br>
>    "expanding this definition of %0">;<br>
>  def note_pp_ambiguous_macro_other : Note<<br>
>    "other definition of %0">;<br>
> +def warn_pp_macro_hides_keyword : Warning<<br>
> +  "keyword or reserved identifier is hidden by macro definition">,<br>
> +  InGroup<KeywordAsMacro>;<br>
> +def warn_pp_macro_is_reserved_id : Warning<<br>
> +  "macro name is a keyword or reserved identifier">, InGroup<KeywordAsMacro>;<br>
> +def warn_pp_defundef_reserved_ident : Warning<<br>
> +  "reserved identifier is used as macro name">, DefaultIgnore,<br>
> +  InGroup<ReservedIdAsMacro>;<br>
><br>
>  def pp_invalid_string_literal : Warning<<br>
>    "invalid string literal, ignoring final '\\'">;<br>
><br>
> Modified: cfe/trunk/include/clang/Basic/IdentifierTable.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/IdentifierTable.h?rev=224012&r1=224011&r2=224012&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/IdentifierTable.h?rev=224012&r1=224011&r2=224012&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/include/clang/Basic/IdentifierTable.h (original)<br>
> +++ cfe/trunk/include/clang/Basic/IdentifierTable.h Thu Dec 11 06:18:08 2014<br>
> @@ -249,6 +249,9 @@ public:<br>
>    }<br>
>    bool isCPlusPlusOperatorKeyword() const { return IsCPPOperatorKeyword; }<br>
><br>
> +  /// \brief Return true if this token is a keyword in the specified language.<br>
> +  bool isKeyword(const LangOptions &LangOpts);<br>
> +<br>
>    /// getFETokenInfo/setFETokenInfo - The language front-end is allowed to<br>
>    /// associate arbitrary metadata with this token.<br>
>    template<typename T><br>
><br>
> Modified: cfe/trunk/lib/Basic/IdentifierTable.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/IdentifierTable.cpp?rev=224012&r1=224011&r2=224012&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/IdentifierTable.cpp?rev=224012&r1=224011&r2=224012&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/Basic/IdentifierTable.cpp (original)<br>
> +++ cfe/trunk/lib/Basic/IdentifierTable.cpp Thu Dec 11 06:18:08 2014<br>
> @@ -122,7 +122,7 @@ namespace {<br>
><br>
>  /// \brief Translates flags as specified in TokenKinds.def into keyword status<br>
>  /// in the given language standard.<br>
> -static KeywordStatus GetKeywordStatus(const LangOptions &LangOpts,<br>
> +static KeywordStatus getKeywordStatus(const LangOptions &LangOpts,<br>
>                                        unsigned Flags) {<br>
>    if (Flags == KEYALL) return KS_Enabled;<br>
>    if (LangOpts.CPlusPlus && (Flags & KEYCXX)) return KS_Enabled;<br>
> @@ -151,7 +151,7 @@ static KeywordStatus GetKeywordStatus(co<br>
>  static void AddKeyword(StringRef Keyword,<br>
>                         tok::TokenKind TokenCode, unsigned Flags,<br>
>                         const LangOptions &LangOpts, IdentifierTable &Table) {<br>
> -  KeywordStatus AddResult = GetKeywordStatus(LangOpts, Flags);<br>
> +  KeywordStatus AddResult = getKeywordStatus(LangOpts, Flags);<br>
><br>
>    // Don't add this keyword under MSVCCompat.<br>
>    if (LangOpts.MSVCCompat && (Flags & KEYNOMS))<br>
> @@ -209,6 +209,31 @@ void IdentifierTable::AddKeywords(const<br>
>                 LangOpts, *this);<br>
>  }<br>
><br>
> +/// \brief Checks if the specified token kind represents a keyword in the<br>
> +/// specified language.<br>
> +/// \returns Status of the keyword in the language.<br>
> +static KeywordStatus getTokenKwStatus(const LangOptions &LangOpts,<br>
> +                                      tok::TokenKind K) {<br>
> +  switch (K) {<br>
> +#define KEYWORD(NAME, FLAGS) \<br>
> +  case tok::kw_##NAME: return getKeywordStatus(LangOpts, FLAGS);<br>
> +#include "clang/Basic/TokenKinds.def"<br>
> +  default: return KS_Disabled;<br>
> +  }<br>
> +}<br>
> +<br>
> +/// \brief Returns true if the identifier represents a keyword in the<br>
> +/// specified language.<br>
> +bool IdentifierInfo::isKeyword(const LangOptions &LangOpts) {<br>
> +  switch (getTokenKwStatus(LangOpts, getTokenID())) {<br>
> +  case KS_Enabled:<br>
> +  case KS_Extension:<br>
> +    return true;<br>
> +  default:<br>
> +    return false;<br>
> +  }<br>
> +}<br>
> +<br>
>  tok::PPKeywordKind IdentifierInfo::getPPKeywordID() const {<br>
>    // We use a perfect hash function here involving the length of the keyword,<br>
>    // the first and third character.  For preprocessor ID's there are no<br>
><br>
> Modified: cfe/trunk/lib/Lex/PPDirectives.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=224012&r1=224011&r2=224012&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=224012&r1=224011&r2=224012&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/lib/Lex/PPDirectives.cpp (original)<br>
> +++ cfe/trunk/lib/Lex/PPDirectives.cpp Thu Dec 11 06:18:08 2014<br>
> @@ -100,6 +100,58 @@ void Preprocessor::DiscardUntilEndOfDire<br>
>    } while (Tmp.isNot(tok::eod));<br>
>  }<br>
><br>
> +/// \brief Enumerates possible cases of #define/#undef a reserved identifier.<br>
> +enum MacroDiag {<br>
> +  MD_NoWarn,        //> Not a reserved identifier<br>
> +  MD_KeywordDef,    //> Macro hides keyword, enabled by default<br>
> +  MD_KeywordUndef,  //> #undef keyword, enabled by default<br>
> +  MD_WarnStrict     //> Other reserved id, disabled by default<br>
> +};<br>
> +<br>
> +/// \brief Checks if the specified identifier is reserved in the specified<br>
> +/// language.<br>
> +/// This function does not check if the identifier is a keyword.<br>
> +static bool isReservedId(StringRef Text, const LangOptions &Lang) {<br>
> +  // C++ [macro.names], C11 7.1.3:<br>
> +  // All identifiers that begin with an underscore and either an uppercase<br>
> +  // letter or another underscore are always reserved for any use.<br>
> +  if (Text.size() >= 2 && Text[0] == '_' &&<br>
> +      (isUppercase(Text[1]) || Text[1] == '_'))<br>
> +    return true;<br>
> +  // C++ [global.names]<br>
> +  // Each name that contains a double underscore ... is reserved to the<br>
> +  // implementation for any use.<br>
> +  if (Lang.CPlusPlus) {<br>
> +    if (Text.find("__") != StringRef::npos)<br>
> +      return true;<br>
> +  }<br>
> +  return false;<br>
> +}<br>
> +<br>
> +static MacroDiag shouldWarnOnMacroDef(Preprocessor &PP, IdentifierInfo *II) {<br>
> +  const LangOptions &Lang = PP.getLangOpts();<br>
> +  StringRef Text = II->getName();<br>
> +  if (isReservedId(Text, Lang))<br>
> +    return MD_WarnStrict;<br>
> +  if (II->isKeyword(Lang))<br>
> +    return MD_KeywordDef;<br>
> +  if (Lang.CPlusPlus && (Text.equals("override") || Text.equals("final")))<br>
> +    return MD_KeywordDef;<br>
> +  return MD_NoWarn;<br>
> +}<br>
> +<br>
> +static MacroDiag shouldWarnOnMacroUndef(Preprocessor &PP, IdentifierInfo *II) {<br>
> +  const LangOptions &Lang = PP.getLangOpts();<br>
> +  if (II->isKeyword(Lang))<br>
> +    return MD_KeywordUndef;<br>
> +  StringRef Text = II->getName();<br>
> +  if (Lang.CPlusPlus && (Text.equals("override") || Text.equals("final")))<br>
> +    return MD_KeywordUndef;<br>
> +  if (isReservedId(Text, Lang))<br>
> +    return MD_WarnStrict;<br>
> +  return MD_NoWarn;<br>
> +}<br>
> +<br>
>  bool Preprocessor::CheckMacroName(Token &MacroNameTok, MacroUse isDefineUndef) {<br>
>    // Missing macro name?<br>
>    if (MacroNameTok.is(tok::eod))<br>
> @@ -140,6 +192,23 @@ bool Preprocessor::CheckMacroName(Token<br>
>      Diag(MacroNameTok, diag::ext_pp_undef_builtin_macro);<br>
>    }<br>
><br>
> +  // Warn if defining/undefining reserved identifier including keywords.<br>
> +  SourceLocation MacroNameLoc = MacroNameTok.getLocation();<br>
> +  if (!SourceMgr.isInSystemHeader(MacroNameLoc) &&<br>
> +      (strcmp(SourceMgr.getBufferName(MacroNameLoc), "<built-in>") != 0)) {<br>
> +    MacroDiag D = MD_NoWarn;<br>
> +    if (isDefineUndef == MU_Define)<br>
> +      D = shouldWarnOnMacroDef(*this, II);<br>
> +    else if (isDefineUndef == MU_Undef)<br>
> +      D = shouldWarnOnMacroUndef(*this, II);<br>
> +    if (D == MD_KeywordDef)<br>
> +      Diag(MacroNameTok, diag::warn_pp_macro_hides_keyword);<br>
> +    if (D == MD_KeywordUndef)<br>
> +      Diag(MacroNameTok, diag::warn_pp_macro_is_reserved_id);<br>
> +    else if (D == MD_WarnStrict)<br>
> +      Diag(MacroNameTok, diag::warn_pp_defundef_reserved_ident);<br>
> +  }<br>
> +<br>
>    // Okay, we got a good identifier.<br>
>    return false;<br>
>  }<br>
><br>
> Modified: cfe/trunk/test/PCH/single-token-macro.c<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/single-token-macro.c?rev=224012&r1=224011&r2=224012&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/PCH/single-token-macro.c?rev=224012&r1=224011&r2=224012&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/test/PCH/single-token-macro.c (original)<br>
> +++ cfe/trunk/test/PCH/single-token-macro.c Thu Dec 11 06:18:08 2014<br>
> @@ -12,6 +12,8 @@<br>
>  #ifndef HEADER<br>
>  #define HEADER<br>
><br>
> +#pragma clang diagnostic ignored "-Wreserved-id-macro"<br>
> +<br>
>  #ifdef __stdcall<br>
>  // __stdcall is defined as __attribute__((__stdcall__)) for targeting mingw32.<br>
>  #undef __stdcall<br>
><br>
> Modified: cfe/trunk/test/Preprocessor/cxx_oper_keyword_ms_compat.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/cxx_oper_keyword_ms_compat.cpp?rev=224012&r1=224011&r2=224012&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/cxx_oper_keyword_ms_compat.cpp?rev=224012&r1=224011&r2=224012&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/test/Preprocessor/cxx_oper_keyword_ms_compat.cpp (original)<br>
> +++ cfe/trunk/test/Preprocessor/cxx_oper_keyword_ms_compat.cpp Thu Dec 11 06:18:08 2014<br>
> @@ -1,6 +1,8 @@<br>
>  // RUN: %clang_cc1 %s -E -verify -fms-extensions<br>
>  // expected-no-diagnostics<br>
><br>
> +#pragma clang diagnostic ignored "-Wkeyword-macro"<br>
> +<br>
>  bool f() {<br>
>    // Check that operators still work before redefining them.<br>
>  #if compl 0 bitand 1<br>
><br>
> Modified: cfe/trunk/test/Sema/thread-specifier.c<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/thread-specifier.c?rev=224012&r1=224011&r2=224012&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/thread-specifier.c?rev=224012&r1=224011&r2=224012&view=diff</a><br>
> ==============================================================================<br>
> --- cfe/trunk/test/Sema/thread-specifier.c (original)<br>
> +++ cfe/trunk/test/Sema/thread-specifier.c Thu Dec 11 06:18:08 2014<br>
> @@ -5,6 +5,8 @@<br>
>  // 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<br>
>  // 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<br>
><br>
> +#pragma clang diagnostic ignored "-Wkeyword-macro"<br>
> +<br>
>  #ifdef __cplusplus<br>
>  // In C++, we define __private_extern__ to extern.<br>
>  #undef __private_extern__<br>
><br>
><br>
> _______________________________________________<br>
> cfe-commits mailing list<br>
> <a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</div></div></blockquote></div></div></div>