xref: /llvm-project/clang/test/Modules/no-transitive-source-location-change.cppm (revision ad9f38d0e3a5e7e06c39dbd7da88a921a49aa805)
1// Testing that adding a new line in a module interface unit won't cause the BMI
2// of consuming module unit changes.
3//
4// RUN: rm -rf %t
5// RUN: split-file %s %t
6//
7// RUN: %clang_cc1 -std=c++20 %t/A.cppm -emit-reduced-module-interface -o %t/A.pcm
8// RUN: %clang_cc1 -std=c++20 %t/A.v1.cppm -emit-reduced-module-interface -o %t/A.v1.pcm
9//
10// The BMI may not be the same since the source location differs.
11// RUN: not diff %t/A.pcm %t/A.v1.pcm &> /dev/null
12//
13// The BMI of B shouldn't change since all the locations remain the same.
14// RUN: %clang_cc1 -std=c++20 %t/B.cppm -emit-reduced-module-interface -fmodule-file=A=%t/A.pcm \
15// RUN:     -o %t/B.pcm
16// RUN: %clang_cc1 -std=c++20 %t/B.cppm -emit-reduced-module-interface -fmodule-file=A=%t/A.v1.pcm \
17// RUN:     -o %t/B.v1.pcm
18// RUN: diff %t/B.v1.pcm %t/B.pcm  &> /dev/null
19//
20// The BMI of C may change since the locations for instantiations changes.
21// RUN: %clang_cc1 -std=c++20 %t/C.cppm -emit-reduced-module-interface -fmodule-file=A=%t/A.pcm \
22// RUN:     -o %t/C.pcm
23// RUN: %clang_cc1 -std=c++20 %t/C.cppm -emit-reduced-module-interface -fmodule-file=A=%t/A.v1.pcm \
24// RUN:     -o %t/C.v1.pcm
25// RUN: not diff %t/C.v1.pcm %t/C.pcm  &> /dev/null
26
27//--- A.cppm
28export module A;
29export template <class T>
30struct C {
31    T func() {
32        return T(43);
33    }
34};
35export int funcA() {
36    return 43;
37}
38
39//--- A.v1.cppm
40export module A;
41
42export template <class T>
43struct C {
44    T func() {
45        return T(43);
46    }
47};
48export int funcA() {
49    return 43;
50}
51
52//--- B.cppm
53export module B;
54import A;
55
56export int funcB() {
57    return funcA();
58}
59
60//--- C.cppm
61export module C;
62import A;
63export inline void testD() {
64    C<int> c;
65    c.func();
66}
67