Use a single note diagnostic for all the precedent/parentheses warnings.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@165384 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
David Blaikie 2012-10-08 01:19:49 +00:00
Родитель 0bea86307e
Коммит 6b34c17699
3 изменённых файлов: 15 добавлений и 21 удалений

Просмотреть файл

@ -3834,16 +3834,14 @@ def warn_precedence_bitwise_rel : Warning<
InGroup<Parentheses>;
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<Parentheses>;
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<BitwiseOpParentheses>;
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<LogicalOpParentheses>;
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<ShiftOpParentheses>;
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">,

Просмотреть файл

@ -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<BinaryOperator>(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);
}

Просмотреть файл

@ -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