177 lines · cpp
1// RUN: rm -rf %t2// RUN: mkdir -p %t3// RUN: split-file %s %t4 5// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/import-diags-tu1.cpp \6// RUN: -o %t/B.pcm7 8// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/import-diags-tu2.cpp \9// RUN: -o %t/C.pcm10 11// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/import-diags-tu3.cpp \12// RUN: -fmodule-file=B=%t/B.pcm -fmodule-file=C=%t/C.pcm -o %t/AOK1.pcm13 14// RUN: %clang_cc1 -std=c++20 -S %t/import-diags-tu4.cpp \15// RUN: -fmodule-file=AOK1=%t/AOK1.pcm -fmodule-file=B=%t/B.pcm \16// RUN: -fmodule-file=C=%t/C.pcm -o %t/tu_3.s -verify17 18// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/import-diags-tu5.cpp \19// RUN: -fmodule-file=B=%t/B.pcm -fmodule-file=C=%t/C.pcm -o %t/BC.pcm -verify20 21// RUN: %clang_cc1 -std=c++20 -S %t/import-diags-tu6.cpp \22// RUN: -fmodule-file=B=%t/B.pcm -fmodule-file=C=%t/C.pcm -o %t/tu_5.s -verify23 24// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/import-diags-tu7.cpp \25// RUN: -fmodule-file=B=%t/B.pcm -o %t/D.pcm -verify26 27// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/import-diags-tu8.cpp \28// RUN: -fmodule-file=B=%t/B.pcm -o %t/D.pcm -verify29 30// RUN: %clang_cc1 -std=c++20 -S %t/import-diags-tu9.cpp \31// RUN: -fmodule-file=B=%t/B.pcm -o %t/tu_8.s -verify32 33// RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/import-diags-tu10.cpp \34// RUN: -o %t/B.pcm -verify35 36// RUN: %clang_cc1 -std=c++20 -emit-obj %t/import-diags-tu11.cpp \37// RUN: -fmodule-file=C=%t/C.pcm -o %t/impl.o38 39// Test again with reduced BMI.40// RUN: rm -rf %t41// RUN: mkdir -p %t42// RUN: split-file %s %t43 44// RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface %t/import-diags-tu1.cpp \45// RUN: -o %t/B.pcm46 47// RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface %t/import-diags-tu2.cpp \48// RUN: -o %t/C.pcm49 50// RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface %t/import-diags-tu3.cpp \51// RUN: -fmodule-file=B=%t/B.pcm -fmodule-file=C=%t/C.pcm -o %t/AOK1.pcm52 53// RUN: %clang_cc1 -std=c++20 -S %t/import-diags-tu4.cpp \54// RUN: -fmodule-file=AOK1=%t/AOK1.pcm -fmodule-file=B=%t/B.pcm \55// RUN: -fmodule-file=C=%t/C.pcm -o %t/tu_3.s -verify56 57// RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface %t/import-diags-tu5.cpp \58// RUN: -fmodule-file=B=%t/B.pcm -fmodule-file=C=%t/C.pcm -o %t/BC.pcm -verify59 60// RUN: %clang_cc1 -std=c++20 -S %t/import-diags-tu6.cpp \61// RUN: -fmodule-file=B=%t/B.pcm -fmodule-file=C=%t/C.pcm -o %t/tu_5.s -verify62 63// RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface %t/import-diags-tu7.cpp \64// RUN: -fmodule-file=B=%t/B.pcm -o %t/D.pcm -verify65 66// RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface %t/import-diags-tu8.cpp \67// RUN: -fmodule-file=B=%t/B.pcm -o %t/D.pcm -verify68 69// RUN: %clang_cc1 -std=c++20 -S %t/import-diags-tu9.cpp \70// RUN: -fmodule-file=B=%t/B.pcm -o %t/tu_8.s -verify71 72// RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface %t/import-diags-tu10.cpp \73// RUN: -o %t/B.pcm -verify74 75// RUN: %clang_cc1 -std=c++20 -emit-obj %t/import-diags-tu11.cpp \76// RUN: -fmodule-file=C=%t/C.pcm -o %t/impl.o77 78// Test diagnostics for incorrect module import sequences.79 80//--- import-diags-tu1.cpp81 82export module B;83 84int foo ();85 86// expected-no-diagnostics87 88//--- import-diags-tu2.cpp89 90export module C;91 92int bar ();93 94// expected-no-diagnostics95 96//--- import-diags-tu3.cpp97 98export module AOK1;99 100import B;101export import C;102 103export int theAnswer ();104 105// expected-no-diagnostics106 107//--- import-diags-tu4.cpp108 109module;110 111module AOK1;112 113export import C; // expected-error {{export declaration can only be used within a module interface}}114 115int theAnswer () { return 42; }116 117//--- import-diags-tu5.cpp118 119export module BC;120 121export import B;122 123int foo () { return 10; }124 125import C; // expected-error {{imports must immediately follow the module declaration}}126 127//--- import-diags-tu6.cpp128 129module B; // implicitly imports B.130 131int foo () { return 10; }132 133import C; // expected-error {{imports must immediately follow the module declaration}}134 135//--- import-diags-tu7.cpp136 137module;138// We can only have preprocessor directives here, which permits139// header units (include-translated or not) and named modules.140import B;141export module D;142 143int delta ();144// expected-no-diagnostics145 146//--- import-diags-tu8.cpp147 148export module D;149 150int delta ();151 152module :private;153 154import B; // expected-error {{imports must immediately follow the module declaration}}155 156//--- import-diags-tu9.cpp157 158module B;159 160import B; // expected-error {{import of module 'B' appears within its own implementation}}161 162//--- import-diags-tu10.cpp163 164export module B;165 166import B; // expected-error {{import of module 'B' appears within its own interface}}167 168//--- import-diags-tu11.cpp169 170int x;171 172import C;173 174int baz() { return 6174; }175 176// expected-no-diagnostics177