On Wed, Sep 20, 2017 at 6:15 AM, Roman Lebedev via cfe-commits <cfe-commits@lists.llvm.org> wrote: > Author: lebedevri > Date: Wed Sep 20 03:15:27 2017 > New Revision: 313747 > > URL: http://llvm.org/viewvc/llvm-project?rev=313747&view=rev > Log: > [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.
Why is it invalid for the comparand to contain a negative value when the enum type is signed? ~Aaron > > No differential, but related to https://reviews.llvm.org/D37629 > > Modified: > cfe/trunk/lib/Sema/SemaChecking.cpp > > Modified: cfe/trunk/lib/Sema/SemaChecking.cpp > URL: > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=313747&r1=313746&r2=313747&view=diff > ============================================================================== > --- cfe/trunk/lib/Sema/SemaChecking.cpp (original) > +++ cfe/trunk/lib/Sema/SemaChecking.cpp Wed Sep 20 03:15:27 2017 > @@ -8592,22 +8592,26 @@ bool CheckTautologicalComparisonWithZero > > 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) > > > _______________________________________________ > cfe-commits mailing list > cfe-commits@lists.llvm.org > http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits