diff options
author | Chuanqi Xu <yedeng.yd@linux.alibaba.com> | 2024-04-16 13:00:06 +0800 |
---|---|---|
committer | Chuanqi Xu <yedeng.yd@linux.alibaba.com> | 2024-04-16 13:06:44 +0800 |
commit | 39016e33b0fe78ddb1f11822f71a8a233af4dca9 (patch) | |
tree | f473653b6f321877a94236c71bd24a977f01206e /clang/lib/CodeGen/CodeGenModule.cpp | |
parent | edb0708dc1ceeaeb3356311a4ddf72a0dc9b224f (diff) | |
download | llvm-39016e33b0fe78ddb1f11822f71a8a233af4dca9.zip llvm-39016e33b0fe78ddb1f11822f71a8a233af4dca9.tar.gz llvm-39016e33b0fe78ddb1f11822f71a8a233af4dca9.tar.bz2 |
[C++20] [Modules] Don't import non-inline function bodies even if it is always-inline
Recommit
https://github.com/llvm/llvm-project/commit/1ecbab56dcbb78268c8d19af34a50591f90b12a0
Close https://github.com/llvm/llvm-project/issues/80949
The new thing in this commit is to allow to import the function body
from instantiations if it is marked with always-inline. See the
discussion in https://github.com/llvm/llvm-project/issues/86893 for
details.
Diffstat (limited to 'clang/lib/CodeGen/CodeGenModule.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index e447496..0c447b2 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -3952,9 +3952,20 @@ bool CodeGenModule::shouldEmitFunction(GlobalDecl GD) { // behavior may break ABI compatibility of the current unit. if (const Module *M = F->getOwningModule(); M && M->getTopLevelModule()->isNamedModule() && - getContext().getCurrentNamedModule() != M->getTopLevelModule() && - !F->hasAttr<AlwaysInlineAttr>()) - return false; + getContext().getCurrentNamedModule() != M->getTopLevelModule()) { + // There are practices to mark template member function as always-inline + // and mark the template as extern explicit instantiation but not give + // the definition for member function. So we have to emit the function + // from explicitly instantiation with always-inline. + // + // See https://github.com/llvm/llvm-project/issues/86893 for details. + // + // TODO: Maybe it is better to give it a warning if we call a non-inline + // function from other module units which is marked as always-inline. + if (!F->isTemplateInstantiation() || !F->hasAttr<AlwaysInlineAttr>()) { + return false; + } + } if (F->hasAttr<NoInlineAttr>()) return false; |