blob: ebbd0ee4e2c65544c8d7684e58263ffa84ccd81d [file] [log] [blame]
Chuanqi Xu18f3bcb2024-07-02 11:29:17 +08001// REQUIRES: !system-windows
2//
3// RUN: rm -rf %t
4// RUN: mkdir -p %t
5// RUN: split-file %s %t
6//
7// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/Base.cppm \
8// RUN: -emit-module-interface -o %t/Base.pcm
9// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/Sub.cppm \
10// RUN: -emit-module-interface -o %t/Sub.pcm -fprebuilt-module-path=%t
11// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/Sub.pcm \
12// RUN: -emit-llvm -o %t/Sub.pcm -o - -fprebuilt-module-path=%t | \
13// RUN: FileCheck %t/Sub.cppm
14// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/main.cpp \
15// RUN: -emit-llvm -fprebuilt-module-path=%t -o - | FileCheck %t/main.cpp
16//
17// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/Mod.cppm \
18// RUN: -emit-module-interface -o %t/Mod.pcm
19// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/Mod.pcm \
20// RUN: -emit-llvm -o - | FileCheck %t/Mod.cppm
21// RUN: %clang_cc1 -std=c++20 -triple %itanium_abi_triple %t/Use.cpp \
22// RUN: -emit-llvm -fprebuilt-module-path=%t -o - | \
23// RUN: FileCheck %t/Use.cpp
24
25//--- Base.cppm
26export module Base;
27
28export template <class>
29class Base
30{
31public:
32 constexpr Base();
33 constexpr virtual ~Base();
34};
35
36template <class X>
37constexpr Base<X>::Base() = default;
38
39template <class X>
40constexpr Base<X>::~Base() = default;
41
42//--- Sub.cppm
43export module Sub;
44export import Base;
45
46export class Sub : public Base<int>
47{
48};
49
50// CHECK: @_ZTIW4Base4BaseIiE = {{.*}}linkonce_odr
51
52//--- main.cpp
53import Sub;
54
55int main()
56{
57 Base<int> *b = new Sub();
58 delete b;
59}
60
61// CHECK: @_ZTIW4Base4BaseIiE = {{.*}}linkonce_odr
62
63//--- Mod.cppm
64export module Mod;
65
66export class NonTemplate {
67public:
68 virtual ~NonTemplate();
69};
70
71// CHECK: @_ZTIW3Mod11NonTemplate = {{.*}}constant
72
73export template <class C>
74class Template {
75public:
76 virtual ~Template();
77};
78
79export template<>
80class Template<char> {
81public:
82 virtual ~Template();
83};
84
85// CHECK: @_ZTIW3Mod8TemplateIcE = {{.*}}constant
86
87export template class Template<unsigned>;
88
89// CHECK: @_ZTIW3Mod8TemplateIjE = {{.*}}weak_odr
90
91export extern template class Template<double>;
92
93auto v = new Template<signed int>();
94
95// CHECK: @_ZTIW3Mod8TemplateIiE = {{.*}}linkonce_odr
96
97//--- Use.cpp
98import Mod;
99
100auto v1 = new NonTemplate();
101auto v2 = new Template<char>();
102auto v3 = new Template<unsigned>();
103auto v4 = new Template<double>();
104auto v5 = new Template<signed int>();
105auto v6 = new Template<NonTemplate>();
106
107// CHECK: @_ZTVW3Mod11NonTemplate = {{.*}}external
108// CHECK: @_ZTVW3Mod8TemplateIcE = {{.*}}external
109// CHECK: @_ZTVW3Mod8TemplateIjE = {{.*}}weak_odr
110// CHECK: @_ZTSW3Mod8TemplateIjE = {{.*}}weak_odr
111// CHECK: @_ZTIW3Mod8TemplateIjE = {{.*}}weak_odr
112// CHECK: @_ZTVW3Mod8TemplateIdE = {{.*}}external
113// CHECK: @_ZTVW3Mod8TemplateIiE = {{.*}}linkonce_odr
114// CHECK: @_ZTSW3Mod8TemplateIiE = {{.*}}linkonce_odr
115// CHECK: @_ZTIW3Mod8TemplateIiE = {{.*}}linkonce_odr
116// CHECK: @_ZTVW3Mod8TemplateIS_11NonTemplateE = {{.*}}linkonce_odr
117// CHECK: @_ZTSW3Mod8TemplateIS_11NonTemplateE = {{.*}}linkonce_odr
118// CHECK: @_ZTIW3Mod8TemplateIS_11NonTemplateE = {{.*}}linkonce_odr