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.
7 // RUN: %clang_cl /c -### -- %s 2>&1 | FileCheck -check-prefix=c %s
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'
13 // RUN: %clang_cl /C /P -### -- %s 2>&1 | FileCheck -check-prefix=C_P %s
17 // RUN: %clang_cl /Dfoo=bar /D bar=baz /DMYDEF#value /DMYDEF2=foo#bar /DMYDEF3#a=b /DMYDEF4# \
18 // RUN: -### -- %s 2>&1 | FileCheck -check-prefix=D %s
21 // D: "-D" "MYDEF=value"
22 // D: "-D" "MYDEF2=foo#bar"
23 // D: "-D" "MYDEF3=a=b"
26 // RUN: %clang_cl /E -### -- %s 2>&1 | FileCheck -check-prefix=E %s
30 // RUN: %clang_cl /EP -### -- %s 2>&1 | FileCheck -check-prefix=EP %s
35 // RUN: %clang_cl /fp:fast /fp:except -### -- %s 2>&1 | FileCheck -check-prefix=fpexcept %s
36 // fpexcept-NOT: -menable-unsafe-fp-math
38 // RUN: %clang_cl /fp:fast /fp:except /fp:except- -### -- %s 2>&1 | FileCheck -check-prefix=fpexcept_ %s
39 // fpexcept_: -menable-unsafe-fp-math
41 // RUN: %clang_cl /fp:precise /fp:fast -### -- %s 2>&1 | FileCheck -check-prefix=fpfast %s
42 // fpfast: -menable-unsafe-fp-math
43 // fpfast: -ffast-math
45 // RUN: %clang_cl /fp:fast /fp:precise -### -- %s 2>&1 | FileCheck -check-prefix=fpprecise %s
46 // fpprecise-NOT: -menable-unsafe-fp-math
47 // fpprecise-NOT: -ffast-math
49 // RUN: %clang_cl /fp:fast /fp:strict -### -- %s 2>&1 | FileCheck -check-prefix=fpstrict %s
50 // fpstrict-NOT: -menable-unsafe-fp-math
51 // fpstrict-NOT: -ffast-math
53 // RUN: %clang_cl /GA -### -- %s 2>&1 | FileCheck -check-prefix=GA %s
54 // GA: -ftls-model=local-exec
56 // RTTI is on by default; just check that we don't error.
57 // RUN: %clang_cl /Zs /GR -- %s 2>&1
59 // RUN: %clang_cl /GR- -### -- %s 2>&1 | FileCheck -check-prefix=GR_ %s
62 // Security Buffer Check is on by default.
63 // RUN: %clang_cl -### -- %s 2>&1 | FileCheck -check-prefix=GS-default %s
64 // GS-default: "-stack-protector" "2"
66 // RUN: %clang_cl /GS -### -- %s 2>&1 | FileCheck -check-prefix=GS %s
67 // GS: "-stack-protector" "2"
69 // RUN: %clang_cl /GS- -### -- %s 2>&1 | FileCheck -check-prefix=GS_ %s
70 // GS_-NOT: -stack-protector
72 // RUN: %clang_cl /Gy -### -- %s 2>&1 | FileCheck -check-prefix=Gy %s
73 // Gy: -ffunction-sections
75 // RUN: %clang_cl /Gy /Gy- -### -- %s 2>&1 | FileCheck -check-prefix=Gy_ %s
76 // Gy_-NOT: -ffunction-sections
78 // RUN: %clang_cl /Gs -### -- %s 2>&1 | FileCheck -check-prefix=Gs %s
79 // Gs: "-mstack-probe-size=0"
80 // RUN: %clang_cl /Gs0 -### -- %s 2>&1 | FileCheck -check-prefix=Gs0 %s
81 // Gs0: "-mstack-probe-size=0"
82 // RUN: %clang_cl /Gs4096 -### -- %s 2>&1 | FileCheck -check-prefix=Gs4096 %s
83 // Gs4096: "-mstack-probe-size=4096"
85 // RUN: %clang_cl /Gw -### -- %s 2>&1 | FileCheck -check-prefix=Gw %s
86 // Gw: -fdata-sections
88 // RUN: %clang_cl /Gw /Gw- -### -- %s 2>&1 | FileCheck -check-prefix=Gw_ %s
89 // Gw_-NOT: -fdata-sections
91 // RUN: %clang_cl /Imyincludedir -### -- %s 2>&1 | FileCheck -check-prefix=SLASH_I %s
92 // RUN: %clang_cl /I myincludedir -### -- %s 2>&1 | FileCheck -check-prefix=SLASH_I %s
93 // SLASH_I: "-I" "myincludedir"
95 // RUN: %clang_cl /imsvcmyincludedir -### -- %s 2>&1 | FileCheck -check-prefix=SLASH_imsvc %s
96 // RUN: %clang_cl /imsvc myincludedir -### -- %s 2>&1 | FileCheck -check-prefix=SLASH_imsvc %s
97 // Clang's resource header directory should be first:
98 // SLASH_imsvc: "-internal-isystem" "{{[^"]*}}lib{{(64)?/|\\\\}}clang{{[^"]*}}include"
99 // SLASH_imsvc: "-internal-isystem" "myincludedir"
101 // RUN: %clang_cl /J -### -- %s 2>&1 | FileCheck -check-prefix=J %s
102 // J: -fno-signed-char
104 // RUN: %clang_cl /Ofoo -### -- %s 2>&1 | FileCheck -check-prefix=O %s
107 // RUN: %clang_cl /Ob0 -### -- %s 2>&1 | FileCheck -check-prefix=Ob0 %s
110 // RUN: %clang_cl /Ob2 -### -- %s 2>&1 | FileCheck -check-prefix=Ob2 %s
111 // RUN: %clang_cl /Odb2 -### -- %s 2>&1 | FileCheck -check-prefix=Ob2 %s
112 // RUN: %clang_cl /O2 /Ob2 -### -- %s 2>&1 | FileCheck -check-prefix=Ob2 %s
113 // Ob2-NOT: warning: argument unused during compilation: '/O2'
114 // Ob2: -finline-functions
116 // RUN: %clang_cl /Ob1 -### -- %s 2>&1 | FileCheck -check-prefix=Ob1 %s
117 // RUN: %clang_cl /Odb1 -### -- %s 2>&1 | FileCheck -check-prefix=Ob1 %s
118 // Ob1: -finline-hint-functions
120 // RUN: %clang_cl /Od -### -- %s 2>&1 | FileCheck -check-prefix=Od %s
123 // RUN: %clang_cl /Oi- /Oi -### -- %s 2>&1 | FileCheck -check-prefix=Oi %s
124 // Oi-NOT: -fno-builtin
126 // RUN: %clang_cl /Oi- -### -- %s 2>&1 | FileCheck -check-prefix=Oi_ %s
129 // RUN: %clang_cl /Os --target=i686-pc-windows-msvc -### -- %s 2>&1 | FileCheck -check-prefix=Os %s
130 // RUN: %clang_cl /Os --target=x86_64-pc-windows-msvc -### -- %s 2>&1 | FileCheck -check-prefix=Os %s
131 // Os-NOT: -mdisable-fp-elim
132 // Os: -momit-leaf-frame-pointer
135 // RUN: %clang_cl /Ot --target=i686-pc-windows-msvc -### -- %s 2>&1 | FileCheck -check-prefix=Ot %s
136 // RUN: %clang_cl /Ot --target=x86_64-pc-windows-msvc -### -- %s 2>&1 | FileCheck -check-prefix=Ot %s
137 // Ot-NOT: -mdisable-fp-elim
138 // Ot: -momit-leaf-frame-pointer
141 // RUN: %clang_cl /Ox --target=i686-pc-windows-msvc -### -- %s 2>&1 | FileCheck -check-prefix=Ox %s
142 // RUN: %clang_cl /Ox --target=x86_64-pc-windows-msvc -### -- %s 2>&1 | FileCheck -check-prefix=Ox %s
143 // Ox-NOT: -mdisable-fp-elim
144 // Ox: -momit-leaf-frame-pointer
147 // RUN: %clang_cl --target=i686-pc-win32 /O2sy- -### -- %s 2>&1 | FileCheck -check-prefix=PR24003 %s
148 // PR24003: -mdisable-fp-elim
149 // PR24003: -momit-leaf-frame-pointer
152 // RUN: %clang_cl --target=i686-pc-win32 -Werror /Oy- /O2 -### -- %s 2>&1 | FileCheck -check-prefix=Oy_2 %s
153 // Oy_2: -momit-leaf-frame-pointer
156 // RUN: %clang_cl /Zs -Werror /Oy -- %s 2>&1
158 // RUN: %clang_cl --target=i686-pc-win32 -Werror /Oy- -### -- %s 2>&1 | FileCheck -check-prefix=Oy_ %s
159 // Oy_: -mdisable-fp-elim
161 // RUN: %clang_cl /Qvec -### -- %s 2>&1 | FileCheck -check-prefix=Qvec %s
162 // Qvec: -vectorize-loops
164 // RUN: %clang_cl /Qvec /Qvec- -### -- %s 2>&1 | FileCheck -check-prefix=Qvec_ %s
165 // Qvec_-NOT: -vectorize-loops
167 // RUN: %clang_cl /showIncludes -### -- %s 2>&1 | FileCheck -check-prefix=showIncludes %s
168 // showIncludes: --show-includes
170 // RUN: %clang_cl /E /showIncludes -### -- %s 2>&1 | FileCheck -check-prefix=showIncludes_E %s
171 // RUN: %clang_cl /EP /showIncludes -### -- %s 2>&1 | FileCheck -check-prefix=showIncludes_E %s
172 // showIncludes_E: warning: argument unused during compilation: '--show-includes'
174 // RUN: %clang_cl /Umymacro -### -- %s 2>&1 | FileCheck -check-prefix=U %s
175 // RUN: %clang_cl /U mymacro -### -- %s 2>&1 | FileCheck -check-prefix=U %s
178 // RUN: %clang_cl /vd2 -### -- %s 2>&1 | FileCheck -check-prefix=VD2 %s
179 // VD2: -vtordisp-mode=2
181 // RUN: %clang_cl /vmg -### -- %s 2>&1 | FileCheck -check-prefix=VMG %s
182 // VMG: "-fms-memptr-rep=virtual"
184 // RUN: %clang_cl /vmg /vms -### -- %s 2>&1 | FileCheck -check-prefix=VMS %s
185 // VMS: "-fms-memptr-rep=single"
187 // RUN: %clang_cl /vmg /vmm -### -- %s 2>&1 | FileCheck -check-prefix=VMM %s
188 // VMM: "-fms-memptr-rep=multiple"
190 // RUN: %clang_cl /vmg /vmv -### -- %s 2>&1 | FileCheck -check-prefix=VMV %s
191 // VMV: "-fms-memptr-rep=virtual"
193 // RUN: %clang_cl /vmg /vmb -### -- %s 2>&1 | FileCheck -check-prefix=VMB %s
194 // VMB: '/vmg' not allowed with '/vmb'
196 // RUN: %clang_cl /vmg /vmm /vms -### -- %s 2>&1 | FileCheck -check-prefix=VMX %s
197 // VMX: '/vms' not allowed with '/vmm'
199 // RUN: %clang_cl /volatile:iso -### -- %s 2>&1 | FileCheck -check-prefix=VOLATILE-ISO %s
200 // VOLATILE-ISO-NOT: "-fms-volatile"
202 // RUN: %clang_cl /volatile:ms -### -- %s 2>&1 | FileCheck -check-prefix=VOLATILE-MS %s
203 // VOLATILE-MS: "-fms-volatile"
205 // RUN: %clang_cl /W0 -### -- %s 2>&1 | FileCheck -check-prefix=W0 %s
208 // RUN: %clang_cl /W1 -### -- %s 2>&1 | FileCheck -check-prefix=W1 %s
209 // RUN: %clang_cl /W2 -### -- %s 2>&1 | FileCheck -check-prefix=W1 %s
210 // RUN: %clang_cl /W3 -### -- %s 2>&1 | FileCheck -check-prefix=W1 %s
211 // RUN: %clang_cl /W4 -### -- %s 2>&1 | FileCheck -check-prefix=W4 %s
212 // RUN: %clang_cl /Wall -### -- %s 2>&1 | FileCheck -check-prefix=W4 %s
216 // RUN: %clang_cl /WX -### -- %s 2>&1 | FileCheck -check-prefix=WX %s
219 // RUN: %clang_cl /WX- -### -- %s 2>&1 | FileCheck -check-prefix=WX_ %s
222 // RUN: %clang_cl /w -### -- %s 2>&1 | FileCheck -check-prefix=w %s
225 // RUN: %clang_cl /Zp -### -- %s 2>&1 | FileCheck -check-prefix=ZP %s
226 // ZP: -fpack-struct=1
228 // RUN: %clang_cl /Zp2 -### -- %s 2>&1 | FileCheck -check-prefix=ZP2 %s
229 // ZP2: -fpack-struct=2
231 // RUN: %clang_cl /Zs -### -- %s 2>&1 | FileCheck -check-prefix=Zs %s
234 // RUN: %clang_cl /FIasdf.h -### -- %s 2>&1 | FileCheck -check-prefix=FI %s
235 // FI: "-include" "asdf.h"
237 // RUN: %clang_cl /FI asdf.h -### -- %s 2>&1 | FileCheck -check-prefix=FI_ %s
238 // FI_: "-include" "asdf.h"
240 // RUN: %clang_cl /TP /c -### -- %s 2>&1 | FileCheck -check-prefix=NO-GX %s
241 // NO-GX-NOT: "-fcxx-exceptions" "-fexceptions"
243 // RUN: %clang_cl /TP /c /GX -### -- %s 2>&1 | FileCheck -check-prefix=GX %s
244 // GX: "-fcxx-exceptions" "-fexceptions"
246 // RUN: %clang_cl /TP /c /GX /GX- -### -- %s 2>&1 | FileCheck -check-prefix=GX_ %s
247 // GX_-NOT: "-fcxx-exceptions" "-fexceptions"
249 // We forward any unrecognized -W diagnostic options to cc1.
250 // RUN: %clang_cl -Wunused-pragmas -### -- %s 2>&1 | FileCheck -check-prefix=WJoined %s
252 // WJoined: "-Wunused-pragmas"
254 // We recognize -f[no-]strict-aliasing.
255 // RUN: %clang_cl -c -### -- %s 2>&1 | FileCheck -check-prefix=DEFAULTSTRICT %s
256 // DEFAULTSTRICT: "-relaxed-aliasing"
257 // RUN: %clang_cl -c -fstrict-aliasing -### -- %s 2>&1 | FileCheck -check-prefix=STRICT %s
258 // STRICT-NOT: "-relaxed-aliasing"
259 // RUN: %clang_cl -c -fno-strict-aliasing -### -- %s 2>&1 | FileCheck -check-prefix=NOSTRICT %s
260 // NOSTRICT: "-relaxed-aliasing"
262 // For some warning ids, we can map from MSVC warning to Clang warning.
263 // RUN: %clang_cl -wd4005 -wd4100 -wd4910 -wd4996 -### -- %s 2>&1 | FileCheck -check-prefix=Wno %s
265 // Wno: "-Wno-macro-redefined"
266 // Wno: "-Wno-unused-parameter"
267 // Wno: "-Wno-dllexport-explicit-instantiation-decl"
268 // Wno: "-Wno-deprecated-declarations"
270 // Ignored options. Check that we don't get "unused during compilation" errors.
271 // RUN: %clang_cl /c \
274 // RUN: /cgthreads4 \
275 // RUN: /cgthreads8 \
276 // RUN: /d2FastFail \
278 // RUN: /errorReport:foo \
292 // RUN: /volatile:iso \
297 // RUN: -### -- %s 2>&1 | FileCheck -check-prefix=IGNORED %s
298 // IGNORED-NOT: argument unused during compilation
299 // IGNORED-NOT: no such file or directory
300 // Don't confuse /openmp- with the /o flag:
301 // IGNORED-NOT: "-o" "penmp-.obj"
303 // Ignored options and compile-only options are ignored for link jobs.
305 // RUN: %clang_cl /nologo -### -- %t.obj 2>&1 | FileCheck -check-prefix=LINKUNUSED %s
306 // RUN: %clang_cl /Dfoo -### -- %t.obj 2>&1 | FileCheck -check-prefix=LINKUNUSED %s
307 // RUN: %clang_cl /MD -### -- %t.obj 2>&1 | FileCheck -check-prefix=LINKUNUSED %s
308 // LINKUNUSED-NOT: argument unused during compilation
310 // Support ignoring warnings about unused arguments.
311 // RUN: %clang_cl /Abracadabra -Qunused-arguments -### -- %s 2>&1 | FileCheck -check-prefix=UNUSED %s
312 // UNUSED-NOT: argument unused during compilation
314 // Unsupported but parsed options. Check that we don't error on them.
315 // (/Zs is for syntax-only)
316 // RUN: %clang_cl /Zs \
324 // RUN: /Fafilename \
327 // RUN: /favor:blend \
331 // RUN: /FpDebug\main.pch \
357 // RUN: /homeparams \
365 // RUN: /Qfast_transcendentals \
367 // RUN: /Qimprecise_fwaits \
369 // RUN: /Qvec-report:2 \
372 // RUN: /volatile:ms \
379 // RUN: /Ycstdafx.h \
383 // RUN: /Yustdafx.h \
391 // RUN: /ZW:nostdlib \
394 // We support -Xclang for forwarding options to cc1.
395 // RUN: %clang_cl -Xclang hellocc1 -### -- %s 2>&1 | FileCheck -check-prefix=Xclang %s
397 // Xclang: "hellocc1"
399 // RTTI is on by default. /GR- controls -fno-rtti-data.
400 // RUN: %clang_cl /c /GR- -### -- %s 2>&1 | FileCheck -check-prefix=NoRTTI %s
401 // NoRTTI: "-fno-rtti-data"
402 // NoRTTI-NOT: "-fno-rtti"
403 // RUN: %clang_cl /c /GR -### -- %s 2>&1 | FileCheck -check-prefix=RTTI %s
404 // RTTI-NOT: "-fno-rtti-data"
405 // RTTI-NOT: "-fno-rtti"
407 // thread safe statics are off for versions < 19.
408 // RUN: %clang_cl /c -### -fms-compatibility-version=18 -- %s 2>&1 | FileCheck -check-prefix=NoThreadSafeStatics %s
409 // RUN: %clang_cl /Zc:threadSafeInit /Zc:threadSafeInit- /c -### -- %s 2>&1 | FileCheck -check-prefix=NoThreadSafeStatics %s
410 // NoThreadSafeStatics: "-fno-threadsafe-statics"
412 // RUN: %clang_cl /Zc:threadSafeInit /c -### -- %s 2>&1 | FileCheck -check-prefix=ThreadSafeStatics %s
413 // ThreadSafeStatics-NOT: "-fno-threadsafe-statics"
415 // RUN: %clang_cl /Zi /c -### -- %s 2>&1 | FileCheck -check-prefix=Zi %s
417 // Zi: "-debug-info-kind=limited"
419 // RUN: %clang_cl /Z7 /c -### -- %s 2>&1 | FileCheck -check-prefix=Z7 %s
421 // Z7: "-debug-info-kind=limited"
423 // RUN: %clang_cl /Zd /c -### -- %s 2>&1 | FileCheck -check-prefix=Z7GMLT %s
424 // Z7GMLT: "-gcodeview"
425 // Z7GMLT: "-debug-info-kind=line-tables-only"
427 // RUN: %clang_cl -gline-tables-only /c -### -- %s 2>&1 | FileCheck -check-prefix=ZGMLT %s
428 // ZGMLT: "-gcodeview"
429 // ZGMLT: "-debug-info-kind=line-tables-only"
431 // RUN: %clang_cl /c -### -- %s 2>&1 | FileCheck -check-prefix=BreproDefault %s
432 // BreproDefault: "-mincremental-linker-compatible"
434 // RUN: %clang_cl /Brepro- /Brepro /c '-###' -- %s 2>&1 | FileCheck -check-prefix=Brepro %s
435 // Brepro: "-mincremental-linker-compatible"
437 // RUN: %clang_cl /Brepro /Brepro- /c '-###' -- %s 2>&1 | FileCheck -check-prefix=Brepro_ %s
438 // Brepro_-NOT: "-mincremental-linker-compatible"
440 // This test was super sneaky: "/Z7" means "line-tables", but "-gdwarf" occurs
441 // later on the command line, so it should win. Interestingly the cc1 arguments
442 // came out right, but had wrong semantics, because an invariant assumed by
443 // CompilerInvocation was violated: it expects that at most one of {gdwarfN,
444 // line-tables-only} appear. If you assume that, then you can safely use
445 // Args.hasArg to test whether a boolean flag is present without caring
446 // where it appeared. And for this test, it appeared to the left of -gdwarf
447 // which made it "win". This test could not detect that bug.
448 // RUN: %clang_cl /Z7 -gdwarf /c -### -- %s 2>&1 | FileCheck -check-prefix=Z7_gdwarf %s
449 // Z7_gdwarf: "-gcodeview"
450 // Z7_gdwarf: "-debug-info-kind=limited"
451 // Z7_gdwarf: "-dwarf-version=4"
453 // RUN: %clang_cl -fmsc-version=1800 -TP -### -- %s 2>&1 | FileCheck -check-prefix=CXX11 %s
456 // RUN: %clang_cl -fmsc-version=1900 -TP -### -- %s 2>&1 | FileCheck -check-prefix=CXX14 %s
459 // RUN: %clang_cl -fmsc-version=1900 -TP -std:c++14 -### -- %s 2>&1 | FileCheck -check-prefix=STDCXX14 %s
460 // STDCXX14: -std=c++14
462 // RUN: %clang_cl -fmsc-version=1900 -TP -std:c++latest -### -- %s 2>&1 | FileCheck -check-prefix=STDCXXLATEST %s
463 // STDCXXLATEST: -std=c++1z
465 // RUN: env CL="/Gy" %clang_cl -### -- %s 2>&1 | FileCheck -check-prefix=ENV-CL %s
466 // ENV-CL: "-ffunction-sections"
468 // RUN: env CL="/Gy" _CL_="/Gy- -- %s" %clang_cl -### 2>&1 | FileCheck -check-prefix=ENV-_CL_ %s
469 // ENV-_CL_-NOT: "-ffunction-sections"
471 // Accept "core" clang options.
472 // (/Zs is for syntax-only, -Werror makes it fail hard on unknown options)
474 // RUN: --driver-mode=cl \
475 // RUN: -fcolor-diagnostics \
476 // RUN: -fno-color-diagnostics \
477 // RUN: -fdiagnostics-color \
478 // RUN: -fno-diagnostics-color \
479 // RUN: -fdiagnostics-parseable-fixits \
480 // RUN: -ferror-limit=10 \
481 // RUN: -fmsc-version=1800 \
482 // RUN: -fno-strict-aliasing \
483 // RUN: -fstrict-aliasing \
484 // RUN: -fsyntax-only \
485 // RUN: -fms-compatibility \
486 // RUN: -fno-ms-compatibility \
487 // RUN: -fms-extensions \
488 // RUN: -fno-ms-extensions \
489 // RUN: -mllvm -disable-llvm-optzns \
490 // RUN: -resource-dir \
491 // RUN: -Wunused-variable \
492 // RUN: -fmacro-backtrace-limit=0 \
493 // RUN: -Werror /Zs -- %s 2>&1