Debian Codegraph @

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

raw
1 // RUN: rm -rf %t
2 // RUN: split-file %s %t
3 //
4 // RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 %t/M.cppm \
5 // RUN: -emit-module-interface -o %t/M.pcm
6 // RUN: %clang_cc1 -std=c++20 %t/Use.cpp -fprebuilt-module-path=%t \
7 // RUN: -triple %itanium_abi_triple \
8 // RUN: -emit-llvm -o - -disable-llvm-passes \
9 // RUN: | FileCheck %t/Use.cpp --check-prefix=CHECK-O0
10 //
11 // RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++20 -O1 %t/M.cppm \
12 // RUN: -emit-module-interface -o %t/M.pcm
13 // RUN: %clang_cc1 -std=c++20 %t/Use.cpp -fprebuilt-module-path=%t -O1 \
14 // RUN: -triple %itanium_abi_triple \
15 // RUN: -emit-llvm -o - -disable-llvm-passes | \
16 // RUN: FileCheck %t/Use.cpp --check-prefix=CHECK-O1
17
18 //--- foo.h
19 int func_in_gmf() {
20 return 43;
21 }
22 int func_in_gmf_not_called() {
23 return 44;
24 }
25
26 template <class T>
27 class A {
28 public:
29 __attribute__((always_inline))
30 inline constexpr int getValue() {
31 return 43;
32 }
33
34 inline constexpr int getValue2() {
35 return 43;
36 }
37 };
38
39 extern template class A<char>;
40
41 //--- M.cppm
42 module;
43 #include "foo.h"
44 export module M;
45 int non_exported_func() {
46 return 43 + func_in_gmf();
47 }
48 export int exported_func() {
49 return non_exported_func();
50 }
51
52 int non_exported_func_not_called() {
53 return 44;
54 }
55 export int func_not_called() {
56 return non_exported_func_not_called();
57 }
58
59 export
60 __attribute__((always_inline))
61 int always_inline_func() {
62 return 45;
63 }
64
65 export using ::A;
66
67 //--- Use.cpp
68 import M;
69 int use() {
70 A<char> a;
71 return exported_func() + always_inline_func() +
72 a.getValue() + a.getValue2();
73 }
74
75 // CHECK-O0: define{{.*}}_Z3usev(
76 // CHECK-O0: declare{{.*}}_ZW1M13exported_funcv(
77 // CHECK-O0: declare{{.*}}_ZW1M18always_inline_funcv(
78 // CHECK-O0: define{{.*}}@_ZN1AIcE8getValueEv(
79 // CHECK-O0: declare{{.*}}@_ZN1AIcE9getValue2Ev(
80 // CHECK-O0-NOT: func_in_gmf
81 // CHECK-O0-NOT: func_in_gmf_not_called
82 // CHECK-O0-NOT: non_exported_func
83 // CHECK-O0-NOT: non_exported_func_not_called
84 // CHECK-O0-NOT: func_not_called
85
86 // Checks that the generated code within optimizations keep the same behavior with
87 // O0 to keep consistent ABI.
88 // CHECK-O1: define{{.*}}_Z3usev(
89 // CHECK-O1: declare{{.*}}_ZW1M13exported_funcv(
90 // CHECK-O1: declare{{.*}}_ZW1M18always_inline_funcv(
91 // CHECK-O1: define{{.*}}@_ZN1AIcE8getValueEv(
92 // CHECK-O1: declare{{.*}}@_ZN1AIcE9getValue2Ev(
93 // CHECK-O1-NOT: func_in_gmf
94 // CHECK-O1-NOT: func_in_gmf_not_called
95 // CHECK-O1-NOT: non_exported_func
96 // CHECK-O1-NOT: non_exported_func_not_called
97 // CHECK-O1-NOT: func_not_called