Skip to content

Commit 9f83f3b

Browse files
committed
CodeGen: handle missed case of COMDAT handling
When Protocol references are constructed, we need to add the reference symbol to a COMDAT group on non-MachO object file formats (MachO handles this by having a coalesced attribute). This adds the missing case. llvm-svn: 306622
1 parent 2af2fd5 commit 9f83f3b

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

clang/lib/CodeGen/CGObjCMac.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6381,16 +6381,15 @@ llvm::Value *CGObjCNonFragileABIMac::GenerateProtocolRef(CodeGenFunction &CGF,
63816381
llvm::GlobalVariable *PTGV = CGM.getModule().getGlobalVariable(ProtocolName);
63826382
if (PTGV)
63836383
return CGF.Builder.CreateAlignedLoad(PTGV, Align);
6384-
PTGV = new llvm::GlobalVariable(
6385-
CGM.getModule(),
6386-
Init->getType(), false,
6387-
llvm::GlobalValue::WeakAnyLinkage,
6388-
Init,
6389-
ProtocolName);
6384+
PTGV = new llvm::GlobalVariable(CGM.getModule(), Init->getType(), false,
6385+
llvm::GlobalValue::WeakAnyLinkage, Init,
6386+
ProtocolName);
63906387
PTGV->setSection(GetSectionName("__objc_protorefs",
63916388
"coalesced,no_dead_strip"));
63926389
PTGV->setVisibility(llvm::GlobalValue::HiddenVisibility);
63936390
PTGV->setAlignment(Align.getQuantity());
6391+
if (!CGM.getTriple().isOSBinFormatMachO())
6392+
PTGV->setComdat(CGM.getModule().getOrInsertComdat(ProtocolName));
63946393
CGM.addCompilerUsedGlobal(PTGV);
63956394
return CGF.Builder.CreateAlignedLoad(PTGV, Align);
63966395
}

clang/test/CodeGenObjC/protocol-comdat.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,24 @@ @protocol P
44
- (void) method;
55
@end
66

7+
@protocol Q;
8+
@protocol R;
9+
710
@interface I<P>
811
@end
912

1013
@implementation I
1114
- (void) method { }
1215
@end
1316

17+
_Bool f(void) {
18+
return @protocol(Q) == @protocol(R);
19+
}
1420

1521
// CHECK: $"\01l_OBJC_PROTOCOL_$_P" = comdat any
1622
// CHECK: $"\01l_OBJC_LABEL_PROTOCOL_$_P" = comdat any
23+
// CHECK: $"\01l_OBJC_PROTOCOL_REFERENCE_$_Q" = comdat any
24+
// CHECK: $"\01l_OBJC_PROTOCOL_REFERENCE_$_R" = comdat any
1725

1826
// CHECK: @"\01l_OBJC_PROTOCOL_$_P" = {{.*}}, comdat
1927
// CHECK: @"\01l_OBJC_LABEL_PROTOCOL_$_P" = {{.*}}, comdat

0 commit comments

Comments
 (0)