[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / ClangScanDeps / P1689.cppm
blobc9ef8f4c83fa2eb0b0c6c4759478cafdc3dfa7e8
1 // The slash direction in linux and windows are different.
2 // UNSUPPORTED: system-windows
3 //
4 // RUN: rm -fr %t
5 // RUN: mkdir -p %t
6 // RUN: split-file %s %t
7 //
8 // RUN: sed "s|DIR|%/t|g" %t/P1689.json.in > %t/P1689.json
9 // RUN: clang-scan-deps -compilation-database %t/P1689.json -format=p1689 | FileCheck %t/Checks.cpp -DPREFIX=%/t
10 // RUN: clang-scan-deps --mode=preprocess-dependency-directives -compilation-database %t/P1689.json -format=p1689 | FileCheck %t/Checks.cpp -DPREFIX=%/t
12 // Check the separated dependency format. This is required by CMake for the case
13 // that we have non-exist files in a fresh build and potentially out-of-date after that.
14 // So the build system need to wrtie a compilation database just for scanning purposes,
15 // which is not so good. So here is the per file mode for P1689.
16 // RUN: clang-scan-deps -format=p1689 \
17 // RUN:   -- %clang++ -std=c++20 -c -fprebuilt-module-path=%t %t/M.cppm -o %t/M.o \
18 // RUN:   | FileCheck %t/M.cppm -DPREFIX=%/t
19 // RUN: clang-scan-deps -format=p1689 \
20 // RUN:   -- %clang++ -std=c++20 -c -fprebuilt-module-path=%t %t/Impl.cpp -o %t/Impl.o \
21 // RUN:   | FileCheck %t/Impl.cpp -DPREFIX=%/t
22 // RUN: clang-scan-deps -format=p1689 \
23 // RUN:   -- %clang++ -std=c++20 -c -fprebuilt-module-path=%t %t/impl_part.cppm -o %t/impl_part.o \
24 // RUN:   | FileCheck %t/impl_part.cppm -DPREFIX=%/t
25 // RUN: clang-scan-deps -format=p1689 \
26 // RUN:   -- %clang++ -std=c++20 -c -fprebuilt-module-path=%t %t/interface_part.cppm -o %t/interface_part.o \
27 // RUN:   | FileCheck %t/interface_part.cppm -DPREFIX=%/t
28 // RUN: clang-scan-deps -format=p1689 \
29 // RUN:   -- %clang++ -std=c++20 -c -fprebuilt-module-path=%t %t/User.cpp -o %t/User.o \
30 // RUN:   | FileCheck %t/User.cpp -DPREFIX=%/t
32 // Check we can generate the make-style dependencies as expected.
33 // RUN: clang-scan-deps -format=p1689 \
34 // RUN:   -- %clang++ -std=c++20 -c -fprebuilt-module-path=%t %t/impl_part.cppm -o %t/impl_part.o \
35 // RUN:      -MT %t/impl_part.o.ddi -MD -MF %t/impl_part.dep
36 // RUN:   cat %t/impl_part.dep | FileCheck %t/impl_part.cppm -DPREFIX=%/t --check-prefix=CHECK-MAKE
38 // Check that we can generate multiple make-style dependency information with compilation database.
39 // RUN: cat %t/P1689.dep | FileCheck %t/Checks.cpp -DPREFIX=%/t --check-prefix=CHECK-MAKE
41 //--- P1689.json.in
44   "directory": "DIR",
45   "command": "clang++ -std=c++20 DIR/M.cppm -c -o DIR/M.o -MT DIR/M.o.ddi -MD -MF DIR/P1689.dep",
46   "file": "DIR/M.cppm",
47   "output": "DIR/M.o"
50   "directory": "DIR",
51   "command": "clang++ -std=c++20 DIR/Impl.cpp -c -o DIR/Impl.o -MT DIR/Impl.o.ddi -MD -MF DIR/P1689.dep",
52   "file": "DIR/Impl.cpp",
53   "output": "DIR/Impl.o"
56   "directory": "DIR",
57   "command": "clang++ -std=c++20 DIR/impl_part.cppm -c -o DIR/impl_part.o -MT DIR/impl_part.o.ddi -MD -MF DIR/P1689.dep",
58   "file": "DIR/impl_part.cppm",
59   "output": "DIR/impl_part.o"
62   "directory": "DIR",
63   "command": "clang++ -std=c++20 DIR/interface_part.cppm -c -o DIR/interface_part.o -MT DIR/interface_part.o.ddi -MD -MF DIR/P1689.dep",
64   "file": "DIR/interface_part.cppm",
65   "output": "DIR/interface_part.o"
68   "directory": "DIR",
69   "command": "clang++ -std=c++20 DIR/User.cpp -c -o DIR/User.o -MT DIR/User.o.ddi -MD -MF DIR/P1689.dep",
70   "file": "DIR/User.cpp",
71   "output": "DIR/User.o"
75 //--- M.cppm
76 export module M;
77 export import :interface_part;
78 import :impl_part;
79 export void Hello();
81 // CHECK: {
82 // CHECK-NEXT:   "revision": 0,
83 // CHECK-NEXT:   "rules": [
84 // CHECK-NEXT:     {
85 // CHECK-NEXT:       "primary-output": "[[PREFIX]]/M.o",
86 // CHECK-NEXT:       "provides": [
87 // CHECK-NEXT:         {
88 // CHECK-NEXT:           "is-interface": true,
89 // CHECK-NEXT:           "logical-name": "M",
90 // CHECK-NEXT:           "source-path": "[[PREFIX]]/M.cppm"
91 // CHECK-NEXT:         }
92 // CHECK-NEXT:       ],
93 // CHECK-NEXT:       "requires": [
94 // CHECK-NEXT:         {
95 // CHECK-NEXT:           "logical-name": "M:interface_part"
96 // CHECK-NEXT:         },
97 // CHECK-NEXT:         {
98 // CHECK-NEXT:           "logical-name": "M:impl_part"
99 // CHECK-NEXT:         }
100 // CHECK-NEXT:       ]
101 // CHECK-NEXT:     }
102 // CHECK-NEXT:   ],
103 // CHECK-NEXT:   "version": 1
104 // CHECK-NEXT: }
106 //--- Impl.cpp
107 module;
108 #include "header.mock"
109 module M;
110 void Hello() {
111     std::cout << "Hello ";
114 // CHECK: {
115 // CHECK-NEXT:   "revision": 0,
116 // CHECK-NEXT:   "rules": [
117 // CHECK-NEXT:     {
118 // CHECK-NEXT:       "primary-output": "[[PREFIX]]/Impl.o",
119 // CHECK-NEXT:       "requires": [
120 // CHECK-NEXT:         {
121 // CHECK-NEXT:           "logical-name": "M"
122 // CHECK-NEXT:         }
123 // CHECK-NEXT:       ]
124 // CHECK-NEXT:     }
125 // CHECK-NEXT:   ],
126 // CHECK-NEXT:   "version": 1
127 // CHECK-NEXT: }
129 //--- impl_part.cppm
130 module;
131 #include "header.mock"
132 module M:impl_part;
133 import :interface_part;
135 std::string W = "World.";
136 void World() {
137     std::cout << W << std::endl;
140 // CHECK: {
141 // CHECK-NEXT:   "revision": 0,
142 // CHECK-NEXT:   "rules": [
143 // CHECK-NEXT:     {
144 // CHECK-NEXT:       "primary-output": "[[PREFIX]]/impl_part.o",
145 // CHECK-NEXT:       "provides": [
146 // CHECK-NEXT:         {
147 // CHECK-NEXT:           "is-interface": false,
148 // CHECK-NEXT:           "logical-name": "M:impl_part",
149 // CHECK-NEXT:           "source-path": "[[PREFIX]]/impl_part.cppm"
150 // CHECK-NEXT:         }
151 // CHECK-NEXT:       ],
152 // CHECK-NEXT:       "requires": [
153 // CHECK-NEXT:         {
154 // CHECK-NEXT:           "logical-name": "M:interface_part"
155 // CHECK-NEXT:         }
156 // CHECK-NEXT:       ]
157 // CHECK-NEXT:     }
158 // CHECK-NEXT:   ],
159 // CHECK-NEXT:   "version": 1
160 // CHECK-NEXT: }
162 // CHECK-MAKE: [[PREFIX]]/impl_part.o.ddi:
163 // CHECK-MAKE:   [[PREFIX]]/impl_part.cppm
164 // CHECK-MAKE:   [[PREFIX]]/header.mock
166 //--- interface_part.cppm
167 export module M:interface_part;
168 export void World();
170 // CHECK: {
171 // CHECK-NEXT:   "revision": 0,
172 // CHECK-NEXT:   "rules": [
173 // CHECK-NEXT:     {
174 // CHECK-NEXT:       "primary-output": "[[PREFIX]]/interface_part.o",
175 // CHECK-NEXT:       "provides": [
176 // CHECK-NEXT:         {
177 // CHECK-NEXT:           "is-interface": true,
178 // CHECK-NEXT:           "logical-name": "M:interface_part",
179 // CHECK-NEXT:           "source-path": "[[PREFIX]]/interface_part.cppm"
180 // CHECK-NEXT:         }
181 // CHECK-NEXT:       ]
182 // CHECK-NEXT:     }
183 // CHECK-NEXT:   ],
184 // CHECK-NEXT:   "version": 1
185 // CHECK-NEXT: }
187 //--- User.cpp
188 import M;
189 import third_party_module;
190 int main() {
191     Hello();
192     World();
193     return 0;
196 // CHECK: {
197 // CHECK-NEXT:   "revision": 0,
198 // CHECK-NEXT:   "rules": [
199 // CHECK-NEXT:     {
200 // CHECK-NEXT:       "primary-output": "[[PREFIX]]/User.o",
201 // CHECK-NEXT:       "requires": [
202 // CHECK-NEXT:         {
203 // CHECK-NEXT:           "logical-name": "M"
204 // CHECK-NEXT:         },
205 // CHECK-NEXT:         {
206 // CHECK-NEXT:           "logical-name": "third_party_module"
207 // CHECK-NEXT:         }
208 // CHECK-NEXT:       ]
209 // CHECK-NEXT:     }
210 // CHECK-NEXT:   ],
211 // CHECK-NEXT:   "version": 1
212 // CHECK-NEXT: }
214 //--- Checks.cpp
215 // CHECK: {
216 // CHECK-NEXT:   "revision": 0,
217 // CHECK-NEXT:   "rules": [
218 // CHECK-NEXT:     {
219 // CHECK-NEXT:       "primary-output": "[[PREFIX]]/Impl.o",
220 // CHECK-NEXT:       "requires": [
221 // CHECK-NEXT:         {
222 // CHECK-NEXT:           "logical-name": "M",
223 // CHECK-NEXT:           "source-path": "[[PREFIX]]/M.cppm"
224 // CHECK-NEXT:         }
225 // CHECK-NEXT:       ]
226 // CHECK-NEXT:     },
227 // CHECK-NEXT:     {
228 // CHECK-NEXT:       "primary-output": "[[PREFIX]]/M.o",
229 // CHECK-NEXT:       "provides": [
230 // CHECK-NEXT:         {
231 // CHECK-NEXT:           "is-interface": true,
232 // CHECK-NEXT:           "logical-name": "M",
233 // CHECK-NEXT:           "source-path": "[[PREFIX]]/M.cppm"
234 // CHECK-NEXT:         }
235 // CHECK-NEXT:       ],
236 // CHECK-NEXT:       "requires": [
237 // CHECK-NEXT:         {
238 // CHECK-NEXT:           "logical-name": "M:interface_part",
239 // CHECK-NEXT:           "source-path": "[[PREFIX]]/interface_part.cppm"
240 // CHECK-NEXT:         },
241 // CHECK-NEXT:         {
242 // CHECK-NEXT:           "logical-name": "M:impl_part",
243 // CHECK-NEXT:           "source-path": "[[PREFIX]]/impl_part.cppm"
244 // CHECK-NEXT:         }
245 // CHECK-NEXT:       ]
246 // CHECK-NEXT:     },
247 // CHECK-NEXT:     {
248 // CHECK-NEXT:       "primary-output": "[[PREFIX]]/User.o",
249 // CHECK-NEXT:       "requires": [
250 // CHECK-NEXT:         {
251 // CHECK-NEXT:           "logical-name": "M",
252 // CHECK-NEXT:           "source-path": "[[PREFIX]]/M.cppm"
253 // CHECK-NEXT:         },
254 // CHECK-NEXT:         {
255 // CHECK-NEXT:           "logical-name": "third_party_module"
256 // CHECK-NEXT:         }
257 // CHECK-NEXT:       ]
258 // CHECK-NEXT:     },
259 // CHECK-NEXT:     {
260 // CHECK-NEXT:       "primary-output": "[[PREFIX]]/impl_part.o",
261 // CHECK-NEXT:       "provides": [
262 // CHECK-NEXT:         {
263 // CHECK-NEXT:           "is-interface": false,
264 // CHECK-NEXT:           "logical-name": "M:impl_part",
265 // CHECK-NEXT:           "source-path": "[[PREFIX]]/impl_part.cppm"
266 // CHECK-NEXT:         }
267 // CHECK-NEXT:       ],
268 // CHECK-NEXT:       "requires": [
269 // CHECK-NEXT:         {
270 // CHECK-NEXT:           "logical-name": "M:interface_part",
271 // CHECK-NEXT:           "source-path": "[[PREFIX]]/interface_part.cppm"
272 // CHECK-NEXT:         }
273 // CHECK-NEXT:       ]
274 // CHECK-NEXT:     },
275 // CHECK-NEXT:     {
276 // CHECK-NEXT:       "primary-output": "[[PREFIX]]/interface_part.o",
277 // CHECK-NEXT:       "provides": [
278 // CHECK-NEXT:         {
279 // CHECK-NEXT:           "is-interface": true,
280 // CHECK-NEXT:           "logical-name": "M:interface_part",
281 // CHECK-NEXT:           "source-path": "[[PREFIX]]/interface_part.cppm"
282 // CHECK-NEXT:         }
283 // CHECK-NEXT:       ]
284 // CHECK-NEXT:     }
285 // CHECK-NEXT:   ],
286 // CHECK-NEXT:   "version": 1
287 // CHECK-NEXT: }
289 // CHECK-MAKE-DAG: [[PREFIX]]/impl_part.o.ddi: \
290 // CHECK-MAKE-DAG-NEXT:   [[PREFIX]]/impl_part.cppm \
291 // CHECK-MAKE-DAG-NEXT:   [[PREFIX]]/header.mock
292 // CHECK-MAKE-DAG: [[PREFIX]]/interface_part.o.ddi: \
293 // CHECK-MAKE-DAG-NEXT:   [[PREFIX]]/interface_part.cppm
294 // CHECK-MAKE-DAG: [[PREFIX]]/M.o.ddi: \
295 // CHECK-MAKE-DAG-NEXT:   [[PREFIX]]/M.cppm
296 // CHECK-MAKE-DAG: [[PREFIX]]/User.o.ddi: \
297 // CHECK-MAKE-DAG-NEXT:   [[PREFIX]]/User.cpp
298 // CHECK-MAKE-DAG: [[PREFIX]]/Impl.o.ddi: \
299 // CHECK-MAKE-DAG-NEXT:   [[PREFIX]]/Impl.cpp \
300 // CHECK-MAKE-DAG-NEXT:   [[PREFIX]]/header.mock
302 //--- header.mock