aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaChecking.cpp
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2012-09-20 19:36:41 +0000
committerFariborz Jahanian <fjahanian@apple.com>2012-09-20 19:36:41 +0000
commita193f20916f0e0e5a3b0f76ca69e2b3870c1a325 (patch)
tree93887348fb543588101aab4a48df867918d0a8bc /lib/Sema/SemaChecking.cpp
parentd4a282be92ee55a0b392e45ce4582231af271d27 (diff)
Improvements to my patch in r164143 per
Richard's comments. // rdar://12202422 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@164316 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaChecking.cpp')
-rw-r--r--lib/Sema/SemaChecking.cpp34
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