[cfe-commits] r92866 - in /cfe/trunk: lib/Sema/SemaChecking.cpp test/Sema/compare.c
John McCall
rjmccall at apple.com
Wed Jan 6 14:57:21 PST 2010
Author: rjmccall
Date: Wed Jan 6 16:57:21 2010
New Revision: 92866
URL: http://llvm.org/viewvc/llvm-project?rev=92866&view=rev
Log:
Don't assert when dealing with unsigned casts of lvalues. Fixes PR5961.
Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/Sema/compare.c
Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=92866&r1=92865&r2=92866&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Wed Jan 6 16:57:21 2010
@@ -1629,15 +1629,17 @@
return IntRange(value.getActiveBits(), true);
}
-IntRange GetValueRange(ASTContext &C, APValue &result,
+IntRange GetValueRange(ASTContext &C, APValue &result, QualType Ty,
unsigned MaxWidth) {
if (result.isInt())
return GetValueRange(C, result.getInt(), MaxWidth);
if (result.isVector()) {
- IntRange R = GetValueRange(C, result.getVectorElt(0), MaxWidth);
- for (unsigned i = 1, e = result.getVectorLength(); i != e; ++i)
- R = IntRange::join(R, GetValueRange(C, result.getVectorElt(i), MaxWidth));
+ IntRange R = GetValueRange(C, result.getVectorElt(0), Ty, MaxWidth);
+ for (unsigned i = 1, e = result.getVectorLength(); i != e; ++i) {
+ IntRange El = GetValueRange(C, result.getVectorElt(i), Ty, MaxWidth);
+ R = IntRange::join(R, El);
+ }
return R;
}
@@ -1649,8 +1651,11 @@
// This can happen with lossless casts to intptr_t of "based" lvalues.
// Assume it might use arbitrary bits.
+ // FIXME: The only reason we need to pass the type in here is to get
+ // the sign right on this one case. It would be nice if APValue
+ // preserved this.
assert(result.isLValue());
- return IntRange(MaxWidth, false);
+ return IntRange(MaxWidth, Ty->isUnsignedIntegerType());
}
/// Pseudo-evaluate the given integer expression, estimating the
@@ -1663,7 +1668,7 @@
// Try a full evaluation first.
Expr::EvalResult result;
if (E->Evaluate(result, C))
- return GetValueRange(C, result.Val, MaxWidth);
+ return GetValueRange(C, result.Val, E->getType(), MaxWidth);
// I think we only want to look through implicit casts here; if the
// user has an explicit widening cast, we should treat the value as
Modified: cfe/trunk/test/Sema/compare.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/compare.c?rev=92866&r1=92865&r2=92866&view=diff
==============================================================================
--- cfe/trunk/test/Sema/compare.c (original)
+++ cfe/trunk/test/Sema/compare.c Wed Jan 6 16:57:21 2010
@@ -266,3 +266,11 @@
if ((x > y ? x : y) > z)
(void) 0;
}
+
+// PR5961
+extern char *ptr4;
+void test4() {
+ long value;
+ if (value < (unsigned long) &ptr4) // expected-warning {{comparison of integers of different signs}}
+ return;
+}
More information about the cfe-commits
mailing list