diff options
| author | Douglas Gregor <dgregor@apple.com> | 2011-12-10 01:22:52 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2011-12-10 01:22:52 +0000 |
| commit | 8ca0c6408e537e70dddbd8f4d7fd11c5eb019c71 (patch) | |
| tree | 196d606fbd6495257f4dc88186e612e79286c0c8 | |
| parent | 036e2bd07acf2dab2a46382627c48f84943dac4b (diff) | |
| download | bcm5719-llvm-8ca0c6408e537e70dddbd8f4d7fd11c5eb019c71.tar.gz bcm5719-llvm-8ca0c6408e537e70dddbd8f4d7fd11c5eb019c71.zip | |
Make sure that we infer __strong, etc. when we instantiate variables
under ARC. Fixes <rdar://problem/10530209>.
llvm-svn: 146307
| -rw-r--r-- | clang/lib/Sema/SemaDeclCXX.cpp | 4 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaDeclObjC.cpp | 4 | ||||
| -rw-r--r-- | clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 6 | ||||
| -rw-r--r-- | clang/test/CodeGenObjCXX/arc.mm | 17 |
4 files changed, 31 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 50e07553a1b..fb0307fb288 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -9528,6 +9528,10 @@ VarDecl *Sema::BuildExceptionDeclaration(Scope *S, ExDeclType, TInfo, SC_None, SC_None); ExDecl->setExceptionVariable(true); + // In ARC, infer 'retaining' for variables of retainable type. + if (getLangOptions().ObjCAutoRefCount && inferObjCARCLifetime(ExDecl)) + Invalid = true; + if (!Invalid && !ExDeclType->isDependentType()) { if (const RecordType *recordType = ExDeclType->getAs<RecordType>()) { // C++ [except.handle]p16: diff --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp index 0fd3b25defe..8dd484a3b55 100644 --- a/clang/lib/Sema/SemaDeclObjC.cpp +++ b/clang/lib/Sema/SemaDeclObjC.cpp @@ -2911,6 +2911,10 @@ VarDecl *Sema::BuildObjCExceptionDecl(TypeSourceInfo *TInfo, QualType T, T, TInfo, SC_None, SC_None); New->setExceptionVariable(true); + // In ARC, infer 'retaining' for variables of retainable type. + if (getLangOptions().ObjCAutoRefCount && inferObjCARCLifetime(New)) + Invalid = true; + if (Invalid) New->setInvalidDecl(); return New; diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 9477192e235..123548e6565 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -351,6 +351,12 @@ Decl *TemplateDeclInstantiator::VisitVarDecl(VarDecl *D) { Sema::LookupOrdinaryName, Sema::ForRedeclaration); if (D->isStaticDataMember()) SemaRef.LookupQualifiedName(Previous, Owner, false); + + // In ARC, infer 'retaining' for variables of retainable type. + if (SemaRef.getLangOptions().ObjCAutoRefCount && + SemaRef.inferObjCARCLifetime(Var)) + Var->setInvalidDecl(); + SemaRef.CheckVariableDeclaration(Var, Previous); if (D->isOutOfLine()) { diff --git a/clang/test/CodeGenObjCXX/arc.mm b/clang/test/CodeGenObjCXX/arc.mm index 49034a0129a..7b7429085fb 100644 --- a/clang/test/CodeGenObjCXX/arc.mm +++ b/clang/test/CodeGenObjCXX/arc.mm @@ -178,6 +178,8 @@ id test36(id z) { // Template instantiation side of rdar://problem/9817306 @interface Test37 ++ alloc; +- init; - (NSArray *) array; @end template <class T> void test37(T *a) { @@ -224,3 +226,18 @@ void send_release() { // CHECK-NEXT: call void @objc_release // CHECK-NEXT: ret void template void send_release<int>(); + +template<typename T> +Test37 *instantiate_init() { + Test37 *result = [[Test37 alloc] init]; + return result; +} + +// CHECK: define weak_odr %2* @_Z16instantiate_initIiEP6Test37v +// CHECK: call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend +// CHECK: call i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend +// CHECK: call i8* @objc_retain +// CHECK: call void @objc_release +// CHECK: call i8* @objc_autoreleaseReturnValue +template Test37* instantiate_init<int>(); + |

