[cfe-commits] r154360 - in /cfe/trunk: lib/Rewrite/RewriteModernObjC.cpp test/Rewriter/objc-modern-implicit-cast.mm
Fariborz Jahanian
fjahanian at apple.com
Mon Apr 9 17:08:18 PDT 2012
Author: fjahanian
Date: Mon Apr 9 19:08:18 2012
New Revision: 154360
URL: http://llvm.org/viewvc/llvm-project?rev=154360&view=rev
Log:
objective-c modern translator: rewriting specific
implicit casts which is needed to produce good c++
code. // rdar://11202764
Added:
cfe/trunk/test/Rewriter/objc-modern-implicit-cast.mm
Modified:
cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp
Modified: cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp?rev=154360&r1=154359&r2=154360&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp (original)
+++ cfe/trunk/lib/Rewrite/RewriteModernObjC.cpp Mon Apr 9 19:08:18 2012
@@ -330,6 +330,7 @@
Stmt *RewriteBreakStmt(BreakStmt *S);
Stmt *RewriteContinueStmt(ContinueStmt *S);
void RewriteCastExpr(CStyleCastExpr *CE);
+ void RewriteImplicitCastObjCExpr(CastExpr *IE);
void RewriteLinkageSpec(LinkageSpecDecl *LSD);
// Block rewriting.
@@ -4459,6 +4460,24 @@
return;
}
+void RewriteModernObjC::RewriteImplicitCastObjCExpr(CastExpr *IC) {
+ CastKind CastKind = IC->getCastKind();
+
+ 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);
+ }
+ return;
+}
+
void RewriteModernObjC::RewriteBlockPointerFunctionArgs(FunctionDecl *FD) {
SourceLocation DeclLoc = FD->getLocation();
unsigned parenCount = 0;
@@ -5336,6 +5355,9 @@
if (CStyleCastExpr *CE = dyn_cast<CStyleCastExpr>(S)) {
RewriteCastExpr(CE);
}
+ 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(),
Added: cfe/trunk/test/Rewriter/objc-modern-implicit-cast.mm
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Rewriter/objc-modern-implicit-cast.mm?rev=154360&view=auto
==============================================================================
--- cfe/trunk/test/Rewriter/objc-modern-implicit-cast.mm (added)
+++ cfe/trunk/test/Rewriter/objc-modern-implicit-cast.mm Mon Apr 9 19:08:18 2012
@@ -0,0 +1,33 @@
+// 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
+
+typedef void(^BL)(void);
+
+id return_id(void(^block)(void)) {
+ return block;
+}
+
+BL return_block(id obj) {
+ return obj;
+}
+
+int main()
+{
+ void(^block)(void);
+ id obj;
+ block = obj; // AnyPointerToBlockPointerCast
+ obj = block; // BlockPointerToObjCPointerCast
+
+ id obj1 = block;
+
+ void(^block1)(void) = obj1;
+
+ return_id(block1);
+
+ return_id(obj1);
+
+ return_block(block1);
+
+ return_block(obj1);
+}
More information about the cfe-commits
mailing list