[cfe-commits] r70504 - in /cfe/trunk: include/clang/Parse/Action.h lib/Parse/ParseObjc.cpp lib/Sema/Sema.h lib/Sema/SemaDeclAttr.cpp lib/Sema/SemaDeclObjC.cpp test/Analysis/retain-release.m
Ted Kremenek
kremenek at apple.com
Thu Apr 30 11:41:06 PDT 2009
Author: kremenek
Date: Thu Apr 30 13:41:06 2009
New Revision: 70504
URL: http://llvm.org/viewvc/llvm-project?rev=70504&view=rev
Log:
Hook up Sema support for attributes on Objective-C method declarations that
appear between the return type and the selector. This is a separate code path
from regular attribute processing, as we only want to (a) accept only a specific
set of attributes in this place and (b) want to distinguish to clients the
context in which an attribute was added to an ObjCMethodDecl.
Currently, the attribute 'objc_ownership_returns' is the only attribute that
uses this new feature. Shortly I will add a warning for 'objc_ownership_returns'
to be placed at the end of a method declaration.
Modified:
cfe/trunk/include/clang/Parse/Action.h
cfe/trunk/lib/Parse/ParseObjc.cpp
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
cfe/trunk/test/Analysis/retain-release.m
Modified: cfe/trunk/include/clang/Parse/Action.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Action.h?rev=70504&r1=70503&r2=70504&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Action.h (original)
+++ cfe/trunk/include/clang/Parse/Action.h Thu Apr 30 13:41:06 2009
@@ -1439,6 +1439,7 @@
Selector Sel, // a unique name for the method.
ObjCArgInfo *ArgInfo, // ArgInfo: Has 'Sel.getNumArgs()' entries.
llvm::SmallVectorImpl<Declarator> &Cdecls, // c-style args
+ AttributeList *ReturnAttrList, // optional
AttributeList *MethodAttrList, // optional
// tok::objc_not_keyword, tok::objc_optional, tok::objc_required
tok::ObjCKeywordKind impKind,
Modified: cfe/trunk/lib/Parse/ParseObjc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseObjc.cpp?rev=70504&r1=70503&r2=70504&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseObjc.cpp (original)
+++ cfe/trunk/lib/Parse/ParseObjc.cpp Thu Apr 30 13:41:06 2009
@@ -705,7 +705,7 @@
Selector Sel = PP.getSelectorTable().getNullarySelector(SelIdent);
return Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(),
mType, IDecl, DSRet, ReturnType, Sel,
- 0, CargNames,
+ 0, CargNames, ReturnAttrs,
MethodAttrs, MethodImplKind);
}
@@ -779,7 +779,7 @@
&KeyIdents[0]);
return Actions.ActOnMethodDeclaration(mLoc, Tok.getLocation(),
mType, IDecl, DSRet, ReturnType, Sel,
- &ArgInfos[0], CargNames,
+ &ArgInfos[0], CargNames, ReturnAttrs,
MethodAttrs,
MethodImplKind, isVariadic);
}
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=70504&r1=70503&r2=70504&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Thu Apr 30 13:41:06 2009
@@ -1071,6 +1071,9 @@
// Decl attributes - this routine is the top level dispatcher.
void ProcessDeclAttributes(Decl *D, const Declarator &PD);
void ProcessDeclAttributeList(Decl *D, const AttributeList *AttrList);
+
+ void ProcessObjCMethDeclReturnAttributeList(ObjCMethodDecl *D,
+ const AttributeList *AttrList);
void WarnUndefinedMethod(SourceLocation ImpLoc, ObjCMethodDecl *method,
bool &IncompleteImpl);
@@ -2186,6 +2189,7 @@
// from the Sel.getNumArgs().
ObjCArgInfo *ArgInfo,
llvm::SmallVectorImpl<Declarator> &Cdecls,
+ AttributeList *ReturnAttrList,
AttributeList *AttrList, tok::ObjCKeywordKind MethodImplKind,
bool isVariadic = false);
Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=70504&r1=70503&r2=70504&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Thu Apr 30 13:41:06 2009
@@ -1697,7 +1697,6 @@
}
}
-
/// ProcessDeclAttributes - Given a declarator (PD) with attributes indicated in
/// it, apply them to D. This is a bit tricky because PD can have attributes
/// specified in many different places, and we need to find and apply them all.
@@ -1719,3 +1718,36 @@
ProcessDeclAttributeList(D, Attrs);
}
+
+/// ProcessObjCMethDeclReturnAttribute - Apply the specific attribute to the
+/// specified ObjCMethodDecl. This is a separate codepath because it
+/// corresponds to attributes applied essentially to the return type of
+/// an Objective-C method declaration (as opposed to attributes that hang off
+/// the end of the method declaration).
+static void ProcessObjCMethDeclReturnAttribute(Decl *D,
+ const AttributeList &Attr,
+ Sema &S) {
+ switch (Attr.getKind()) {
+ // Checker-specific.
+ case AttributeList::AT_objc_ownership_returns:
+ HandleObjCOwnershipReturnsAttr(D, Attr, S); break;
+ break;
+ default:
+ S.Diag(Attr.getLoc(), diag::warn_attribute_ignored) << Attr.getName();
+ break;
+ }
+}
+
+/// ProcessObjCMethDeclAttributeList - Apply all the decl attributes in the
+/// specified attribute list to the specified ObjCMethodDecl. This is
+/// a separate codepath because it corresponds to attributes applied
+/// essentiallyto the return type of an Objective-C method declaration
+/// (as opposed to attributes that hang off the end of the method declaration).
+void Sema::ProcessObjCMethDeclReturnAttributeList(ObjCMethodDecl *D,
+ const AttributeList *AttrList)
+{
+ while (AttrList) {
+ ProcessObjCMethDeclReturnAttribute(D, *AttrList, *this);
+ AttrList = AttrList->getNext();
+ }
+}
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=70504&r1=70503&r2=70504&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Thu Apr 30 13:41:06 2009
@@ -1509,6 +1509,7 @@
// from the Sel.getNumArgs().
ObjCArgInfo *ArgInfo,
llvm::SmallVectorImpl<Declarator> &Cdecls,
+ AttributeList *ReturnAttrList,
AttributeList *AttrList, tok::ObjCKeywordKind MethodDeclKind,
bool isVariadic) {
Decl *ClassDecl = classDecl.getAs<Decl>();
@@ -1590,6 +1591,9 @@
if (AttrList)
ProcessDeclAttributeList(ObjCMethod, AttrList);
+
+ if (ReturnAttrList)
+ ProcessObjCMethDeclReturnAttributeList(ObjCMethod, ReturnAttrList);
// For implementations (which can be very "coarse grain"), we add the
// method now. This allows the AST to implement lookup methods that work
Modified: cfe/trunk/test/Analysis/retain-release.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/retain-release.m?rev=70504&r1=70503&r2=70504&view=diff
==============================================================================
--- cfe/trunk/test/Analysis/retain-release.m (original)
+++ cfe/trunk/test/Analysis/retain-release.m Thu Apr 30 13:41:06 2009
@@ -431,11 +431,10 @@
//===----------------------------------------------------------------------===//
@interface TestOwnershipAttr : NSObject
-- (NSString*) returnsAnOwnedString __attribute__((objc_ownership_returns));
-
-// We have parsing support for the attribute before the selector, but no Sema
-// support yet.
-- (NSString*) __attribute__((objc_ownership_returns)) returnsAnOwnedString2;
+- (NSString*) __attribute__((objc_ownership_returns)) returnsAnOwnedString;
+// Soon we won't accept __attribute__((objc_ownership_returns)) at the end
+// of a method decl.
+- (NSString*) returnsAnOwnedString2 __attribute__((objc_ownership_returns));
- (void) myRetain:(id)__attribute__((objc_ownership_retain))obj;
- (void) myCFRetain:(id)__attribute__((objc_ownership_cfretain))obj;
More information about the cfe-commits
mailing list