From: Chris Lattner Date: Mon, 13 Apr 2009 06:04:39 +0000 (+0000) Subject: fix rdar://6774906, a crash handling implicit conversions between pointers X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ecca7536488e425417dcb005c39cc15ae1947aab;p=clang fix rdar://6774906, a crash handling implicit conversions between pointers in different address spaces. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@68941 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h index 514c69e72c..62750087c0 100644 --- a/include/clang/AST/Type.h +++ b/include/clang/AST/Type.h @@ -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; } diff --git a/test/Sema/address_spaces.c b/test/Sema/address_spaces.c index 8f637268a4..b79799f023 100644 --- a/test/Sema/address_spaces.c +++ b/test/Sema/address_spaces.c @@ -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 *'}} +} +