]> granicus.if.org Git - clang/commitdiff
fix rdar://6774906, a crash handling implicit conversions between pointers
authorChris Lattner <sabre@nondot.org>
Mon, 13 Apr 2009 06:04:39 +0000 (06:04 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 13 Apr 2009 06:04:39 +0000 (06:04 +0000)
in different address spaces.

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

include/clang/AST/Type.h
test/Sema/address_spaces.c

index 514c69e72c37946bf59cb528de29bea042eb2b7c..62750087c0673f58a4afbe3707204b11fde733bb 100644 (file)
@@ -1956,11 +1956,10 @@ inline QualType::GCAttrTypes QualType::getObjCGCAttr() const {
 /// "int". However, it is not more qualified than "const volatile
 /// int".
 inline bool QualType::isMoreQualifiedThan(QualType Other) const {
-  // FIXME: Handle address spaces
   unsigned MyQuals = this->getCVRQualifiers();
   unsigned OtherQuals = Other.getCVRQualifiers();
-  assert(this->getAddressSpace() == 0 && "Address space not checked");
-  assert(Other.getAddressSpace() == 0 && "Address space not checked");
+  if (getAddressSpace() != Other.getAddressSpace())
+    return false;
   return MyQuals != OtherQuals && (MyQuals | OtherQuals) == MyQuals;
 }
 
@@ -1969,11 +1968,10 @@ inline bool QualType::isMoreQualifiedThan(QualType Other) const {
 /// int" is at least as qualified as "const int", "volatile int",
 /// "int", and "const volatile int".
 inline bool QualType::isAtLeastAsQualifiedAs(QualType Other) const {
-  // FIXME: Handle address spaces
   unsigned MyQuals = this->getCVRQualifiers();
   unsigned OtherQuals = Other.getCVRQualifiers();
-  assert(this->getAddressSpace() == 0 && "Address space not checked");
-  assert(Other.getAddressSpace() == 0 && "Address space not checked");
+  if (getAddressSpace() != Other.getAddressSpace())
+    return false;
   return (MyQuals | OtherQuals) == MyQuals;
 }
 
index 8f637268a4e9109e9e1fe1b9959613dbeca8407a..b79799f0230c4c3fe9400ad68d86313d5bacb389 100644 (file)
@@ -22,3 +22,11 @@ struct _st {
  int x, y;
 } s __attribute ((address_space(1))) = {1, 1};
 
+
+// rdar://6774906
+__attribute__((address_space(256))) void * * const base = 0;
+void * get_0(void) {
+  return base[0];  // expected-error {{illegal implicit cast between two pointers with different address spaces}} \
+                      expected-warning {{returning 'void __attribute__((address_space(256)))*' discards qualifiers, expected 'void *'}}
+}
+