1 // RUN: rm -rf %t 2 // RUN: mkdir -p %t 3 // RUN: split-file %s %t 4 5 // RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/import-diags-tu1.cpp \ 6 // RUN: -o %t/B.pcm 7 8 // RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/import-diags-tu2.cpp \ 9 // RUN: -o %t/C.pcm 10 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.pcm 13 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 -verify 17 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 -verify 20 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 -verify 23 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 -verify 26 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 -verify 29 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 -verify 32 33 // RUN: %clang_cc1 -std=c++20 -emit-module-interface %t/import-diags-tu10.cpp \ 34 // RUN: -o %t/B.pcm -verify 35 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.o 38 39 // Test again with reduced BMI. 40 // RUN: rm -rf %t 41 // RUN: mkdir -p %t 42 // RUN: split-file %s %t 43 44 // RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface %t/import-diags-tu1.cpp \ 45 // RUN: -o %t/B.pcm 46 47 // RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface %t/import-diags-tu2.cpp \ 48 // RUN: -o %t/C.pcm 49 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.pcm 52 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 -verify 56 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 -verify 59 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 -verify 62 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 -verify 65 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 -verify 68 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 -verify 71 72 // RUN: %clang_cc1 -std=c++20 -emit-reduced-module-interface %t/import-diags-tu10.cpp \ 73 // RUN: -o %t/B.pcm -verify 74 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.o 77 78 // Test diagnostics for incorrect module import sequences. 79 80 //--- import-diags-tu1.cpp 81 82 export module B; 83 84 int foo (); 85 86 // expected-no-diagnostics 87 88 //--- import-diags-tu2.cpp 89 90 export module C; 91 92 int bar (); 93 94 // expected-no-diagnostics 95 96 //--- import-diags-tu3.cpp 97 98 export module AOK1; 99 100 import B; 101 export import C; 102 103 export int theAnswer (); 104 105 // expected-no-diagnostics 106 107 //--- import-diags-tu4.cpp 108 109 module; 110 111 module AOK1; 112 113 export import C; // expected-error {{export declaration can only be used within a module purview}} 114 theAnswer()115int theAnswer () { return 42; } 116 117 //--- import-diags-tu5.cpp 118 119 export module BC; 120 121 export import B; 122 foo()123int foo () { return 10; } 124 125 import C; // expected-error {{imports must immediately follow the module declaration}} 126 127 //--- import-diags-tu6.cpp 128 129 module B; // implicitly imports B. 130 foo()131int foo () { return 10; } 132 133 import C; // expected-error {{imports must immediately follow the module declaration}} 134 135 //--- import-diags-tu7.cpp 136 137 module; 138 // We can only have preprocessor directives here, which permits 139 // header units (include-translated or not) and named modules. 140 import B; 141 export module D; 142 143 int delta (); 144 // expected-no-diagnostics 145 146 //--- import-diags-tu8.cpp 147 148 export module D; 149 150 int delta (); 151 152 module :private; 153 154 import B; // expected-error {{imports must immediately follow the module declaration}} 155 156 //--- import-diags-tu9.cpp 157 158 module B; 159 160 import B; // expected-error {{import of module 'B' appears within its own implementation}} 161 162 //--- import-diags-tu10.cpp 163 164 export module B; 165 166 import B; // expected-error {{import of module 'B' appears within its own interface}} 167 168 //--- import-diags-tu11.cpp 169 170 int x; 171 172 import C; 173 baz()174int baz() { return 6174; } 175 176 // expected-no-diagnostics 177