]> granicus.if.org Git - clang/commitdiff
Fix a rewrite bug. // rdar://9039342
authorFariborz Jahanian <fjahanian@apple.com>
Thu, 24 Feb 2011 21:29:21 +0000 (21:29 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Thu, 24 Feb 2011 21:29:21 +0000 (21:29 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126435 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Rewrite/RewriteObjC.cpp
test/Rewriter/rewrite-foreach-5.m
test/Rewriter/rewrite-foreach-6.m
test/Rewriter/rewrite-foreach-protocol-id.m [new file with mode: 0644]

index 875a0c7a84c531aa967886d6a88c5f8092472455..78e370b97743991b03ba8242b461ce6a865849dc 100644 (file)
@@ -298,6 +298,7 @@ namespace {
     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 @@ Stmt *RewriteObjC::SynthBlockInitExpr(BlockExpr *Exp,
   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 @@ Stmt *RewriteObjC::RewriteFunctionBodyOrGlobalInitializer(Stmt *S) {
     //   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.
index adfd7f837841628efcdf4162e9029beeb0ee1eb3..7baccc37898cb1f6801a155aeb58ade836bf8708 100644 (file)
@@ -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;
index 2aa19aecb82c5be25c6ad4c40a489422ebe48ee4..96b472a60eef63e8abb83ef3e6184d483767c061 100644 (file)
@@ -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;
 
diff --git a/test/Rewriter/rewrite-foreach-protocol-id.m b/test/Rewriter/rewrite-foreach-protocol-id.m
new file mode 100644 (file)
index 0000000..85d0d0d
--- /dev/null
@@ -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);
+
+@protocol CoreDAVLeafDataPayload @end
+
+@class NSString;
+
+@interface CoreDAVAction
+- (id) context;
+@end
+
+@interface I
+{
+  id uuidsToAddActions;
+}
+@end
+
+@implementation I
+- (void) Meth {
+  for (id<CoreDAVLeafDataPayload> uuid in uuidsToAddActions) {
+    CoreDAVAction *action = 0;
+    id <CoreDAVLeafDataPayload> payload = [action context];
+  }
+}
+@end