]> granicus.if.org Git - clang/commitdiff
Objective-C. Fixes a regression when figuring out linkage
authorFariborz Jahanian <fjahanian@apple.com>
Mon, 3 Mar 2014 21:53:57 +0000 (21:53 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Mon, 3 Mar 2014 21:53:57 +0000 (21:53 +0000)
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
test/CodeGenObjC/forward-protocol-metadata-symbols.m [new file with mode: 0644]

index 044bc18c1e7c9e0bc46835fe9e8ebc560a625699..7f2432c08c7be92814f13a6c0e31342847bdc0eb 100644 (file)
@@ -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 (file)
index 0000000..c28adb3
--- /dev/null
@@ -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 <P0>
++(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