diff options
author | John McCall <rjmccall@apple.com> | 2011-06-17 06:42:21 +0000 |
---|---|---|
committer | John McCall <rjmccall@apple.com> | 2011-06-17 06:42:21 +0000 |
commit | 7acddacc921cd0b3f813443a8641eeddb82dfbd4 (patch) | |
tree | d5abc49c4f8c85ffeb9505ae60ef9e3f1f6f9231 /lib/AST/DeclObjC.cpp | |
parent | 3724020559653f11d1327ff41676a06afe3a678f (diff) |
Objective-C fast enumeration loop variables are not retained in ARC, but
they should still be officially __strong for the purposes of errors,
block capture, etc. Make a new bit on variables, isARCPseudoStrong(),
and set this for 'self' and these enumeration-loop variables. Change
the code that was looking for the old patterns to look for this bit,
and change IR generation to find this bit and treat the resulting
variable as __unsafe_unretained for the purposes of init/destroy in
the two places it can come up.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133243 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/DeclObjC.cpp')
-rw-r--r-- | lib/AST/DeclObjC.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp index 99eb0d386b..67f6531d79 100644 --- a/lib/AST/DeclObjC.cpp +++ b/lib/AST/DeclObjC.cpp @@ -474,19 +474,22 @@ void ObjCMethodDecl::createImplicitParams(ASTContext &Context, } else // we have a factory method. selfTy = Context.getObjCClassType(); + bool selfIsPseudoStrong = false; bool selfIsConsumed = false; if (isInstanceMethod() && Context.getLangOptions().ObjCAutoRefCount) { selfIsConsumed = hasAttr<NSConsumesSelfAttr>(); - // 'self' is always __strong, although as a special case we don't - // actually retain it except in init methods. + // 'self' is always __strong. It's actually pseudo-strong except + // in init methods, though. Qualifiers qs; qs.setObjCLifetime(Qualifiers::OCL_Strong); selfTy = Context.getQualifiedType(selfTy, qs); // In addition, 'self' is const unless this is an init method. - if (getMethodFamily() != OMF_init) + if (getMethodFamily() != OMF_init) { selfTy = selfTy.withConst(); + selfIsPseudoStrong = true; + } } ImplicitParamDecl *self @@ -497,6 +500,9 @@ void ObjCMethodDecl::createImplicitParams(ASTContext &Context, if (selfIsConsumed) self->addAttr(new (Context) NSConsumedAttr(SourceLocation(), Context)); + if (selfIsPseudoStrong) + self->setARCPseudoStrong(true); + setCmdDecl(ImplicitParamDecl::Create(Context, this, SourceLocation(), &Context.Idents.get("_cmd"), Context.getObjCSelType())); |