Skip to content

Commit b5dffd4

Browse files
authored
[C++20] [Modules] Don't emit function bodies which is noinline and av… (#68501)
…ailabl externally A workaround for #60996 As the title suggested, we can avoid emitting available externally functions which is marked as noinline already. Such functions should contribute nothing for optimizations. The update for docs will be sent seperately if this got approved.
1 parent 057ec76 commit b5dffd4

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3849,6 +3849,9 @@ bool CodeGenModule::shouldEmitFunction(GlobalDecl GD) {
38493849
if (CodeGenOpts.OptimizationLevel == 0 && !F->hasAttr<AlwaysInlineAttr>())
38503850
return false;
38513851

3852+
if (F->hasAttr<NoInlineAttr>())
3853+
return false;
3854+
38523855
if (F->hasAttr<DLLImportAttr>() && !F->hasAttr<AlwaysInlineAttr>()) {
38533856
// Check whether it would be safe to inline this dllimport function.
38543857
DLLImportFunctionVisitor Visitor;
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// RUN: rm -rf %t
2+
// RUN: split-file %s %t
3+
// RUN: cd %t
4+
//
5+
// RUN: %clang_cc1 -std=c++20 -O1 -triple %itanium_abi_triple %t/a.cppm \
6+
// RUN: -emit-module-interface -o %t/a.pcm
7+
// RUN: %clang_cc1 -std=c++20 -O1 -triple %itanium_abi_triple %t/b.cppm \
8+
// RUN: -emit-module-interface -fprebuilt-module-path=%t -o %t/b.pcm
9+
// RUN: %clang_cc1 -std=c++20 -O1 -triple %itanium_abi_triple %t/c.cppm \
10+
// RUN: -emit-module-interface -fprebuilt-module-path=%t -o %t/c.pcm
11+
// RUN: %clang_cc1 -std=c++20 -O1 -triple %itanium_abi_triple %t/c.pcm -S \
12+
// RUN: -emit-llvm -disable-llvm-passes -o - | FileCheck %t/c.cppm
13+
14+
//--- a.cppm
15+
export module a;
16+
export int a() {
17+
return 43;
18+
}
19+
export __attribute__((noinline)) int a_noinline() {
20+
return 44;
21+
}
22+
23+
//--- b.cppm
24+
export module b;
25+
export import a;
26+
export int b() {
27+
return 43 + a();
28+
}
29+
30+
export __attribute__((noinline)) int b_noinline() {
31+
return 43 + a();
32+
}
33+
34+
//--- c.cppm
35+
export module c;
36+
export import b;
37+
export int c() {
38+
return 43 + b() + a() + b_noinline() + a_noinline();
39+
}
40+
41+
// CHECK: define{{.*}}available_externally{{.*}}@_ZW1b1bv(
42+
// CHECK: define{{.*}}available_externally{{.*}}@_ZW1a1av(
43+
44+
// CHECK: declare{{.*}}@_ZW1b10b_noinlinev()
45+
// CHECK: declare{{.*}}@_ZW1a10a_noinlinev()

0 commit comments

Comments
 (0)