]> granicus.if.org Git - clang/commitdiff
Fix PR 5422: handle lvalue results when evaluating 'based' ptrtoints as part of
authorJohn McCall <rjmccall@apple.com>
Wed, 11 Nov 2009 22:52:37 +0000 (22:52 +0000)
committerJohn McCall <rjmccall@apple.com>
Wed, 11 Nov 2009 22:52:37 +0000 (22:52 +0000)
the -Wconversion check.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86891 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/Sema.cpp
test/Sema/conversion.c

index 5c92b65f82ce7c9e594adc8b701b938b7ea73642..f6f572feec0a985280b97ee771c219ce262a1d5e 100644 (file)
@@ -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;
 }
                                
 
index 0c7d86aa4a83c4c82679ec0c21282d6e4d877f3b..bca23f8f8df88d9948892995d46e8f94290b01af 100644 (file)
@@ -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}}
+}