From: Fariborz Jahanian Date: Fri, 22 Nov 2013 18:43:41 +0000 (+0000) Subject: ObjectiveC modern translator. Fixes a translation bug X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9f8ce20da1c4abeadfab0baefed51e2c7111b82b;p=clang ObjectiveC modern translator. Fixes a translation bug tranalation @protocol expression. // rdar://15517895 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@195480 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Rewrite/Frontend/RewriteModernObjC.cpp b/lib/Rewrite/Frontend/RewriteModernObjC.cpp index ae33ac816e..a248675d77 100644 --- a/lib/Rewrite/Frontend/RewriteModernObjC.cpp +++ b/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/test/Rewriter/protocol-rewrite-1.m b/test/Rewriter/protocol-rewrite-1.m index 541b7ee9ba..0c5104fbb5 100644 --- a/test/Rewriter/protocol-rewrite-1.m +++ b/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