From 06c0167a16cfa5e2b063bf60bf70c074a794b44d Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Mon, 3 Mar 2014 21:53:57 +0000 Subject: [PATCH] Objective-C. Fixes a regression when figuring out linkage for metadata symbols for forward referenced protocols which are never defined. // rdar://16203115 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@202761 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGObjCMac.cpp | 3 ++- .../forward-protocol-metadata-symbols.m | 24 +++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 test/CodeGenObjC/forward-protocol-metadata-symbols.m diff --git a/lib/CodeGen/CGObjCMac.cpp b/lib/CodeGen/CGObjCMac.cpp index 044bc18c1e..7f2432c08c 100644 --- a/lib/CodeGen/CGObjCMac.cpp +++ b/lib/CodeGen/CGObjCMac.cpp @@ -2660,6 +2660,7 @@ llvm::Constant *CGObjCMac::GetOrEmitProtocol(const ObjCProtocolDecl *PD) { if (Entry) { // Already created, fix the linkage and update the initializer. + Entry->setLinkage(llvm::GlobalValue::PrivateLinkage); Entry->setInitializer(Init); } else { Entry = @@ -6357,7 +6358,7 @@ llvm::Constant *CGObjCNonFragileABIMac::GetOrEmitProtocol( if (Entry) { // Already created, fix the linkage and update the initializer. - assert(Entry->getLinkage() == llvm::GlobalValue::WeakAnyLinkage); + Entry->setLinkage(llvm::GlobalValue::WeakAnyLinkage); Entry->setInitializer(Init); } else { Entry = diff --git a/test/CodeGenObjC/forward-protocol-metadata-symbols.m b/test/CodeGenObjC/forward-protocol-metadata-symbols.m new file mode 100644 index 0000000000..c28adb3f8a --- /dev/null +++ b/test/CodeGenObjC/forward-protocol-metadata-symbols.m @@ -0,0 +1,24 @@ +// RUN: %clang_cc1 -emit-llvm -x objective-c %s -o - | FileCheck %s +// rdar://16203115 + +@interface NSObject @end + +@protocol P0; + +@interface A : NSObject ++(Class) getClass; +@end + +@implementation A ++(Class) getClass { return self; } +@end + +int main() { + Protocol *P0 = @protocol(P0); + return 0; +} + +// CHECK: @"\01l_OBJC_PROTOCOL_$_P0" = weak hidden global +// CHECK: @"\01l_OBJC_CLASS_PROTOCOLS_$_A" = private global +// CHECK: @"\01l_OBJC_LABEL_PROTOCOL_$_P0" = weak hidden global +// CHECK: @"\01l_OBJC_PROTOCOL_REFERENCE_$_P0" = weak hidden global -- 2.40.0