[cfe-commits] r163813 - in /cfe/trunk/lib/Sema: SemaDeclObjC.cpp SemaType.cpp
Fariborz Jahanian
fjahanian at apple.com
Thu Sep 13 10:29:07 PDT 2012
Author: fjahanian
Date: Thu Sep 13 12:29:07 2012
New Revision: 163813
URL: http://llvm.org/viewvc/llvm-project?rev=163813&view=rev
Log:
Move no explicit ownership warning to SemaType.cpp.
// rdar://12280826
Modified:
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
cfe/trunk/lib/Sema/SemaType.cpp
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=163813&r1=163812&r2=163813&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Thu Sep 13 12:29:07 2012
@@ -282,28 +282,6 @@
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->isObjCIndirectLifetimeType())
- return true;
- if (!T->isPointerType() && !T->isReferenceType())
- return true;
- 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();
- return lifetime == Qualifiers::OCL_None;
- }
- 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) {
@@ -335,11 +313,6 @@
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);
Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=163813&r1=163812&r2=163813&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Thu Sep 13 12:29:07 2012
@@ -3335,6 +3335,36 @@
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
@@ -3370,6 +3400,8 @@
// 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).
More information about the cfe-commits
mailing list