[cfe-commits] r101699 - in /cfe/trunk: lib/Sema/SemaDeclObjC.cpp test/SemaObjC/ibaction.m
Ted Kremenek
kremenek at apple.com
Sat Apr 17 21:59:38 PDT 2010
Author: kremenek
Date: Sat Apr 17 23:59:38 2010
New Revision: 101699
URL: http://llvm.org/viewvc/llvm-project?rev=101699&view=rev
Log:
Allow the 'ibaction' attribute to be attached to method declarations (and not issue a warning).
Added:
cfe/trunk/test/SemaObjC/ibaction.m
Modified:
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=101699&r1=101698&r2=101699&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Sat Apr 17 23:59:38 2010
@@ -1492,6 +1492,16 @@
return ret;
}
+static inline
+bool containsInvalidMethodImplAttribute(const AttributeList *A) {
+ // The 'ibaction' attribute is allowed on method definitions because of
+ // how the IBAction macro is used on both method declarations and definitions.
+ // If the method definitions contains any other attributes, return true.
+ while (A && A->getKind() == AttributeList::AT_IBAction)
+ A = A->getNext();
+ return A != NULL;
+}
+
Sema::DeclPtrTy Sema::ActOnMethodDeclaration(
SourceLocation MethodLoc, SourceLocation EndLoc,
tok::TokenKind MethodType, DeclPtrTy classDecl,
@@ -1618,7 +1628,7 @@
}
InterfaceMD = ImpDecl->getClassInterface()->getMethod(Sel,
MethodType == tok::minus);
- if (AttrList)
+ if (containsInvalidMethodImplAttribute(AttrList))
Diag(EndLoc, diag::warn_attribute_method_def);
} else if (ObjCCategoryImplDecl *CatImpDecl =
dyn_cast<ObjCCategoryImplDecl>(ClassDecl)) {
@@ -1629,7 +1639,7 @@
PrevMethod = CatImpDecl->getClassMethod(Sel);
CatImpDecl->addClassMethod(ObjCMethod);
}
- if (AttrList)
+ if (containsInvalidMethodImplAttribute(AttrList))
Diag(EndLoc, diag::warn_attribute_method_def);
}
if (PrevMethod) {
Added: cfe/trunk/test/SemaObjC/ibaction.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/ibaction.m?rev=101699&view=auto
==============================================================================
--- cfe/trunk/test/SemaObjC/ibaction.m (added)
+++ cfe/trunk/test/SemaObjC/ibaction.m Sat Apr 17 23:59:38 2010
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 %s -verify
+
+ at interface Foo
+{
+ __attribute__((iboutlet)) id myoutlet;
+}
+- (void) __attribute__((ibaction)) myMessage:(id)msg;
+ at end
+
+ at implementation Foo
+// Normally attributes should not be attached to method definitions, but
+// we allow 'ibaction' to be attached because it can be expanded from
+// the IBAction macro.
+- (void) __attribute__((ibaction)) myMessage:(id)msg {} // no-warning
+ at end
More information about the cfe-commits
mailing list