Modular Codegen: Don't home/modularize static functions in headers

Consistent with various workarounds in the backwards compatible modules
that allow static functions in headers to exist, be deduplicated to some
degree, and not generally fail right out of the gate... do the same with
modular codegen as there are enough cases (including in libstdc++ and in
LLVM itself - though I cleaned up the easy ones) that it's worth
supporting as a migration/backcompat step.

Simply create a separate, internal linkage function in each object that
needs it. If an available_externally/modularized function references a
static function, but the modularized function is eventually dropped and
not inlined, the static function will be dropped as unreferenced.

llvm-svn: 317274
diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp b/clang/lib/Serialization/ASTWriterDecl.cpp
index 8037958..bf34d01 100644
--- a/clang/lib/Serialization/ASTWriterDecl.cpp
+++ b/clang/lib/Serialization/ASTWriterDecl.cpp
@@ -2258,15 +2258,22 @@
   assert(FD->doesThisDeclarationHaveABody());
   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);
+    Optional<GVALinkage> Linkage;
+    if (Writer->WritingModule->Kind == Module::ModuleInterfaceUnit) {
+      // 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.)
+      Linkage = Writer->Context->GetGVALinkageForFunction(FD);
+      ModulesCodegen = *Linkage == GVA_StrongExternal;
+    }
+    if (Writer->Context->getLangOpts().ModulesCodegen) {
+      // Under -fmodules-codegen, codegen is performed for all non-internal,
+      // non-always_inline functions.
+      if (!Linkage)
+        Linkage = Writer->Context->GetGVALinkageForFunction(FD);
+      ModulesCodegen = *Linkage != GVA_Internal;
+    }
   }
   Record->push_back(ModulesCodegen);
   if (ModulesCodegen)