From: Fariborz Jahanian Date: Wed, 12 Sep 2012 20:34:47 +0000 (+0000) Subject: objective-C arc: don't issue no explicit ownership warning when X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=00024796eaa29055e76fc99ffdc668c702e6fe9d;p=clang objective-C arc: don't issue no explicit ownership warning when __autoreleasing is explicitely added to param type. // rdar://12280826 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@163738 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDeclObjC.cpp b/lib/Sema/SemaDeclObjC.cpp index e81429cc4c..2dc2b0cba1 100644 --- a/lib/Sema/SemaDeclObjC.cpp +++ b/lib/Sema/SemaDeclObjC.cpp @@ -282,11 +282,10 @@ void Sema::AddAnyMethodToGlobalPool(Decl *D) { AddFactoryMethodToGlobalPool(MDecl, true); } -/// StrongPointerToObjCPointer - returns true when pointer to ObjC pointer -/// is __strong, or when it is any other type. It returns false when -/// pointer to ObjC pointer is not __strong. +/// HasExplicitOwnershipAttr - returns true when pointer to ObjC pointer +/// has explicit ownership attribute; false otherwise. static bool -StrongPointerToObjCPointer(Sema &S, ParmVarDecl *Param) { +HasExplicitOwnershipAttr(Sema &S, ParmVarDecl *Param) { QualType T = Param->getType(); if (!T->isObjCIndirectLifetimeType()) return true; @@ -296,8 +295,11 @@ StrongPointerToObjCPointer(Sema &S, ParmVarDecl *Param) { ? T->getAs()->getPointeeType() : T->getAs()->getPointeeType(); if (T->isObjCLifetimeType()) { - Qualifiers::ObjCLifetime lifetime = T.getObjCLifetime(); - return lifetime == Qualifiers::OCL_Strong; + // when lifetime is Qualifiers::OCL_None it means that it has + // no implicit ownership qualifier (which means it is explicit). + Qualifiers::ObjCLifetime lifetime = + T.getLocalQualifiers().getObjCLifetime(); + return lifetime == Qualifiers::OCL_None; } return true; } @@ -335,7 +337,7 @@ void Sema::ActOnStartOfObjCMethodDef(Scope *FnBodyScope, Decl *D) { Param->setInvalidDecl(); if (!Param->isInvalidDecl() && getLangOpts().ObjCAutoRefCount && - !StrongPointerToObjCPointer(*this, Param)) + !HasExplicitOwnershipAttr(*this, Param)) Diag(Param->getLocation(), diag::warn_arc_strong_pointer_objc_pointer) << Param->getType(); diff --git a/test/SemaObjC/arc-objc-lifetime.m b/test/SemaObjC/arc-objc-lifetime.m index d47428d1d6..08d2dbe16c 100644 --- a/test/SemaObjC/arc-objc-lifetime.m +++ b/test/SemaObjC/arc-objc-lifetime.m @@ -56,3 +56,14 @@ typedef void (^T) (); - (void) N : (__strong NSObject***) arg0 : (__strong NSObject

***)arg : (float**) arg1 : (double) arg2 {} - (void) BLOCK : (T*) arg0 : (T)arg : (__strong T*) arg1 {} // expected-warning {{method parameter of type '__autoreleasing T *' (aka 'void (^__autoreleasing *)()') with no explicit ownership}} @end + +// rdar://12280826 +@class NSMutableDictionary, NSError; +@interface Radar12280826 +- (void)createInferiorTransportAndSetEnvironment:(NSMutableDictionary*)environment error:(__autoreleasing NSError**)error; +@end + +@implementation Radar12280826 +- (void)createInferiorTransportAndSetEnvironment:(NSMutableDictionary*)environment error:(__autoreleasing NSError**)error {} +@end +