From dac86fd24c563640486b46ab73ea1d809f73b177 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Mon, 8 Oct 2012 01:19:49 +0000 Subject: [PATCH] Use a single note diagnostic for all the precedent/parentheses warnings. llvm-svn: 165384 --- .../include/clang/Basic/DiagnosticSemaKinds.td | 12 ++---------- clang/lib/Sema/SemaExpr.cpp | 18 ++++++++++-------- clang/test/Sema/parentheses.c | 6 +++--- 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 3cc6d23de60a..882c77d1d166 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3834,16 +3834,14 @@ def warn_precedence_bitwise_rel : Warning< InGroup; def note_precedence_bitwise_first : Note< "place parentheses around the %0 expression to evaluate it first">; -def note_precedence_bitwise_silence : Note< - "place parentheses around the %0 expression to silence this warning">; +def note_precedence_silence : Note< + "place parentheses around the '%0' expression to silence this warning">; def warn_precedence_conditional : Warning< "operator '?:' has lower precedence than '%0'; '%0' will be evaluated first">, InGroup; def note_precedence_conditional_first : Note< "place parentheses around the '?:' expression to evaluate it first">; -def note_precedence_conditional_silence : Note< - "place parentheses around the '%0' expression to silence this warning">; def warn_logical_instead_of_bitwise : Warning< "use of logical '%0' with constant operand">, @@ -3855,18 +3853,12 @@ def note_logical_instead_of_bitwise_remove_constant : Note< def warn_bitwise_and_in_bitwise_or : Warning< "'&' within '|'">, InGroup; -def note_bitwise_and_in_bitwise_or_silence : Note< - "place parentheses around the '&' expression to silence this warning">; def warn_logical_and_in_logical_or : Warning< "'&&' within '||'">, InGroup; -def note_logical_and_in_logical_or_silence : Note< - "place parentheses around the '&&' expression to silence this warning">; def warn_addition_in_bitshift : Warning< "'%0' within '%1'">, InGroup; -def note_addition_in_bitshift_silence : Note< - "place parentheses around the '%0' expression to silence this warning">; def warn_self_assignment : Warning< "explicitly assigning a variable of type %0 to itself">, diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index dcb3736bd7b5..7c73c17df8bb 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -5304,7 +5304,7 @@ static void DiagnoseConditionalPrecedence(Sema &Self, << BinaryOperator::getOpcodeStr(CondOpcode); SuggestParentheses(Self, OpLoc, - Self.PDiag(diag::note_precedence_conditional_silence) + Self.PDiag(diag::note_precedence_silence) << BinaryOperator::getOpcodeStr(CondOpcode), SourceRange(Condition->getLocStart(), Condition->getLocEnd())); @@ -8475,7 +8475,7 @@ static void DiagnoseBitwisePrecedence(Sema &Self, BinaryOperatorKind Opc, Self.Diag(OpLoc, diag::warn_precedence_bitwise_rel) << DiagRange << BinOp::getOpcodeStr(Opc) << OpStr; SuggestParentheses(Self, OpLoc, - Self.PDiag(diag::note_precedence_bitwise_silence) << OpStr, + Self.PDiag(diag::note_precedence_silence) << OpStr, (isLeftComp ? LHSExpr : RHSExpr)->getSourceRange()); SuggestParentheses(Self, OpLoc, Self.PDiag(diag::note_precedence_bitwise_first) << BinOp::getOpcodeStr(Opc), @@ -8492,7 +8492,8 @@ EmitDiagnosticForBitwiseAndInBitwiseOr(Sema &Self, SourceLocation OpLoc, Self.Diag(Bop->getOperatorLoc(), diag::warn_bitwise_and_in_bitwise_or) << Bop->getSourceRange() << OpLoc; SuggestParentheses(Self, Bop->getOperatorLoc(), - Self.PDiag(diag::note_bitwise_and_in_bitwise_or_silence), + Self.PDiag(diag::note_precedence_silence) + << Bop->getOpcodeStr(), Bop->getSourceRange()); } @@ -8506,7 +8507,8 @@ EmitDiagnosticForLogicalAndInLogicalOr(Sema &Self, SourceLocation OpLoc, Self.Diag(Bop->getOperatorLoc(), diag::warn_logical_and_in_logical_or) << Bop->getSourceRange() << OpLoc; SuggestParentheses(Self, Bop->getOperatorLoc(), - Self.PDiag(diag::note_logical_and_in_logical_or_silence), + Self.PDiag(diag::note_precedence_silence) + << Bop->getOpcodeStr(), Bop->getSourceRange()); } @@ -8574,11 +8576,11 @@ static void DiagnoseAdditionInShift(Sema &S, SourceLocation OpLoc, Expr *SubExpr, StringRef shift) { if (BinaryOperator *Bop = dyn_cast(SubExpr)) { if (Bop->getOpcode() == BO_Add || Bop->getOpcode() == BO_Sub) { - StringRef op = Bop->getOpcode() == BO_Add ? "+" : "-"; + StringRef Op = Bop->getOpcodeStr(); S.Diag(Bop->getOperatorLoc(), diag::warn_addition_in_bitshift) - << Bop->getSourceRange() << OpLoc << op << shift; + << Bop->getSourceRange() << OpLoc << Op << shift; SuggestParentheses(S, Bop->getOperatorLoc(), - S.PDiag(diag::note_addition_in_bitshift_silence) << op, + S.PDiag(diag::note_precedence_silence) << Op, Bop->getSourceRange()); } } @@ -8608,7 +8610,7 @@ static void DiagnoseBinOpPrecedence(Sema &Self, BinaryOperatorKind Opc, if ((Opc == BO_Shl && LHSExpr->getType()->isIntegralType(Self.getASTContext())) || Opc == BO_Shr) { - StringRef shift = Opc == BO_Shl ? "<<" : ">>"; + StringRef shift = BinaryOperator::getOpcodeStr(Opc); DiagnoseAdditionInShift(Self, OpLoc, LHSExpr, shift); DiagnoseAdditionInShift(Self, OpLoc, RHSExpr, shift); } diff --git a/clang/test/Sema/parentheses.c b/clang/test/Sema/parentheses.c index 9751336018b7..c3b3aa77c5e6 100644 --- a/clang/test/Sema/parentheses.c +++ b/clang/test/Sema/parentheses.c @@ -13,13 +13,13 @@ void if_assign(void) { void bitwise_rel(unsigned i) { (void)(i & 0x2 == 0); // expected-warning {{& has lower precedence than ==}} \ // expected-note{{place parentheses around the & expression to evaluate it first}} \ - // expected-note{{place parentheses around the == expression to silence this warning}} + // expected-note{{place parentheses around the '==' expression to silence this warning}} (void)(0 == i & 0x2); // expected-warning {{& has lower precedence than ==}} \ // expected-note{{place parentheses around the & expression to evaluate it first}} \ - // expected-note{{place parentheses around the == expression to silence this warning}} + // expected-note{{place parentheses around the '==' expression to silence this warning}} (void)(i & 0xff < 30); // expected-warning {{& has lower precedence than <}} \ // expected-note{{place parentheses around the & expression to evaluate it first}} \ - // expected-note{{place parentheses around the < expression to silence this warning}} + // expected-note{{place parentheses around the '<' expression to silence this warning}} (void)((i & 0x2) == 0); (void)(i & (0x2 == 0)); // Eager logical op