[clang] [C++20] [Modules] Don't import function bodies from other module units even with optimizations (PR #71031)

Chuanqi Xu via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 2 01:07:29 PDT 2023


================
@@ -3856,10 +3856,19 @@ CodeGenModule::isTriviallyRecursive(const FunctionDecl *FD) {
 bool CodeGenModule::shouldEmitFunction(GlobalDecl GD) {
   if (getFunctionLinkage(GD) != llvm::Function::AvailableExternallyLinkage)
     return true;
+
   const auto *F = cast<FunctionDecl>(GD.getDecl());
   if (CodeGenOpts.OptimizationLevel == 0 && !F->hasAttr<AlwaysInlineAttr>())
     return false;
 
+  // We don't import function bodies from other named module units since that
+  // behavior may break ABI compatibility of the current unit.
+  Module *M = F->getOwningModule();
+  if (M && M->isModulePurview() &&
+      getContext().getCurrentNamedModule() != M->getTopLevelModule() &&
+      !F->hasAttr<AlwaysInlineAttr>())
+    return false;
----------------
ChuanqiXu9 wrote:

Oh, yes. I'll address it in the next round of changes.

https://github.com/llvm/llvm-project/pull/71031


More information about the cfe-commits mailing list