[cfe-commits] r126435 - in /cfe/trunk: lib/Rewrite/RewriteObjC.cpp test/Rewriter/rewrite-foreach-5.m test/Rewriter/rewrite-foreach-6.m test/Rewriter/rewrite-foreach-protocol-id.m

Fariborz Jahanian fjahanian at apple.com
Thu Feb 24 13:29:21 PST 2011


Author: fjahanian
Date: Thu Feb 24 15:29:21 2011
New Revision: 126435

URL: http://llvm.org/viewvc/llvm-project?rev=126435&view=rev
Log:
Fix a rewrite bug. // rdar://9039342


Added:
    cfe/trunk/test/Rewriter/rewrite-foreach-protocol-id.m
Modified:
    cfe/trunk/lib/Rewrite/RewriteObjC.cpp
    cfe/trunk/test/Rewriter/rewrite-foreach-5.m
    cfe/trunk/test/Rewriter/rewrite-foreach-6.m

Modified: cfe/trunk/lib/Rewrite/RewriteObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/RewriteObjC.cpp?rev=126435&r1=126434&r2=126435&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/RewriteObjC.cpp (original)
+++ cfe/trunk/lib/Rewrite/RewriteObjC.cpp Thu Feb 24 15:29:21 2011
@@ -298,6 +298,7 @@
     Stmt *RewriteObjCThrowStmt(ObjCAtThrowStmt *S);
     Stmt *RewriteObjCForCollectionStmt(ObjCForCollectionStmt *S,
                                        SourceLocation OrigEnd);
+    bool IsDeclStmtInForeachHeader(DeclStmt *DS);
     CallExpr *SynthesizeCallToFunctionDecl(FunctionDecl *FD,
                                       Expr **args, unsigned nargs,
                                       SourceLocation StartLoc=SourceLocation(),
@@ -5459,6 +5460,13 @@
   return NewRep;
 }
 
+bool RewriteObjC::IsDeclStmtInForeachHeader(DeclStmt *DS) {
+  if (const ObjCForCollectionStmt * CS = 
+      dyn_cast<ObjCForCollectionStmt>(Stmts.back()))
+        return CS->getElement() == DS;
+  return false;
+}
+
 //===----------------------------------------------------------------------===//
 // Function Body / Expression rewriting
 //===----------------------------------------------------------------------===//
@@ -5681,7 +5689,7 @@
     //   for (id <FooProtocol> index in someArray) ;
     // This is because RewriteObjCForCollectionStmt() does textual rewriting 
     // and it depends on the original text locations/positions.
-    if (Stmts.empty() || !isa<ObjCForCollectionStmt>(Stmts.back()))
+    if (Stmts.empty() || !IsDeclStmtInForeachHeader(DS))
       RewriteObjCQualifiedInterfaceTypes(*DS->decl_begin());
 
     // Blocks rewrite rules.

Modified: cfe/trunk/test/Rewriter/rewrite-foreach-5.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/rewrite-foreach-5.m?rev=126435&r1=126434&r2=126435&view=diff
==============================================================================
--- cfe/trunk/test/Rewriter/rewrite-foreach-5.m (original)
+++ cfe/trunk/test/Rewriter/rewrite-foreach-5.m Thu Feb 24 15:29:21 2011
@@ -1,4 +1,8 @@
-// RUN: %clang_cc1 -rewrite-objc %s -o -
+// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp
+// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
+
+void *sel_registerName(const char *);
+void objc_enumerationMutation(id);
 
 @interface MyList
 - (id) allKeys;

Modified: cfe/trunk/test/Rewriter/rewrite-foreach-6.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/rewrite-foreach-6.m?rev=126435&r1=126434&r2=126435&view=diff
==============================================================================
--- cfe/trunk/test/Rewriter/rewrite-foreach-6.m (original)
+++ cfe/trunk/test/Rewriter/rewrite-foreach-6.m Thu Feb 24 15:29:21 2011
@@ -1,8 +1,12 @@
-// RUN: %clang_cc1 %s -rewrite-objc -o -
+// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp
+// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
 // rdar://5716356
 // FIXME: Should be able to pipe into clang, but code is not
 // yet correct for other reasons: rdar://5716940
 
+void *sel_registerName(const char *);
+void objc_enumerationMutation(id);
+
 @class NSNotification;
 @class NSMutableArray;
 

Added: cfe/trunk/test/Rewriter/rewrite-foreach-protocol-id.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/rewrite-foreach-protocol-id.m?rev=126435&view=auto
==============================================================================
--- cfe/trunk/test/Rewriter/rewrite-foreach-protocol-id.m (added)
+++ cfe/trunk/test/Rewriter/rewrite-foreach-protocol-id.m Thu Feb 24 15:29:21 2011
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp
+// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
+// rdar:// 9039342
+
+void *sel_registerName(const char *);
+void objc_enumerationMutation(id);
+
+ at protocol CoreDAVLeafDataPayload @end
+
+ at class NSString;
+
+ at interface CoreDAVAction
+- (id) context;
+ at end
+
+ at interface I
+{
+  id uuidsToAddActions;
+}
+ at end
+
+ at implementation I
+- (void) Meth {
+  for (id<CoreDAVLeafDataPayload> uuid in uuidsToAddActions) {
+    CoreDAVAction *action = 0;
+    id <CoreDAVLeafDataPayload> payload = [action context];
+  }
+}
+ at end





More information about the cfe-commits mailing list