]> granicus.if.org Git - clang/commitdiff
Use a single note diagnostic for all the precedent/parentheses warnings.
authorDavid Blaikie <dblaikie@gmail.com>
Mon, 8 Oct 2012 01:19:49 +0000 (01:19 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Mon, 8 Oct 2012 01:19:49 +0000 (01:19 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@165384 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaExpr.cpp
test/Sema/parentheses.c

index 3cc6d23de60a14b91a536f222a08816dac39a772..882c77d1d166aaef796c478a6091a213ffa90986 100644 (file)
@@ -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">,
index dcb3736bd7b5bf5243d227d5cfb188ccdc94719a..7c73c17df8bbdcc0b1b42bb4592392ac2869a9a6 100644 (file)
@@ -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);
   }
index 9751336018b7b184a15ade20f9ef405f9feb6978..c3b3aa77c5e669db0f28f23e329dcedd963cbe65 100644 (file)
@@ -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