aboutsummaryrefslogtreecommitdiff
path: root/clang/lib
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2012-08-30 23:56:02 +0000
committerFariborz Jahanian <fjahanian@apple.com>2012-08-30 23:56:02 +0000
commitcd278ffa285694df0bcb22fdff270af1cf03559a (patch)
treed01bf56a9c2fc2ba3ea7dd9b45886986ec9f19cc /clang/lib
parentd1545e371547a52c28ae5e2404657656c9737333 (diff)
downloadllvm-cd278ffa285694df0bcb22fdff270af1cf03559a.zip
llvm-cd278ffa285694df0bcb22fdff270af1cf03559a.tar.gz
llvm-cd278ffa285694df0bcb22fdff270af1cf03559a.tar.bz2
objective-C ARC: under -Wexplicit-ownership-type diagnose those
method parameter types which are reference to an objective-C pointer to object with no explicit ownership. // rdar://10907090 llvm-svn: 162959
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Sema/SemaDeclObjC.cpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaDeclObjC.cpp b/clang/lib/Sema/SemaDeclObjC.cpp
index 457cb1b..f4d63fa 100644
--- a/clang/lib/Sema/SemaDeclObjC.cpp
+++ b/clang/lib/Sema/SemaDeclObjC.cpp
@@ -282,6 +282,26 @@ 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.
+static bool
+StrongPointerToObjCPointer(Sema &S, ParmVarDecl *Param) {
+ QualType T = Param->getType();
+ if (!T->isObjCIndirectLifetimeType())
+ return true;
+ if (!T->isPointerType() && !T->isReferenceType())
+ return true;
+ T = T->isPointerType()
+ ? T->getAs<PointerType>()->getPointeeType()
+ : T->getAs<ReferenceType>()->getPointeeType();
+ if (T->isObjCLifetimeType()) {
+ Qualifiers::ObjCLifetime lifetime = T.getObjCLifetime();
+ return lifetime == Qualifiers::OCL_Strong;
+ }
+ return true;
+}
+
/// ActOnStartOfObjCMethodDef - This routine sets up parameters; invisible
/// and user declared, in the method definition's AST.
void Sema::ActOnStartOfObjCMethodDef(Scope *FnBodyScope, Decl *D) {
@@ -313,6 +333,12 @@ void Sema::ActOnStartOfObjCMethodDef(Scope *FnBodyScope, Decl *D) {
RequireCompleteType(Param->getLocation(), Param->getType(),
diag::err_typecheck_decl_incomplete_type))
Param->setInvalidDecl();
+ if (!Param->isInvalidDecl() &&
+ getLangOpts().ObjCAutoRefCount &&
+ !StrongPointerToObjCPointer(*this, Param))
+ Diag(Param->getLocation(), diag::warn_arc_strong_pointer_objc_pointer) <<
+ Param->getType();
+
if ((*PI)->getIdentifier())
PushOnScopeChains(*PI, FnBodyScope);
}