From: Douglas Gregor Date: Sat, 10 Dec 2011 01:22:52 +0000 (+0000) Subject: Make sure that we infer __strong, etc. when we instantiate variables X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9aab9c4116bb3ea876d92d4af10bff7f4c451f24;p=clang Make sure that we infer __strong, etc. when we instantiate variables under ARC. Fixes . git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146307 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp index 50e07553a1..fb0307fb28 100644 --- a/lib/Sema/SemaDeclCXX.cpp +++ b/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()) { // C++ [except.handle]p16: diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index 0fd3b25def..8dd484a3b5 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/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/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index 9477192e23..123548e656 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/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/test/CodeGenObjCXX/arc.mm b/test/CodeGenObjCXX/arc.mm index 49034a0129..7b7429085f 100644 --- a/test/CodeGenObjCXX/arc.mm +++ b/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 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(); + +template +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(); +