diff options
author | Saleem Abdulrasool <compnerd@compnerd.org> | 2017-06-29 00:54:44 +0000 |
---|---|---|
committer | Saleem Abdulrasool <compnerd@compnerd.org> | 2017-06-29 00:54:44 +0000 |
commit | 9f83f3b2511d6b7b396d9f98a7cda4dab4d42a34 (patch) | |
tree | c1a143fb79830cead84d2c9d62908fbc082bace5 | |
parent | 2af2fd5f76cc57ac9a42338a889d669bb67dd01c (diff) | |
download | bcm5719-llvm-9f83f3b2511d6b7b396d9f98a7cda4dab4d42a34.tar.gz bcm5719-llvm-9f83f3b2511d6b7b396d9f98a7cda4dab4d42a34.zip |
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
-rw-r--r-- | clang/lib/CodeGen/CGObjCMac.cpp | 11 | ||||
-rw-r--r-- | clang/test/CodeGenObjC/protocol-comdat.m | 8 |
2 files changed, 13 insertions, 6 deletions
diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp index 7976c53d9e9..224d2d6606a 100644 --- a/clang/lib/CodeGen/CGObjCMac.cpp +++ b/clang/lib/CodeGen/CGObjCMac.cpp @@ -6381,16 +6381,15 @@ llvm::Value *CGObjCNonFragileABIMac::GenerateProtocolRef(CodeGenFunction &CGF, llvm::GlobalVariable *PTGV = CGM.getModule().getGlobalVariable(ProtocolName); if (PTGV) return CGF.Builder.CreateAlignedLoad(PTGV, Align); - PTGV = new llvm::GlobalVariable( - CGM.getModule(), - Init->getType(), false, - llvm::GlobalValue::WeakAnyLinkage, - Init, - ProtocolName); + PTGV = new llvm::GlobalVariable(CGM.getModule(), Init->getType(), false, + llvm::GlobalValue::WeakAnyLinkage, Init, + ProtocolName); PTGV->setSection(GetSectionName("__objc_protorefs", "coalesced,no_dead_strip")); PTGV->setVisibility(llvm::GlobalValue::HiddenVisibility); PTGV->setAlignment(Align.getQuantity()); + if (!CGM.getTriple().isOSBinFormatMachO()) + PTGV->setComdat(CGM.getModule().getOrInsertComdat(ProtocolName)); CGM.addCompilerUsedGlobal(PTGV); return CGF.Builder.CreateAlignedLoad(PTGV, Align); } diff --git a/clang/test/CodeGenObjC/protocol-comdat.m b/clang/test/CodeGenObjC/protocol-comdat.m index 65e1b9fa2c8..a19ba8cf35d 100644 --- a/clang/test/CodeGenObjC/protocol-comdat.m +++ b/clang/test/CodeGenObjC/protocol-comdat.m @@ -4,6 +4,9 @@ - (void) method; @end +@protocol Q; +@protocol R; + @interface I<P> @end @@ -11,9 +14,14 @@ - (void) method { } @end +_Bool f(void) { + return @protocol(Q) == @protocol(R); +} // CHECK: $"\01l_OBJC_PROTOCOL_$_P" = comdat any // CHECK: $"\01l_OBJC_LABEL_PROTOCOL_$_P" = comdat any +// CHECK: $"\01l_OBJC_PROTOCOL_REFERENCE_$_Q" = comdat any +// CHECK: $"\01l_OBJC_PROTOCOL_REFERENCE_$_R" = comdat any // CHECK: @"\01l_OBJC_PROTOCOL_$_P" = {{.*}}, comdat // CHECK: @"\01l_OBJC_LABEL_PROTOCOL_$_P" = {{.*}}, comdat |