[PATCH] D43829: [Sema] Add -Wparentheses warnings for macros (PR 18971)

2018-02-27 Thread Chijun Sima via Phabricator via cfe-commits
NutshellySima created this revision.
NutshellySima added a reviewer: rsmith.
Herald added a subscriber: cfe-commits.

Before, clang does not warn -Wlogical-op-parentheses and 
-Wbitwise-op-parentheses in macros, thus miss some cases like PR 18971 and 
mismatch gcc's behavior.

Fix this by enabling the warning even when the expression is in macros.

Patch by Chijun Sima.


Repository:
  rC Clang

https://reviews.llvm.org/D43829

Files:
  lib/Sema/SemaExpr.cpp


Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -12024,15 +12024,14 @@
 DiagnoseBitwisePrecedence(Self, Opc, OpLoc, LHSExpr, RHSExpr);
 
   // Diagnose "arg1 & arg2 | arg3"
-  if ((Opc == BO_Or || Opc == BO_Xor) &&
-  !OpLoc.isMacroID()/* Don't warn in macros. */) {
+  if (Opc == BO_Or || Opc == BO_Xor) {
 DiagnoseBitwiseOpInBitwiseOp(Self, Opc, OpLoc, LHSExpr);
 DiagnoseBitwiseOpInBitwiseOp(Self, Opc, OpLoc, RHSExpr);
   }
 
   // Warn about arg1 || arg2 && arg3, as GCC 4.3+ does.
   // We don't warn for 'assert(a || b && "bad")' since this is safe.
-  if (Opc == BO_LOr && !OpLoc.isMacroID()/* Don't warn in macros. */) {
+  if (Opc == BO_LOr) {
 DiagnoseLogicalAndInLogicalOrLHS(Self, OpLoc, LHSExpr, RHSExpr);
 DiagnoseLogicalAndInLogicalOrRHS(Self, OpLoc, LHSExpr, RHSExpr);
   }


Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -12024,15 +12024,14 @@
 DiagnoseBitwisePrecedence(Self, Opc, OpLoc, LHSExpr, RHSExpr);
 
   // Diagnose "arg1 & arg2 | arg3"
-  if ((Opc == BO_Or || Opc == BO_Xor) &&
-  !OpLoc.isMacroID()/* Don't warn in macros. */) {
+  if (Opc == BO_Or || Opc == BO_Xor) {
 DiagnoseBitwiseOpInBitwiseOp(Self, Opc, OpLoc, LHSExpr);
 DiagnoseBitwiseOpInBitwiseOp(Self, Opc, OpLoc, RHSExpr);
   }
 
   // Warn about arg1 || arg2 && arg3, as GCC 4.3+ does.
   // We don't warn for 'assert(a || b && "bad")' since this is safe.
-  if (Opc == BO_LOr && !OpLoc.isMacroID()/* Don't warn in macros. */) {
+  if (Opc == BO_LOr) {
 DiagnoseLogicalAndInLogicalOrLHS(Self, OpLoc, LHSExpr, RHSExpr);
 DiagnoseLogicalAndInLogicalOrRHS(Self, OpLoc, LHSExpr, RHSExpr);
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D43829: [Sema] Add -Wparentheses warnings for macros (PR 18971)

2018-02-27 Thread Chijun Sima via Phabricator via cfe-commits
NutshellySima added a comment.

In https://reviews.llvm.org/D43829#1020957, @lebedev.ri wrote:

> Tests?


Thanks for your advice, I'll add one.


Repository:
  rC Clang

https://reviews.llvm.org/D43829



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits