[PATCH] D142609: [Clang] Fix -Wconstant-logical-operand when LHS is a constant
Shivam Gupta via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 3 07:41:53 PST 2023
xgupta added inline comments.
================
Comment at: clang/lib/Sema/SemaExpr.cpp:13611-13653
if (RHS.get()->EvaluateAsInt(EVResult, Context)) {
llvm::APSInt Result = EVResult.Val.getInt();
if ((getLangOpts().Bool && !RHS.get()->getType()->isBooleanType() &&
!RHS.get()->getExprLoc().isMacroID()) ||
(Result != 0 && Result != 1)) {
Diag(Loc, diag::warn_logical_instead_of_bitwise)
<< RHS.get()->getSourceRange() << (Opc == BO_LAnd ? "&&" : "||");
----------------
nickdesaulniers wrote:
> There seems to be a lot of duplication between the two; should we move these into a static function that's called twice? Perhaps Op1 and Op2 would be better identifiers than LHS RHS in that case?
I have tried many ways, but couldn't figure out a way to do it with function, unrelated test cases started failing.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D142609/new/
https://reviews.llvm.org/D142609
More information about the cfe-commits
mailing list