Skip to content

Commit 1ecbab5

Browse files
committed
[C++20] [Modules] Don't import non-inline function bodies even if it is marked as always_inline
Close #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.
1 parent ead0a97 commit 1ecbab5

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -3985,8 +3985,7 @@ bool CodeGenModule::shouldEmitFunction(GlobalDecl GD) {
39853985
// behavior may break ABI compatibility of the current unit.
39863986
if (const Module *M = F->getOwningModule();
39873987
M && M->getTopLevelModule()->isNamedModule() &&
3988-
getContext().getCurrentNamedModule() != M->getTopLevelModule() &&
3989-
!F->hasAttr<AlwaysInlineAttr>())
3988+
getContext().getCurrentNamedModule() != M->getTopLevelModule())
39903989
return false;
39913990

39923991
if (F->hasAttr<NoInlineAttr>())

clang/test/CodeGenCXX/module-funcs-from-imports.cppm

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ int use() {
5353
return exported_func() + always_inline_func();
5454
}
5555

56-
// Checks that none of the function (except the always_inline_func) in the importees
56+
// Checks that none of the function in the importees
5757
// are generated in the importer's code.
5858
// CHECK-O0: define{{.*}}_Z3usev(
5959
// CHECK-O0: declare{{.*}}_ZW1M13exported_funcv(
60-
// CHECK-O0: define{{.*}}available_externally{{.*}}_ZW1M18always_inline_funcv(
60+
// CHECK-O0: declare{{.*}}_ZW1M18always_inline_funcv(
6161
// CHECK-O0-NOT: func_in_gmf
6262
// CHECK-O0-NOT: func_in_gmf_not_called
6363
// CHECK-O0-NOT: non_exported_func
@@ -68,7 +68,7 @@ int use() {
6868
// O0 to keep consistent ABI.
6969
// CHECK-O1: define{{.*}}_Z3usev(
7070
// CHECK-O1: declare{{.*}}_ZW1M13exported_funcv(
71-
// CHECK-O1: define{{.*}}available_externally{{.*}}_ZW1M18always_inline_funcv(
71+
// CHECK-O1: declare{{.*}}_ZW1M18always_inline_funcv(
7272
// CHECK-O1-NOT: func_in_gmf
7373
// CHECK-O1-NOT: func_in_gmf_not_called
7474
// CHECK-O1-NOT: non_exported_func

0 commit comments

Comments
 (0)