diff options
author | Roman Lebedev <lebedev.ri@gmail.com> | 2017-09-20 10:15:27 +0000 |
---|---|---|
committer | Roman Lebedev <lebedev.ri@gmail.com> | 2017-09-20 10:15:27 +0000 |
commit | b513ebfc0f6ec2fa2fba7aa32ededf0e2e1e1e35 (patch) | |
tree | aebac9f0a7e056b830337eb5e2ec6f5f8f1693fb /clang/lib/Sema/SemaChecking.cpp | |
parent | cefe7e1142c082816dc3da743e4be45a2fdfe723 (diff) | |
download | bcm5719-llvm-b513ebfc0f6ec2fa2fba7aa32ededf0e2e1e1e35.tar.gz bcm5719-llvm-b513ebfc0f6ec2fa2fba7aa32ededf0e2e1e1e35.zip |
[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
llvm-svn: 313747
Diffstat (limited to 'clang/lib/Sema/SemaChecking.cpp')
-rw-r--r-- | clang/lib/Sema/SemaChecking.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 87634ad57e5..9ff8f6347e7 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -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) |