diff options
| author | Fariborz Jahanian <fjahanian@apple.com> | 2013-09-05 23:04:33 +0000 |
|---|---|---|
| committer | Fariborz Jahanian <fjahanian@apple.com> | 2013-09-05 23:04:33 +0000 |
| commit | c24879e2de0e35b2f46bfd8068c323b7070737af (patch) | |
| tree | aada9d5e50bd89c4126142b11255beca3d67db32 /clang/lib | |
| parent | 53d0b492f57b3f7b28858c4d9c299ee8c72f9a02 (diff) | |
| download | bcm5719-llvm-c24879e2de0e35b2f46bfd8068c323b7070737af.tar.gz bcm5719-llvm-c24879e2de0e35b2f46bfd8068c323b7070737af.zip | |
ObjectiveC migrator: tighten the rules for when
inferring NS_RETURNS_RETAINED, etc., return annotations.
Do not infer if these annotations are implicit
from the naming convention. Also add inference for
NS_CONSUMES_SELF annotation.
llvm-svn: 190106
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/ARCMigrate/ObjCMT.cpp | 40 |
1 files changed, 32 insertions, 8 deletions
diff --git a/clang/lib/ARCMigrate/ObjCMT.cpp b/clang/lib/ARCMigrate/ObjCMT.cpp index 251cbaf2219..8490d00e126 100644 --- a/clang/lib/ARCMigrate/ObjCMT.cpp +++ b/clang/lib/ARCMigrate/ObjCMT.cpp @@ -996,7 +996,8 @@ ObjCMigrateASTConsumer::CF_BRIDGING_KIND bool FuncIsReturnAnnotated = (FuncDecl->getAttr<CFReturnsRetainedAttr>() || FuncDecl->getAttr<CFReturnsNotRetainedAttr>() || FuncDecl->getAttr<NSReturnsRetainedAttr>() || - FuncDecl->getAttr<NSReturnsNotRetainedAttr>()); + FuncDecl->getAttr<NSReturnsNotRetainedAttr>() || + FuncDecl->getAttr<NSReturnsAutoreleasedAttr>()); // Trivial case of when funciton is annotated and has no argument. if (FuncIsReturnAnnotated && FuncDecl->getNumParams() == 0) @@ -1072,12 +1073,24 @@ void ObjCMigrateASTConsumer::AddCFAnnotations(ASTContext &Ctx, AnnotationString = " CF_RETURNS_NOT_RETAINED"; } else if (Ret.getObjKind() == RetEffect::ObjC) { - if (Ret.isOwned() && - Ctx.Idents.get("NS_RETURNS_RETAINED").hasMacroDefinition()) - AnnotationString = " NS_RETURNS_RETAINED"; - else if (Ret.notOwned() && - Ctx.Idents.get("NS_RETURNS_NOT_RETAINED").hasMacroDefinition()) - AnnotationString = " NS_RETURNS_NOT_RETAINED"; + ObjCMethodFamily OMF = MethodDecl->getMethodFamily(); + switch (OMF) { + case clang::OMF_alloc: + case clang::OMF_new: + case clang::OMF_copy: + case clang::OMF_init: + case clang::OMF_mutableCopy: + break; + + default: + if (Ret.isOwned() && + Ctx.Idents.get("NS_RETURNS_RETAINED").hasMacroDefinition()) + AnnotationString = " NS_RETURNS_RETAINED"; + else if (Ret.notOwned() && + Ctx.Idents.get("NS_RETURNS_NOT_RETAINED").hasMacroDefinition()) + AnnotationString = " NS_RETURNS_NOT_RETAINED"; + break; + } } if (AnnotationString) { @@ -1111,7 +1124,18 @@ void ObjCMigrateASTConsumer::migrateAddMethodAnnotation( bool MethodIsReturnAnnotated = (MethodDecl->getAttr<CFReturnsRetainedAttr>() || MethodDecl->getAttr<CFReturnsNotRetainedAttr>() || MethodDecl->getAttr<NSReturnsRetainedAttr>() || - MethodDecl->getAttr<NSReturnsNotRetainedAttr>()); + MethodDecl->getAttr<NSReturnsNotRetainedAttr>() || + MethodDecl->getAttr<NSReturnsAutoreleasedAttr>()); + + if (CE.getReceiver() == DecRefMsg && + !MethodDecl->getAttr<NSConsumesSelfAttr>() && + MethodDecl->getMethodFamily() != OMF_init && + MethodDecl->getMethodFamily() != OMF_release && + Ctx.Idents.get("NS_CONSUMES_SELF").hasMacroDefinition()) { + edit::Commit commit(*Editor); + commit.insertBefore(MethodDecl->getLocEnd(), " NS_CONSUMES_SELF"); + Editor->commit(commit); + } // Trivial case of when funciton is annotated and has no argument. if (MethodIsReturnAnnotated && |

