[cfe-commits] r162628 - in /cfe/trunk: lib/Sema/SemaDeclObjC.cpp test/SemaObjC/method-attributes.m

Fariborz Jahanian fjahanian at apple.com
Fri Aug 24 16:50:14 PDT 2012


Author: fjahanian
Date: Fri Aug 24 18:50:13 2012
New Revision: 162628

URL: http://llvm.org/viewvc/llvm-project?rev=162628&view=rev
Log:
objective-C: Do not warn if align attribute on method
declaration is not provided. It is only necessary on
the method implementation. // rdar://11593375

Modified:
    cfe/trunk/lib/Sema/SemaDeclObjC.cpp
    cfe/trunk/test/SemaObjC/method-attributes.m

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=162628&r1=162627&r2=162628&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Fri Aug 24 18:50:13 2012
@@ -2435,26 +2435,49 @@
 }
 
 static inline
+unsigned countAlignAttr(const AttrVec &A) {
+  unsigned count=0;
+  for (AttrVec::const_iterator i = A.begin(), e = A.end(); i != e; ++i)
+    if ((*i)->getKind() == attr::Aligned)
+      ++count;
+  return count;
+}
+
+static inline
 bool containsInvalidMethodImplAttribute(ObjCMethodDecl *IMD,
                                         const AttrVec &A) {
   // If method is only declared in implementation (private method),
   // No need to issue any diagnostics on method definition with attributes.
   if (!IMD)
     return false;
-
+  
   // method declared in interface has no attribute. 
-  // But implementation has attributes. This is invalid
+  // But implementation has attributes. This is invalid.
+  // Except when implementation has 'Align' attribute which is
+  // immaterial to method declared in interface.
   if (!IMD->hasAttrs())
-    return true;
+    return (A.size() > countAlignAttr(A));
 
   const AttrVec &D = IMD->getAttrs();
-  if (D.size() != A.size())
-    return true;
 
+  unsigned countAlignOnImpl = countAlignAttr(A);
+  if (!countAlignOnImpl && (A.size() != D.size()))
+    return true;
+  else if (countAlignOnImpl) {
+    unsigned countAlignOnDecl = countAlignAttr(D);
+    if (countAlignOnDecl && (A.size() != D.size()))
+      return true;
+    else if (!countAlignOnDecl && 
+             ((A.size()-countAlignOnImpl) != D.size()))
+      return true;
+  }
+  
   // attributes on method declaration and definition must match exactly.
   // Note that we have at most a couple of attributes on methods, so this
   // n*n search is good enough.
   for (AttrVec::const_iterator i = A.begin(), e = A.end(); i != e; ++i) {
+    if ((*i)->getKind() == attr::Aligned)
+      continue;
     bool match = false;
     for (AttrVec::const_iterator i1 = D.begin(), e1 = D.end(); i1 != e1; ++i1) {
       if ((*i)->getKind() == (*i1)->getKind()) {
@@ -2465,6 +2488,7 @@
     if (!match)
       return true;
   }
+  
   return false;
 }
 

Modified: cfe/trunk/test/SemaObjC/method-attributes.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/method-attributes.m?rev=162628&r1=162627&r2=162628&view=diff
==============================================================================
--- cfe/trunk/test/SemaObjC/method-attributes.m (original)
+++ cfe/trunk/test/SemaObjC/method-attributes.m Fri Aug 24 18:50:13 2012
@@ -55,3 +55,32 @@
 - (IBAction)doSomething2:(id)sender {} // expected-warning {{attributes on method implementation and its declaration must match}}
 - (IBAction)doSomething3:(id)sender {}
 @end
+
+// rdar://11593375
+ at interface NSObject @end
+
+ at interface Test : NSObject
+-(id)method __attribute__((deprecated));
+-(id)method1;
+-(id)method2 __attribute__((aligned(16)));
+- (id) method3: (int)arg1 __attribute__((aligned(16)))  __attribute__((deprecated)) __attribute__((unavailable)); // expected-note {{method 'method3:' declared here}}
+- (id) method4: (int)arg1 __attribute__((aligned(16)))  __attribute__((deprecated)) __attribute__((unavailable)); 
+ at end
+
+ at implementation Test
+-(id)method __attribute__((aligned(16))) __attribute__((aligned(16))) __attribute__((deprecated)) {
+    return self;
+}
+-(id)method1 __attribute__((aligned(16))) {
+    return self;
+}
+-(id)method2 {
+    return self;
+}
+- (id) method3: (int)arg1 __attribute__((deprecated)) __attribute__((unavailable)) {  // expected-warning {{attributes on method implementation and its declaration must match}}
+        return self;
+}
+- (id) method4: (int)arg1 __attribute__((aligned(16))) __attribute__((deprecated)) __attribute__((unavailable)) {
+  return self;
+}
+ at end





More information about the cfe-commits mailing list