diff options
Diffstat (limited to 'lib/Sema/SemaChecking.cpp')
-rw-r--r-- | lib/Sema/SemaChecking.cpp | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index 77058acc57..e85024fc55 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -4302,41 +4302,40 @@ static void CheckTrivialUnsignedComparison(Sema &S, BinaryOperator *E) { } static void DiagnoseOutOfRangeComparison(Sema &S, BinaryOperator *E, - Expr *lit, Expr *other, + Expr *Constant, Expr *Other, llvm::APSInt Value, - bool rhsLiteral) { + bool RhsConstant) { BinaryOperatorKind op = E->getOpcode(); - QualType OtherT = other->getType(); - const Type *OtherPtrT = S.Context.getCanonicalType(OtherT).getTypePtr(); - const Type *LitPtrT = S.Context.getCanonicalType(lit->getType()).getTypePtr(); - if (OtherPtrT == LitPtrT) + QualType OtherT = Other->getType(); + QualType ConstantT = Constant->getType(); + if (S.Context.hasSameUnqualifiedType(OtherT, ConstantT)) return; - assert((OtherT->isIntegerType() && LitPtrT->isIntegerType()) + assert((OtherT->isIntegerType() && ConstantT->isIntegerType()) && "comparison with non-integer type"); + // FIXME. handle cases for signedness to catch (signed char)N == 200 IntRange OtherRange = IntRange::forValueOfType(S.Context, OtherT); - IntRange LitRange = GetExprRange(S.Context, lit); + IntRange LitRange = GetValueRange(S.Context, Value, Value.getBitWidth()); if (OtherRange.Width >= LitRange.Width) return; - std::string PrettySourceValue = Value.toString(10); bool IsTrue = true; if (op == BO_EQ) IsTrue = false; else if (op == BO_NE) IsTrue = true; - else if (rhsLiteral) { + else if (RhsConstant) { if (op == BO_GT || op == BO_GE) IsTrue = !LitRange.NonNegative; else // op == BO_LT || op == BO_LE IsTrue = LitRange.NonNegative; - } - else { + } else { if (op == BO_LT || op == BO_LE) IsTrue = !LitRange.NonNegative; else // op == BO_GT || op == BO_GE IsTrue = LitRange.NonNegative; } - S.Diag(E->getOperatorLoc(), diag::warn_outof_range_compare) - << PrettySourceValue << other->getType() << IsTrue + SmallString<16> PrettySourceValue(Value.toString(10)); + S.Diag(E->getOperatorLoc(), diag::warn_out_of_range_compare) + << PrettySourceValue << OtherT << IsTrue << E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange(); } @@ -4363,7 +4362,7 @@ static void AnalyzeComparison(Sema &S, BinaryOperator *E) { bool IsComparisonConstant = false; - // Check that an integer constant comparison results in a value + // Check whether an integer constant comparison results in a value // of 'true' or 'false'. if (T->isIntegralType(S.Context)) { llvm::APSInt RHSValue; @@ -4379,9 +4378,8 @@ static void AnalyzeComparison(Sema &S, BinaryOperator *E) { else IsComparisonConstant = (IsRHSIntegralLiteral && IsLHSIntegralLiteral); - } - else if (!T->hasUnsignedIntegerRepresentation()) - IsComparisonConstant = E->isIntegerConstantExpr(S.Context); + } else if (!T->hasUnsignedIntegerRepresentation()) + IsComparisonConstant = E->isIntegerConstantExpr(S.Context); // We don't do anything special if this isn't an unsigned integral // comparison: we're only interested in integral comparisons, and |