xref: /llvm-project/clang/test/Modules/function-transitive-change.cppm (revision dfa7ff97b24dc5a3dd714b45af288812c13d0110)
1// Test that, in C++20 modules reduced BMI, the implementation detail changes
2// in non-inline function may not propagate while the inline function changes
3// can get propagate.
4//
5// RUN: rm -rf %t
6// RUN: split-file %s %t
7// RUN: cd %t
8//
9// RUN: %clang_cc1 -std=c++20 %t/a.cppm -emit-reduced-module-interface -o %t/a.pcm
10// RUN: %clang_cc1 -std=c++20 %t/a.v1.cppm -emit-reduced-module-interface -o %t/a.v1.pcm
11//
12// The BMI of A should differ since the different implementation.
13// RUN: not diff %t/a.pcm %t/a.v1.pcm &> /dev/null
14//
15// The BMI of B should change since the dependent inline function changes
16// RUN: %clang_cc1 -std=c++20 %t/b.cppm -emit-reduced-module-interface -fmodule-file=a=%t/a.pcm \
17// RUN:     -o %t/b.pcm
18// RUN: %clang_cc1 -std=c++20 %t/b.cppm -emit-reduced-module-interface -fmodule-file=a=%t/a.v1.pcm \
19// RUN:     -o %t/b.v1.pcm
20// RUN: not diff %t/b.v1.pcm %t/b.pcm  &> /dev/null
21//
22// Test the case with unused partitions.
23// RUN: %clang_cc1 -std=c++20 %t/M-A.cppm -emit-reduced-module-interface -o %t/M-A.pcm
24// RUN: %clang_cc1 -std=c++20 %t/M-B.cppm -emit-reduced-module-interface -o %t/M-B.pcm
25// RUN: %clang_cc1 -std=c++20 %t/M.cppm -emit-reduced-module-interface -o %t/M.pcm \
26// RUN:     -fmodule-file=M:partA=%t/M-A.pcm \
27// RUN:     -fmodule-file=M:partB=%t/M-B.pcm
28// RUN: %clang_cc1 -std=c++20 %t/N.cppm -emit-reduced-module-interface -o %t/N.pcm \
29// RUN:     -fmodule-file=M:partA=%t/M-A.pcm \
30// RUN:     -fmodule-file=M:partB=%t/M-B.pcm \
31// RUN:     -fmodule-file=M=%t/M.pcm
32//
33// Now we change `M-A.cppm` to `M-A.v1.cppm`.
34// RUN: %clang_cc1 -std=c++20 %t/M-A.v1.cppm -emit-reduced-module-interface -o %t/M-A.v1.pcm
35// RUN: %clang_cc1 -std=c++20 %t/M.cppm -emit-reduced-module-interface -o %t/M.v1.pcm \
36// RUN:     -fmodule-file=M:partA=%t/M-A.v1.pcm \
37// RUN:     -fmodule-file=M:partB=%t/M-B.pcm
38// RUN: %clang_cc1 -std=c++20 %t/N.cppm -emit-reduced-module-interface -o %t/N.v1.pcm \
39// RUN:     -fmodule-file=M:partA=%t/M-A.v1.pcm \
40// RUN:     -fmodule-file=M:partB=%t/M-B.pcm \
41// RUN:     -fmodule-file=M=%t/M.v1.pcm
42//
43// The BMI of N can keep unchanged since the N didn't use the changed partition unit 'M:A'.
44// RUN: diff %t/N.v1.pcm %t/N.pcm  &> /dev/null
45
46//--- a.cppm
47export module a;
48export inline int a() {
49    return 48;
50}
51
52//--- a.v1.cppm
53export module a;
54export inline int a() {
55    return 50;
56}
57
58//--- b.cppm
59export module b;
60import a;
61export inline int b() {
62    return a();
63}
64
65//--- M-A.cppm
66export module M:partA;
67export inline int a() {
68    return 43;
69}
70
71//--- M-A.v1.cppm
72export module M:partA;
73export inline int a() {
74    return 50;
75}
76
77//--- M-B.cppm
78export module M:partB;
79export inline int b() {
80    return 44;
81}
82
83//--- M.cppm
84export module M;
85export import :partA;
86export import :partB;
87
88//--- N.cppm
89export module N;
90import M;
91
92export inline int n() {
93    return b();
94}
95