From: Craig Topper Date: Sat, 14 Nov 2015 02:09:55 +0000 (+0000) Subject: Use %select to merge similar diagnostics. NFC X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=09bdc14343983d2cb845778c5d9b4499778a2b40;p=clang Use %select to merge similar diagnostics. NFC git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@253119 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticLexKinds.td b/include/clang/Basic/DiagnosticLexKinds.td index e6b2394dc5..34e4759a85 100644 --- a/include/clang/Basic/DiagnosticLexKinds.td +++ b/include/clang/Basic/DiagnosticLexKinds.td @@ -13,9 +13,8 @@ let Component = "Lex", CategoryName = "Lexical or Preprocessor Issue" in { -def null_in_string : Warning<"null character(s) preserved in string literal">, - InGroup; -def null_in_char : Warning<"null character(s) preserved in character literal">, +def null_in_char_or_string : Warning< + "null character(s) preserved in %select{char|string}0 literal">, InGroup; def null_in_file : Warning<"null character ignored">, InGroup; def warn_nested_block_comment : Warning<"'/*' within block comment">, @@ -67,10 +66,8 @@ def ext_token_used : Extension<"extension used">, def warn_cxx11_keyword : Warning<"'%0' is a keyword in C++11">, InGroup, DefaultIgnore; -def ext_unterminated_string : ExtWarn<"missing terminating '\"' character">, - InGroup; -def ext_unterminated_char : ExtWarn<"missing terminating ' character">, - InGroup; +def ext_unterminated_char_or_string : ExtWarn< + "missing terminating %select{'|'\"'}0 character">, InGroup; def ext_empty_character : ExtWarn<"empty character constant">, InGroup; def err_unterminated_block_comment : Error<"unterminated /* comment">; @@ -154,9 +151,8 @@ def ext_nonstandard_escape : Extension< "use of non-standard escape character '\\%0'">; def ext_unknown_escape : ExtWarn<"unknown escape sequence '\\%0'">, InGroup>; -def err_invalid_decimal_digit : Error<"invalid digit '%0' in decimal constant">; -def err_invalid_binary_digit : Error<"invalid digit '%0' in binary constant">; -def err_invalid_octal_digit : Error<"invalid digit '%0' in octal constant">; +def err_invalid_digit : Error< + "invalid digit '%0' in %select{decimal|octal|binary}1 constant">; def err_invalid_suffix_constant : Error< "invalid suffix '%0' on %select{integer|floating}1 constant">; def warn_cxx11_compat_digit_separator : Warning< @@ -173,10 +169,8 @@ def err_multichar_utf_character_literal : Error< def err_exponent_has_no_digits : Error<"exponent has no digits">; def ext_imaginary_constant : Extension< "imaginary constants are a GNU extension">, InGroup; -def err_hexconstant_requires_exponent : Error< - "hexadecimal floating constants require an exponent">; -def err_hexconstant_requires_digits : Error< - "hexadecimal floating constants require a significand">; +def err_hexconstant_requires: Error< + "hexadecimal floating constants require %select{an exponent|a significand}0">; def ext_hexconstant_invalid : Extension< "hexadecimal floating constants are a C99 feature">, InGroup; def ext_binary_literal : Extension< @@ -187,8 +181,8 @@ def warn_cxx11_compat_binary_literal : Warning< "binary integer literals are incompatible with C++ standards before C++14">, InGroup, DefaultIgnore; def err_pascal_string_too_long : Error<"Pascal string is too long">; -def err_octal_escape_too_large : Error<"octal escape sequence out of range">; -def err_hex_escape_too_large : Error<"hex escape sequence out of range">; +def err_escape_too_large : Error< + "%select{hex|octal}0 escape sequence out of range">; def ext_string_too_long : Extension<"string literal of length %0 exceeds " "maximum length %1 that %select{C90|ISO C99|C++}2 compilers are required to " "support">, InGroup; @@ -304,10 +298,9 @@ def pp_invalid_string_literal : Warning< "invalid string literal, ignoring final '\\'">; def warn_pp_expr_overflow : Warning< "integer overflow in preprocessor expression">; -def warn_pp_convert_lhs_to_positive : Warning< - "left side of operator converted from negative value to unsigned: %0">; -def warn_pp_convert_rhs_to_positive : Warning< - "right side of operator converted from negative value to unsigned: %0">; +def warn_pp_convert_to_positive : Warning< + "%select{left|right}0 side of operator converted from negative value to " + "unsigned: %1">; def ext_pp_import_directive : Extension<"#import is a language extension">, InGroup>; diff --git a/lib/Lex/Lexer.cpp b/lib/Lex/Lexer.cpp index a3ec1b3b0e..cc22ee9dbd 100644 --- a/lib/Lex/Lexer.cpp +++ b/lib/Lex/Lexer.cpp @@ -1732,7 +1732,7 @@ bool Lexer::LexStringLiteral(Token &Result, const char *CurPtr, if (C == '\n' || C == '\r' || // Newline. (C == 0 && CurPtr-1 == BufferEnd)) { // End of file. if (!isLexingRawMode() && !LangOpts.AsmPreprocessor) - Diag(BufferPtr, diag::ext_unterminated_string); + Diag(BufferPtr, diag::ext_unterminated_char_or_string) << 1; FormTokenWithChars(Result, CurPtr-1, tok::unknown); return true; } @@ -1756,7 +1756,7 @@ bool Lexer::LexStringLiteral(Token &Result, const char *CurPtr, // If a nul character existed in the string, warn about it. if (NulCharacter && !isLexingRawMode()) - Diag(NulCharacter, diag::null_in_string); + Diag(NulCharacter, diag::null_in_char_or_string) << 1; // Update the location of the token as well as the BufferPtr instance var. const char *TokStart = BufferPtr; @@ -1872,7 +1872,7 @@ bool Lexer::LexAngledStringLiteral(Token &Result, const char *CurPtr) { // If a nul character existed in the string, warn about it. if (NulCharacter && !isLexingRawMode()) - Diag(NulCharacter, diag::null_in_string); + Diag(NulCharacter, diag::null_in_char_or_string) << 1; // Update the location of token as well as BufferPtr. const char *TokStart = BufferPtr; @@ -1914,7 +1914,7 @@ bool Lexer::LexCharConstant(Token &Result, const char *CurPtr, if (C == '\n' || C == '\r' || // Newline. (C == 0 && CurPtr-1 == BufferEnd)) { // End of file. if (!isLexingRawMode() && !LangOpts.AsmPreprocessor) - Diag(BufferPtr, diag::ext_unterminated_char); + Diag(BufferPtr, diag::ext_unterminated_char_or_string) << 0; FormTokenWithChars(Result, CurPtr-1, tok::unknown); return true; } @@ -1938,7 +1938,7 @@ bool Lexer::LexCharConstant(Token &Result, const char *CurPtr, // If a nul character existed in the character, warn about it. if (NulCharacter && !isLexingRawMode()) - Diag(NulCharacter, diag::null_in_char); + Diag(NulCharacter, diag::null_in_char_or_string) << 0; // Update the location of token as well as BufferPtr. const char *TokStart = BufferPtr; diff --git a/lib/Lex/LiteralSupport.cpp b/lib/Lex/LiteralSupport.cpp index 6a112d63b0..1e7858af89 100644 --- a/lib/Lex/LiteralSupport.cpp +++ b/lib/Lex/LiteralSupport.cpp @@ -159,7 +159,7 @@ static unsigned ProcessCharEscape(const char *ThisTokBegin, // Check for overflow. if (Overflow && Diags) // Too many digits to fit in Diag(Diags, Features, Loc, ThisTokBegin, EscapeBegin, ThisTokBuf, - diag::err_hex_escape_too_large); + diag::err_escape_too_large) << 0; break; } case '0': case '1': case '2': case '3': @@ -182,7 +182,7 @@ static unsigned ProcessCharEscape(const char *ThisTokBegin, if (CharWidth != 32 && (ResultChar >> CharWidth) != 0) { if (Diags) Diag(Diags, Features, Loc, ThisTokBegin, EscapeBegin, ThisTokBuf, - diag::err_octal_escape_too_large); + diag::err_escape_too_large) << 1; ResultChar &= ~0U >> (32-CharWidth); } break; @@ -538,7 +538,7 @@ NumericLiteralParser::NumericLiteralParser(StringRef TokSpelling, // Done. } else if (isHexDigit(*s) && !(*s == 'e' || *s == 'E')) { PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, s - ThisTokBegin), - diag::err_invalid_decimal_digit) << StringRef(s, 1); + diag::err_invalid_digit) << StringRef(s, 1) << 0; hadError = true; return; } else if (*s == '.') { @@ -766,7 +766,7 @@ void NumericLiteralParser::ParseNumberStartingWithZero(SourceLocation TokLoc) { if (noSignificand) { PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, s - ThisTokBegin), - diag::err_hexconstant_requires_digits); + diag::err_hexconstant_requires) << 1; hadError = true; return; } @@ -793,7 +793,7 @@ void NumericLiteralParser::ParseNumberStartingWithZero(SourceLocation TokLoc) { PP.Diag(TokLoc, diag::ext_hexconstant_invalid); } else if (saw_period) { PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, s-ThisTokBegin), - diag::err_hexconstant_requires_exponent); + diag::err_hexconstant_requires) << 0; hadError = true; } return; @@ -817,7 +817,7 @@ void NumericLiteralParser::ParseNumberStartingWithZero(SourceLocation TokLoc) { // Done. } else if (isHexDigit(*s)) { PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, s-ThisTokBegin), - diag::err_invalid_binary_digit) << StringRef(s, 1); + diag::err_invalid_digit) << StringRef(s, 1) << 2; hadError = true; } // Other suffixes will be diagnosed by the caller. @@ -847,7 +847,7 @@ void NumericLiteralParser::ParseNumberStartingWithZero(SourceLocation TokLoc) { // the code is using an incorrect base. if (isHexDigit(*s) && *s != 'e' && *s != 'E') { PP.Diag(PP.AdvanceToTokenCharacter(TokLoc, s-ThisTokBegin), - diag::err_invalid_octal_digit) << StringRef(s, 1); + diag::err_invalid_digit) << StringRef(s, 1) << 1; hadError = true; return; } diff --git a/lib/Lex/PPExpressions.cpp b/lib/Lex/PPExpressions.cpp index d2156d49cf..c40598c067 100644 --- a/lib/Lex/PPExpressions.cpp +++ b/lib/Lex/PPExpressions.cpp @@ -549,12 +549,12 @@ static bool EvaluateDirectiveSubExpr(PPValue &LHS, unsigned MinPrec, // value was negative, warn about it. if (ValueLive && Res.isUnsigned()) { if (!LHS.isUnsigned() && LHS.Val.isNegative()) - PP.Diag(OpLoc, diag::warn_pp_convert_lhs_to_positive) + PP.Diag(OpLoc, diag::warn_pp_convert_to_positive) << 0 << LHS.Val.toString(10, true) + " to " + LHS.Val.toString(10, false) << LHS.getRange() << RHS.getRange(); if (!RHS.isUnsigned() && RHS.Val.isNegative()) - PP.Diag(OpLoc, diag::warn_pp_convert_rhs_to_positive) + PP.Diag(OpLoc, diag::warn_pp_convert_to_positive) << 1 << RHS.Val.toString(10, true) + " to " + RHS.Val.toString(10, false) << LHS.getRange() << RHS.getRange(); diff --git a/test/Misc/warning-flags-enabled.c b/test/Misc/warning-flags-enabled.c index ba29e7ac51..b809465a0e 100644 --- a/test/Misc/warning-flags-enabled.c +++ b/test/Misc/warning-flags-enabled.c @@ -3,7 +3,7 @@ // This shows warnings which are on by default. // We just check a few to make sure it's doing something sensible. // -// CHECK: ext_unterminated_string +// CHECK: ext_unterminated_char_or_string // CHECK: warn_condition_is_assignment // CHECK: warn_null_arg diff --git a/test/Misc/warning-flags.c b/test/Misc/warning-flags.c index 5cc769faad..69e820542a 100644 --- a/test/Misc/warning-flags.c +++ b/test/Misc/warning-flags.c @@ -18,7 +18,7 @@ This test serves two purposes: The list of warnings below should NEVER grow. It should gradually shrink to 0. -CHECK: Warnings without flags (85): +CHECK: Warnings without flags (84): CHECK-NEXT: ext_excess_initializers CHECK-NEXT: ext_excess_initializers_in_char_array_initializer CHECK-NEXT: ext_expected_semi_decl_list @@ -84,8 +84,7 @@ CHECK-NEXT: warn_objc_property_copy_missing_on_block CHECK-NEXT: warn_objc_protocol_qualifier_missing_id CHECK-NEXT: warn_on_superclass_use CHECK-NEXT: warn_partial_specs_not_deducible -CHECK-NEXT: warn_pp_convert_lhs_to_positive -CHECK-NEXT: warn_pp_convert_rhs_to_positive +CHECK-NEXT: warn_pp_convert_to_positive CHECK-NEXT: warn_pp_expr_overflow CHECK-NEXT: warn_pp_line_decimal CHECK-NEXT: warn_pragma_pack_pop_identifer_and_alignment