aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/Sema/Sema.cpp12
-rw-r--r--test/Sema/conversion.c6
2 files changed, 15 insertions, 3 deletions
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp
index 5c92b65f82..f6f572feec 100644
--- a/lib/Sema/Sema.cpp
+++ b/lib/Sema/Sema.cpp
@@ -424,9 +424,15 @@ static bool IsSameIntAfterCast(const APValue &value, unsigned TargetWidth) {
return true;
}
- assert(value.isComplexInt());
- return IsSameIntAfterCast(value.getComplexIntReal(), TargetWidth) &&
- IsSameIntAfterCast(value.getComplexIntImag(), TargetWidth);
+ if (value.isComplexInt()) {
+ return IsSameIntAfterCast(value.getComplexIntReal(), TargetWidth) &&
+ IsSameIntAfterCast(value.getComplexIntImag(), TargetWidth);
+ }
+
+ // This can happen with lossless casts to intptr_t of "based" lvalues.
+ // Assume it might use arbitrary bits.
+ assert(value.isLValue());
+ return false;
}
diff --git a/test/Sema/conversion.c b/test/Sema/conversion.c
index 0c7d86aa4a..bca23f8f8d 100644
--- a/test/Sema/conversion.c
+++ b/test/Sema/conversion.c
@@ -229,3 +229,9 @@ void test15(char c) {
c = c + 1 + c * 2;
c = (short) c + 1 + c * 2; // expected-warning {{implicit cast loses integer precision}}
}
+
+// PR 5422
+extern void *test16_external;
+void test16(void) {
+ int a = (unsigned long) &test16_external; // expected-warning {{implicit cast loses integer precision}}
+}