]> granicus.if.org Git - clang/commitdiff
modern objective-c translator: translation of implicit
authorFariborz Jahanian <fjahanian@apple.com>
Mon, 16 Apr 2012 22:14:01 +0000 (22:14 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Mon, 16 Apr 2012 22:14:01 +0000 (22:14 +0000)
cast to/from block pointer types. // rdar://11202764
Also, many more modern translator tests.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154869 91177308-0d34-0410-b5e6-96231b3b80d8

15 files changed:
lib/Rewrite/RewriteModernObjC.cpp
test/Rewriter/blockcast3.mm
test/Rewriter/instancetype-test.mm
test/Rewriter/objc-modern-implicit-cast.mm
test/Rewriter/rewrite-block-consts.mm
test/Rewriter/rewrite-block-literal.mm
test/Rewriter/rewrite-block-pointer.mm
test/Rewriter/rewrite-byref-in-nested-blocks.mm
test/Rewriter/rewrite-elaborated-type.mm
test/Rewriter/rewrite-foreach-in-block.mm
test/Rewriter/rewrite-nested-blocks-1.mm
test/Rewriter/rewrite-nested-blocks-2.mm
test/Rewriter/rewrite-nested-blocks.mm
test/Rewriter/rewrite-nested-property-in-blocks.mm
test/Rewriter/rewrite-unique-block-api.mm

index b3d85a4ad39f8c32aad7da66e2dac98d79eb9902..5d124aba9f2c9c44f8acd9f6cd1a76d1f0498789 100644 (file)
@@ -4460,19 +4460,18 @@ void RewriteModernObjC::RewriteCastExpr(CStyleCastExpr *CE) {
 
 void RewriteModernObjC::RewriteImplicitCastObjCExpr(CastExpr *IC) {
   CastKind CastKind = IC->getCastKind();
+  if (CastKind != CK_BlockPointerToObjCPointerCast &&
+      CastKind != CK_AnyPointerToBlockPointerCast)
+    return;
   
-  if (CastKind == CK_BlockPointerToObjCPointerCast) {
-    CStyleCastExpr * CastExpr = 
-      NoTypeInfoCStyleCastExpr(Context, IC->getType(), CK_BitCast, IC);
-    ReplaceStmt(IC, CastExpr);
-  }
-  else if (CastKind == CK_AnyPointerToBlockPointerCast) {
-    QualType BlockT = IC->getType();
-    (void)convertBlockPointerToFunctionPointer(BlockT);
-    CStyleCastExpr * CastExpr = 
-      NoTypeInfoCStyleCastExpr(Context, BlockT, CK_BitCast, IC);
-    ReplaceStmt(IC, CastExpr);
-  }
+  QualType QT = IC->getType();
+  (void)convertBlockPointerToFunctionPointer(QT);
+  std::string TypeString(QT.getAsString(Context->getPrintingPolicy()));
+  std::string Str = "(";
+  Str += TypeString;
+  Str += ")";
+  InsertText(IC->getSubExpr()->getLocStart(), &Str[0], Str.size());
+
   return;
 }
 
@@ -5357,12 +5356,10 @@ Stmt *RewriteModernObjC::RewriteFunctionBodyOrGlobalInitializer(Stmt *S) {
   if (CStyleCastExpr *CE = dyn_cast<CStyleCastExpr>(S)) {
     RewriteCastExpr(CE);
   }
-#if 0
-  // FIXME. Cannot safely rewrite ImplicitCasts. This is the 2nd failed
-  // attempt: (id)((__typeof(z))_Block_copy((const void *)(z)));
   if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(S)) {
     RewriteImplicitCastObjCExpr(ICE);
   }
+#if 0
 
   if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(S)) {
     CastExpr *Replacement = new (Context) CastExpr(ICE->getType(),
index 8b35528cfbeb23a033a150f8ca3fa5f0fdb13c7f..ceafcff3b0916e41e5f75506ec9965418436d15c 100644 (file)
@@ -1,5 +1,8 @@
-// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp
+// RUN: %clang_cc1 -E %s -o %t.mm
+// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %t.mm -o %t-rw.cpp
 // RUN: FileCheck -check-prefix LP --input-file=%t-rw.cpp %s
+// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %t.mm -o %t-modern-rw.cpp
+// RUN: FileCheck -check-prefix LP --input-file=%t-modern-rw.cpp %s
 // radar 7607781
 
 typedef struct {
@@ -20,4 +23,4 @@ void f(const void **arg) {
                });
 }
 
-// CHECK-LP: (struct __Block_byref_q_0 *)&q
+// CHECK-LP: (__Block_byref_q_0 *)&q
index a92a3f7f7b0065047d97ce33bed12c74db1fae64..788505562c39306f3d2c0572f54296de682a1e5b 100644 (file)
@@ -1,5 +1,7 @@
-// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp
-// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
+// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp
+// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
+// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fms-extensions -rewrite-objc %s -o %t-modern-rw.cpp
+// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-modern-rw.cpp
 
 void *sel_registerName(const char *);
 
index 33c5b7388262c7fe131da157601d641ba3e25b5c..e6121991e56b0f7e59ec33c9f25e3ef3b2cc3099 100644 (file)
@@ -1,7 +1,6 @@
 // RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %s -o %t-rw.cpp
 // RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
 // rdar://11202764
-// XFAIL: *
 
 typedef void(^BL)(void);
 
index fca10edd4f61127e3db843ba86e80915cf30d879..1d6de8cd6abc290c102e377af1d77ad4e54b844a 100644 (file)
@@ -1,5 +1,5 @@
 // RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp
-// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
+// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D__block="" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
 // rdar:// 8243071
 
 void x(int y) {}
index 732d0b9f8db9ddf709a47865473122c490639522..083312e79dd7e31aadd62d6e8dbb8da910b939f3 100644 (file)
@@ -1,7 +1,9 @@
 // RUN: %clang_cc1 -E %s -o %t.mm
 // RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %t.mm -o - | FileCheck %s
 // RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp
-// RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
+// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
+// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-modern-rw.cpp
+// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"Class=void*" -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-modern-rw.cpp
 
 // rdar: // 11006566
 
index 4838b74439ff5db5db3f496474efa94539204622..58407a7ac5cf68ba69b94c7371d673e8965e838f 100644 (file)
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp
 // RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
+// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-modern-rw.cpp
+// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-modern-rw.cpp
 // radar 7638400
 
 typedef void * id;
index b1ff46b5ce4a8e3e858279ad5d5c381d86d24a6b..a65938345637c2931c539282fd88ace65754f41e 100644 (file)
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp
 // RUN: %clang_cc1 -fsyntax-only -fblocks -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
+// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-modern-rw.cpp
+// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-modern-rw.cpp
 // radar 7692350
 
 void f(void (^block)(void));
index bef56b93b9b457f1a59db5be9ccce63fef7814a7..a0c7e43b0429b06731d91d9e676f35a6fce36262 100644 (file)
@@ -1,5 +1,7 @@
-// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp
+// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp
 // RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D_Bool=bool -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
+// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fms-extensions -rewrite-objc %s -o %t-modern-rw.cpp
+// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D_Bool=bool -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-modern-rw.cpp
 // radar 8143056
 
 typedef struct objc_class *Class;
@@ -29,6 +31,8 @@ struct NSSlice {
   }
 @end
 
+@interface I1 @end
+
 @implementation I1
 + (struct s1 *) f0 {
   return 0;
index d0a8728310e9a6855ee9099cfcde5fb2e35de287..fd34212d672e6a4314653f2f228340f7cc1ef5d4 100644 (file)
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp
 // RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
+// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-modern-rw.cpp
+// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-modern-rw.cpp
 // rdar:// 9878420
 
 void objc_enumerationMutation(id);
index 672486b1f9e2d4ae0cce2e49027339d921f6e533..25b17cfce179ca7ad5ec37695802f4dfd6f59f6f 100644 (file)
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %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
+// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-modern-rw.cpp
+// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-modern-rw.cpp
 // radar 7696893
 
 void *sel_registerName(const char *);
index 1555767086695b17e4a4d767e1f98c2277047b07..d1513f3a5fa021f77dd886d390b10ad5eae32e9e 100644 (file)
@@ -1,6 +1,9 @@
 // RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %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
 // grep "static void __FUNC_block_copy_" %t-rw.cpp | count 2
+// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-modern-rw.cpp
+// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"id=void*" -D"SEL=void*" -D"__declspec(X)=" %t-modern-rw.cpp
+// grep "static void __FUNC_block_copy_" %t-modern-rw.cpp | count 2
 // rdar://8499592
 
 void Outer(void (^bk)());
index 6c860ef7e7209d314875e8cd5f13940f70d39d94..d492afa18d49ffb7a44b208e0a368d8d4b9e05fb 100644 (file)
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp
 // RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
+// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-modern-rw.cpp
+// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-modern-rw.cpp
 // radar 7682149
 
 
index 6a03d7319d68414a07644845d7d1dceb6b699f03..7f9361ed0788dfdc2075344ec90d59a33e2484e6 100755 (executable)
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp
 // RUN: %clang_cc1 -fsyntax-only -fms-extensions -Wno-address-of-temporary -Did="void *" -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
+// RUN: %clang_cc1 -x objective-c++ -Wno-return-type -fblocks -fms-extensions -rewrite-objc %s -o %t-modern-rw.cpp
+// RUN: %clang_cc1 -fsyntax-only -fms-extensions -Wno-address-of-temporary -Did="void *" -D"SEL=void*" -D"__declspec(X)=" %t-modern-rw.cpp
 // radar 8608293
 
 void *sel_registerName(const char *);
index 2c0c4a9094dbb7e03dad4922234d42688dc97fe8..1dcc1b67fe7bda7572e1ee44b8a48e182286e110 100644 (file)
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc -fobjc-fragile-abi %s -o %t-rw.cpp
 // RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-rw.cpp
+// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %s -o %t-modern-rw.cpp
+// RUN: %clang_cc1 -fsyntax-only -Wno-address-of-temporary -D"SEL=void*" -D"__declspec(X)=" %t-modern-rw.cpp
 // radar 7630551
 
 void f(void (^b)(char c));