From 8590d86ea35d0dd04711edd6b8dc57fa9a528305 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Sat, 14 Apr 2012 17:13:08 +0000 Subject: [PATCH] objective-c modern translator: Make metadata definition for protocols static. // rdar://11248048 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154753 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Rewrite/RewriteModernObjC.cpp | 9 ++------- test/Rewriter/rewrite-modern-protocol-1.mm | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 7 deletions(-) create mode 100644 test/Rewriter/rewrite-modern-protocol-1.mm diff --git a/lib/Rewrite/RewriteModernObjC.cpp b/lib/Rewrite/RewriteModernObjC.cpp index b783c92dc7..b3d85a4ad3 100644 --- a/lib/Rewrite/RewriteModernObjC.cpp +++ b/lib/Rewrite/RewriteModernObjC.cpp @@ -5616,13 +5616,11 @@ void RewriteModernObjC::Initialize(ASTContext &context) { // These are currently generated. Preamble += "\n#pragma section(\".objc_classlist$B\", long, read, write)\n"; Preamble += "#pragma section(\".objc_catlist$B\", long, read, write)\n"; - Preamble += "#pragma section(\".objc_protolist$B\", long, read, write)\n"; Preamble += "#pragma section(\".objc_imageinfo$B\", long, read, write)\n"; Preamble += "#pragma section(\".objc_nlclslist$B\", long, read, write)\n"; Preamble += "#pragma section(\".objc_nlcatlist$B\", long, read, write)\n"; Preamble += "#pragma section(\".objc_protorefs$B\", long, read, write)\n"; // These are generated but not necessary for functionality. - Preamble += "#pragma section(\".datacoal_nt$B\", long, read, write)\n"; Preamble += "#pragma section(\".cat_cls_meth$B\", long, read, write)\n"; Preamble += "#pragma section(\".inst_meth$B\", long, read, write)\n"; Preamble += "#pragma section(\".cls_meth$B\", long, read, write)\n"; @@ -6593,7 +6591,7 @@ void RewriteModernObjC::RewriteObjCProtocolMetaData(ObjCProtocolDecl *PDecl, // Writer out root metadata for current protocol: struct _protocol_t Result += "\n"; if (LangOpts.MicrosoftExt) - Result += "__declspec(allocate(\".datacoal_nt$B\")) "; + Result += "static "; Result += "struct _protocol_t _OBJC_PROTOCOL_"; Result += PDecl->getNameAsString(); Result += " __attribute__ ((used, section (\"__DATA,__datacoal_nt,coalesced\"))) = {\n"; @@ -6651,11 +6649,8 @@ void RewriteModernObjC::RewriteObjCProtocolMetaData(ObjCProtocolDecl *PDecl, else Result += "\t0\n};\n"; - // Use this protocol meta-data to build protocol list table in section - // .objc_protolist$B - // Unspecified visibility means 'private extern'. if (LangOpts.MicrosoftExt) - Result += "__declspec(allocate(\".objc_protolist$B\")) "; + Result += "static "; Result += "struct _protocol_t *"; Result += "_OBJC_LABEL_PROTOCOL_$_"; Result += PDecl->getNameAsString(); Result += " = &_OBJC_PROTOCOL_"; Result += PDecl->getNameAsString(); diff --git a/test/Rewriter/rewrite-modern-protocol-1.mm b/test/Rewriter/rewrite-modern-protocol-1.mm new file mode 100644 index 0000000000..7b737fe61d --- /dev/null +++ b/test/Rewriter/rewrite-modern-protocol-1.mm @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -E %s -o %t.mm +// RUN: %clang_cc1 -x objective-c++ -fblocks -fms-extensions -rewrite-objc %t.mm -o - | FileCheck %s +// rdar://11248048 + +@protocol NSCopying @end + +@interface INTF +@end + +@implementation INTF @end + +// CHECK: static struct _protocol_t _OBJC_PROTOCOL_NSCopying +// CHECK: static struct _protocol_t *_OBJC_LABEL_PROTOCOL_$_NSCopying = &_OBJC_PROTOCOL_NSCopying; +