• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Note: %s and %S must be preceded by --, otherwise it may be interpreted as a
2 // command-line option, e.g. on Mac where %s is commonly under /Users.
3 
4 // /Yc
5 // RUN: %clang_cl -Werror /Ycpchfile.h /FIpchfile.h /c -### -- %s 2>&1 \
6 // RUN:   | FileCheck -check-prefix=CHECK-YC %s
7 // 1. Build .pch file.
8 // CHECK-YC: cc1
9 // CHECK-YC: -emit-pch
10 // CHECK-YC: -o
11 // CHECK-YC: pchfile.pch
12 // CHECK-YC: -x
13 // CHECK-YC: "c++"
14 // 2. Use .pch file.
15 // CHECK-YC: cc1
16 // CHECK-YC: -emit-obj
17 // CHECK-YC: -include-pch
18 // CHECK-YC: pchfile.pch
19 
20 // /Yc /Fo
21 // /Fo overrides the .obj output filename, but not the .pch filename
22 // RUN: %clang_cl -Werror /Fomyobj.obj /Ycpchfile.h /FIpchfile.h /c -### -- %s 2>&1 \
23 // RUN:   | FileCheck -check-prefix=CHECK-YCO %s
24 // 1. Build .pch file.
25 // CHECK-YCO: cc1
26 // CHECK-YCO: -emit-pch
27 // CHECK-YCO: -o
28 // CHECK-YCO: pchfile.pch
29 // 2. Use .pch file.
30 // CHECK-YCO: cc1
31 // CHECK-YCO: -emit-obj
32 // CHECK-YCO: -include-pch
33 // CHECK-YCO: pchfile.pch
34 // CHECK-YCO: -o
35 // CHECK-YCO: myobj.obj
36 
37 // /Yc /Y-
38 // /Y- disables pch generation
39 // RUN: %clang_cl -Werror /Y- /Ycpchfile.h /FIpchfile.h /c -### -- %s 2>&1 \
40 // RUN:   | FileCheck -check-prefix=CHECK-YC-Y_ %s
41 // CHECK-YC-Y_-NOT: -emit-pch
42 // CHECK-YC-Y_-NOT: -include-pch
43 
44 // /Yu
45 // RUN: %clang_cl -Werror /Yupchfile.h /FIpchfile.h /c -### -- %s 2>&1 \
46 // RUN:   | FileCheck -check-prefix=CHECK-YU %s
47 // Use .pch file, but don't build it.
48 // CHECK-YU-NOT: -emit-pch
49 // CHECK-YU: cc1
50 // CHECK-YU: -emit-obj
51 // CHECK-YU: -include-pch
52 // CHECK-YU: pchfile.pch
53 
54 // /Yu /Y-
55 // RUN: %clang_cl -Werror /Y- /Yupchfile.h /FIpchfile.h /c -### -- %s 2>&1 \
56 // RUN:   | FileCheck -check-prefix=CHECK-YU-Y_ %s
57 // CHECK-YU-Y_-NOT: -emit-pch
58 // CHECK-YU-Y_-NOT: -include-pch
59 
60 // /Yc /Yu -- /Yc overrides /Yc if they both refer to the same file
61 // RUN: %clang_cl -Werror /Ycpchfile.h /Yupchfile.h /FIpchfile.h /c -### -- %s 2>&1 \
62 // RUN:   | FileCheck -check-prefix=CHECK-YC-YU %s
63 // 1. Build .pch file.
64 // CHECK-YC-YU: cc1
65 // CHECK-YC-YU: -emit-pch
66 // CHECK-YC-YU: -o
67 // CHECK-YC-YU: pchfile.pch
68 // 2. Use .pch file.
69 // CHECK-YC-YU: cc1
70 // CHECK-YC-YU: -emit-obj
71 // CHECK-YC-YU: -include-pch
72 // CHECK-YC-YU: pchfile.pch
73 
74 // If /Yc /Yu refer to different files, semantics are pretty wonky.  Since this
75 // doesn't seem like something that's important in practice, just punt for now.
76 // RUN: %clang_cl -Werror /Ycfoo1.h /Yufoo2.h /FIfoo1.h /FIfoo2.h /c -### -- %s 2>&1 \
77 // RUN:   | FileCheck -check-prefix=CHECK-YC-YU-MISMATCH %s
78 // CHECK-YC-YU-MISMATCH: error: support for '/Yc' and '/Yu' with different filenames not implemented yet; flags ignored
79 
80 // Similarly, punt on /Yc with more than one input file.
81 // RUN: %clang_cl -Werror /Ycfoo1.h /FIfoo1.h /c -### -- %s %s 2>&1 \
82 // RUN:   | FileCheck -check-prefix=CHECK-YC-MULTIINPUT %s
83 // CHECK-YC-MULTIINPUT: error: support for '/Yc' with more than one source file not implemented yet; flag ignored
84 
85 // /Yc /Yu /Y-
86 // RUN: %clang_cl -Werror /Ycpchfile.h /Yupchfile.h /FIpchfile.h /Y- /c -### -- %s 2>&1 \
87 // RUN:   | FileCheck -check-prefix=CHECK-YC-YU-Y_ %s
88 // CHECK-YC-YU-Y_-NOT: -emit-pch
89 // CHECK-YC-YU-Y_-NOT: -include-pch
90 
91 // Test computation of pch filename in various cases.
92 
93 // /Yu /Fpout.pch => out.pch is filename
94 // RUN: %clang_cl -Werror /Yupchfile.h /FIpchfile.h /Fpout.pch /c -### -- %s 2>&1 \
95 // RUN:   | FileCheck -check-prefix=CHECK-YUFP1 %s
96 // Use .pch file, but don't build it.
97 // CHECK-YUFP1: -include-pch
98 // CHECK-YUFP1: out.pch
99 
100 // /Yu /Fpout => out.pch is filename (.pch gets added if no extension present)
101 // RUN: %clang_cl -Werror /Yupchfile.h /FIpchfile.h /Fpout.pch /c -### -- %s 2>&1 \
102 // RUN:   | FileCheck -check-prefix=CHECK-YUFP2 %s
103 // Use .pch file, but don't build it.
104 // CHECK-YUFP2: -include-pch
105 // CHECK-YUFP2: out.pch
106 
107 // /Yu /Fpout.bmp => out.bmp is filename (.pch not added when extension present)
108 // RUN: %clang_cl -Werror /Yupchfile.h /FIpchfile.h /Fpout.bmp /c -### -- %s 2>&1 \
109 // RUN:   | FileCheck -check-prefix=CHECK-YUFP3 %s
110 // Use .pch file, but don't build it.
111 // CHECK-YUFP3: -include-pch
112 // CHECK-YUFP3: out.bmp
113 
114 // /Yusub/dir.h => sub/dir.pch
115 // RUN: %clang_cl -Werror /Yusub/pchfile.h /FIsub/pchfile.h /c -### -- %s 2>&1 \
116 // RUN:   | FileCheck -check-prefix=CHECK-YUFP4 %s
117 // Use .pch file, but don't build it.
118 // CHECK-YUFP4: -include-pch
119 // CHECK-YUFP4: sub/pchfile.pch
120 
121 // /Yudir.h /Isub => dir.pch
122 // RUN: %clang_cl -Werror /Yupchfile.h /FIpchfile.h /Isub /c -### -- %s 2>&1 \
123 // RUN:   | FileCheck -check-prefix=CHECK-YUFP5 %s
124 // Use .pch file, but don't build it.
125 // CHECK-YUFP5: -include-pch
126 // CHECK-YUFP5: pchfile.pch
127 
128 // FIXME: /Fpdir: use dir/VCx0.pch when dir is directory, where x is major MSVS
129 // version in use.
130 
131 // Spot-check one use of /Fp with /Yc too, else trust the /Yu test cases above
132 // also all assume to /Yc.
133 // RUN: %clang_cl -Werror /Ycpchfile.h /FIpchfile.h /Fpsub/file.pch /c -### -- %s 2>&1 \
134 // RUN:   | FileCheck -check-prefix=CHECK-YCFP %s
135 // 1. Build .pch file.
136 // CHECK-YCFP: cc1
137 // CHECK-YCFP: -emit-pch
138 // CHECK-YCFP: -o
139 // CHECK-YCFP: sub/file.pch
140 // 2. Use .pch file.
141 // CHECK-YCFP: cc1
142 // CHECK-YCFP: -emit-obj
143 // CHECK-YCFP: -include-pch
144 // CHECK-YCFP: sub/file.pch
145 
146 // /Ycfoo2.h /FIfoo1.h /FIfoo2.h /FIfoo3.h
147 // => foo1 and foo2 go into pch, foo3 into main compilation
148 // /Yc
149 // RUN: %clang_cl -Werror /Ycfoo2.h /FIfoo1.h /FIfoo2.h /FIfoo3.h /c -### -- %s 2>&1 \
150 // RUN:   | FileCheck -check-prefix=CHECK-YCFIFIFI %s
151 // 1. Build .pch file: Includes foo1.h (but NOT foo3.h) and compiles foo2.h
152 // CHECK-YCFIFIFI: cc1
153 // CHECK-YCFIFIFI: -emit-pch
154 // CHECK-YCFIFIFI: -include
155 // CHECK-YCFIFIFI: foo1.h
156 // CHECK-YCFIFIFI-NOT: foo2.h
157 // CHECK-YCFIFIFI-NOT: foo3.h
158 // CHECK-YCFIFIFI: -o
159 // CHECK-YCFIFIFI: foo2.pch
160 // CHECK-YCFIFIFI: -x
161 // CHECK-YCFIFIFI: "c++"
162 // CHECK-YCFIFIFI: foo2.h
163 // 2. Use .pch file: Inlucdes foo2.pch and foo3.h
164 // CHECK-YCFIFIFI: cc1
165 // CHECK-YCFIFIFI: -emit-obj
166 // CHECK-YCFIFIFI-NOT: foo1.h
167 // CHECK-YCFIFIFI-NOT: foo2.h
168 // CHECK-YCFIFIFI: -include-pch
169 // CHECK-YCFIFIFI: foo2.pch
170 // CHECK-YCFIFIFI: -include
171 // CHECK-YCFIFIFI: foo3.h
172 
173 // /Yucfoo2.h /FIfoo1.h /FIfoo2.h /FIfoo3.h
174 // => foo1 foo2 filtered out, foo3 into main compilation
175 // RUN: %clang_cl -Werror /Yufoo2.h /FIfoo1.h /FIfoo2.h /FIfoo3.h /c -### -- %s 2>&1 \
176 // RUN:   | FileCheck -check-prefix=CHECK-YUFIFIFI %s
177 // Use .pch file, but don't build it.
178 // CHECK-YUFIFIFI-NOT: -emit-pch
179 // CHECK-YUFIFIFI: cc1
180 // CHECK-YUFIFIFI: -emit-obj
181 // CHECK-YUFIFIFI-NOT: foo1.h
182 // CHECK-YUFIFIFI-NOT: foo2.h
183 // CHECK-YUFIFIFI: -include-pch
184 // CHECK-YUFIFIFI: foo2.pch
185 // CHECK-YUFIFIFI: -include
186 // CHECK-YUFIFIFI: foo3.h
187 
188 // FIXME: Implement support for /Ycfoo.h / /Yufoo.h without /FIfoo.h
189 // RUN: %clang_cl -Werror /Ycfoo.h /c -### -- %s 2>&1 \
190 // RUN:   | FileCheck -check-prefix=CHECK-YC-NOFI %s
191 // CHECK-YC-NOFI: error: support for '/Yc' without a corresponding /FI flag not implemented yet; flag ignored
192 // RUN: %clang_cl -Werror /Yufoo.h /c -### -- %s 2>&1 \
193 // RUN:   | FileCheck -check-prefix=CHECK-YU-NOFI %s
194 // CHECK-YU-NOFI: error: support for '/Yu' without a corresponding /FI flag not implemented yet; flag ignored
195 
196 // /Yc and /FI relative to /I paths...
197 // The rules are:
198 // Yu/Yc and FI parameter must match exactly, else it's not found
199 // Must match literally exactly: /FI./foo.h /Ycfoo.h does _not_ work.
200 // However, the path can be relative to /I paths.
201 // FIXME: Update the error messages below once /FI is no longer required, but
202 // these test cases all should stay failures as they fail with cl.exe.
203 
204 // Check that ./ isn't canonicalized away.
205 // RUN: %clang_cl -Werror /Ycpchfile.h /FI./pchfile.h /c -### -- %s 2>&1 \
206 // RUN:   | FileCheck -check-prefix=CHECK-YC-I1 %s
207 // CHECK-YC-I1: support for '/Yc' without a corresponding /FI flag not implemented yet; flag ignored
208 
209 // Check that ./ isn't canonicalized away.
210 // RUN: %clang_cl -Werror /Yc./pchfile.h /FIpchfile.h /c -### -- %s 2>&1 \
211 // RUN:   | FileCheck -check-prefix=CHECK-YC-I2 %s
212 // CHECK-YC-I2: support for '/Yc' without a corresponding /FI flag not implemented yet; flag ignored
213 
214 // With an actual /I argument.
215 // RUN: %clang_cl -Werror /Ifoo /Ycpchfile.h /FIpchfile.h /c -### -- %s 2>&1 \
216 // RUN:   | FileCheck -check-prefix=CHECK-YC-I3 %s
217 // 1. This writes pchfile.pch into the root dir, even if this will pick up
218 //    foo/pchfile.h
219 // CHECK-YC-I3: cc1
220 // CHECK-YC-I3: -emit-pch
221 // CHECK-YC-I3: -o
222 // CHECK-YC-I3: pchfile.pch
223 // 2. Use .pch file.
224 // CHECK-YC-I3: cc1
225 // CHECK-YC-I3: -emit-obj
226 // CHECK-YC-I3: -include-pch
227 // CHECK-YC-I3: pchfile.pch
228 
229 // Check that ./ isn't canonicalized away for /Yu either.
230 // RUN: %clang_cl -Werror /Yupchfile.h /FI./pchfile.h /c -### -- %s 2>&1 \
231 // RUN:   | FileCheck -check-prefix=CHECK-YU-I1 %s
232 // CHECK-YU-I1: support for '/Yu' without a corresponding /FI flag not implemented yet; flag ignored
233 
234 // But /FIfoo/bar.h /Ycfoo\bar.h does work, as does /FIfOo.h /Ycfoo.H
235 // FIXME: This part isn't implemented yet. The following two tests should not
236 // show an error but do regular /Yu handling.
237 // RUN: %clang_cl -Werror /YupchFILE.h /FI./pchfile.h /c -### -- %s 2>&1 \
238 // RUN:   | FileCheck -check-prefix=CHECK-YU-CASE %s
239 // CHECK-YU-CASE: support for '/Yu' without a corresponding /FI flag not implemented yet; flag ignored
240 // RUN: %clang_cl -Werror /Yu./pchfile.h /FI.\pchfile.h /c -### -- %s 2>&1 \
241 // RUN:   | FileCheck -check-prefix=CHECK-YU-SLASH %s
242 // CHECK-YU-SLASH: support for '/Yu' without a corresponding /FI flag not implemented yet; flag ignored
243 
244 // cl.exe warns on multiple /Yc, /Yu, /Fp arguments, but clang-cl silently just
245 // uses the last one.  This is true for e.g. /Fo too, so not warning on this
246 // is self-consistent with clang-cl's flag handling.
247 
248 // Interaction with /fallback
249 
250 // /Yc /fallback => /Yc not passed on (but /FI is)
251 // RUN: %clang_cl -Werror /Ycpchfile.h /FIpchfile.h /Fpfoo.pch /fallback /c -### -- %s 2>&1 \
252 // RUN:   | FileCheck -check-prefix=CHECK-YC-FALLBACK %s
253 // Note that in /fallback builds, if creation of the pch fails the main compile
254 // does still run so that /fallback can have an effect (this part is not tested)
255 // CHECK-YC-FALLBACK: cc1
256 // CHECK-YC-FALLBACK: -emit-obj
257 // CHECK-YC-FALLBACK: -include-pch
258 // CHECK-YC-FALLBACK: foo.pch
259 // CHECK-YC-FALLBACK: ||
260 // CHECK-YC-FALLBACK: cl.exe
261 // CHECK-YC-FALLBACK-NOT: -include-pch
262 // CHECK-YC-FALLBACK-NOT: /Ycpchfile.h
263 // CHECK-YC-FALLBACK: /FIpchfile.h
264 // CHECK-YC-FALLBACK-NOT: /Fpfoo.pch
265 
266 // /Yu /fallback => /Yu not passed on (but /FI is)
267 // RUN: %clang_cl -Werror /Yupchfile.h /FIpchfile.h /Fpfoo.pch /fallback /c -### -- %s 2>&1 \
268 // RUN:   | FileCheck -check-prefix=CHECK-YU-FALLBACK %s
269 // CHECK-YU-FALLBACK-NOT: -emit-pch
270 // CHECK-YU-FALLBACK: cc1
271 // CHECK-YU-FALLBACK: -emit-obj
272 // CHECK-YU-FALLBACK: -include-pch
273 // CHECK-YU-FALLBACK: foo.pch
274 // CHECK-YU-FALLBACK: ||
275 // CHECK-YU-FALLBACK: cl.exe
276 // CHECK-YU-FALLBACK-NOT: -include-pch
277 // CHECK-YU-FALLBACK-NOT: /Yupchfile.h
278 // CHECK-YU-FALLBACK: /FIpchfile.h
279 // CHECK-YU-FALLBACK-NOT: /Fpfoo.pch
280 
281 // /FI without /Yu => pch file not used, even if it exists (different from
282 // -include, which picks up .gch files if they exist).
283 // RUN: touch %t.pch
284 // RUN: %clang_cl -Werror /FI%t.pch /Fp%t.pch /c -### -- %s 2>&1 \
285 // RUN:   | FileCheck -check-prefix=CHECK-FI %s
286 // CHECK-FI-NOT: -include-pch
287 // CHECK-FI: -include
288 
289 // Test interaction of /Yc with language mode flags.
290 
291 // If /TC changes the input language to C, a c pch file should be produced.
292 // RUN: %clang_cl /TC -Werror /Ycpchfile.h /FIpchfile.h /c -### -- %s 2>&1 \
293 // RUN:   | FileCheck -check-prefix=CHECK-YCTC %s
294 // CHECK-YCTC: cc1
295 // CHECK-YCTC: -emit-pch
296 // CHECK-YCTC: -o
297 // CHECK-YCTC: pchfile.pch
298 // CHECK-YCTC: -x
299 // CHECK-YCTC: "c"
300 
301 // Also check lower-case /Tc variant.
302 // RUN: %clang_cl -Werror /Ycpchfile.h /FIpchfile.h /c -### /Tc%s 2>&1 \
303 // RUN:   | FileCheck -check-prefix=CHECK-YCTc %s
304 // CHECK-YCTc: cc1
305 // CHECK-YCTc: -emit-pch
306 // CHECK-YCTc: -o
307 // CHECK-YCTc: pchfile.pch
308 // CHECK-YCTc: -x
309 // CHECK-YCTc: "c"
310 
311 // Don't crash when a non-source file is passed.
312 // RUN: %clang_cl -Werror /Ycpchfile.h /FIpchfile.h /c -### -- %S/Inputs/file.prof 2>&1 \
313 // RUN:   | FileCheck -check-prefix=CHECK-NoSource %s
314 // CHECK-NoSource: file.prof:{{.*}}input unused
315 
316 // ...but if an explicit file turns the file into a source file, handle it:
317 // RUN: %clang_cl /TP -Werror /Ycpchfile.h /FIpchfile.h /c -### -- %S/Inputs/file.prof 2>&1 \
318 // RUN:   | FileCheck -check-prefix=CHECK-NoSourceTP %s
319 // CHECK-NoSourceTP: cc1
320 // CHECK-NoSourceTP: -emit-pch
321 // CHECK-NoSourceTP: -o
322 // CHECK-NoSourceTP: pchfile.pch
323 // CHECK-NoSourceTP: -x
324 // CHECK-NoSourceTP: "c++"
325