r190106 - ObjectiveC migrator: tighten the rules for when
Fariborz Jahanian
fjahanian at apple.com
Thu Sep 5 16:04:33 PDT 2013
Author: fjahanian
Date: Thu Sep 5 18:04:33 2013
New Revision: 190106
URL: http://llvm.org/viewvc/llvm-project?rev=190106&view=rev
Log:
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.
Modified:
cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
cfe/trunk/test/ARCMT/objcmt-arc-cf-annotations.m.result
Modified: cfe/trunk/lib/ARCMigrate/ObjCMT.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ARCMigrate/ObjCMT.cpp?rev=190106&r1=190105&r2=190106&view=diff
==============================================================================
--- cfe/trunk/lib/ARCMigrate/ObjCMT.cpp (original)
+++ cfe/trunk/lib/ARCMigrate/ObjCMT.cpp Thu Sep 5 18:04:33 2013
@@ -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::AddCFAnnota
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::migrateAddM
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 &&
Modified: cfe/trunk/test/ARCMT/objcmt-arc-cf-annotations.m.result
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ARCMT/objcmt-arc-cf-annotations.m.result?rev=190106&r1=190105&r2=190106&view=diff
==============================================================================
--- cfe/trunk/test/ARCMT/objcmt-arc-cf-annotations.m.result (original)
+++ cfe/trunk/test/ARCMT/objcmt-arc-cf-annotations.m.result Thu Sep 5 18:04:33 2013
@@ -1368,7 +1368,7 @@ typedef NSString* MyStringTy;
- (NSString*) returnsAnOwnedCFString CF_RETURNS_RETAINED; // no-warning
- (MyStringTy) returnsAnOwnedTypedString NS_RETURNS_RETAINED; // no-warning
- (NSString*) newString NS_RETURNS_NOT_RETAINED; // no-warning
-- (NSString*) newString_auto NS_RETURNS_AUTORELEASED NS_RETURNS_NOT_RETAINED; // no-warning
+- (NSString*) newString_auto NS_RETURNS_AUTORELEASED; // no-warning
- (NSString*) newStringNoAttr;
- (int) returnsAnOwnedInt NS_RETURNS_RETAINED; // expected-warning{{'ns_returns_retained' attribute only applies to methods that return an Objective-C object}}
- (id) pseudoInit NS_CONSUMES_SELF NS_RETURNS_RETAINED;
More information about the cfe-commits
mailing list