From: John McCall Date: Sat, 26 Mar 2011 02:56:45 +0000 (+0000) Subject: Allow GC qualifiers to be added/removed by conversions from/to void* X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2234873111009eb8655d63362cedc422eb9fc517;p=clang Allow GC qualifiers to be added/removed by conversions from/to void* without a warning. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@128328 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/Type.h b/include/clang/AST/Type.h index 963f4b5543..6e8fd4da0d 100644 --- a/include/clang/AST/Type.h +++ b/include/clang/AST/Type.h @@ -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; } diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index c2f3a434b8..dbddc38451 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -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; diff --git a/test/SemaObjC/attr-objc-gc.m b/test/SemaObjC/attr-objc-gc.m index a826317415..9ca12c9315 100644 --- a/test/SemaObjC/attr-objc-gc.m +++ b/test/SemaObjC/attr-objc-gc.m @@ -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; +}