1 // Note: %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 
5 // Alias options:
6 
7 // RUN: %clang_cl /c -### -- %s 2>&1 | FileCheck -check-prefix=c %s
8 // c: -c
9 
10 // RUN: %clang_cl /C -### -- %s 2>&1 | FileCheck -check-prefix=C %s
11 // C: error: invalid argument '-C' only allowed with '/E, /P or /EP'
12 
13 // RUN: %clang_cl /C /P -### -- %s 2>&1 | FileCheck -check-prefix=C_P %s
14 // C_P: "-E"
15 // C_P: "-C"
16 
17 // RUN: %clang_cl /Dfoo=bar -### -- %s 2>&1 | FileCheck -check-prefix=D %s
18 // RUN: %clang_cl /D foo=bar -### -- %s 2>&1 | FileCheck -check-prefix=D %s
19 // D: "-D" "foo=bar"
20 
21 // RUN: %clang_cl /E -### -- %s 2>&1 | FileCheck -check-prefix=E %s
22 // E: "-E"
23 // E: "-o" "-"
24 
25 // RUN: %clang_cl /EP -### -- %s 2>&1 | FileCheck -check-prefix=EP %s
26 // EP: "-E"
27 // EP: "-P"
28 // EP: "-o" "-"
29 
30 // RUN: %clang_cl /fp:fast /fp:except -### -- %s 2>&1 | FileCheck -check-prefix=fpexcept %s
31 // fpexcept-NOT: -menable-unsafe-fp-math
32 
33 // RUN: %clang_cl /fp:fast /fp:except /fp:except- -### -- %s 2>&1 | FileCheck -check-prefix=fpexcept_ %s
34 // fpexcept_: -menable-unsafe-fp-math
35 
36 // RUN: %clang_cl /fp:precise /fp:fast -### -- %s 2>&1 | FileCheck -check-prefix=fpfast %s
37 // fpfast: -menable-unsafe-fp-math
38 // fpfast: -ffast-math
39 
40 // RUN: %clang_cl /fp:fast /fp:precise -### -- %s 2>&1 | FileCheck -check-prefix=fpprecise %s
41 // fpprecise-NOT: -menable-unsafe-fp-math
42 // fpprecise-NOT: -ffast-math
43 
44 // RUN: %clang_cl /fp:fast /fp:strict -### -- %s 2>&1 | FileCheck -check-prefix=fpstrict %s
45 // fpstrict-NOT: -menable-unsafe-fp-math
46 // fpstrict-NOT: -ffast-math
47 
48 // RUN: %clang_cl /GA -### -- %s 2>&1 | FileCheck -check-prefix=GA %s
49 // GA: -ftls-model=local-exec
50 
51 // RTTI is on by default; just check that we don't error.
52 // RUN: %clang_cl /Zs /GR -- %s 2>&1
53 
54 // RUN: %clang_cl /GR- -### -- %s 2>&1 | FileCheck -check-prefix=GR_ %s
55 // GR_: -fno-rtti
56 
57 // RUN: %clang_cl /Gy -### -- %s 2>&1 | FileCheck -check-prefix=Gy %s
58 // Gy: -ffunction-sections
59 
60 // RUN: %clang_cl /Gy /Gy- -### -- %s 2>&1 | FileCheck -check-prefix=Gy_ %s
61 // Gy_-NOT: -ffunction-sections
62 
63 // RUN: %clang_cl /Gs -### -- %s 2>&1 | FileCheck -check-prefix=Gs %s
64 // Gs: "-mstack-probe-size=0"
65 // RUN: %clang_cl /Gs0 -### -- %s 2>&1 | FileCheck -check-prefix=Gs0 %s
66 // Gs0: "-mstack-probe-size=0"
67 // RUN: %clang_cl /Gs4096 -### -- %s 2>&1 | FileCheck -check-prefix=Gs4096 %s
68 // Gs4096: "-mstack-probe-size=4096"
69 
70 // RUN: %clang_cl /Gw -### -- %s 2>&1 | FileCheck -check-prefix=Gw %s
71 // Gw: -fdata-sections
72 
73 // RUN: %clang_cl /Gw /Gw- -### -- %s 2>&1 | FileCheck -check-prefix=Gw_ %s
74 // Gw_-NOT: -fdata-sections
75 
76 // RUN: %clang_cl /Imyincludedir -### -- %s 2>&1 | FileCheck -check-prefix=SLASH_I %s
77 // RUN: %clang_cl /I myincludedir -### -- %s 2>&1 | FileCheck -check-prefix=SLASH_I %s
78 // SLASH_I: "-I" "myincludedir"
79 
80 // RUN: %clang_cl /J -### -- %s 2>&1 | FileCheck -check-prefix=J %s
81 // J: -fno-signed-char
82 
83 // RUN: %clang_cl /Ofoo -### -- %s 2>&1 | FileCheck -check-prefix=O %s
84 // O: /Ofoo
85 
86 // RUN: %clang_cl /Ob0 -### -- %s 2>&1 | FileCheck -check-prefix=Ob0 %s
87 // Ob0: -fno-inline
88 
89 // RUN: %clang_cl /Od -### -- %s 2>&1 | FileCheck -check-prefix=Od %s
90 // Od: -O0
91 
92 // RUN: %clang_cl /Oi- /Oi -### -- %s 2>&1 | FileCheck -check-prefix=Oi %s
93 // Oi-NOT: -fno-builtin
94 
95 // RUN: %clang_cl /Oi- -### -- %s 2>&1 | FileCheck -check-prefix=Oi_ %s
96 // Oi_: -fno-builtin
97 
98 // RUN: %clang_cl /Os --target=i686-pc-windows-msvc -### -- %s 2>&1 | FileCheck -check-prefix=Os %s
99 // RUN: %clang_cl /Os --target=x86_64-pc-windows-msvc -### -- %s 2>&1 | FileCheck -check-prefix=Os %s
100 // Os-NOT: -mdisable-fp-elim
101 // Os: -momit-leaf-frame-pointer
102 // Os: -Os
103 
104 // RUN: %clang_cl /Ot --target=i686-pc-windows-msvc -### -- %s 2>&1 | FileCheck -check-prefix=Ot %s
105 // RUN: %clang_cl /Ot --target=x86_64-pc-windows-msvc -### -- %s 2>&1 | FileCheck -check-prefix=Ot %s
106 // Ot-NOT: -mdisable-fp-elim
107 // Ot: -momit-leaf-frame-pointer
108 // Ot: -O2
109 
110 // RUN: %clang_cl /Ox --target=i686-pc-windows-msvc -### -- %s 2>&1 | FileCheck -check-prefix=Ox %s
111 // RUN: %clang_cl /Ox --target=x86_64-pc-windows-msvc -### -- %s 2>&1 | FileCheck -check-prefix=Ox %s
112 // Ox-NOT: -mdisable-fp-elim
113 // Ox: -momit-leaf-frame-pointer
114 // Ox: -O2
115 
116 // RUN: %clang_cl --target=i686-pc-win32 /O2sy- -### -- %s 2>&1 | FileCheck -check-prefix=PR24003 %s
117 // PR24003: -mdisable-fp-elim
118 // PR24003: -momit-leaf-frame-pointer
119 // PR24003: -Os
120 
121 // RUN: %clang_cl /Zs /Oy -- %s 2>&1
122 
123 // RUN: %clang_cl --target=i686-pc-win32 /Oy- -### -- %s 2>&1 | FileCheck -check-prefix=Oy_ %s
124 // Oy_: -mdisable-fp-elim
125 
126 // RUN: %clang_cl /Qvec -### -- %s 2>&1 | FileCheck -check-prefix=Qvec %s
127 // Qvec: -vectorize-loops
128 
129 // RUN: %clang_cl /Qvec /Qvec- -### -- %s 2>&1 | FileCheck -check-prefix=Qvec_ %s
130 // Qvec_-NOT: -vectorize-loops
131 
132 // RUN: %clang_cl /showIncludes -### -- %s 2>&1 | FileCheck -check-prefix=showIncludes %s
133 // showIncludes: --show-includes
134 
135 // RUN: %clang_cl /E /showIncludes -### -- %s 2>&1 | FileCheck -check-prefix=showIncludes_E %s
136 // RUN: %clang_cl /EP /showIncludes -### -- %s 2>&1 | FileCheck -check-prefix=showIncludes_E %s
137 // showIncludes_E: warning: argument unused during compilation: '--show-includes'
138 
139 // RUN: %clang_cl /Umymacro -### -- %s 2>&1 | FileCheck -check-prefix=U %s
140 // RUN: %clang_cl /U mymacro -### -- %s 2>&1 | FileCheck -check-prefix=U %s
141 // U: "-U" "mymacro"
142 
143 // RUN: %clang_cl /vd2 -### -- %s 2>&1 | FileCheck -check-prefix=VD2 %s
144 // VD2: -vtordisp-mode=2
145 
146 // RUN: %clang_cl /vmg -### -- %s 2>&1 | FileCheck -check-prefix=VMG %s
147 // VMG: "-fms-memptr-rep=virtual"
148 
149 // RUN: %clang_cl /vmg /vms -### -- %s 2>&1 | FileCheck -check-prefix=VMS %s
150 // VMS: "-fms-memptr-rep=single"
151 
152 // RUN: %clang_cl /vmg /vmm -### -- %s 2>&1 | FileCheck -check-prefix=VMM %s
153 // VMM: "-fms-memptr-rep=multiple"
154 
155 // RUN: %clang_cl /vmg /vmv -### -- %s 2>&1 | FileCheck -check-prefix=VMV %s
156 // VMV: "-fms-memptr-rep=virtual"
157 
158 // RUN: %clang_cl /vmg /vmb -### -- %s 2>&1 | FileCheck -check-prefix=VMB %s
159 // VMB: '/vmg' not allowed with '/vmb'
160 
161 // RUN: %clang_cl /vmg /vmm /vms -### -- %s 2>&1 | FileCheck -check-prefix=VMX %s
162 // VMX: '/vms' not allowed with '/vmm'
163 
164 // RUN: %clang_cl /volatile:iso -### -- %s 2>&1 | FileCheck -check-prefix=VOLATILE-ISO %s
165 // VOLATILE-ISO-NOT: "-fms-volatile"
166 
167 // RUN: %clang_cl /volatile:ms -### -- %s 2>&1 | FileCheck -check-prefix=VOLATILE-MS %s
168 // VOLATILE-MS: "-fms-volatile"
169 
170 // RUN: %clang_cl /W0 -### -- %s 2>&1 | FileCheck -check-prefix=W0 %s
171 // W0: -w
172 
173 // RUN: %clang_cl /W1 -### -- %s 2>&1 | FileCheck -check-prefix=W1 %s
174 // RUN: %clang_cl /W2 -### -- %s 2>&1 | FileCheck -check-prefix=W1 %s
175 // RUN: %clang_cl /W3 -### -- %s 2>&1 | FileCheck -check-prefix=W1 %s
176 // RUN: %clang_cl /W4 -### -- %s 2>&1 | FileCheck -check-prefix=W4 %s
177 // RUN: %clang_cl /Wall -### -- %s 2>&1 | FileCheck -check-prefix=W4 %s
178 // W1: -Wall
179 // W4: -WCL4
180 
181 // RUN: %clang_cl /WX -### -- %s 2>&1 | FileCheck -check-prefix=WX %s
182 // WX: -Werror
183 
184 // RUN: %clang_cl /WX- -### -- %s 2>&1 | FileCheck -check-prefix=WX_ %s
185 // WX_: -Wno-error
186 
187 // RUN: %clang_cl /w -### -- %s 2>&1 | FileCheck -check-prefix=w %s
188 // w: -w
189 
190 // RUN: %clang_cl /Zp -### -- %s 2>&1 | FileCheck -check-prefix=ZP %s
191 // ZP: -fpack-struct=1
192 
193 // RUN: %clang_cl /Zp2 -### -- %s 2>&1 | FileCheck -check-prefix=ZP2 %s
194 // ZP2: -fpack-struct=2
195 
196 // RUN: %clang_cl /Zs -### -- %s 2>&1 | FileCheck -check-prefix=Zs %s
197 // Zs: -fsyntax-only
198 
199 // RUN: %clang_cl /FIasdf.h -### -- %s 2>&1 | FileCheck -check-prefix=FI %s
200 // FI: "-include" "asdf.h"
201 
202 // RUN: %clang_cl /FI asdf.h -### -- %s 2>&1 | FileCheck -check-prefix=FI_ %s
203 // FI_: "-include" "asdf.h"
204 
205 // We forward any unrecognized -W diagnostic options to cc1.
206 // RUN: %clang_cl -Wunused-pragmas -### -- %s 2>&1 | FileCheck -check-prefix=WJoined %s
207 // WJoined: "-cc1"
208 // WJoined: "-Wunused-pragmas"
209 
210 // We recognize -f[no-]strict-aliasing.
211 // RUN: %clang_cl -c -### -- %s 2>&1 | FileCheck -check-prefix=DEFAULTSTRICT %s
212 // DEFAULTSTRICT: "-relaxed-aliasing"
213 // RUN: %clang_cl -c -fstrict-aliasing -### -- %s 2>&1 | FileCheck -check-prefix=STRICT %s
214 // STRICT-NOT: "-relaxed-aliasing"
215 // RUN: %clang_cl -c -fno-strict-aliasing -### -- %s 2>&1 | FileCheck -check-prefix=NOSTRICT %s
216 // NOSTRICT: "-relaxed-aliasing"
217 
218 // For some warning ids, we can map from MSVC warning to Clang warning.
219 // RUN: %clang_cl -wd4005 -wd4100 -wd4910 -wd4996 -### -- %s 2>&1 | FileCheck -check-prefix=Wno %s
220 // Wno: "-cc1"
221 // Wno: "-Wno-macro-redefined"
222 // Wno: "-Wno-unused-parameter"
223 // Wno: "-Wno-dllexport-explicit-instantiation-decl"
224 // Wno: "-Wno-deprecated-declarations"
225 
226 // Ignored options. Check that we don't get "unused during compilation" errors.
227 // RUN: %clang_cl /c \
228 // RUN:    /analyze- \
229 // RUN:    /bigobj \
230 // RUN:    /cgthreads4 \
231 // RUN:    /cgthreads8 \
232 // RUN:    /d2Zi+ \
233 // RUN:    /errorReport:foo \
234 // RUN:    /Fdfoo \
235 // RUN:    /FS \
236 // RUN:    /Gd \
237 // RUN:    /GF \
238 // RUN:    /GS- \
239 // RUN:    /kernel- \
240 // RUN:    /nologo \
241 // RUN:    /Ob1 \
242 // RUN:    /Ob2 \
243 // RUN:    /openmp- \
244 // RUN:    /RTC1 \
245 // RUN:    /sdl \
246 // RUN:    /sdl- \
247 // RUN:    /vmg \
248 // RUN:    /volatile:iso \
249 // RUN:    /w12345 \
250 // RUN:    /wd1234 \
251 // RUN:    /Zo \
252 // RUN:    /Zo- \
253 // RUN:    -### -- %s 2>&1 | FileCheck -check-prefix=IGNORED %s
254 // IGNORED-NOT: argument unused during compilation
255 // IGNORED-NOT: no such file or directory
256 // Don't confuse /openmp- with the /o flag:
257 // IGNORED-NOT: "-o" "penmp-.obj"
258 
259 // Ignored options and compile-only options are ignored for link jobs.
260 // RUN: touch %t.obj
261 // RUN: %clang_cl /nologo -### -- %t.obj 2>&1 | FileCheck -check-prefix=LINKUNUSED %s
262 // RUN: %clang_cl /Dfoo -### -- %t.obj 2>&1 | FileCheck -check-prefix=LINKUNUSED %s
263 // RUN: %clang_cl /MD -### -- %t.obj 2>&1 | FileCheck -check-prefix=LINKUNUSED %s
264 // LINKUNUSED-NOT: argument unused during compilation
265 
266 // Support ignoring warnings about unused arguments.
267 // RUN: %clang_cl /Abracadabra -Qunused-arguments -### -- %s 2>&1 | FileCheck -check-prefix=UNUSED %s
268 // UNUSED-NOT: argument unused during compilation
269 
270 // Unsupported but parsed options. Check that we don't error on them.
271 // (/Zs is for syntax-only)
272 // RUN: %clang_cl /Zs \
273 // RUN:     /AIfoo \
274 // RUN:     /clr:pure \
275 // RUN:     /docname \
276 // RUN:     /EHsc \
277 // RUN:     /F \
278 // RUN:     /FA \
279 // RUN:     /FAc \
280 // RUN:     /Fafilename \
281 // RUN:     /FAs \
282 // RUN:     /FAu \
283 // RUN:     /favor:blend \
284 // RUN:     /FC \
285 // RUN:     /Fifoo \
286 // RUN:     /Fmfoo \
287 // RUN:     /FpDebug\main.pch \
288 // RUN:     /Frfoo \
289 // RUN:     /FRfoo \
290 // RUN:     /FU foo \
291 // RUN:     /Fx \
292 // RUN:     /G1 \
293 // RUN:     /G2 \
294 // RUN:     /GA \
295 // RUN:     /Gd \
296 // RUN:     /Ge \
297 // RUN:     /Gh \
298 // RUN:     /GH \
299 // RUN:     /GL \
300 // RUN:     /GL- \
301 // RUN:     /Gm \
302 // RUN:     /Gm- \
303 // RUN:     /Gr \
304 // RUN:     /GS \
305 // RUN:     /GT \
306 // RUN:     /guard:cf \
307 // RUN:     /guard:cf- \
308 // RUN:     /GX \
309 // RUN:     /Gv \
310 // RUN:     /Gz \
311 // RUN:     /GZ \
312 // RUN:     /H \
313 // RUN:     /homeparams \
314 // RUN:     /hotpatch \
315 // RUN:     /kernel \
316 // RUN:     /LN \
317 // RUN:     /MP \
318 // RUN:     /o foo.obj \
319 // RUN:     /ofoo.obj \
320 // RUN:     /openmp \
321 // RUN:     /Qfast_transcendentals \
322 // RUN:     /QIfist \
323 // RUN:     /Qimprecise_fwaits \
324 // RUN:     /Qpar \
325 // RUN:     /Qvec-report:2 \
326 // RUN:     /u \
327 // RUN:     /V \
328 // RUN:     /volatile:ms \
329 // RUN:     /wfoo \
330 // RUN:     /WL \
331 // RUN:     /Wp64 \
332 // RUN:     /X \
333 // RUN:     /Y- \
334 // RUN:     /Yc \
335 // RUN:     /Ycstdafx.h \
336 // RUN:     /Yd \
337 // RUN:     /Yl- \
338 // RUN:     /Ylfoo \
339 // RUN:     /Yustdafx.h \
340 // RUN:     /Z7 \
341 // RUN:     /Za \
342 // RUN:     /Ze \
343 // RUN:     /Zg \
344 // RUN:     /Zi \
345 // RUN:     /ZI \
346 // RUN:     /Zl \
347 // RUN:     /ZW:nostdlib \
348 // RUN:     -- %s 2>&1
349 
350 // We support -Xclang for forwarding options to cc1.
351 // RUN: %clang_cl -Xclang hellocc1 -### -- %s 2>&1 | FileCheck -check-prefix=Xclang %s
352 // Xclang: "-cc1"
353 // Xclang: "hellocc1"
354 
355 // RTTI is on by default. /GR- controls -fno-rtti-data.
356 // RUN: %clang_cl /c /GR- -### -- %s 2>&1 | FileCheck -check-prefix=NoRTTI %s
357 // NoRTTI: "-fno-rtti-data"
358 // NoRTTI-NOT: "-fno-rtti"
359 // RUN: %clang_cl /c /GR -### -- %s 2>&1 | FileCheck -check-prefix=RTTI %s
360 // RTTI-NOT: "-fno-rtti-data"
361 // RTTI-NOT: "-fno-rtti"
362 
363 // thread safe statics are off for versions < 19.
364 // RUN: %clang_cl /c -### -- %s 2>&1 | FileCheck -check-prefix=NoThreadSafeStatics %s
365 // RUN: %clang_cl /Zc:threadSafeInit /Zc:threadSafeInit- /c -### -- %s 2>&1 | FileCheck -check-prefix=NoThreadSafeStatics %s
366 // NoThreadSafeStatics: "-fno-threadsafe-statics"
367 
368 // RUN: %clang_cl /Zc:threadSafeInit /c -### -- %s 2>&1 | FileCheck -check-prefix=ThreadSafeStatics %s
369 // ThreadSafeStatics-NOT: "-fno-threadsafe-statics"
370 
371 // RUN: %clang_cl /Zi /c -### -- %s 2>&1 | FileCheck -check-prefix=Zi %s
372 // Zi: "-gcodeview"
373 // Zi: "-debug-info-kind=line-tables-only"
374 
375 // RUN: %clang_cl /Z7 /c -### -- %s 2>&1 | FileCheck -check-prefix=Z7 %s
376 // Z7: "-gcodeview"
377 // Z7: "-debug-info-kind=line-tables-only"
378 
379 // RUN: %clang_cl /c -### -- %s 2>&1 | FileCheck -check-prefix=BreproDefault %s
380 // BreproDefault: "-mincremental-linker-compatible"
381 
382 // RUN: %clang_cl /Brepro- /Brepro /c '-###' -- %s 2>&1 | FileCheck -check-prefix=Brepro %s
383 // Brepro: "-mincremental-linker-compatible"
384 
385 // RUN: %clang_cl /Brepro /Brepro- /c '-###' -- %s 2>&1 | FileCheck -check-prefix=Brepro_ %s
386 // Brepro_-NOT: "-mincremental-linker-compatible"
387 
388 // This test was super sneaky: "/Z7" means "line-tables", but "-gdwarf" occurs
389 // later on the command line, so it should win. Interestingly the cc1 arguments
390 // came out right, but had wrong semantics, because an invariant assumed by
391 // CompilerInvocation was violated: it expects that at most one of {gdwarfN,
392 // line-tables-only} appear. If you assume that, then you can safely use
393 // Args.hasArg to test whether a boolean flag is present without caring
394 // where it appeared. And for this test, it appeared to the left of -gdwarf
395 // which made it "win". This test could not detect that bug.
396 // RUN: %clang_cl /Z7 -gdwarf /c -### -- %s 2>&1 | FileCheck -check-prefix=Z7_gdwarf %s
397 // Z7_gdwarf: "-gcodeview"
398 // Z7_gdwarf: "-debug-info-kind=limited"
399 // Z7_gdwarf: "-dwarf-version=4"
400 
401 // RUN: %clang_cl -fmsc-version=1800 -TP -### -- %s 2>&1 | FileCheck -check-prefix=CXX11 %s
402 // CXX11: -std=c++11
403 
404 // RUN: %clang_cl -fmsc-version=1900 -TP -### -- %s 2>&1 | FileCheck -check-prefix=CXX14 %s
405 // CXX14: -std=c++14
406 
407 // RUN: env CL="/Gy" %clang_cl -### -- %s 2>&1 | FileCheck -check-prefix=ENV-CL %s
408 // ENV-CL: "-ffunction-sections"
409 
410 // RUN: env CL="/Gy" _CL_="/Gy- -- %s" %clang_cl -### 2>&1 | FileCheck -check-prefix=ENV-_CL_ %s
411 // ENV-_CL_-NOT: "-ffunction-sections"
412 
413 // Accept "core" clang options.
414 // (/Zs is for syntax-only, -Werror makes it fail hard on unknown options)
415 // RUN: %clang_cl \
416 // RUN:     --driver-mode=cl \
417 // RUN:     -fcolor-diagnostics \
418 // RUN:     -fno-color-diagnostics \
419 // RUN:     -fdiagnostics-color \
420 // RUN:     -fno-diagnostics-color \
421 // RUN:     -fdiagnostics-parseable-fixits \
422 // RUN:     -ferror-limit=10 \
423 // RUN:     -fmsc-version=1800 \
424 // RUN:     -fno-strict-aliasing \
425 // RUN:     -fstrict-aliasing \
426 // RUN:     -fsyntax-only \
427 // RUN:     -fms-compatibility \
428 // RUN:     -fno-ms-compatibility \
429 // RUN:     -fms-extensions \
430 // RUN:     -fno-ms-extensions \
431 // RUN:     -mllvm -disable-llvm-optzns \
432 // RUN:     -Wunused-variable \
433 // RUN:     -fmacro-backtrace-limit=0 \
434 // RUN:     -Werror /Zs -- %s 2>&1
435 
436 
f()437 void f() { }
438