summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChuanqi Xu <yedeng.yd@linux.alibaba.com>2024-02-18 15:08:02 +0800
committerChuanqi Xu <yedeng.yd@linux.alibaba.com>2024-02-18 15:15:28 +0800
commit1ecbab56dcbb78268c8d19af34a50591f90b12a0 (patch)
tree6d8f4d0681c557210f328f5f6ea81ead2f1d089d
parentead0a9777f8ccb5c26d50d96bade6cd5b47f496b (diff)
[C++20] [Modules] Don't import non-inline function bodies even if it is marked as always_inline
Close https://github.com/llvm/llvm-project/issues/80949 Previously, I thought the always-inline function can be an exception to enable optimizations as much as possible. However, it looks like it breaks the ABI requirement we discussed later. So it looks better to not import non-inline function bodies at all even if the function bodies are marked as always_inline. It doesn't produce regressions in some degree since the always_inline still works in the same TU.
-rw-r--r--clang/lib/CodeGen/CodeGenModule.cpp3
-rw-r--r--clang/test/CodeGenCXX/module-funcs-from-imports.cppm6
2 files changed, 4 insertions, 5 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index c984260b082c..836cd34a16c0 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3985,8 +3985,7 @@ 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>())
+ getContext().getCurrentNamedModule() != M->getTopLevelModule())
return false;
if (F->hasAttr<NoInlineAttr>())
diff --git a/clang/test/CodeGenCXX/module-funcs-from-imports.cppm b/clang/test/CodeGenCXX/module-funcs-from-imports.cppm
index 33cdf437110a..8d04328eaf3f 100644
--- a/clang/test/CodeGenCXX/module-funcs-from-imports.cppm
+++ b/clang/test/CodeGenCXX/module-funcs-from-imports.cppm
@@ -53,11 +53,11 @@ int use() {
return exported_func() + always_inline_func();
}
-// Checks that none of the function (except the always_inline_func) in the importees
+// Checks that none of the function in the importees
// are generated in the importer's code.
// CHECK-O0: define{{.*}}_Z3usev(
// CHECK-O0: declare{{.*}}_ZW1M13exported_funcv(
-// CHECK-O0: define{{.*}}available_externally{{.*}}_ZW1M18always_inline_funcv(
+// CHECK-O0: declare{{.*}}_ZW1M18always_inline_funcv(
// CHECK-O0-NOT: func_in_gmf
// CHECK-O0-NOT: func_in_gmf_not_called
// CHECK-O0-NOT: non_exported_func
@@ -68,7 +68,7 @@ int use() {
// O0 to keep consistent ABI.
// CHECK-O1: define{{.*}}_Z3usev(
// CHECK-O1: declare{{.*}}_ZW1M13exported_funcv(
-// CHECK-O1: define{{.*}}available_externally{{.*}}_ZW1M18always_inline_funcv(
+// CHECK-O1: declare{{.*}}_ZW1M18always_inline_funcv(
// CHECK-O1-NOT: func_in_gmf
// CHECK-O1-NOT: func_in_gmf_not_called
// CHECK-O1-NOT: non_exported_func