mirror of https://github.com/microsoft/clang.git
[Sema] CheckTautologicalComparisonWithZero(): always complain about enums
Hopefully fixes test-clang-msc-x64-on-i686-linux-RA build. The underlying problem is that the enum is signed there. Yet still, it is invalid for it to contain negative values, so the comparison is always tautological in this case. No differential, but related to https://reviews.llvm.org/D37629 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@313747 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
c0bcf3b945
commit
2100b0595f
|
@ -8592,22 +8592,26 @@ bool CheckTautologicalComparisonWithZero(Sema &S, BinaryOperator *E) {
|
|||
|
||||
bool Match = true;
|
||||
|
||||
if (Op == BO_LT && isNonBooleanUnsignedValue(LHS) && IsZero(S, RHS)) {
|
||||
if (Op == BO_LT && IsZero(S, RHS) &&
|
||||
(isNonBooleanUnsignedValue(LHS) || HasEnumType(LHS))) {
|
||||
S.Diag(E->getOperatorLoc(),
|
||||
HasEnumType(LHS) ? diag::warn_lunsigned_enum_always_true_comparison
|
||||
: diag::warn_lunsigned_always_true_comparison)
|
||||
<< "< 0" << false << LHS->getSourceRange() << RHS->getSourceRange();
|
||||
} else if (Op == BO_GE && isNonBooleanUnsignedValue(LHS) && IsZero(S, RHS)) {
|
||||
} else if (Op == BO_GE && IsZero(S, RHS) &&
|
||||
(isNonBooleanUnsignedValue(LHS) || HasEnumType(LHS))) {
|
||||
S.Diag(E->getOperatorLoc(),
|
||||
HasEnumType(LHS) ? diag::warn_lunsigned_enum_always_true_comparison
|
||||
: diag::warn_lunsigned_always_true_comparison)
|
||||
<< ">= 0" << true << LHS->getSourceRange() << RHS->getSourceRange();
|
||||
} else if (Op == BO_GT && isNonBooleanUnsignedValue(RHS) && IsZero(S, LHS)) {
|
||||
} else if (Op == BO_GT && IsZero(S, LHS) &&
|
||||
(isNonBooleanUnsignedValue(RHS) || HasEnumType(RHS))) {
|
||||
S.Diag(E->getOperatorLoc(),
|
||||
HasEnumType(RHS) ? diag::warn_runsigned_enum_always_true_comparison
|
||||
: diag::warn_runsigned_always_true_comparison)
|
||||
<< "0 >" << false << LHS->getSourceRange() << RHS->getSourceRange();
|
||||
} else if (Op == BO_LE && isNonBooleanUnsignedValue(RHS) && IsZero(S, LHS)) {
|
||||
} else if (Op == BO_LE && IsZero(S, LHS) &&
|
||||
(isNonBooleanUnsignedValue(RHS) || HasEnumType(RHS))) {
|
||||
S.Diag(E->getOperatorLoc(),
|
||||
HasEnumType(RHS) ? diag::warn_runsigned_enum_always_true_comparison
|
||||
: diag::warn_runsigned_always_true_comparison)
|
||||
|
|
Loading…
Reference in New Issue