@@ -13890,44 +13890,44 @@ void Sema::diagnoseLogicalInsteadOfBitwise(Expr *Op1, Expr *Op2,
13890
13890
Op2->getType()->isIntegerType() && !Op2->isValueDependent() &&
13891
13891
// Don't warn in macros or template instantiations.
13892
13892
!Loc.isMacroID() && !inTemplateInstantiation() &&
13893
- !Op2->getExprLoc().isMacroID() &&
13894
- !Op1->getExprLoc().isMacroID()) {
13893
+ !Op2->getExprLoc().isMacroID() && !Op1->getExprLoc().isMacroID()) {
13895
13894
bool IsOp1InMacro = Op1->getExprLoc().isMacroID();
13896
13895
bool IsOp2InMacro = Op2->getExprLoc().isMacroID();
13897
13896
13898
13897
// Exclude the specific expression from triggering the warning.
13899
- if (!(IsOp1InMacro && IsOp2InMacro && Op1->getSourceRange() == Op2->getSourceRange())) {
13900
- // If the RHS can be constant folded, and if it constant folds to something
13901
- // that isn't 0 or 1 (which indicate a potential logical operation that
13902
- // happened to fold to true/false) then warn.
13903
- // Parens on the RHS are ignored.
13904
- // If the RHS can be constant folded, and if it constant folds to something
13905
- // that isn't 0 or 1 (which indicate a potential logical operation that
13906
- // happened to fold to true/false) then warn.
13907
- // Parens on the RHS are ignored.
13908
- Expr::EvalResult EVResult;
13909
- if (Op2->EvaluateAsInt(EVResult, Context)) {
13910
- llvm::APSInt Result = EVResult.Val.getInt();
13911
- if ((getLangOpts().Bool && !Op2->getType()->isBooleanType() &&
13912
- !Op2->getExprLoc().isMacroID()) ||
13913
- (Result != 0 && Result != 1)) {
13914
- Diag(Loc, diag::warn_logical_instead_of_bitwise)
13915
- << Op2->getSourceRange() << (Opc == BO_LAnd ? "&&" : "||");
13916
- // Suggest replacing the logical operator with the bitwise version
13917
- Diag(Loc, diag::note_logical_instead_of_bitwise_change_operator)
13918
- << (Opc == BO_LAnd ? "&" : "|")
13919
- << FixItHint::CreateReplacement(
13920
- SourceRange(Loc, getLocForEndOfToken(Loc)),
13921
- Opc == BO_LAnd ? "&" : "|");
13922
- if (Opc == BO_LAnd)
13923
- // Suggest replacing "Foo() && kNonZero" with "Foo()"
13924
- Diag(Loc, diag::note_logical_instead_of_bitwise_remove_constant)
13925
- << FixItHint::CreateRemoval(SourceRange(
13926
- getLocForEndOfToken(Op1->getEndLoc()), Op2->getEndLoc()));
13898
+ if (!(IsOp1InMacro && IsOp2InMacro &&
13899
+ Op1->getSourceRange() == Op2->getSourceRange())) {
13900
+ // If the RHS can be constant folded, and if it constant folds to
13901
+ // something that isn't 0 or 1 (which indicate a potential logical
13902
+ // operation that happened to fold to true/false) then warn. Parens on the
13903
+ // RHS are ignored. If the RHS can be constant folded, and if it constant
13904
+ // folds to something that isn't 0 or 1 (which indicate a potential
13905
+ // logical operation that happened to fold to true/false) then warn.
13906
+ // Parens on the RHS are ignored.
13907
+ Expr::EvalResult EVResult;
13908
+ if (Op2->EvaluateAsInt(EVResult, Context)) {
13909
+ llvm::APSInt Result = EVResult.Val.getInt();
13910
+ if ((getLangOpts().Bool && !Op2->getType()->isBooleanType() &&
13911
+ !Op2->getExprLoc().isMacroID()) ||
13912
+ (Result != 0 && Result != 1)) {
13913
+ Diag(Loc, diag::warn_logical_instead_of_bitwise)
13914
+ << Op2->getSourceRange() << (Opc == BO_LAnd ? "&&" : "||");
13915
+ // Suggest replacing the logical operator with the bitwise version
13916
+ Diag(Loc, diag::note_logical_instead_of_bitwise_change_operator)
13917
+ << (Opc == BO_LAnd ? "&" : "|")
13918
+ << FixItHint::CreateReplacement(
13919
+ SourceRange(Loc, getLocForEndOfToken(Loc)),
13920
+ Opc == BO_LAnd ? "&" : "|");
13921
+ if (Opc == BO_LAnd)
13922
+ // Suggest replacing "Foo() && kNonZero" with "Foo()"
13923
+ Diag(Loc, diag::note_logical_instead_of_bitwise_remove_constant)
13924
+ << FixItHint::CreateRemoval(
13925
+ SourceRange(getLocForEndOfToken(Op1->getEndLoc()),
13926
+ Op2->getEndLoc()));
13927
+ }
13927
13928
}
13928
13929
}
13929
13930
}
13930
- }
13931
13931
}
13932
13932
13933
13933
// C99 6.5.[13,14]
0 commit comments