Higuoxing created this revision. Herald added a subscriber: cfe-commits. Higuoxing edited the summary of this revision.
Hi, As you see, to avoid some expression like assert(x || y && "some messages"); clang will skip all the parentheses check if the expression is in `macro`; and this rule is a little bit loose, if a function which takes boolean variables defined in `macros`, clang will not check parentheses for these functions; So, in this patch I add a string type checking, if and only if a function defined in macro and the RHS of boolean expression is a string, then skip the parentheses checking :) Thanks for reviewing :) Repository: rC Clang https://reviews.llvm.org/D47687 Files: lib/Sema/SemaExpr.cpp Index: lib/Sema/SemaExpr.cpp =================================================================== --- lib/Sema/SemaExpr.cpp +++ lib/Sema/SemaExpr.cpp @@ -12310,7 +12310,14 @@ // 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. */) { + StringLiteral* diagnoseRHSToBeString + = dyn_cast<StringLiteral>(RHSExpr->IgnoreImpCasts()); + if (Opc == BO_LOr && + !(OpLoc.isMacroID() && + diagnoseRHSToBeString) + /* Don't warn in macros, + if and only if RHS could be + evaluated as string */) { DiagnoseLogicalAndInLogicalOrLHS(Self, OpLoc, LHSExpr, RHSExpr); DiagnoseLogicalAndInLogicalOrRHS(Self, OpLoc, LHSExpr, RHSExpr); }
Index: lib/Sema/SemaExpr.cpp =================================================================== --- lib/Sema/SemaExpr.cpp +++ lib/Sema/SemaExpr.cpp @@ -12310,7 +12310,14 @@ // 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. */) { + StringLiteral* diagnoseRHSToBeString + = dyn_cast<StringLiteral>(RHSExpr->IgnoreImpCasts()); + if (Opc == BO_LOr && + !(OpLoc.isMacroID() && + diagnoseRHSToBeString) + /* Don't warn in macros, + if and only if RHS could be + evaluated as string */) { 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