]> granicus.if.org Git - clang/blob - test/Driver/cl-options.c
clang-cl: make /Wall turn on both -Wall and -Wextra (PR25563)
[clang] / test / Driver / cl-options.c
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 -wd4996 -wd4910 -### -- %s 2>&1 | FileCheck -check-prefix=Wno %s
220 // Wno: "-cc1"
221 // Wno: "-Wno-macro-redefined"
222 // Wno: "-Wno-deprecated-declarations"
223 // Wno: "-Wno-dllexport-explicit-instantiation-decl"
224
225 // Ignored options. Check that we don't get "unused during compilation" errors.
226 // RUN: %clang_cl /c \
227 // RUN:    /analyze- \
228 // RUN:    /bigobj \
229 // RUN:    /cgthreads4 \
230 // RUN:    /cgthreads8 \
231 // RUN:    /d2Zi+ \
232 // RUN:    /errorReport:foo \
233 // RUN:    /Fdfoo \
234 // RUN:    /FS \
235 // RUN:    /Gd \
236 // RUN:    /GF \
237 // RUN:    /GS- \
238 // RUN:    /kernel- \
239 // RUN:    /nologo \
240 // RUN:    /Ob1 \
241 // RUN:    /Ob2 \
242 // RUN:    /openmp- \
243 // RUN:    /RTC1 \
244 // RUN:    /sdl \
245 // RUN:    /sdl- \
246 // RUN:    /vmg \
247 // RUN:    /volatile:iso \
248 // RUN:    /w12345 \
249 // RUN:    /wd1234 \
250 // RUN:    /Zo \
251 // RUN:    /Zo- \
252 // RUN:    -### -- %s 2>&1 | FileCheck -check-prefix=IGNORED %s
253 // IGNORED-NOT: argument unused during compilation
254 // IGNORED-NOT: no such file or directory
255 // Don't confuse /openmp- with the /o flag:
256 // IGNORED-NOT: "-o" "penmp-.obj"
257
258 // Ignored options and compile-only options are ignored for link jobs.
259 // RUN: touch %t.obj
260 // RUN: %clang_cl /nologo -### -- %t.obj 2>&1 | FileCheck -check-prefix=LINKUNUSED %s
261 // RUN: %clang_cl /Dfoo -### -- %t.obj 2>&1 | FileCheck -check-prefix=LINKUNUSED %s
262 // RUN: %clang_cl /MD -### -- %t.obj 2>&1 | FileCheck -check-prefix=LINKUNUSED %s
263 // LINKUNUSED-NOT: argument unused during compilation
264
265 // Support ignoring warnings about unused arguments.
266 // RUN: %clang_cl /Abracadabra -Qunused-arguments -### -- %s 2>&1 | FileCheck -check-prefix=UNUSED %s
267 // UNUSED-NOT: argument unused during compilation
268
269 // Unsupported but parsed options. Check that we don't error on them.
270 // (/Zs is for syntax-only)
271 // RUN: %clang_cl /Zs \
272 // RUN:     /AIfoo \
273 // RUN:     /clr:pure \
274 // RUN:     /docname \
275 // RUN:     /EHsc \
276 // RUN:     /F \
277 // RUN:     /FA \
278 // RUN:     /FAc \
279 // RUN:     /Fafilename \
280 // RUN:     /FAs \
281 // RUN:     /FAu \
282 // RUN:     /favor:blend \
283 // RUN:     /FC \
284 // RUN:     /Fifoo \
285 // RUN:     /Fmfoo \
286 // RUN:     /FpDebug\main.pch \
287 // RUN:     /Frfoo \
288 // RUN:     /FRfoo \
289 // RUN:     /FU foo \
290 // RUN:     /Fx \
291 // RUN:     /G1 \
292 // RUN:     /G2 \
293 // RUN:     /GA \
294 // RUN:     /Gd \
295 // RUN:     /Ge \
296 // RUN:     /Gh \
297 // RUN:     /GH \
298 // RUN:     /GL \
299 // RUN:     /GL- \
300 // RUN:     /Gm \
301 // RUN:     /Gm- \
302 // RUN:     /Gr \
303 // RUN:     /GS \
304 // RUN:     /GT \
305 // RUN:     /guard:cf \
306 // RUN:     /guard:cf- \
307 // RUN:     /GX \
308 // RUN:     /Gv \
309 // RUN:     /Gz \
310 // RUN:     /GZ \
311 // RUN:     /H \
312 // RUN:     /homeparams \
313 // RUN:     /hotpatch \
314 // RUN:     /kernel \
315 // RUN:     /LN \
316 // RUN:     /MP \
317 // RUN:     /o foo.obj \
318 // RUN:     /ofoo.obj \
319 // RUN:     /openmp \
320 // RUN:     /Qfast_transcendentals \
321 // RUN:     /QIfist \
322 // RUN:     /Qimprecise_fwaits \
323 // RUN:     /Qpar \
324 // RUN:     /Qvec-report:2 \
325 // RUN:     /u \
326 // RUN:     /V \
327 // RUN:     /volatile:ms \
328 // RUN:     /wfoo \
329 // RUN:     /WL \
330 // RUN:     /Wp64 \
331 // RUN:     /X \
332 // RUN:     /Y- \
333 // RUN:     /Yc \
334 // RUN:     /Ycstdafx.h \
335 // RUN:     /Yd \
336 // RUN:     /Yl- \
337 // RUN:     /Ylfoo \
338 // RUN:     /Yustdafx.h \
339 // RUN:     /Z7 \
340 // RUN:     /Za \
341 // RUN:     /Ze \
342 // RUN:     /Zg \
343 // RUN:     /Zi \
344 // RUN:     /ZI \
345 // RUN:     /Zl \
346 // RUN:     /ZW:nostdlib \
347 // RUN:     -- %s 2>&1
348
349 // We support -Xclang for forwarding options to cc1.
350 // RUN: %clang_cl -Xclang hellocc1 -### -- %s 2>&1 | FileCheck -check-prefix=Xclang %s
351 // Xclang: "-cc1"
352 // Xclang: "hellocc1"
353
354 // RTTI is on by default. /GR- controls -fno-rtti-data.
355 // RUN: %clang_cl /c /GR- -### -- %s 2>&1 | FileCheck -check-prefix=NoRTTI %s
356 // NoRTTI: "-fno-rtti-data"
357 // NoRTTI-NOT: "-fno-rtti"
358 // RUN: %clang_cl /c /GR -### -- %s 2>&1 | FileCheck -check-prefix=RTTI %s
359 // RTTI-NOT: "-fno-rtti-data"
360 // RTTI-NOT: "-fno-rtti"
361
362 // thread safe statics are off for versions < 19.
363 // RUN: %clang_cl /c -### -- %s 2>&1 | FileCheck -check-prefix=NoThreadSafeStatics %s
364 // RUN: %clang_cl /Zc:threadSafeInit /Zc:threadSafeInit- /c -### -- %s 2>&1 | FileCheck -check-prefix=NoThreadSafeStatics %s
365 // NoThreadSafeStatics: "-fno-threadsafe-statics"
366
367 // RUN: %clang_cl /Zc:threadSafeInit /c -### -- %s 2>&1 | FileCheck -check-prefix=ThreadSafeStatics %s
368 // ThreadSafeStatics-NOT: "-fno-threadsafe-statics"
369
370 // RUN: %clang_cl /Zi /c -### -- %s 2>&1 | FileCheck -check-prefix=Zi %s
371 // Zi: "-gcodeview"
372 // Zi: "-debug-info-kind=line-tables-only"
373
374 // RUN: %clang_cl /Z7 /c -### -- %s 2>&1 | FileCheck -check-prefix=Z7 %s
375 // Z7: "-gcodeview"
376 // Z7: "-debug-info-kind=line-tables-only"
377
378 // This test was super sneaky: "/Z7" means "line-tables", but "-gdwarf" occurs
379 // later on the command line, so it should win. Interestingly the cc1 arguments
380 // came out right, but had wrong semantics, because an invariant assumed by
381 // CompilerInvocation was violated: it expects that at most one of {gdwarfN,
382 // line-tables-only} appear. If you assume that, then you can safely use
383 // Args.hasArg to test whether a boolean flag is present without caring
384 // where it appeared. And for this test, it appeared to the left of -gdwarf
385 // which made it "win". This test could not detect that bug.
386 // RUN: %clang_cl /Z7 -gdwarf /c -### -- %s 2>&1 | FileCheck -check-prefix=Z7_gdwarf %s
387 // Z7_gdwarf: "-gcodeview"
388 // Z7_gdwarf: "-debug-info-kind=limited"
389 // Z7_gdwarf: "-dwarf-version=4"
390
391 // RUN: %clang_cl -fmsc-version=1800 -TP -### -- %s 2>&1 | FileCheck -check-prefix=CXX11 %s
392 // CXX11: -std=c++11
393
394 // RUN: %clang_cl -fmsc-version=1900 -TP -### -- %s 2>&1 | FileCheck -check-prefix=CXX14 %s
395 // CXX14: -std=c++14
396
397 // RUN: env CL="/Gy" %clang_cl -### -- %s 2>&1 | FileCheck -check-prefix=ENV-CL %s
398 // ENV-CL: "-ffunction-sections"
399
400 // RUN: env CL="/Gy" _CL_="/Gy- -- %s" %clang_cl -### 2>&1 | FileCheck -check-prefix=ENV-_CL_ %s
401 // ENV-_CL_-NOT: "-ffunction-sections"
402
403 // Accept "core" clang options.
404 // (/Zs is for syntax-only, -Werror makes it fail hard on unknown options)
405 // RUN: %clang_cl \
406 // RUN:     --driver-mode=cl \
407 // RUN:     -fcolor-diagnostics \
408 // RUN:     -fno-color-diagnostics \
409 // RUN:     -fdiagnostics-color \
410 // RUN:     -fno-diagnostics-color \
411 // RUN:     -fdiagnostics-parseable-fixits \
412 // RUN:     -ferror-limit=10 \
413 // RUN:     -fmsc-version=1800 \
414 // RUN:     -fno-strict-aliasing \
415 // RUN:     -fstrict-aliasing \
416 // RUN:     -fsyntax-only \
417 // RUN:     -fms-compatibility \
418 // RUN:     -fno-ms-compatibility \
419 // RUN:     -fms-extensions \
420 // RUN:     -fno-ms-extensions \
421 // RUN:     -mllvm -disable-llvm-optzns \
422 // RUN:     -Wunused-variable \
423 // RUN:     -fmacro-backtrace-limit=0 \
424 // RUN:     -Werror /Zs -- %s 2>&1
425
426
427 void f() { }