From e89bad5fbd3746be1b4b0d4461a66791baaea3db Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Tue, 20 Aug 2013 20:45:28 +0000 Subject: [PATCH] ObjectiveC migrator: More tweaking of heuristics for an audited cf function to not include those which are annotated by user. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188823 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/ARCMigrate/ObjCMT.cpp | 15 ++++++++++----- test/ARCMT/objcmt-arc-cf-annotations.m.result | 12 ------------ 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/lib/ARCMigrate/ObjCMT.cpp b/lib/ARCMigrate/ObjCMT.cpp index 0147297c0b..aa432e02ea 100644 --- a/lib/ARCMigrate/ObjCMT.cpp +++ b/lib/ARCMigrate/ObjCMT.cpp @@ -843,10 +843,17 @@ bool ObjCMigrateASTConsumer::migrateAddFunctionAnnotation( const FunctionDecl *FuncDecl) { if (FuncDecl->hasBody()) return false; - bool HasAtLeastOnePointer = false; + CallEffects CE = CallEffects::getEffect(FuncDecl); - if (!FuncDecl->getAttr() && - !FuncDecl->getAttr()) { + bool FuncIsReturnAnnotated = (FuncDecl->getAttr() || + FuncDecl->getAttr()); + + // Trivial case of when funciton is annotated and has no argument. + if (FuncIsReturnAnnotated && FuncDecl->getNumParams() == 0) + return false; + + bool HasAtLeastOnePointer = FuncIsReturnAnnotated; + if (!FuncIsReturnAnnotated) { RetEffect Ret = CE.getReturnValue(); const char *AnnotationString = 0; if (Ret.getObjKind() == RetEffect::CF && Ret.isOwned()) { @@ -866,8 +873,6 @@ bool ObjCMigrateASTConsumer::migrateAddFunctionAnnotation( else if (!AuditedType(FuncDecl->getResultType(), HasAtLeastOnePointer)) return false; } - else - HasAtLeastOnePointer = true; // At this point result type is either annotated or audited. // Now, how about argument types. diff --git a/test/ARCMT/objcmt-arc-cf-annotations.m.result b/test/ARCMT/objcmt-arc-cf-annotations.m.result index a9b0ac85cf..9e96cb498d 100644 --- a/test/ARCMT/objcmt-arc-cf-annotations.m.result +++ b/test/ARCMT/objcmt-arc-cf-annotations.m.result @@ -1002,14 +1002,8 @@ void IOServiceNameMatching_wrapper(const char * name) { IOServiceNameMatching(name); // expected-warning{{leak}} } - -CF_IMPLICIT_BRIDGING_ENABLED - CF_RETURNS_RETAINED CFDictionaryRef CreateDict(); -CF_IMPLICIT_BRIDGING_DISABLED - - void IOServiceAddNotification_wrapper(mach_port_t masterPort, const io_name_t notificationType, mach_port_t wakePort, uintptr_t reference, io_iterator_t * notification ) { @@ -2053,15 +2047,9 @@ void test_drain() { // value as tracked, even if the object isn't a known CF type. //===----------------------------------------------------------------------===// - -CF_IMPLICIT_BRIDGING_ENABLED - MyCFType getCustom() __attribute__((cf_returns_not_retained)); MyCFType makeCustom() __attribute__((cf_returns_retained)); -CF_IMPLICIT_BRIDGING_DISABLED - - void testCustomReturnsRetained() { MyCFType obj = makeCustom(); // expected-warning {{leak of an object stored into 'obj'}} } -- 2.40.0