[modules ts] Do not emit strong function definitions from the module interface unit in every user.
llvm-svn: 307232
diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp b/clang/lib/Serialization/ASTWriterDecl.cpp
index 2d648cb..ec21ca2 100644
--- a/clang/lib/Serialization/ASTWriterDecl.cpp
+++ b/clang/lib/Serialization/ASTWriterDecl.cpp
@@ -2233,8 +2233,18 @@
Writer->ClearSwitchCaseIDs();
assert(FD->doesThisDeclarationHaveABody());
- bool ModulesCodegen = Writer->Context->getLangOpts().ModulesCodegen &&
- Writer->WritingModule && !FD->isDependentContext();
+ bool ModulesCodegen = false;
+ if (Writer->WritingModule && !FD->isDependentContext()) {
+ // Under -fmodules-codegen, codegen is performed for all defined functions.
+ // When building a C++ Modules TS module interface unit, a strong definition
+ // in the module interface is provided by the compilation of that module
+ // interface unit, not by its users. (Inline functions are still emitted
+ // in module users.)
+ ModulesCodegen =
+ Writer->Context->getLangOpts().ModulesCodegen ||
+ (Writer->WritingModule->Kind == Module::ModuleInterfaceUnit &&
+ Writer->Context->GetGVALinkageForFunction(FD) == GVA_StrongExternal);
+ }
Record->push_back(ModulesCodegen);
if (ModulesCodegen)
Writer->ModularCodegenDecls.push_back(Writer->GetDeclRef(FD));