Author: Richard Smith Date: 2020-08-31T20:59:20-07:00 New Revision: 113861b444610aebd1c05760a3e0ee6284f42211
URL: https://github.com/llvm/llvm-project/commit/113861b444610aebd1c05760a3e0ee6284f42211 DIFF: https://github.com/llvm/llvm-project/commit/113861b444610aebd1c05760a3e0ee6284f42211.diff LOG: Fix -Wcompound-token-split to give the same warnings under -E -frewrite-includes. Remove the special-case (and highly implausible) diagnostic for a compound token that crosses a file boundary, and instead model that case the same as a compound token separated by whitespace, so that file transitions and presumed file transitions behave the same way. Added: Modified: clang/include/clang/Basic/DiagnosticParseKinds.td clang/lib/Parse/Parser.cpp clang/test/Parser/compound-token-split.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Basic/DiagnosticParseKinds.td b/clang/include/clang/Basic/DiagnosticParseKinds.td index 42da8bbad74f..0e51fef8659e 100644 --- a/clang/include/clang/Basic/DiagnosticParseKinds.td +++ b/clang/include/clang/Basic/DiagnosticParseKinds.td @@ -70,9 +70,6 @@ def subst_compound_token_kind : TextSubstitution< def warn_compound_token_split_by_macro : Warning< "%sub{subst_compound_token_kind}0,1,2,3 appear in diff erent " "macro expansion contexts">, InGroup<CompoundTokenSplitByMacro>; -def warn_compound_token_split_by_file : Warning< - "%sub{subst_compound_token_kind}0,1,2,3 appear in diff erent source files">, - InGroup<CompoundTokenSplit>; def note_compound_token_split_second_token_here : Note< "%select{|second }0%1 token is here">; def warn_compound_token_split_by_whitespace : Warning< diff --git a/clang/lib/Parse/Parser.cpp b/clang/lib/Parse/Parser.cpp index 70e6e74ade89..c72ffde8fc26 100644 --- a/clang/lib/Parse/Parser.cpp +++ b/clang/lib/Parse/Parser.cpp @@ -233,13 +233,12 @@ void Parser::checkCompoundToken(SourceLocation FirstTokLoc, return; SourceLocation SecondTokLoc = Tok.getLocation(); - // We expect both tokens to come from the same FileID. - FileID FirstID = PP.getSourceManager().getFileID(FirstTokLoc); - FileID SecondID = PP.getSourceManager().getFileID(SecondTokLoc); - if (FirstID != SecondID) { - Diag(FirstTokLoc, (FirstTokLoc.isMacroID() || SecondTokLoc.isMacroID()) - ? diag::warn_compound_token_split_by_macro - : diag::warn_compound_token_split_by_file) + // If either token is in a macro, we expect both tokens to come from the same + // macro expansion. + if ((FirstTokLoc.isMacroID() || SecondTokLoc.isMacroID()) && + PP.getSourceManager().getFileID(FirstTokLoc) != + PP.getSourceManager().getFileID(SecondTokLoc)) { + Diag(FirstTokLoc, diag::warn_compound_token_split_by_macro) << (FirstTokKind == Tok.getKind()) << FirstTokKind << Tok.getKind() << static_cast<int>(Op) << SourceRange(FirstTokLoc); Diag(SecondTokLoc, diag::note_compound_token_split_second_token_here) @@ -249,7 +248,7 @@ void Parser::checkCompoundToken(SourceLocation FirstTokLoc, } // We expect the tokens to abut. - if (Tok.hasLeadingSpace()) { + if (Tok.hasLeadingSpace() || Tok.isAtStartOfLine()) { SourceLocation SpaceLoc = PP.getLocForEndOfToken(FirstTokLoc); if (SpaceLoc.isInvalid()) SpaceLoc = FirstTokLoc; diff --git a/clang/test/Parser/compound-token-split.cpp b/clang/test/Parser/compound-token-split.cpp index 0f1774a10714..6b77bf386087 100644 --- a/clang/test/Parser/compound-token-split.cpp +++ b/clang/test/Parser/compound-token-split.cpp @@ -1,8 +1,12 @@ // RUN: %clang_cc1 %s -verify // RUN: %clang_cc1 %s -verify=expected,space -Wcompound-token-split +// Ensure we get the same warnings after -frewrite-includes +// RUN: %clang_cc1 %s -E -frewrite-includes -o %t +// RUN: %clang_cc1 -x c++ %t -verify=expected,space -Wcompound-token-split + #ifdef LSQUARE -[ // expected-note {{second '[' token is here}} +[ #else #define VAR(type, name, init) type name = (init) @@ -26,7 +30,7 @@ int f2() { return n; } -[ // expected-warning-re {{{{^}}'[' tokens introducing attribute appear in diff erent source files}} +[ // space-warning-re {{{{^}}'[' tokens introducing attribute are separated by whitespace}} #define LSQUARE #include __FILE__ noreturn ]] void g(); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits