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

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 2 01:04:30 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;
----------------
tbaederr wrote:

```suggestion
  if (const Module *M = F->getOwningModule();
      M && M->isModulePurview() &&
      getContext().getCurrentNamedModule() != M->getTopLevelModule() &&
      !F->hasAttr<AlwaysInlineAttr>())
    return false;
```

Should work, right?

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


More information about the cfe-commits mailing list