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 0abdbb0..e497354 100644
--- a/include/clang/AST/ASTContext.h
+++ b/include/clang/AST/ASTContext.h
@@ -945,7 +945,7 @@
/// 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 e76238c..a64d149 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -4339,24 +4339,30 @@
/// 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<PointerType>()->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<PointerType>()->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<ArrayType>(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 2f7c9cf..ada8a1d 100644
--- a/lib/Sema/SemaType.cpp
+++ b/lib/Sema/SemaType.cpp
@@ -310,7 +310,7 @@
case DeclaratorChunk::Pointer:
case DeclaratorChunk::BlockPointer:
innermost = i;
- return;
+ continue;
case DeclaratorChunk::Reference:
case DeclaratorChunk::MemberPointer: