diff options
author | Chuanqi Xu <yedeng.yd@linux.alibaba.com> | 2023-11-07 23:04:45 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-07 23:04:45 +0800 |
commit | 8ee9da02325cebf359de987f7ac8e1d3d629affe (patch) | |
tree | f2f4c2a744dadcb002551953db659fa12117df72 /clang/lib/CodeGen/CodeGenModule.cpp | |
parent | 066eea75d38957353824b46474413ef2632d01a7 (diff) | |
download | llvm-8ee9da02325cebf359de987f7ac8e1d3d629affe.zip llvm-8ee9da02325cebf359de987f7ac8e1d3d629affe.tar.gz llvm-8ee9da02325cebf359de987f7ac8e1d3d629affe.tar.bz2 |
[C++20] [Modules] Don't import function bodies from other module units even with optimizations (#71031)
Close https://github.com/llvm/llvm-project/issues/60996.
Previously, clang will try to import function bodies from other module
units to get more optimization oppotunities as much as possible. Then
the motivation becomes the direct cause of the above issue.
However, according to the discussion in SG15, the behavior of importing
function bodies from other module units breaks the ABI compatibility. It
is unwanted. So the original behavior of clang is incorrect. This patch
choose to not import function bodies from other module units in all
cases to follow the expectation.
Note that the desired optimized BMI idea is discarded too. Since it will
still break the ABI compatibility after we import function bodies
seperately.
The release note will be added seperately.
There is a similar issue for variable definitions. I'll try to handle
that in a different commit.
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index f721017..2e96fff 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -3851,10 +3851,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. + if (const Module *M = F->getOwningModule(); + M && M->isModulePurview() && + getContext().getCurrentNamedModule() != M->getTopLevelModule() && + !F->hasAttr<AlwaysInlineAttr>()) + return false; + if (F->hasAttr<NoInlineAttr>()) return false; |