xref: /llvm-project/clang/test/Modules/pr60085.cppm (revision 7c1d9b15eee3a34678addab2bab66f3020ac0753)
1// RUN: rm -rf %t
2// RUN: mkdir %t
3// RUN: split-file %s %t
4//
5// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/d.cppm \
6// RUN:     -emit-module-interface -o %t/d.pcm
7// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/c.cppm \
8// RUN:     -emit-module-interface -o %t/c.pcm -fprebuilt-module-path=%t
9// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/b.cppm \
10// RUN:     -emit-module-interface -o %t/b.pcm -fprebuilt-module-path=%t
11// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/a.cppm \
12// RUN:     -emit-module-interface -o %t/a.pcm -fprebuilt-module-path=%t
13// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/a.pcm \
14// RUN:     -emit-llvm -disable-llvm-passes -o - -fprebuilt-module-path=%t \
15// RUN:     | FileCheck %t/a.cppm
16
17// Test again with reduced BMI.
18// RUN: rm -rf %t
19// RUN: mkdir %t
20// RUN: split-file %s %t
21//
22// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/d.cppm \
23// RUN:     -emit-reduced-module-interface -o %t/d.pcm
24// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/c.cppm \
25// RUN:     -emit-reduced-module-interface -o %t/c.pcm -fprebuilt-module-path=%t
26// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/b.cppm \
27// RUN:     -emit-reduced-module-interface -o %t/b.pcm -fprebuilt-module-path=%t
28// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/a.cppm \
29// RUN:     -emit-module-interface -o %t/a.pcm -fprebuilt-module-path=%t
30// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/a.pcm \
31// RUN:     -emit-llvm -disable-llvm-passes -o - -fprebuilt-module-path=%t \
32// RUN:		| FileCheck %t/a.cppm
33
34//--- d.cppm
35export module d;
36
37export template<typename>
38struct integer {
39	using type = int;
40
41	static constexpr auto value() {
42		return 0;
43	}
44
45	friend constexpr void f(integer const x) {
46		x.value();
47	}
48};
49
50export constexpr void ddd(auto const value) {
51	f(value);
52}
53
54
55template<typename T>
56constexpr auto dd = T();
57
58export template<typename T>
59constexpr auto d() {
60	dd<T>;
61}
62
63//--- c.cppm
64export module c;
65
66import d;
67
68template<typename T>
69auto cc = T();
70
71auto c() {
72	cc<integer<int>>;
73	integer<int>().value();
74}
75
76//--- b.cppm
77export module b;
78
79import d;
80
81auto b() {
82	integer<int>::type;
83}
84
85//--- a.cppm
86export module a;
87
88import b;
89import c;
90import d;
91
92constexpr void aa() {
93	d<integer<unsigned>>();
94	ddd(integer<int>());
95}
96
97export extern "C" void a() {
98	aa();
99}
100
101// Checks that we emit the IR successfully.
102// CHECK: define{{.*}}@a(
103