diff options
-rw-r--r-- | clang/lib/AST/ASTContext.cpp | 19 | ||||
-rw-r--r-- | clang/test/SemaObjC/gc-attr-block-ivar.m | 17 | ||||
-rw-r--r-- | clang/test/SemaObjC/objc2-merge-gc-attribue-decl.m | 4 |
3 files changed, 35 insertions, 5 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index 7e03f56f62f..386a5f3c7bd 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -4303,11 +4303,24 @@ QualType ASTContext::mergeFunctionTypes(QualType lhs, QualType rhs) { bool allRTypes = true; // Check return type - QualType retType = mergeTypes(lbase->getResultType(), rbase->getResultType()); + QualType LRES = lbase->getResultType(); + QualType RRES = rbase->getResultType(); + Qualifiers::GC GC_L = LRES.getObjCGCAttr(); + Qualifiers::GC GC_R = RRES.getObjCGCAttr(); + // __weak/__strong attribute on one function/block return type but + // not the other is OK. + if (GC_L != GC_R) { + if (GC_R == Qualifiers::GCNone) + RRES = getObjCGCQualType(RRES, GC_L); + else if (GC_L == Qualifiers::GCNone) + LRES = getObjCGCQualType(LRES, GC_R); + } + + QualType retType = mergeTypes(LRES, RRES); if (retType.isNull()) return QualType(); - if (getCanonicalType(retType) != getCanonicalType(lbase->getResultType())) + if (getCanonicalType(retType) != getCanonicalType(LRES)) allLTypes = false; - if (getCanonicalType(retType) != getCanonicalType(rbase->getResultType())) + if (getCanonicalType(retType) != getCanonicalType(RRES)) allRTypes = false; // FIXME: double check this bool NoReturn = lbase->getNoReturnAttr() || rbase->getNoReturnAttr(); diff --git a/clang/test/SemaObjC/gc-attr-block-ivar.m b/clang/test/SemaObjC/gc-attr-block-ivar.m new file mode 100644 index 00000000000..c3e00337fdf --- /dev/null +++ b/clang/test/SemaObjC/gc-attr-block-ivar.m @@ -0,0 +1,17 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -fblocks -fobjc-gc %s + +@interface Intf { +@public + void (^block) (id); + __weak void (^weak_block) (id); + void (*fptr) (id); + __weak void (*weak_fptr) (id); +} +@end + +int main() { + Intf *observer; + return (observer->block != observer->weak_block || + observer->fptr != observer->weak_fptr); +} + diff --git a/clang/test/SemaObjC/objc2-merge-gc-attribue-decl.m b/clang/test/SemaObjC/objc2-merge-gc-attribue-decl.m index 673a7417e38..f8d5f0018d7 100644 --- a/clang/test/SemaObjC/objc2-merge-gc-attribue-decl.m +++ b/clang/test/SemaObjC/objc2-merge-gc-attribue-decl.m @@ -10,8 +10,8 @@ extern id p1; extern id CFRunLoopGetMain(); extern __strong id CFRunLoopGetMain(); -extern __weak id WLoopGetMain(); // expected-note {{previous declaration is here}} -extern id WLoopGetMain(); // expected-error {{conflicting types for 'WLoopGetMain'}} +extern __weak id WLoopGetMain(); +extern id WLoopGetMain(); extern id p3; // expected-note {{previous definition is here}} extern __weak id p3; // expected-error {{redefinition of 'p3' with a different type}} |