Skip to content

Commit

Permalink
Fixing a formatting mistake; NFC
Browse files Browse the repository at this point in the history
There was a brace that was hanging out in the middle of nowhere, this
fixes that issue.
  • Loading branch information
AaronBallman committed Aug 3, 2023
1 parent 43ad521 commit 9f72df7
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions clang/lib/Sema/SemaExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13890,44 +13890,44 @@ void Sema::diagnoseLogicalInsteadOfBitwise(Expr *Op1, Expr *Op2,
Op2->getType()->isIntegerType() && !Op2->isValueDependent() &&
// Don't warn in macros or template instantiations.
!Loc.isMacroID() && !inTemplateInstantiation() &&
!Op2->getExprLoc().isMacroID() &&
!Op1->getExprLoc().isMacroID()) {
!Op2->getExprLoc().isMacroID() && !Op1->getExprLoc().isMacroID()) {
bool IsOp1InMacro = Op1->getExprLoc().isMacroID();
bool IsOp2InMacro = Op2->getExprLoc().isMacroID();

// Exclude the specific expression from triggering the warning.
if (!(IsOp1InMacro && IsOp2InMacro && Op1->getSourceRange() == Op2->getSourceRange())) {
// If the RHS can be constant folded, and if it constant folds to something
// that isn't 0 or 1 (which indicate a potential logical operation that
// happened to fold to true/false) then warn.
// Parens on the RHS are ignored.
// If the RHS can be constant folded, and if it constant folds to something
// that isn't 0 or 1 (which indicate a potential logical operation that
// happened to fold to true/false) then warn.
// Parens on the RHS are ignored.
Expr::EvalResult EVResult;
if (Op2->EvaluateAsInt(EVResult, Context)) {
llvm::APSInt Result = EVResult.Val.getInt();
if ((getLangOpts().Bool && !Op2->getType()->isBooleanType() &&
!Op2->getExprLoc().isMacroID()) ||
(Result != 0 && Result != 1)) {
Diag(Loc, diag::warn_logical_instead_of_bitwise)
<< Op2->getSourceRange() << (Opc == BO_LAnd ? "&&" : "||");
// Suggest replacing the logical operator with the bitwise version
Diag(Loc, diag::note_logical_instead_of_bitwise_change_operator)
<< (Opc == BO_LAnd ? "&" : "|")
<< FixItHint::CreateReplacement(
SourceRange(Loc, getLocForEndOfToken(Loc)),
Opc == BO_LAnd ? "&" : "|");
if (Opc == BO_LAnd)
// Suggest replacing "Foo() && kNonZero" with "Foo()"
Diag(Loc, diag::note_logical_instead_of_bitwise_remove_constant)
<< FixItHint::CreateRemoval(SourceRange(
getLocForEndOfToken(Op1->getEndLoc()), Op2->getEndLoc()));
if (!(IsOp1InMacro && IsOp2InMacro &&
Op1->getSourceRange() == Op2->getSourceRange())) {
// If the RHS can be constant folded, and if it constant folds to
// something that isn't 0 or 1 (which indicate a potential logical
// operation that happened to fold to true/false) then warn. Parens on the
// RHS are ignored. If the RHS can be constant folded, and if it constant
// folds to something that isn't 0 or 1 (which indicate a potential
// logical operation that happened to fold to true/false) then warn.
// Parens on the RHS are ignored.
Expr::EvalResult EVResult;
if (Op2->EvaluateAsInt(EVResult, Context)) {
llvm::APSInt Result = EVResult.Val.getInt();
if ((getLangOpts().Bool && !Op2->getType()->isBooleanType() &&
!Op2->getExprLoc().isMacroID()) ||
(Result != 0 && Result != 1)) {
Diag(Loc, diag::warn_logical_instead_of_bitwise)
<< Op2->getSourceRange() << (Opc == BO_LAnd ? "&&" : "||");
// Suggest replacing the logical operator with the bitwise version
Diag(Loc, diag::note_logical_instead_of_bitwise_change_operator)
<< (Opc == BO_LAnd ? "&" : "|")
<< FixItHint::CreateReplacement(
SourceRange(Loc, getLocForEndOfToken(Loc)),
Opc == BO_LAnd ? "&" : "|");
if (Opc == BO_LAnd)
// Suggest replacing "Foo() && kNonZero" with "Foo()"
Diag(Loc, diag::note_logical_instead_of_bitwise_remove_constant)
<< FixItHint::CreateRemoval(
SourceRange(getLocForEndOfToken(Op1->getEndLoc()),
Op2->getEndLoc()));
}
}
}
}
}
}

// C99 6.5.[13,14]
Expand Down

0 comments on commit 9f72df7

Please sign in to comment.