]> granicus.if.org Git - clang/commitdiff
Make sure that we infer __strong, etc. when we instantiate variables
authorDouglas Gregor <dgregor@apple.com>
Sat, 10 Dec 2011 01:22:52 +0000 (01:22 +0000)
committerDouglas Gregor <dgregor@apple.com>
Sat, 10 Dec 2011 01:22:52 +0000 (01:22 +0000)
under ARC. Fixes <rdar://problem/10530209>.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@146307 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclCXX.cpp
lib/Sema/SemaDeclObjC.cpp
lib/Sema/SemaTemplateInstantiateDecl.cpp
test/CodeGenObjCXX/arc.mm

index 50e07553a1b448c8dcdf7d1265a9093073e5d2fd..fb0307fb2884a6d1d4a7fc39bae391e780b85839 100644 (file)
@@ -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:
index 0fd3b25defeaaba78acbb57fa7de5b7666d2826e..8dd484a3b5598c72f9cb07dbcad16152ba257375 100644 (file)
@@ -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;
index 9477192e2352fd48f877ce38753b83b142667d52..123548e656528ce9229a760e837b30d220790960 100644 (file)
@@ -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()) {
index 49034a0129abd8715124c8a5dfae2effe5a0a31f..7b7429085fbf9335344fcd8db5e81777ebdc7dfd 100644 (file)
@@ -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>();
+