Skip to content

Commit 986a01f

Browse files
dpaoliellosivadeilra
authored andcommitted
Apply 0031-inlinecomdat.patch
1 parent 3887953 commit 986a01f

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6310,6 +6310,19 @@ void CodeGenModule::EmitGlobalFunctionDefinition(GlobalDecl GD,
63106310
auto *Fn = cast<llvm::Function>(GV);
63116311
setFunctionLinkage(GD, Fn);
63126312

6313+
// MSVC generates a COMDAT for other compilation units for any used inline.
6314+
if (auto const *FD = dyn_cast<const FunctionDecl>(D)) {
6315+
if (getTriple().isWindowsMSVCEnvironment() && (FD->getLanguageLinkage() == CLanguageLinkage)) {
6316+
auto CheckRedeclForInline = [](const FunctionDecl *Redecl) {
6317+
return Redecl->isInlineSpecified();
6318+
};
6319+
6320+
if (any_of(FD->redecls(), CheckRedeclForInline)) {
6321+
Fn->setLinkage(llvm::Function::ExternalLinkage);
6322+
}
6323+
}
6324+
}
6325+
63136326
// FIXME: this is redundant with part of setFunctionDefinitionAttributes
63146327
setGVProperties(Fn, GD);
63156328

0 commit comments

Comments
 (0)