Skip to content

Commit 601645c

Browse files
committed
[clang] Fix FIXME in dynamic initializer emission, NFCI
This potentially affects platforms that support comdats other than ELF, COFF, or wasm, but that is the intention of the FIXME, and if they don't want this behavior, they probably shouldn't advertise comdat support.
1 parent 2092f35 commit 601645c

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

clang/lib/CodeGen/CGDeclCXX.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -640,13 +640,13 @@ CodeGenModule::EmitCXXGlobalVarDeclInitFunc(const VarDecl *D,
640640
addUsedGlobal(COMDATKey);
641641
}
642642

643-
// If we used a COMDAT key for the global ctor, the init function can be
644-
// discarded if the global ctor entry is discarded.
645-
// FIXME: Do we need to restrict this to ELF and Wasm?
643+
// If comdats are in use and supported, place the initializer function into
644+
// the comdat group of the global. In the MS ABI, initializers are mangled
645+
// and have their own comdat, so we don't include them in the group for
646+
// consistency with MSVC.
646647
llvm::Comdat *C = Addr->getComdat();
647-
if (COMDATKey && C &&
648-
(getTarget().getTriple().isOSBinFormatELF() ||
649-
getTarget().getTriple().isOSBinFormatWasm())) {
648+
if (COMDATKey && C && getTriple().supportsCOMDAT() &&
649+
!getTarget().getCXXABI().isMicrosoft()) {
650650
Fn->setComdat(C);
651651
}
652652
} else {

0 commit comments

Comments
 (0)