Allow GC qualifiers to be added/removed by conversions from/to void*

without a warning.

llvm-svn: 128328
This commit is contained in:
John McCall 2011-03-26 02:56:45 +00:00
parent 9a624fa993
commit 7853595253
3 changed files with 22 additions and 0 deletions

View File

@ -213,6 +213,11 @@ public:
assert(type);
setObjCGCAttr(type);
}
Qualifiers withoutObjCGCAttr() const {
Qualifiers qs = *this;
qs.removeObjCGCAttr();
return qs;
}
bool hasAddressSpace() const { return Mask & AddressSpaceMask; }
unsigned getAddressSpace() const { return Mask >> AddressSpaceShift; }

View File

@ -5803,6 +5803,12 @@ checkPointerTypesForAssignment(Sema &S, QualType lhsType, QualType rhsType) {
if (lhq.getAddressSpace() != rhq.getAddressSpace())
ConvTy = Sema::IncompatiblePointerDiscardsQualifiers;
// It's okay to add or remove GC qualifiers when converting to
// and from void*.
else if (lhq.withoutObjCGCAttr().compatiblyIncludes(rhq.withoutObjCGCAttr())
&& (lhptee->isVoidType() || rhptee->isVoidType()))
; // keep old
// For GCC compatibility, other qualifier mismatches are treated
// as still compatible in C.
else ConvTy = Sema::CompatiblePointerDiscardsQualifiers;

View File

@ -17,3 +17,14 @@ static WEAK int h; // expected-warning {{'objc_gc' only applies to pointer types
/* expected-warning {{'__weak' only applies to pointer types; type here is 'int'}}*/ static __we\
ak int i;
// rdar://problem/9126213
void test2(id __attribute((objc_gc(strong))) *strong,
id __attribute((objc_gc(weak))) *weak) {
void *opaque;
opaque = strong;
strong = opaque;
opaque = weak;
weak = opaque;
}