]> granicus.if.org Git - clang/commitdiff
Move back the stuff about missing ownership attribute warning
authorFariborz Jahanian <fjahanian@apple.com>
Thu, 13 Sep 2012 18:53:14 +0000 (18:53 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Thu, 13 Sep 2012 18:53:14 +0000 (18:53 +0000)
to SemaDeclObjC and apply some simplification per John's
comment. // rdar://12280826

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@163824 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDeclObjC.cpp
lib/Sema/SemaType.cpp

index e80cc824823f62f3b46b36e77f7a9793fe6dfc08..bf7755fbdf828bf1c0332b637b99f862490baaa2 100644 (file)
@@ -282,6 +282,28 @@ void Sema::AddAnyMethodToGlobalPool(Decl *D) {
     AddFactoryMethodToGlobalPool(MDecl, true);
 }
 
+/// HasExplicitOwnershipAttr - returns true when pointer to ObjC pointer
+/// has explicit ownership attribute; false otherwise.
+static bool
+HasExplicitOwnershipAttr(Sema &S, ParmVarDecl *Param) {
+  QualType T = Param->getType();
+  
+  if (!T->isPointerType() && !T->isReferenceType())
+    return true;
+  
+  if (const PointerType *PT = T->getAs<PointerType>()) {
+    T = PT->getPointeeType();
+  } else if (const ReferenceType *RT = T->getAs<ReferenceType>()) {
+    T = RT->getPointeeType();
+  } else {
+    return true;
+  }
+  
+  // If we have a lifetime qualifier, but it's local, we must have 
+  // inferred it. So, it is implicit.
+  return !T.getLocalQualifiers().hasObjCLifetime();
+}
+
 /// 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 +335,11 @@ 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 &&
+        !HasExplicitOwnershipAttr(*this, Param))
+      Diag(Param->getLocation(), diag::warn_arc_strong_pointer_objc_pointer) <<
+            Param->getType();
     
     if ((*PI)->getIdentifier())
       PushOnScopeChains(*PI, FnBodyScope);
index dc7dc04c48ff2c50ced87479d473bd115a74688c..39d367f07930753da8d82d3a49327afaceaddc94 100644 (file)
@@ -3335,36 +3335,6 @@ Sema::GetTypeSourceInfoForDeclarator(Declarator &D, QualType T,
   return TInfo;
 }
 
-
-/// checkImplicitObjCParamAttribute - diagnoses when pointer to ObjC pointer
-/// has implicit ownership attribute.
-static void
-checkImplicitObjCParamAttribute(Sema &S, Declarator &D, QualType T) {
-  if (!S.getLangOpts().ObjCAutoRefCount ||
-      !S.OriginalLexicalContext ||
-      (S.OriginalLexicalContext->getDeclKind() != Decl::ObjCImplementation &&
-       S.OriginalLexicalContext->getDeclKind() != Decl::ObjCCategoryImpl))
-    return;
-  
-  if (!T->isObjCIndirectLifetimeType())
-    return;
-  if (!T->isPointerType() && !T->isReferenceType())
-    return;
-  QualType OrigT = T;
-  T = T->isPointerType() 
-    ? T->getAs<PointerType>()->getPointeeType() 
-    : T->getAs<ReferenceType>()->getPointeeType();
-  if (T->isObjCLifetimeType()) {
-    // 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();
-    if (lifetime != Qualifiers::OCL_None)
-      S.Diag(D.getLocStart(), diag::warn_arc_strong_pointer_objc_pointer)
-      << OrigT;
-  }
-}
-
 /// \brief Create a LocInfoType to hold the given QualType and TypeSourceInfo.
 ParsedType Sema::CreateParsedType(QualType T, TypeSourceInfo *TInfo) {
   // FIXME: LocInfoTypes are "transient", only needed for passing to/from Parser
@@ -3400,8 +3370,6 @@ TypeResult Sema::ActOnTypeName(Scope *S, Declarator &D) {
   // to apply them to the actual parameter declaration.
   if (D.getContext() != Declarator::ObjCParameterContext)
     checkUnusedDeclAttributes(D);
-  else
-    checkImplicitObjCParamAttribute(*this, D, T);
 
   if (getLangOpts().CPlusPlus) {
     // Check that there are no default arguments (C++ only).