From d38951acff28b72b0709370659121a0f74379704 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Fri, 22 Nov 2013 18:43:41 +0000 Subject: [PATCH] ObjectiveC modern translator. Fixes a translation bug tranalation @protocol expression. // rdar://15517895 llvm-svn: 195480 --- .../Rewrite/Frontend/RewriteModernObjC.cpp | 9 +++---- clang/test/Rewriter/protocol-rewrite-1.m | 27 ++++++++++++++++++- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/clang/lib/Rewrite/Frontend/RewriteModernObjC.cpp b/clang/lib/Rewrite/Frontend/RewriteModernObjC.cpp index ae33ac816e3d..a248675d771c 100644 --- a/clang/lib/Rewrite/Frontend/RewriteModernObjC.cpp +++ b/clang/lib/Rewrite/Frontend/RewriteModernObjC.cpp @@ -3733,12 +3733,9 @@ Stmt *RewriteModernObjC::RewriteObjCProtocolExpr(ObjCProtocolExpr *Exp) { SC_Extern); DeclRefExpr *DRE = new (Context) DeclRefExpr(VD, false, getProtocolType(), VK_LValue, SourceLocation()); - Expr *DerefExpr = new (Context) UnaryOperator(DRE, UO_AddrOf, - Context->getPointerType(DRE->getType()), - VK_RValue, OK_Ordinary, SourceLocation()); - CastExpr *castExpr = NoTypeInfoCStyleCastExpr(Context, DerefExpr->getType(), - CK_BitCast, - DerefExpr); + CastExpr *castExpr = + NoTypeInfoCStyleCastExpr( + Context, Context->getPointerType(DRE->getType()), CK_BitCast, DRE); ReplaceStmt(Exp, castExpr); ProtocolExprDecls.insert(Exp->getProtocol()->getCanonicalDecl()); // delete Exp; leak for now, see RewritePropertyOrImplicitSetter() usage for more info. diff --git a/clang/test/Rewriter/protocol-rewrite-1.m b/clang/test/Rewriter/protocol-rewrite-1.m index 541b7ee9baba..0c5104fbb56a 100644 --- a/clang/test/Rewriter/protocol-rewrite-1.m +++ b/clang/test/Rewriter/protocol-rewrite-1.m @@ -1,4 +1,7 @@ -// RUN: %clang_cc1 -rewrite-objc -fobjc-runtime=macosx-fragile-10.5 %s -o - +// RUN: %clang_cc1 -x objective-c -Wno-objc-root-class -fms-extensions -rewrite-objc %s -o %t-rw.cpp +// RUN: FileCheck --input-file=%t-rw.cpp %s +// rdar://9846759 +// rdar://15517895 typedef struct MyWidget { int a; @@ -46,3 +49,25 @@ int main(void) { return 0; } + +// rdar://15517895 +@class NSObject; + +@interface NSProtocolChecker ++ (id)protocolCheckerWithTarget:(NSObject *)anObject protocol:(Protocol *)aProtocol; +@end + +@protocol NSConnectionVersionedProtocol +@end + + +@interface NSConnection @end + +@implementation NSConnection +- (void) Meth { + [NSProtocolChecker protocolCheckerWithTarget:0 protocol:@protocol(NSConnectionVersionedProtocol)]; +} +@end + +// CHECK: static struct _protocol_t *_OBJC_PROTOCOL_REFERENCE_$_NSConnectionVersionedProtocol = &_OBJC_PROTOCOL_NSConnectionVersionedProtocol +// CHECK: sel_registerName("protocolCheckerWithTarget:protocol:"), (NSObject *)0, (Protocol *)_OBJC_PROTOCOL_REFERENCE_$_NSConnectionVersionedProtocol