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

Chijun Sima via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 27 11:06:00 PST 2018


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);
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43829.136107.patch
Type: text/x-patch
Size: 919 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180227/f875e96f/attachment.bin>


More information about the cfe-commits mailing list