From: John McCall Date: Wed, 12 Jan 2011 00:34:59 +0000 (+0000) Subject: Slight bugfix to the attribute-distribution logic for GC attributes. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ae278a3a57595349a411f6474938d4dd1b263a0e;p=clang Slight bugfix to the attribute-distribution logic for GC attributes. Slight optimization of getObjCGCAttrKind. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@123295 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/AST/ASTContext.h b/include/clang/AST/ASTContext.h index 0abdbb05a5..e497354684 100644 --- a/include/clang/AST/ASTContext.h +++ b/include/clang/AST/ASTContext.h @@ -945,7 +945,7 @@ public: /// getObjCGCAttr - Returns one of GCNone, Weak or Strong objc's /// garbage collection attribute. /// - Qualifiers::GC getObjCGCAttrKind(const QualType &Ty) const; + Qualifiers::GC getObjCGCAttrKind(QualType Ty) const; /// areCompatibleVectorTypes - Return true if the given vector types /// are of the same unqualified type or if they are equivalent to the same diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index e76238cb22..a64d149d80 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -4339,24 +4339,30 @@ bool ASTContext::isObjCNSObjectType(QualType Ty) const { /// getObjCGCAttr - Returns one of GCNone, Weak or Strong objc's /// garbage collection attribute. /// -Qualifiers::GC ASTContext::getObjCGCAttrKind(const QualType &Ty) const { - Qualifiers::GC GCAttrs = Qualifiers::GCNone; - if (getLangOptions().ObjC1 && - getLangOptions().getGCMode() != LangOptions::NonGC) { - GCAttrs = Ty.getObjCGCAttr(); - // Default behavious under objective-c's gc is for objective-c pointers - // (or pointers to them) be treated as though they were declared - // as __strong. - if (GCAttrs == Qualifiers::GCNone) { - if (Ty->isObjCObjectPointerType() || Ty->isBlockPointerType()) - GCAttrs = Qualifiers::Strong; - else if (Ty->isPointerType()) - return getObjCGCAttrKind(Ty->getAs()->getPointeeType()); - } - // Non-pointers have none gc'able attribute regardless of the attribute - // set on them. - else if (!Ty->isAnyPointerType() && !Ty->isBlockPointerType()) - return Qualifiers::GCNone; +Qualifiers::GC ASTContext::getObjCGCAttrKind(QualType Ty) const { + if (getLangOptions().getGCMode() == LangOptions::NonGC) + return Qualifiers::GCNone; + + assert(getLangOptions().ObjC1); + Qualifiers::GC GCAttrs = Ty.getObjCGCAttr(); + + // Default behaviour under objective-C's gc is for ObjC pointers + // (or pointers to them) be treated as though they were declared + // as __strong. + if (GCAttrs == Qualifiers::GCNone) { + if (Ty->isObjCObjectPointerType() || Ty->isBlockPointerType()) + return Qualifiers::Strong; + else if (Ty->isPointerType()) + return getObjCGCAttrKind(Ty->getAs()->getPointeeType()); + } else { + // It's not valid to set GC attributes on anything that isn't a + // pointer. +#ifndef NDEBUG + QualType CT = Ty->getCanonicalTypeInternal(); + while (const ArrayType *AT = dyn_cast(CT)) + CT = AT->getElementType(); + assert(CT->isAnyPointerType() || CT->isBlockPointerType()); +#endif } return GCAttrs; } diff --git a/lib/Sema/SemaType.cpp b/lib/Sema/SemaType.cpp index 2f7c9cf642..ada8a1d8a2 100644 --- a/lib/Sema/SemaType.cpp +++ b/lib/Sema/SemaType.cpp @@ -310,7 +310,7 @@ distributeObjCPointerTypeAttrFromDeclarator(TypeProcessingState &state, case DeclaratorChunk::Pointer: case DeclaratorChunk::BlockPointer: innermost = i; - return; + continue; case DeclaratorChunk::Reference: case DeclaratorChunk::MemberPointer: