diff options
author | Ted Kremenek <kremenek@apple.com> | 2011-11-14 21:59:25 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2011-11-14 21:59:25 +0000 |
commit | 1fcdaa9c058e65ca4251a3a752e42b5cbd1db736 (patch) | |
tree | c4f91aa23c68659656e58fc7392e751ee9bd936a /clang/lib/AST/DeclObjC.cpp | |
parent | 8e7fbcc3e4713f72444f940fc5bf3ba33b9ddd06 (diff) | |
download | bcm5719-llvm-1fcdaa9c058e65ca4251a3a752e42b5cbd1db736.tar.gz bcm5719-llvm-1fcdaa9c058e65ca4251a3a752e42b5cbd1db736.zip |
ARC: make assignment to 'self' within class methods illegal. Fixes <rdar://problem/10416568>.
llvm-svn: 144572
Diffstat (limited to 'clang/lib/AST/DeclObjC.cpp')
-rw-r--r-- | clang/lib/AST/DeclObjC.cpp | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/clang/lib/AST/DeclObjC.cpp b/clang/lib/AST/DeclObjC.cpp index 35ee7c6ccdb..766b673bde6 100644 --- a/clang/lib/AST/DeclObjC.cpp +++ b/clang/lib/AST/DeclObjC.cpp @@ -580,17 +580,26 @@ void ObjCMethodDecl::createImplicitParams(ASTContext &Context, bool selfIsPseudoStrong = false; bool selfIsConsumed = false; - if (isInstanceMethod() && Context.getLangOptions().ObjCAutoRefCount) { - selfIsConsumed = hasAttr<NSConsumesSelfAttr>(); - - // 'self' is always __strong. It's actually pseudo-strong except - // in init methods (or methods labeled ns_consumes_self), 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 && !selfIsConsumed) { + + if (Context.getLangOptions().ObjCAutoRefCount) { + if (isInstanceMethod()) { + selfIsConsumed = hasAttr<NSConsumesSelfAttr>(); + + // 'self' is always __strong. It's actually pseudo-strong except + // in init methods (or methods labeled ns_consumes_self), 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 && !selfIsConsumed) { + selfTy = selfTy.withConst(); + selfIsPseudoStrong = true; + } + } + else { + assert(isClassMethod()); + // 'self' is always const in class methods. selfTy = selfTy.withConst(); selfIsPseudoStrong = true; } |