xref: /minix3/external/bsd/llvm/dist/clang/docs/UsersManual.rst (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc============================
2*f4a2713aSLionel SambucClang Compiler User's Manual
3*f4a2713aSLionel Sambuc============================
4*f4a2713aSLionel Sambuc
5*f4a2713aSLionel Sambuc.. contents::
6*f4a2713aSLionel Sambuc   :local:
7*f4a2713aSLionel Sambuc
8*f4a2713aSLionel SambucIntroduction
9*f4a2713aSLionel Sambuc============
10*f4a2713aSLionel Sambuc
11*f4a2713aSLionel SambucThe Clang Compiler is an open-source compiler for the C family of
12*f4a2713aSLionel Sambucprogramming languages, aiming to be the best in class implementation of
13*f4a2713aSLionel Sambucthese languages. Clang builds on the LLVM optimizer and code generator,
14*f4a2713aSLionel Sambucallowing it to provide high-quality optimization and code generation
15*f4a2713aSLionel Sambucsupport for many targets. For more general information, please see the
16*f4a2713aSLionel Sambuc`Clang Web Site <http://clang.llvm.org>`_ or the `LLVM Web
17*f4a2713aSLionel SambucSite <http://llvm.org>`_.
18*f4a2713aSLionel Sambuc
19*f4a2713aSLionel SambucThis document describes important notes about using Clang as a compiler
20*f4a2713aSLionel Sambucfor an end-user, documenting the supported features, command line
21*f4a2713aSLionel Sambucoptions, etc. If you are interested in using Clang to build a tool that
22*f4a2713aSLionel Sambucprocesses code, please see :doc:`InternalsManual`. If you are interested in the
23*f4a2713aSLionel Sambuc`Clang Static Analyzer <http://clang-analyzer.llvm.org>`_, please see its web
24*f4a2713aSLionel Sambucpage.
25*f4a2713aSLionel Sambuc
26*f4a2713aSLionel SambucClang is designed to support the C family of programming languages,
27*f4a2713aSLionel Sambucwhich includes :ref:`C <c>`, :ref:`Objective-C <objc>`, :ref:`C++ <cxx>`, and
28*f4a2713aSLionel Sambuc:ref:`Objective-C++ <objcxx>` as well as many dialects of those. For
29*f4a2713aSLionel Sambuclanguage-specific information, please see the corresponding language
30*f4a2713aSLionel Sambucspecific section:
31*f4a2713aSLionel Sambuc
32*f4a2713aSLionel Sambuc-  :ref:`C Language <c>`: K&R C, ANSI C89, ISO C90, ISO C94 (C89+AMD1), ISO
33*f4a2713aSLionel Sambuc   C99 (+TC1, TC2, TC3).
34*f4a2713aSLionel Sambuc-  :ref:`Objective-C Language <objc>`: ObjC 1, ObjC 2, ObjC 2.1, plus
35*f4a2713aSLionel Sambuc   variants depending on base language.
36*f4a2713aSLionel Sambuc-  :ref:`C++ Language <cxx>`
37*f4a2713aSLionel Sambuc-  :ref:`Objective C++ Language <objcxx>`
38*f4a2713aSLionel Sambuc
39*f4a2713aSLionel SambucIn addition to these base languages and their dialects, Clang supports a
40*f4a2713aSLionel Sambucbroad variety of language extensions, which are documented in the
41*f4a2713aSLionel Sambuccorresponding language section. These extensions are provided to be
42*f4a2713aSLionel Sambuccompatible with the GCC, Microsoft, and other popular compilers as well
43*f4a2713aSLionel Sambucas to improve functionality through Clang-specific features. The Clang
44*f4a2713aSLionel Sambucdriver and language features are intentionally designed to be as
45*f4a2713aSLionel Sambuccompatible with the GNU GCC compiler as reasonably possible, easing
46*f4a2713aSLionel Sambucmigration from GCC to Clang. In most cases, code "just works".
47*f4a2713aSLionel SambucClang also provides an alternative driver, :ref:`clang-cl`, that is designed
48*f4a2713aSLionel Sambucto be compatible with the Visual C++ compiler, cl.exe.
49*f4a2713aSLionel Sambuc
50*f4a2713aSLionel SambucIn addition to language specific features, Clang has a variety of
51*f4a2713aSLionel Sambucfeatures that depend on what CPU architecture or operating system is
52*f4a2713aSLionel Sambucbeing compiled for. Please see the :ref:`Target-Specific Features and
53*f4a2713aSLionel SambucLimitations <target_features>` section for more details.
54*f4a2713aSLionel Sambuc
55*f4a2713aSLionel SambucThe rest of the introduction introduces some basic :ref:`compiler
56*f4a2713aSLionel Sambucterminology <terminology>` that is used throughout this manual and
57*f4a2713aSLionel Sambuccontains a basic :ref:`introduction to using Clang <basicusage>` as a
58*f4a2713aSLionel Sambuccommand line compiler.
59*f4a2713aSLionel Sambuc
60*f4a2713aSLionel Sambuc.. _terminology:
61*f4a2713aSLionel Sambuc
62*f4a2713aSLionel SambucTerminology
63*f4a2713aSLionel Sambuc-----------
64*f4a2713aSLionel Sambuc
65*f4a2713aSLionel SambucFront end, parser, backend, preprocessor, undefined behavior,
66*f4a2713aSLionel Sambucdiagnostic, optimizer
67*f4a2713aSLionel Sambuc
68*f4a2713aSLionel Sambuc.. _basicusage:
69*f4a2713aSLionel Sambuc
70*f4a2713aSLionel SambucBasic Usage
71*f4a2713aSLionel Sambuc-----------
72*f4a2713aSLionel Sambuc
73*f4a2713aSLionel SambucIntro to how to use a C compiler for newbies.
74*f4a2713aSLionel Sambuc
75*f4a2713aSLionel Sambuccompile + link compile then link debug info enabling optimizations
76*f4a2713aSLionel Sambucpicking a language to use, defaults to C99 by default. Autosenses based
77*f4a2713aSLionel Sambucon extension. using a makefile
78*f4a2713aSLionel Sambuc
79*f4a2713aSLionel SambucCommand Line Options
80*f4a2713aSLionel Sambuc====================
81*f4a2713aSLionel Sambuc
82*f4a2713aSLionel SambucThis section is generally an index into other sections. It does not go
83*f4a2713aSLionel Sambucinto depth on the ones that are covered by other sections. However, the
84*f4a2713aSLionel Sambucfirst part introduces the language selection and other high level
85*f4a2713aSLionel Sambucoptions like :option:`-c`, :option:`-g`, etc.
86*f4a2713aSLionel Sambuc
87*f4a2713aSLionel SambucOptions to Control Error and Warning Messages
88*f4a2713aSLionel Sambuc---------------------------------------------
89*f4a2713aSLionel Sambuc
90*f4a2713aSLionel Sambuc.. option:: -Werror
91*f4a2713aSLionel Sambuc
92*f4a2713aSLionel Sambuc  Turn warnings into errors.
93*f4a2713aSLionel Sambuc
94*f4a2713aSLionel Sambuc.. This is in plain monospaced font because it generates the same label as
95*f4a2713aSLionel Sambuc.. -Werror, and Sphinx complains.
96*f4a2713aSLionel Sambuc
97*f4a2713aSLionel Sambuc``-Werror=foo``
98*f4a2713aSLionel Sambuc
99*f4a2713aSLionel Sambuc  Turn warning "foo" into an error.
100*f4a2713aSLionel Sambuc
101*f4a2713aSLionel Sambuc.. option:: -Wno-error=foo
102*f4a2713aSLionel Sambuc
103*f4a2713aSLionel Sambuc  Turn warning "foo" into an warning even if :option:`-Werror` is specified.
104*f4a2713aSLionel Sambuc
105*f4a2713aSLionel Sambuc.. option:: -Wfoo
106*f4a2713aSLionel Sambuc
107*f4a2713aSLionel Sambuc  Enable warning "foo".
108*f4a2713aSLionel Sambuc
109*f4a2713aSLionel Sambuc.. option:: -Wno-foo
110*f4a2713aSLionel Sambuc
111*f4a2713aSLionel Sambuc  Disable warning "foo".
112*f4a2713aSLionel Sambuc
113*f4a2713aSLionel Sambuc.. option:: -w
114*f4a2713aSLionel Sambuc
115*f4a2713aSLionel Sambuc  Disable all warnings.
116*f4a2713aSLionel Sambuc
117*f4a2713aSLionel Sambuc.. option:: -Weverything
118*f4a2713aSLionel Sambuc
119*f4a2713aSLionel Sambuc  :ref:`Enable all warnings. <diagnostics_enable_everything>`
120*f4a2713aSLionel Sambuc
121*f4a2713aSLionel Sambuc.. option:: -pedantic
122*f4a2713aSLionel Sambuc
123*f4a2713aSLionel Sambuc  Warn on language extensions.
124*f4a2713aSLionel Sambuc
125*f4a2713aSLionel Sambuc.. option:: -pedantic-errors
126*f4a2713aSLionel Sambuc
127*f4a2713aSLionel Sambuc  Error on language extensions.
128*f4a2713aSLionel Sambuc
129*f4a2713aSLionel Sambuc.. option:: -Wsystem-headers
130*f4a2713aSLionel Sambuc
131*f4a2713aSLionel Sambuc  Enable warnings from system headers.
132*f4a2713aSLionel Sambuc
133*f4a2713aSLionel Sambuc.. option:: -ferror-limit=123
134*f4a2713aSLionel Sambuc
135*f4a2713aSLionel Sambuc  Stop emitting diagnostics after 123 errors have been produced. The default is
136*f4a2713aSLionel Sambuc  20, and the error limit can be disabled with :option:`-ferror-limit=0`.
137*f4a2713aSLionel Sambuc
138*f4a2713aSLionel Sambuc.. option:: -ftemplate-backtrace-limit=123
139*f4a2713aSLionel Sambuc
140*f4a2713aSLionel Sambuc  Only emit up to 123 template instantiation notes within the template
141*f4a2713aSLionel Sambuc  instantiation backtrace for a single warning or error. The default is 10, and
142*f4a2713aSLionel Sambuc  the limit can be disabled with :option:`-ftemplate-backtrace-limit=0`.
143*f4a2713aSLionel Sambuc
144*f4a2713aSLionel Sambuc.. _cl_diag_formatting:
145*f4a2713aSLionel Sambuc
146*f4a2713aSLionel SambucFormatting of Diagnostics
147*f4a2713aSLionel Sambuc^^^^^^^^^^^^^^^^^^^^^^^^^
148*f4a2713aSLionel Sambuc
149*f4a2713aSLionel SambucClang aims to produce beautiful diagnostics by default, particularly for
150*f4a2713aSLionel Sambucnew users that first come to Clang. However, different people have
151*f4a2713aSLionel Sambucdifferent preferences, and sometimes Clang is driven by another program
152*f4a2713aSLionel Sambucthat wants to parse simple and consistent output, not a person. For
153*f4a2713aSLionel Sambucthese cases, Clang provides a wide range of options to control the exact
154*f4a2713aSLionel Sambucoutput format of the diagnostics that it generates.
155*f4a2713aSLionel Sambuc
156*f4a2713aSLionel Sambuc.. _opt_fshow-column:
157*f4a2713aSLionel Sambuc
158*f4a2713aSLionel Sambuc**-f[no-]show-column**
159*f4a2713aSLionel Sambuc   Print column number in diagnostic.
160*f4a2713aSLionel Sambuc
161*f4a2713aSLionel Sambuc   This option, which defaults to on, controls whether or not Clang
162*f4a2713aSLionel Sambuc   prints the column number of a diagnostic. For example, when this is
163*f4a2713aSLionel Sambuc   enabled, Clang will print something like:
164*f4a2713aSLionel Sambuc
165*f4a2713aSLionel Sambuc   ::
166*f4a2713aSLionel Sambuc
167*f4a2713aSLionel Sambuc         test.c:28:8: warning: extra tokens at end of #endif directive [-Wextra-tokens]
168*f4a2713aSLionel Sambuc         #endif bad
169*f4a2713aSLionel Sambuc                ^
170*f4a2713aSLionel Sambuc                //
171*f4a2713aSLionel Sambuc
172*f4a2713aSLionel Sambuc   When this is disabled, Clang will print "test.c:28: warning..." with
173*f4a2713aSLionel Sambuc   no column number.
174*f4a2713aSLionel Sambuc
175*f4a2713aSLionel Sambuc   The printed column numbers count bytes from the beginning of the
176*f4a2713aSLionel Sambuc   line; take care if your source contains multibyte characters.
177*f4a2713aSLionel Sambuc
178*f4a2713aSLionel Sambuc.. _opt_fshow-source-location:
179*f4a2713aSLionel Sambuc
180*f4a2713aSLionel Sambuc**-f[no-]show-source-location**
181*f4a2713aSLionel Sambuc   Print source file/line/column information in diagnostic.
182*f4a2713aSLionel Sambuc
183*f4a2713aSLionel Sambuc   This option, which defaults to on, controls whether or not Clang
184*f4a2713aSLionel Sambuc   prints the filename, line number and column number of a diagnostic.
185*f4a2713aSLionel Sambuc   For example, when this is enabled, Clang will print something like:
186*f4a2713aSLionel Sambuc
187*f4a2713aSLionel Sambuc   ::
188*f4a2713aSLionel Sambuc
189*f4a2713aSLionel Sambuc         test.c:28:8: warning: extra tokens at end of #endif directive [-Wextra-tokens]
190*f4a2713aSLionel Sambuc         #endif bad
191*f4a2713aSLionel Sambuc                ^
192*f4a2713aSLionel Sambuc                //
193*f4a2713aSLionel Sambuc
194*f4a2713aSLionel Sambuc   When this is disabled, Clang will not print the "test.c:28:8: "
195*f4a2713aSLionel Sambuc   part.
196*f4a2713aSLionel Sambuc
197*f4a2713aSLionel Sambuc.. _opt_fcaret-diagnostics:
198*f4a2713aSLionel Sambuc
199*f4a2713aSLionel Sambuc**-f[no-]caret-diagnostics**
200*f4a2713aSLionel Sambuc   Print source line and ranges from source code in diagnostic.
201*f4a2713aSLionel Sambuc   This option, which defaults to on, controls whether or not Clang
202*f4a2713aSLionel Sambuc   prints the source line, source ranges, and caret when emitting a
203*f4a2713aSLionel Sambuc   diagnostic. For example, when this is enabled, Clang will print
204*f4a2713aSLionel Sambuc   something like:
205*f4a2713aSLionel Sambuc
206*f4a2713aSLionel Sambuc   ::
207*f4a2713aSLionel Sambuc
208*f4a2713aSLionel Sambuc         test.c:28:8: warning: extra tokens at end of #endif directive [-Wextra-tokens]
209*f4a2713aSLionel Sambuc         #endif bad
210*f4a2713aSLionel Sambuc                ^
211*f4a2713aSLionel Sambuc                //
212*f4a2713aSLionel Sambuc
213*f4a2713aSLionel Sambuc**-f[no-]color-diagnostics**
214*f4a2713aSLionel Sambuc   This option, which defaults to on when a color-capable terminal is
215*f4a2713aSLionel Sambuc   detected, controls whether or not Clang prints diagnostics in color.
216*f4a2713aSLionel Sambuc
217*f4a2713aSLionel Sambuc   When this option is enabled, Clang will use colors to highlight
218*f4a2713aSLionel Sambuc   specific parts of the diagnostic, e.g.,
219*f4a2713aSLionel Sambuc
220*f4a2713aSLionel Sambuc   .. nasty hack to not lose our dignity
221*f4a2713aSLionel Sambuc
222*f4a2713aSLionel Sambuc   .. raw:: html
223*f4a2713aSLionel Sambuc
224*f4a2713aSLionel Sambuc       <pre>
225*f4a2713aSLionel Sambuc         <b><span style="color:black">test.c:28:8: <span style="color:magenta">warning</span>: extra tokens at end of #endif directive [-Wextra-tokens]</span></b>
226*f4a2713aSLionel Sambuc         #endif bad
227*f4a2713aSLionel Sambuc                <span style="color:green">^</span>
228*f4a2713aSLionel Sambuc                <span style="color:green">//</span>
229*f4a2713aSLionel Sambuc       </pre>
230*f4a2713aSLionel Sambuc
231*f4a2713aSLionel Sambuc   When this is disabled, Clang will just print:
232*f4a2713aSLionel Sambuc
233*f4a2713aSLionel Sambuc   ::
234*f4a2713aSLionel Sambuc
235*f4a2713aSLionel Sambuc         test.c:2:8: warning: extra tokens at end of #endif directive [-Wextra-tokens]
236*f4a2713aSLionel Sambuc         #endif bad
237*f4a2713aSLionel Sambuc                ^
238*f4a2713aSLionel Sambuc                //
239*f4a2713aSLionel Sambuc
240*f4a2713aSLionel Sambuc**-fansi-escape-codes**
241*f4a2713aSLionel Sambuc   Controls whether ANSI escape codes are used instead of the Windows Console
242*f4a2713aSLionel Sambuc   API to output colored diagnostics. This option is only used on Windows and
243*f4a2713aSLionel Sambuc   defaults to off.
244*f4a2713aSLionel Sambuc
245*f4a2713aSLionel Sambuc.. option:: -fdiagnostics-format=clang/msvc/vi
246*f4a2713aSLionel Sambuc
247*f4a2713aSLionel Sambuc   Changes diagnostic output format to better match IDEs and command line tools.
248*f4a2713aSLionel Sambuc
249*f4a2713aSLionel Sambuc   This option controls the output format of the filename, line number,
250*f4a2713aSLionel Sambuc   and column printed in diagnostic messages. The options, and their
251*f4a2713aSLionel Sambuc   affect on formatting a simple conversion diagnostic, follow:
252*f4a2713aSLionel Sambuc
253*f4a2713aSLionel Sambuc   **clang** (default)
254*f4a2713aSLionel Sambuc       ::
255*f4a2713aSLionel Sambuc
256*f4a2713aSLionel Sambuc           t.c:3:11: warning: conversion specifies type 'char *' but the argument has type 'int'
257*f4a2713aSLionel Sambuc
258*f4a2713aSLionel Sambuc   **msvc**
259*f4a2713aSLionel Sambuc       ::
260*f4a2713aSLionel Sambuc
261*f4a2713aSLionel Sambuc           t.c(3,11) : warning: conversion specifies type 'char *' but the argument has type 'int'
262*f4a2713aSLionel Sambuc
263*f4a2713aSLionel Sambuc   **vi**
264*f4a2713aSLionel Sambuc       ::
265*f4a2713aSLionel Sambuc
266*f4a2713aSLionel Sambuc           t.c +3:11: warning: conversion specifies type 'char *' but the argument has type 'int'
267*f4a2713aSLionel Sambuc
268*f4a2713aSLionel Sambuc**-f[no-]diagnostics-show-name**
269*f4a2713aSLionel Sambuc   Enable the display of the diagnostic name.
270*f4a2713aSLionel Sambuc   This option, which defaults to off, controls whether or not Clang
271*f4a2713aSLionel Sambuc   prints the associated name.
272*f4a2713aSLionel Sambuc
273*f4a2713aSLionel Sambuc.. _opt_fdiagnostics-show-option:
274*f4a2713aSLionel Sambuc
275*f4a2713aSLionel Sambuc**-f[no-]diagnostics-show-option**
276*f4a2713aSLionel Sambuc   Enable ``[-Woption]`` information in diagnostic line.
277*f4a2713aSLionel Sambuc
278*f4a2713aSLionel Sambuc   This option, which defaults to on, controls whether or not Clang
279*f4a2713aSLionel Sambuc   prints the associated :ref:`warning group <cl_diag_warning_groups>`
280*f4a2713aSLionel Sambuc   option name when outputting a warning diagnostic. For example, in
281*f4a2713aSLionel Sambuc   this output:
282*f4a2713aSLionel Sambuc
283*f4a2713aSLionel Sambuc   ::
284*f4a2713aSLionel Sambuc
285*f4a2713aSLionel Sambuc         test.c:28:8: warning: extra tokens at end of #endif directive [-Wextra-tokens]
286*f4a2713aSLionel Sambuc         #endif bad
287*f4a2713aSLionel Sambuc                ^
288*f4a2713aSLionel Sambuc                //
289*f4a2713aSLionel Sambuc
290*f4a2713aSLionel Sambuc   Passing **-fno-diagnostics-show-option** will prevent Clang from
291*f4a2713aSLionel Sambuc   printing the [:ref:`-Wextra-tokens <opt_Wextra-tokens>`] information in
292*f4a2713aSLionel Sambuc   the diagnostic. This information tells you the flag needed to enable
293*f4a2713aSLionel Sambuc   or disable the diagnostic, either from the command line or through
294*f4a2713aSLionel Sambuc   :ref:`#pragma GCC diagnostic <pragma_GCC_diagnostic>`.
295*f4a2713aSLionel Sambuc
296*f4a2713aSLionel Sambuc.. _opt_fdiagnostics-show-category:
297*f4a2713aSLionel Sambuc
298*f4a2713aSLionel Sambuc.. option:: -fdiagnostics-show-category=none/id/name
299*f4a2713aSLionel Sambuc
300*f4a2713aSLionel Sambuc   Enable printing category information in diagnostic line.
301*f4a2713aSLionel Sambuc
302*f4a2713aSLionel Sambuc   This option, which defaults to "none", controls whether or not Clang
303*f4a2713aSLionel Sambuc   prints the category associated with a diagnostic when emitting it.
304*f4a2713aSLionel Sambuc   Each diagnostic may or many not have an associated category, if it
305*f4a2713aSLionel Sambuc   has one, it is listed in the diagnostic categorization field of the
306*f4a2713aSLionel Sambuc   diagnostic line (in the []'s).
307*f4a2713aSLionel Sambuc
308*f4a2713aSLionel Sambuc   For example, a format string warning will produce these three
309*f4a2713aSLionel Sambuc   renditions based on the setting of this option:
310*f4a2713aSLionel Sambuc
311*f4a2713aSLionel Sambuc   ::
312*f4a2713aSLionel Sambuc
313*f4a2713aSLionel Sambuc         t.c:3:11: warning: conversion specifies type 'char *' but the argument has type 'int' [-Wformat]
314*f4a2713aSLionel Sambuc         t.c:3:11: warning: conversion specifies type 'char *' but the argument has type 'int' [-Wformat,1]
315*f4a2713aSLionel Sambuc         t.c:3:11: warning: conversion specifies type 'char *' but the argument has type 'int' [-Wformat,Format String]
316*f4a2713aSLionel Sambuc
317*f4a2713aSLionel Sambuc   This category can be used by clients that want to group diagnostics
318*f4a2713aSLionel Sambuc   by category, so it should be a high level category. We want dozens
319*f4a2713aSLionel Sambuc   of these, not hundreds or thousands of them.
320*f4a2713aSLionel Sambuc
321*f4a2713aSLionel Sambuc.. _opt_fdiagnostics-fixit-info:
322*f4a2713aSLionel Sambuc
323*f4a2713aSLionel Sambuc**-f[no-]diagnostics-fixit-info**
324*f4a2713aSLionel Sambuc   Enable "FixIt" information in the diagnostics output.
325*f4a2713aSLionel Sambuc
326*f4a2713aSLionel Sambuc   This option, which defaults to on, controls whether or not Clang
327*f4a2713aSLionel Sambuc   prints the information on how to fix a specific diagnostic
328*f4a2713aSLionel Sambuc   underneath it when it knows. For example, in this output:
329*f4a2713aSLionel Sambuc
330*f4a2713aSLionel Sambuc   ::
331*f4a2713aSLionel Sambuc
332*f4a2713aSLionel Sambuc         test.c:28:8: warning: extra tokens at end of #endif directive [-Wextra-tokens]
333*f4a2713aSLionel Sambuc         #endif bad
334*f4a2713aSLionel Sambuc                ^
335*f4a2713aSLionel Sambuc                //
336*f4a2713aSLionel Sambuc
337*f4a2713aSLionel Sambuc   Passing **-fno-diagnostics-fixit-info** will prevent Clang from
338*f4a2713aSLionel Sambuc   printing the "//" line at the end of the message. This information
339*f4a2713aSLionel Sambuc   is useful for users who may not understand what is wrong, but can be
340*f4a2713aSLionel Sambuc   confusing for machine parsing.
341*f4a2713aSLionel Sambuc
342*f4a2713aSLionel Sambuc.. _opt_fdiagnostics-print-source-range-info:
343*f4a2713aSLionel Sambuc
344*f4a2713aSLionel Sambuc**-fdiagnostics-print-source-range-info**
345*f4a2713aSLionel Sambuc   Print machine parsable information about source ranges.
346*f4a2713aSLionel Sambuc   This option makes Clang print information about source ranges in a machine
347*f4a2713aSLionel Sambuc   parsable format after the file/line/column number information. The
348*f4a2713aSLionel Sambuc   information is a simple sequence of brace enclosed ranges, where each range
349*f4a2713aSLionel Sambuc   lists the start and end line/column locations. For example, in this output:
350*f4a2713aSLionel Sambuc
351*f4a2713aSLionel Sambuc   ::
352*f4a2713aSLionel Sambuc
353*f4a2713aSLionel Sambuc       exprs.c:47:15:{47:8-47:14}{47:17-47:24}: error: invalid operands to binary expression ('int *' and '_Complex float')
354*f4a2713aSLionel Sambuc          P = (P-42) + Gamma*4;
355*f4a2713aSLionel Sambuc              ~~~~~~ ^ ~~~~~~~
356*f4a2713aSLionel Sambuc
357*f4a2713aSLionel Sambuc   The {}'s are generated by -fdiagnostics-print-source-range-info.
358*f4a2713aSLionel Sambuc
359*f4a2713aSLionel Sambuc   The printed column numbers count bytes from the beginning of the
360*f4a2713aSLionel Sambuc   line; take care if your source contains multibyte characters.
361*f4a2713aSLionel Sambuc
362*f4a2713aSLionel Sambuc.. option:: -fdiagnostics-parseable-fixits
363*f4a2713aSLionel Sambuc
364*f4a2713aSLionel Sambuc   Print Fix-Its in a machine parseable form.
365*f4a2713aSLionel Sambuc
366*f4a2713aSLionel Sambuc   This option makes Clang print available Fix-Its in a machine
367*f4a2713aSLionel Sambuc   parseable format at the end of diagnostics. The following example
368*f4a2713aSLionel Sambuc   illustrates the format:
369*f4a2713aSLionel Sambuc
370*f4a2713aSLionel Sambuc   ::
371*f4a2713aSLionel Sambuc
372*f4a2713aSLionel Sambuc        fix-it:"t.cpp":{7:25-7:29}:"Gamma"
373*f4a2713aSLionel Sambuc
374*f4a2713aSLionel Sambuc   The range printed is a half-open range, so in this example the
375*f4a2713aSLionel Sambuc   characters at column 25 up to but not including column 29 on line 7
376*f4a2713aSLionel Sambuc   in t.cpp should be replaced with the string "Gamma". Either the
377*f4a2713aSLionel Sambuc   range or the replacement string may be empty (representing strict
378*f4a2713aSLionel Sambuc   insertions and strict erasures, respectively). Both the file name
379*f4a2713aSLionel Sambuc   and the insertion string escape backslash (as "\\\\"), tabs (as
380*f4a2713aSLionel Sambuc   "\\t"), newlines (as "\\n"), double quotes(as "\\"") and
381*f4a2713aSLionel Sambuc   non-printable characters (as octal "\\xxx").
382*f4a2713aSLionel Sambuc
383*f4a2713aSLionel Sambuc   The printed column numbers count bytes from the beginning of the
384*f4a2713aSLionel Sambuc   line; take care if your source contains multibyte characters.
385*f4a2713aSLionel Sambuc
386*f4a2713aSLionel Sambuc.. option:: -fno-elide-type
387*f4a2713aSLionel Sambuc
388*f4a2713aSLionel Sambuc   Turns off elision in template type printing.
389*f4a2713aSLionel Sambuc
390*f4a2713aSLionel Sambuc   The default for template type printing is to elide as many template
391*f4a2713aSLionel Sambuc   arguments as possible, removing those which are the same in both
392*f4a2713aSLionel Sambuc   template types, leaving only the differences. Adding this flag will
393*f4a2713aSLionel Sambuc   print all the template arguments. If supported by the terminal,
394*f4a2713aSLionel Sambuc   highlighting will still appear on differing arguments.
395*f4a2713aSLionel Sambuc
396*f4a2713aSLionel Sambuc   Default:
397*f4a2713aSLionel Sambuc
398*f4a2713aSLionel Sambuc   ::
399*f4a2713aSLionel Sambuc
400*f4a2713aSLionel Sambuc       t.cc:4:5: note: candidate function not viable: no known conversion from 'vector<map<[...], map<float, [...]>>>' to 'vector<map<[...], map<double, [...]>>>' for 1st argument;
401*f4a2713aSLionel Sambuc
402*f4a2713aSLionel Sambuc   -fno-elide-type:
403*f4a2713aSLionel Sambuc
404*f4a2713aSLionel Sambuc   ::
405*f4a2713aSLionel Sambuc
406*f4a2713aSLionel Sambuc       t.cc:4:5: note: candidate function not viable: no known conversion from 'vector<map<int, map<float, int>>>' to 'vector<map<int, map<double, int>>>' for 1st argument;
407*f4a2713aSLionel Sambuc
408*f4a2713aSLionel Sambuc.. option:: -fdiagnostics-show-template-tree
409*f4a2713aSLionel Sambuc
410*f4a2713aSLionel Sambuc   Template type diffing prints a text tree.
411*f4a2713aSLionel Sambuc
412*f4a2713aSLionel Sambuc   For diffing large templated types, this option will cause Clang to
413*f4a2713aSLionel Sambuc   display the templates as an indented text tree, one argument per
414*f4a2713aSLionel Sambuc   line, with differences marked inline. This is compatible with
415*f4a2713aSLionel Sambuc   -fno-elide-type.
416*f4a2713aSLionel Sambuc
417*f4a2713aSLionel Sambuc   Default:
418*f4a2713aSLionel Sambuc
419*f4a2713aSLionel Sambuc   ::
420*f4a2713aSLionel Sambuc
421*f4a2713aSLionel Sambuc       t.cc:4:5: note: candidate function not viable: no known conversion from 'vector<map<[...], map<float, [...]>>>' to 'vector<map<[...], map<double, [...]>>>' for 1st argument;
422*f4a2713aSLionel Sambuc
423*f4a2713aSLionel Sambuc   With :option:`-fdiagnostics-show-template-tree`:
424*f4a2713aSLionel Sambuc
425*f4a2713aSLionel Sambuc   ::
426*f4a2713aSLionel Sambuc
427*f4a2713aSLionel Sambuc       t.cc:4:5: note: candidate function not viable: no known conversion for 1st argument;
428*f4a2713aSLionel Sambuc         vector<
429*f4a2713aSLionel Sambuc           map<
430*f4a2713aSLionel Sambuc             [...],
431*f4a2713aSLionel Sambuc             map<
432*f4a2713aSLionel Sambuc               [float != double],
433*f4a2713aSLionel Sambuc               [...]>>>
434*f4a2713aSLionel Sambuc
435*f4a2713aSLionel Sambuc.. _cl_diag_warning_groups:
436*f4a2713aSLionel Sambuc
437*f4a2713aSLionel SambucIndividual Warning Groups
438*f4a2713aSLionel Sambuc^^^^^^^^^^^^^^^^^^^^^^^^^
439*f4a2713aSLionel Sambuc
440*f4a2713aSLionel SambucTODO: Generate this from tblgen. Define one anchor per warning group.
441*f4a2713aSLionel Sambuc
442*f4a2713aSLionel Sambuc.. _opt_wextra-tokens:
443*f4a2713aSLionel Sambuc
444*f4a2713aSLionel Sambuc.. option:: -Wextra-tokens
445*f4a2713aSLionel Sambuc
446*f4a2713aSLionel Sambuc   Warn about excess tokens at the end of a preprocessor directive.
447*f4a2713aSLionel Sambuc
448*f4a2713aSLionel Sambuc   This option, which defaults to on, enables warnings about extra
449*f4a2713aSLionel Sambuc   tokens at the end of preprocessor directives. For example:
450*f4a2713aSLionel Sambuc
451*f4a2713aSLionel Sambuc   ::
452*f4a2713aSLionel Sambuc
453*f4a2713aSLionel Sambuc         test.c:28:8: warning: extra tokens at end of #endif directive [-Wextra-tokens]
454*f4a2713aSLionel Sambuc         #endif bad
455*f4a2713aSLionel Sambuc                ^
456*f4a2713aSLionel Sambuc
457*f4a2713aSLionel Sambuc   These extra tokens are not strictly conforming, and are usually best
458*f4a2713aSLionel Sambuc   handled by commenting them out.
459*f4a2713aSLionel Sambuc
460*f4a2713aSLionel Sambuc.. option:: -Wambiguous-member-template
461*f4a2713aSLionel Sambuc
462*f4a2713aSLionel Sambuc   Warn about unqualified uses of a member template whose name resolves to
463*f4a2713aSLionel Sambuc   another template at the location of the use.
464*f4a2713aSLionel Sambuc
465*f4a2713aSLionel Sambuc   This option, which defaults to on, enables a warning in the
466*f4a2713aSLionel Sambuc   following code:
467*f4a2713aSLionel Sambuc
468*f4a2713aSLionel Sambuc   ::
469*f4a2713aSLionel Sambuc
470*f4a2713aSLionel Sambuc       template<typename T> struct set{};
471*f4a2713aSLionel Sambuc       template<typename T> struct trait { typedef const T& type; };
472*f4a2713aSLionel Sambuc       struct Value {
473*f4a2713aSLionel Sambuc         template<typename T> void set(typename trait<T>::type value) {}
474*f4a2713aSLionel Sambuc       };
475*f4a2713aSLionel Sambuc       void foo() {
476*f4a2713aSLionel Sambuc         Value v;
477*f4a2713aSLionel Sambuc         v.set<double>(3.2);
478*f4a2713aSLionel Sambuc       }
479*f4a2713aSLionel Sambuc
480*f4a2713aSLionel Sambuc   C++ [basic.lookup.classref] requires this to be an error, but,
481*f4a2713aSLionel Sambuc   because it's hard to work around, Clang downgrades it to a warning
482*f4a2713aSLionel Sambuc   as an extension.
483*f4a2713aSLionel Sambuc
484*f4a2713aSLionel Sambuc.. option:: -Wbind-to-temporary-copy
485*f4a2713aSLionel Sambuc
486*f4a2713aSLionel Sambuc   Warn about an unusable copy constructor when binding a reference to a
487*f4a2713aSLionel Sambuc   temporary.
488*f4a2713aSLionel Sambuc
489*f4a2713aSLionel Sambuc   This option, which defaults to on, enables warnings about binding a
490*f4a2713aSLionel Sambuc   reference to a temporary when the temporary doesn't have a usable
491*f4a2713aSLionel Sambuc   copy constructor. For example:
492*f4a2713aSLionel Sambuc
493*f4a2713aSLionel Sambuc   ::
494*f4a2713aSLionel Sambuc
495*f4a2713aSLionel Sambuc         struct NonCopyable {
496*f4a2713aSLionel Sambuc           NonCopyable();
497*f4a2713aSLionel Sambuc         private:
498*f4a2713aSLionel Sambuc           NonCopyable(const NonCopyable&);
499*f4a2713aSLionel Sambuc         };
500*f4a2713aSLionel Sambuc         void foo(const NonCopyable&);
501*f4a2713aSLionel Sambuc         void bar() {
502*f4a2713aSLionel Sambuc           foo(NonCopyable());  // Disallowed in C++98; allowed in C++11.
503*f4a2713aSLionel Sambuc         }
504*f4a2713aSLionel Sambuc
505*f4a2713aSLionel Sambuc   ::
506*f4a2713aSLionel Sambuc
507*f4a2713aSLionel Sambuc         struct NonCopyable2 {
508*f4a2713aSLionel Sambuc           NonCopyable2();
509*f4a2713aSLionel Sambuc           NonCopyable2(NonCopyable2&);
510*f4a2713aSLionel Sambuc         };
511*f4a2713aSLionel Sambuc         void foo(const NonCopyable2&);
512*f4a2713aSLionel Sambuc         void bar() {
513*f4a2713aSLionel Sambuc           foo(NonCopyable2());  // Disallowed in C++98; allowed in C++11.
514*f4a2713aSLionel Sambuc         }
515*f4a2713aSLionel Sambuc
516*f4a2713aSLionel Sambuc   Note that if ``NonCopyable2::NonCopyable2()`` has a default argument
517*f4a2713aSLionel Sambuc   whose instantiation produces a compile error, that error will still
518*f4a2713aSLionel Sambuc   be a hard error in C++98 mode even if this warning is turned off.
519*f4a2713aSLionel Sambuc
520*f4a2713aSLionel SambucOptions to Control Clang Crash Diagnostics
521*f4a2713aSLionel Sambuc------------------------------------------
522*f4a2713aSLionel Sambuc
523*f4a2713aSLionel SambucAs unbelievable as it may sound, Clang does crash from time to time.
524*f4a2713aSLionel SambucGenerally, this only occurs to those living on the `bleeding
525*f4a2713aSLionel Sambucedge <http://llvm.org/releases/download.html#svn>`_. Clang goes to great
526*f4a2713aSLionel Sambuclengths to assist you in filing a bug report. Specifically, Clang
527*f4a2713aSLionel Sambucgenerates preprocessed source file(s) and associated run script(s) upon
528*f4a2713aSLionel Sambuca crash. These files should be attached to a bug report to ease
529*f4a2713aSLionel Sambucreproducibility of the failure. Below are the command line options to
530*f4a2713aSLionel Sambuccontrol the crash diagnostics.
531*f4a2713aSLionel Sambuc
532*f4a2713aSLionel Sambuc.. option:: -fno-crash-diagnostics
533*f4a2713aSLionel Sambuc
534*f4a2713aSLionel Sambuc  Disable auto-generation of preprocessed source files during a clang crash.
535*f4a2713aSLionel Sambuc
536*f4a2713aSLionel SambucThe -fno-crash-diagnostics flag can be helpful for speeding the process
537*f4a2713aSLionel Sambucof generating a delta reduced test case.
538*f4a2713aSLionel Sambuc
539*f4a2713aSLionel SambucLanguage and Target-Independent Features
540*f4a2713aSLionel Sambuc========================================
541*f4a2713aSLionel Sambuc
542*f4a2713aSLionel SambucControlling Errors and Warnings
543*f4a2713aSLionel Sambuc-------------------------------
544*f4a2713aSLionel Sambuc
545*f4a2713aSLionel SambucClang provides a number of ways to control which code constructs cause
546*f4a2713aSLionel Sambucit to emit errors and warning messages, and how they are displayed to
547*f4a2713aSLionel Sambucthe console.
548*f4a2713aSLionel Sambuc
549*f4a2713aSLionel SambucControlling How Clang Displays Diagnostics
550*f4a2713aSLionel Sambuc^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
551*f4a2713aSLionel Sambuc
552*f4a2713aSLionel SambucWhen Clang emits a diagnostic, it includes rich information in the
553*f4a2713aSLionel Sambucoutput, and gives you fine-grain control over which information is
554*f4a2713aSLionel Sambucprinted. Clang has the ability to print this information, and these are
555*f4a2713aSLionel Sambucthe options that control it:
556*f4a2713aSLionel Sambuc
557*f4a2713aSLionel Sambuc#. A file/line/column indicator that shows exactly where the diagnostic
558*f4a2713aSLionel Sambuc   occurs in your code [:ref:`-fshow-column <opt_fshow-column>`,
559*f4a2713aSLionel Sambuc   :ref:`-fshow-source-location <opt_fshow-source-location>`].
560*f4a2713aSLionel Sambuc#. A categorization of the diagnostic as a note, warning, error, or
561*f4a2713aSLionel Sambuc   fatal error.
562*f4a2713aSLionel Sambuc#. A text string that describes what the problem is.
563*f4a2713aSLionel Sambuc#. An option that indicates how to control the diagnostic (for
564*f4a2713aSLionel Sambuc   diagnostics that support it)
565*f4a2713aSLionel Sambuc   [:ref:`-fdiagnostics-show-option <opt_fdiagnostics-show-option>`].
566*f4a2713aSLionel Sambuc#. A :ref:`high-level category <diagnostics_categories>` for the diagnostic
567*f4a2713aSLionel Sambuc   for clients that want to group diagnostics by class (for diagnostics
568*f4a2713aSLionel Sambuc   that support it)
569*f4a2713aSLionel Sambuc   [:ref:`-fdiagnostics-show-category <opt_fdiagnostics-show-category>`].
570*f4a2713aSLionel Sambuc#. The line of source code that the issue occurs on, along with a caret
571*f4a2713aSLionel Sambuc   and ranges that indicate the important locations
572*f4a2713aSLionel Sambuc   [:ref:`-fcaret-diagnostics <opt_fcaret-diagnostics>`].
573*f4a2713aSLionel Sambuc#. "FixIt" information, which is a concise explanation of how to fix the
574*f4a2713aSLionel Sambuc   problem (when Clang is certain it knows)
575*f4a2713aSLionel Sambuc   [:ref:`-fdiagnostics-fixit-info <opt_fdiagnostics-fixit-info>`].
576*f4a2713aSLionel Sambuc#. A machine-parsable representation of the ranges involved (off by
577*f4a2713aSLionel Sambuc   default)
578*f4a2713aSLionel Sambuc   [:ref:`-fdiagnostics-print-source-range-info <opt_fdiagnostics-print-source-range-info>`].
579*f4a2713aSLionel Sambuc
580*f4a2713aSLionel SambucFor more information please see :ref:`Formatting of
581*f4a2713aSLionel SambucDiagnostics <cl_diag_formatting>`.
582*f4a2713aSLionel Sambuc
583*f4a2713aSLionel SambucDiagnostic Mappings
584*f4a2713aSLionel Sambuc^^^^^^^^^^^^^^^^^^^
585*f4a2713aSLionel Sambuc
586*f4a2713aSLionel SambucAll diagnostics are mapped into one of these 5 classes:
587*f4a2713aSLionel Sambuc
588*f4a2713aSLionel Sambuc-  Ignored
589*f4a2713aSLionel Sambuc-  Note
590*f4a2713aSLionel Sambuc-  Warning
591*f4a2713aSLionel Sambuc-  Error
592*f4a2713aSLionel Sambuc-  Fatal
593*f4a2713aSLionel Sambuc
594*f4a2713aSLionel Sambuc.. _diagnostics_categories:
595*f4a2713aSLionel Sambuc
596*f4a2713aSLionel SambucDiagnostic Categories
597*f4a2713aSLionel Sambuc^^^^^^^^^^^^^^^^^^^^^
598*f4a2713aSLionel Sambuc
599*f4a2713aSLionel SambucThough not shown by default, diagnostics may each be associated with a
600*f4a2713aSLionel Sambuchigh-level category. This category is intended to make it possible to
601*f4a2713aSLionel Sambuctriage builds that produce a large number of errors or warnings in a
602*f4a2713aSLionel Sambucgrouped way.
603*f4a2713aSLionel Sambuc
604*f4a2713aSLionel SambucCategories are not shown by default, but they can be turned on with the
605*f4a2713aSLionel Sambuc:ref:`-fdiagnostics-show-category <opt_fdiagnostics-show-category>` option.
606*f4a2713aSLionel SambucWhen set to "``name``", the category is printed textually in the
607*f4a2713aSLionel Sambucdiagnostic output. When it is set to "``id``", a category number is
608*f4a2713aSLionel Sambucprinted. The mapping of category names to category id's can be obtained
609*f4a2713aSLionel Sambucby running '``clang   --print-diagnostic-categories``'.
610*f4a2713aSLionel Sambuc
611*f4a2713aSLionel SambucControlling Diagnostics via Command Line Flags
612*f4a2713aSLionel Sambuc^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
613*f4a2713aSLionel Sambuc
614*f4a2713aSLionel SambucTODO: -W flags, -pedantic, etc
615*f4a2713aSLionel Sambuc
616*f4a2713aSLionel Sambuc.. _pragma_gcc_diagnostic:
617*f4a2713aSLionel Sambuc
618*f4a2713aSLionel SambucControlling Diagnostics via Pragmas
619*f4a2713aSLionel Sambuc^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
620*f4a2713aSLionel Sambuc
621*f4a2713aSLionel SambucClang can also control what diagnostics are enabled through the use of
622*f4a2713aSLionel Sambucpragmas in the source code. This is useful for turning off specific
623*f4a2713aSLionel Sambucwarnings in a section of source code. Clang supports GCC's pragma for
624*f4a2713aSLionel Sambuccompatibility with existing source code, as well as several extensions.
625*f4a2713aSLionel Sambuc
626*f4a2713aSLionel SambucThe pragma may control any warning that can be used from the command
627*f4a2713aSLionel Sambucline. Warnings may be set to ignored, warning, error, or fatal. The
628*f4a2713aSLionel Sambucfollowing example code will tell Clang or GCC to ignore the -Wall
629*f4a2713aSLionel Sambucwarnings:
630*f4a2713aSLionel Sambuc
631*f4a2713aSLionel Sambuc.. code-block:: c
632*f4a2713aSLionel Sambuc
633*f4a2713aSLionel Sambuc  #pragma GCC diagnostic ignored "-Wall"
634*f4a2713aSLionel Sambuc
635*f4a2713aSLionel SambucIn addition to all of the functionality provided by GCC's pragma, Clang
636*f4a2713aSLionel Sambucalso allows you to push and pop the current warning state. This is
637*f4a2713aSLionel Sambucparticularly useful when writing a header file that will be compiled by
638*f4a2713aSLionel Sambucother people, because you don't know what warning flags they build with.
639*f4a2713aSLionel Sambuc
640*f4a2713aSLionel SambucIn the below example :option:`-Wmultichar` is ignored for only a single line of
641*f4a2713aSLionel Sambuccode, after which the diagnostics return to whatever state had previously
642*f4a2713aSLionel Sambucexisted.
643*f4a2713aSLionel Sambuc
644*f4a2713aSLionel Sambuc.. code-block:: c
645*f4a2713aSLionel Sambuc
646*f4a2713aSLionel Sambuc  #pragma clang diagnostic push
647*f4a2713aSLionel Sambuc  #pragma clang diagnostic ignored "-Wmultichar"
648*f4a2713aSLionel Sambuc
649*f4a2713aSLionel Sambuc  char b = 'df'; // no warning.
650*f4a2713aSLionel Sambuc
651*f4a2713aSLionel Sambuc  #pragma clang diagnostic pop
652*f4a2713aSLionel Sambuc
653*f4a2713aSLionel SambucThe push and pop pragmas will save and restore the full diagnostic state
654*f4a2713aSLionel Sambucof the compiler, regardless of how it was set. That means that it is
655*f4a2713aSLionel Sambucpossible to use push and pop around GCC compatible diagnostics and Clang
656*f4a2713aSLionel Sambucwill push and pop them appropriately, while GCC will ignore the pushes
657*f4a2713aSLionel Sambucand pops as unknown pragmas. It should be noted that while Clang
658*f4a2713aSLionel Sambucsupports the GCC pragma, Clang and GCC do not support the exact same set
659*f4a2713aSLionel Sambucof warnings, so even when using GCC compatible #pragmas there is no
660*f4a2713aSLionel Sambucguarantee that they will have identical behaviour on both compilers.
661*f4a2713aSLionel Sambuc
662*f4a2713aSLionel SambucIn addition to controlling warnings and errors generated by the compiler, it is
663*f4a2713aSLionel Sambucpossible to generate custom warning and error messages through the following
664*f4a2713aSLionel Sambucpragmas:
665*f4a2713aSLionel Sambuc
666*f4a2713aSLionel Sambuc.. code-block:: c
667*f4a2713aSLionel Sambuc
668*f4a2713aSLionel Sambuc  // The following will produce warning messages
669*f4a2713aSLionel Sambuc  #pragma message "some diagnostic message"
670*f4a2713aSLionel Sambuc  #pragma GCC warning "TODO: replace deprecated feature"
671*f4a2713aSLionel Sambuc
672*f4a2713aSLionel Sambuc  // The following will produce an error message
673*f4a2713aSLionel Sambuc  #pragma GCC error "Not supported"
674*f4a2713aSLionel Sambuc
675*f4a2713aSLionel SambucThese pragmas operate similarly to the ``#warning`` and ``#error`` preprocessor
676*f4a2713aSLionel Sambucdirectives, except that they may also be embedded into preprocessor macros via
677*f4a2713aSLionel Sambucthe C99 ``_Pragma`` operator, for example:
678*f4a2713aSLionel Sambuc
679*f4a2713aSLionel Sambuc.. code-block:: c
680*f4a2713aSLionel Sambuc
681*f4a2713aSLionel Sambuc  #define STR(X) #X
682*f4a2713aSLionel Sambuc  #define DEFER(M,...) M(__VA_ARGS__)
683*f4a2713aSLionel Sambuc  #define CUSTOM_ERROR(X) _Pragma(STR(GCC error(X " at line " DEFER(STR,__LINE__))))
684*f4a2713aSLionel Sambuc
685*f4a2713aSLionel Sambuc  CUSTOM_ERROR("Feature not available");
686*f4a2713aSLionel Sambuc
687*f4a2713aSLionel SambucControlling Diagnostics in System Headers
688*f4a2713aSLionel Sambuc^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
689*f4a2713aSLionel Sambuc
690*f4a2713aSLionel SambucWarnings are suppressed when they occur in system headers. By default,
691*f4a2713aSLionel Sambucan included file is treated as a system header if it is found in an
692*f4a2713aSLionel Sambucinclude path specified by ``-isystem``, but this can be overridden in
693*f4a2713aSLionel Sambucseveral ways.
694*f4a2713aSLionel Sambuc
695*f4a2713aSLionel SambucThe ``system_header`` pragma can be used to mark the current file as
696*f4a2713aSLionel Sambucbeing a system header. No warnings will be produced from the location of
697*f4a2713aSLionel Sambucthe pragma onwards within the same file.
698*f4a2713aSLionel Sambuc
699*f4a2713aSLionel Sambuc.. code-block:: c
700*f4a2713aSLionel Sambuc
701*f4a2713aSLionel Sambuc  char a = 'xy'; // warning
702*f4a2713aSLionel Sambuc
703*f4a2713aSLionel Sambuc  #pragma clang system_header
704*f4a2713aSLionel Sambuc
705*f4a2713aSLionel Sambuc  char b = 'ab'; // no warning
706*f4a2713aSLionel Sambuc
707*f4a2713aSLionel SambucThe :option:`-isystem-prefix` and :option:`-ino-system-prefix` command-line
708*f4a2713aSLionel Sambucarguments can be used to override whether subsets of an include path are
709*f4a2713aSLionel Sambuctreated as system headers. When the name in a ``#include`` directive is
710*f4a2713aSLionel Sambucfound within a header search path and starts with a system prefix, the
711*f4a2713aSLionel Sambucheader is treated as a system header. The last prefix on the
712*f4a2713aSLionel Sambuccommand-line which matches the specified header name takes precedence.
713*f4a2713aSLionel SambucFor instance:
714*f4a2713aSLionel Sambuc
715*f4a2713aSLionel Sambuc.. code-block:: console
716*f4a2713aSLionel Sambuc
717*f4a2713aSLionel Sambuc  $ clang -Ifoo -isystem bar -isystem-prefix x/ -ino-system-prefix x/y/
718*f4a2713aSLionel Sambuc
719*f4a2713aSLionel SambucHere, ``#include "x/a.h"`` is treated as including a system header, even
720*f4a2713aSLionel Sambucif the header is found in ``foo``, and ``#include "x/y/b.h"`` is treated
721*f4a2713aSLionel Sambucas not including a system header, even if the header is found in
722*f4a2713aSLionel Sambuc``bar``.
723*f4a2713aSLionel Sambuc
724*f4a2713aSLionel SambucA ``#include`` directive which finds a file relative to the current
725*f4a2713aSLionel Sambucdirectory is treated as including a system header if the including file
726*f4a2713aSLionel Sambucis treated as a system header.
727*f4a2713aSLionel Sambuc
728*f4a2713aSLionel Sambuc.. _diagnostics_enable_everything:
729*f4a2713aSLionel Sambuc
730*f4a2713aSLionel SambucEnabling All Warnings
731*f4a2713aSLionel Sambuc^^^^^^^^^^^^^^^^^^^^^
732*f4a2713aSLionel Sambuc
733*f4a2713aSLionel SambucIn addition to the traditional ``-W`` flags, one can enable **all**
734*f4a2713aSLionel Sambucwarnings by passing :option:`-Weverything`. This works as expected with
735*f4a2713aSLionel Sambuc:option:`-Werror`, and also includes the warnings from :option:`-pedantic`.
736*f4a2713aSLionel Sambuc
737*f4a2713aSLionel SambucNote that when combined with :option:`-w` (which disables all warnings), that
738*f4a2713aSLionel Sambucflag wins.
739*f4a2713aSLionel Sambuc
740*f4a2713aSLionel SambucControlling Static Analyzer Diagnostics
741*f4a2713aSLionel Sambuc^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
742*f4a2713aSLionel Sambuc
743*f4a2713aSLionel SambucWhile not strictly part of the compiler, the diagnostics from Clang's
744*f4a2713aSLionel Sambuc`static analyzer <http://clang-analyzer.llvm.org>`_ can also be
745*f4a2713aSLionel Sambucinfluenced by the user via changes to the source code. See the available
746*f4a2713aSLionel Sambuc`annotations <http://clang-analyzer.llvm.org/annotations.html>`_ and the
747*f4a2713aSLionel Sambucanalyzer's `FAQ
748*f4a2713aSLionel Sambucpage <http://clang-analyzer.llvm.org/faq.html#exclude_code>`_ for more
749*f4a2713aSLionel Sambucinformation.
750*f4a2713aSLionel Sambuc
751*f4a2713aSLionel Sambuc.. _usersmanual-precompiled-headers:
752*f4a2713aSLionel Sambuc
753*f4a2713aSLionel SambucPrecompiled Headers
754*f4a2713aSLionel Sambuc-------------------
755*f4a2713aSLionel Sambuc
756*f4a2713aSLionel Sambuc`Precompiled headers <http://en.wikipedia.org/wiki/Precompiled_header>`__
757*f4a2713aSLionel Sambucare a general approach employed by many compilers to reduce compilation
758*f4a2713aSLionel Sambuctime. The underlying motivation of the approach is that it is common for
759*f4a2713aSLionel Sambucthe same (and often large) header files to be included by multiple
760*f4a2713aSLionel Sambucsource files. Consequently, compile times can often be greatly improved
761*f4a2713aSLionel Sambucby caching some of the (redundant) work done by a compiler to process
762*f4a2713aSLionel Sambucheaders. Precompiled header files, which represent one of many ways to
763*f4a2713aSLionel Sambucimplement this optimization, are literally files that represent an
764*f4a2713aSLionel Sambucon-disk cache that contains the vital information necessary to reduce
765*f4a2713aSLionel Sambucsome of the work needed to process a corresponding header file. While
766*f4a2713aSLionel Sambucdetails of precompiled headers vary between compilers, precompiled
767*f4a2713aSLionel Sambucheaders have been shown to be highly effective at speeding up program
768*f4a2713aSLionel Sambuccompilation on systems with very large system headers (e.g., Mac OS/X).
769*f4a2713aSLionel Sambuc
770*f4a2713aSLionel SambucGenerating a PCH File
771*f4a2713aSLionel Sambuc^^^^^^^^^^^^^^^^^^^^^
772*f4a2713aSLionel Sambuc
773*f4a2713aSLionel SambucTo generate a PCH file using Clang, one invokes Clang with the
774*f4a2713aSLionel Sambuc:option:`-x <language>-header` option. This mirrors the interface in GCC
775*f4a2713aSLionel Sambucfor generating PCH files:
776*f4a2713aSLionel Sambuc
777*f4a2713aSLionel Sambuc.. code-block:: console
778*f4a2713aSLionel Sambuc
779*f4a2713aSLionel Sambuc  $ gcc -x c-header test.h -o test.h.gch
780*f4a2713aSLionel Sambuc  $ clang -x c-header test.h -o test.h.pch
781*f4a2713aSLionel Sambuc
782*f4a2713aSLionel SambucUsing a PCH File
783*f4a2713aSLionel Sambuc^^^^^^^^^^^^^^^^
784*f4a2713aSLionel Sambuc
785*f4a2713aSLionel SambucA PCH file can then be used as a prefix header when a :option:`-include`
786*f4a2713aSLionel Sambucoption is passed to ``clang``:
787*f4a2713aSLionel Sambuc
788*f4a2713aSLionel Sambuc.. code-block:: console
789*f4a2713aSLionel Sambuc
790*f4a2713aSLionel Sambuc  $ clang -include test.h test.c -o test
791*f4a2713aSLionel Sambuc
792*f4a2713aSLionel SambucThe ``clang`` driver will first check if a PCH file for ``test.h`` is
793*f4a2713aSLionel Sambucavailable; if so, the contents of ``test.h`` (and the files it includes)
794*f4a2713aSLionel Sambucwill be processed from the PCH file. Otherwise, Clang falls back to
795*f4a2713aSLionel Sambucdirectly processing the content of ``test.h``. This mirrors the behavior
796*f4a2713aSLionel Sambucof GCC.
797*f4a2713aSLionel Sambuc
798*f4a2713aSLionel Sambuc.. note::
799*f4a2713aSLionel Sambuc
800*f4a2713aSLionel Sambuc  Clang does *not* automatically use PCH files for headers that are directly
801*f4a2713aSLionel Sambuc  included within a source file. For example:
802*f4a2713aSLionel Sambuc
803*f4a2713aSLionel Sambuc  .. code-block:: console
804*f4a2713aSLionel Sambuc
805*f4a2713aSLionel Sambuc    $ clang -x c-header test.h -o test.h.pch
806*f4a2713aSLionel Sambuc    $ cat test.c
807*f4a2713aSLionel Sambuc    #include "test.h"
808*f4a2713aSLionel Sambuc    $ clang test.c -o test
809*f4a2713aSLionel Sambuc
810*f4a2713aSLionel Sambuc  In this example, ``clang`` will not automatically use the PCH file for
811*f4a2713aSLionel Sambuc  ``test.h`` since ``test.h`` was included directly in the source file and not
812*f4a2713aSLionel Sambuc  specified on the command line using :option:`-include`.
813*f4a2713aSLionel Sambuc
814*f4a2713aSLionel SambucRelocatable PCH Files
815*f4a2713aSLionel Sambuc^^^^^^^^^^^^^^^^^^^^^
816*f4a2713aSLionel Sambuc
817*f4a2713aSLionel SambucIt is sometimes necessary to build a precompiled header from headers
818*f4a2713aSLionel Sambucthat are not yet in their final, installed locations. For example, one
819*f4a2713aSLionel Sambucmight build a precompiled header within the build tree that is then
820*f4a2713aSLionel Sambucmeant to be installed alongside the headers. Clang permits the creation
821*f4a2713aSLionel Sambucof "relocatable" precompiled headers, which are built with a given path
822*f4a2713aSLionel Sambuc(into the build directory) and can later be used from an installed
823*f4a2713aSLionel Sambuclocation.
824*f4a2713aSLionel Sambuc
825*f4a2713aSLionel SambucTo build a relocatable precompiled header, place your headers into a
826*f4a2713aSLionel Sambucsubdirectory whose structure mimics the installed location. For example,
827*f4a2713aSLionel Sambucif you want to build a precompiled header for the header ``mylib.h``
828*f4a2713aSLionel Sambucthat will be installed into ``/usr/include``, create a subdirectory
829*f4a2713aSLionel Sambuc``build/usr/include`` and place the header ``mylib.h`` into that
830*f4a2713aSLionel Sambucsubdirectory. If ``mylib.h`` depends on other headers, then they can be
831*f4a2713aSLionel Sambucstored within ``build/usr/include`` in a way that mimics the installed
832*f4a2713aSLionel Sambuclocation.
833*f4a2713aSLionel Sambuc
834*f4a2713aSLionel SambucBuilding a relocatable precompiled header requires two additional
835*f4a2713aSLionel Sambucarguments. First, pass the ``--relocatable-pch`` flag to indicate that
836*f4a2713aSLionel Sambucthe resulting PCH file should be relocatable. Second, pass
837*f4a2713aSLionel Sambuc:option:`-isysroot /path/to/build`, which makes all includes for your library
838*f4a2713aSLionel Sambucrelative to the build directory. For example:
839*f4a2713aSLionel Sambuc
840*f4a2713aSLionel Sambuc.. code-block:: console
841*f4a2713aSLionel Sambuc
842*f4a2713aSLionel Sambuc  # clang -x c-header --relocatable-pch -isysroot /path/to/build /path/to/build/mylib.h mylib.h.pch
843*f4a2713aSLionel Sambuc
844*f4a2713aSLionel SambucWhen loading the relocatable PCH file, the various headers used in the
845*f4a2713aSLionel SambucPCH file are found from the system header root. For example, ``mylib.h``
846*f4a2713aSLionel Sambuccan be found in ``/usr/include/mylib.h``. If the headers are installed
847*f4a2713aSLionel Sambucin some other system root, the :option:`-isysroot` option can be used provide
848*f4a2713aSLionel Sambuca different system root from which the headers will be based. For
849*f4a2713aSLionel Sambucexample, :option:`-isysroot /Developer/SDKs/MacOSX10.4u.sdk` will look for
850*f4a2713aSLionel Sambuc``mylib.h`` in ``/Developer/SDKs/MacOSX10.4u.sdk/usr/include/mylib.h``.
851*f4a2713aSLionel Sambuc
852*f4a2713aSLionel SambucRelocatable precompiled headers are intended to be used in a limited
853*f4a2713aSLionel Sambucnumber of cases where the compilation environment is tightly controlled
854*f4a2713aSLionel Sambucand the precompiled header cannot be generated after headers have been
855*f4a2713aSLionel Sambucinstalled.
856*f4a2713aSLionel Sambuc
857*f4a2713aSLionel SambucControlling Code Generation
858*f4a2713aSLionel Sambuc---------------------------
859*f4a2713aSLionel Sambuc
860*f4a2713aSLionel SambucClang provides a number of ways to control code generation. The options
861*f4a2713aSLionel Sambucare listed below.
862*f4a2713aSLionel Sambuc
863*f4a2713aSLionel Sambuc**-f[no-]sanitize=check1,check2,...**
864*f4a2713aSLionel Sambuc   Turn on runtime checks for various forms of undefined or suspicious
865*f4a2713aSLionel Sambuc   behavior.
866*f4a2713aSLionel Sambuc
867*f4a2713aSLionel Sambuc   This option controls whether Clang adds runtime checks for various
868*f4a2713aSLionel Sambuc   forms of undefined or suspicious behavior, and is disabled by
869*f4a2713aSLionel Sambuc   default. If a check fails, a diagnostic message is produced at
870*f4a2713aSLionel Sambuc   runtime explaining the problem. The main checks are:
871*f4a2713aSLionel Sambuc
872*f4a2713aSLionel Sambuc   -  .. _opt_fsanitize_address:
873*f4a2713aSLionel Sambuc
874*f4a2713aSLionel Sambuc      ``-fsanitize=address``:
875*f4a2713aSLionel Sambuc      :doc:`AddressSanitizer`, a memory error
876*f4a2713aSLionel Sambuc      detector.
877*f4a2713aSLionel Sambuc   -  ``-fsanitize=init-order``: Make AddressSanitizer check for
878*f4a2713aSLionel Sambuc      dynamic initialization order problems. Implied by ``-fsanitize=address``.
879*f4a2713aSLionel Sambuc   -  ``-fsanitize=address-full``: AddressSanitizer with all the
880*f4a2713aSLionel Sambuc      experimental features listed below.
881*f4a2713aSLionel Sambuc   -  ``-fsanitize=integer``: Enables checks for undefined or
882*f4a2713aSLionel Sambuc      suspicious integer behavior.
883*f4a2713aSLionel Sambuc   -  .. _opt_fsanitize_thread:
884*f4a2713aSLionel Sambuc
885*f4a2713aSLionel Sambuc      ``-fsanitize=thread``: :doc:`ThreadSanitizer`, a data race detector.
886*f4a2713aSLionel Sambuc   -  .. _opt_fsanitize_memory:
887*f4a2713aSLionel Sambuc
888*f4a2713aSLionel Sambuc      ``-fsanitize=memory``: :doc:`MemorySanitizer`,
889*f4a2713aSLionel Sambuc      an *experimental* detector of uninitialized reads. Not ready for
890*f4a2713aSLionel Sambuc      widespread use.
891*f4a2713aSLionel Sambuc   -  .. _opt_fsanitize_undefined:
892*f4a2713aSLionel Sambuc
893*f4a2713aSLionel Sambuc      ``-fsanitize=undefined``: Fast and compatible undefined behavior
894*f4a2713aSLionel Sambuc      checker. Enables the undefined behavior checks that have small
895*f4a2713aSLionel Sambuc      runtime cost and no impact on address space layout or ABI. This
896*f4a2713aSLionel Sambuc      includes all of the checks listed below other than
897*f4a2713aSLionel Sambuc      ``unsigned-integer-overflow``.
898*f4a2713aSLionel Sambuc
899*f4a2713aSLionel Sambuc   -  ``-fsanitize=undefined-trap``: This includes all sanitizers
900*f4a2713aSLionel Sambuc      included by ``-fsanitize=undefined``, except those that require
901*f4a2713aSLionel Sambuc      runtime support. This group of sanitizers is intended to be
902*f4a2713aSLionel Sambuc      used in conjunction with the ``-fsanitize-undefined-trap-on-error``
903*f4a2713aSLionel Sambuc      flag. This includes all of the checks listed below other than
904*f4a2713aSLionel Sambuc      ``unsigned-integer-overflow`` and ``vptr``.
905*f4a2713aSLionel Sambuc   -  ``-fsanitize=dataflow``: :doc:`DataFlowSanitizer`, a general data
906*f4a2713aSLionel Sambuc      flow analysis.
907*f4a2713aSLionel Sambuc
908*f4a2713aSLionel Sambuc   The following more fine-grained checks are also available:
909*f4a2713aSLionel Sambuc
910*f4a2713aSLionel Sambuc   -  ``-fsanitize=alignment``: Use of a misaligned pointer or creation
911*f4a2713aSLionel Sambuc      of a misaligned reference.
912*f4a2713aSLionel Sambuc   -  ``-fsanitize=bool``: Load of a ``bool`` value which is neither
913*f4a2713aSLionel Sambuc      ``true`` nor ``false``.
914*f4a2713aSLionel Sambuc   -  ``-fsanitize=bounds``: Out of bounds array indexing, in cases
915*f4a2713aSLionel Sambuc      where the array bound can be statically determined.
916*f4a2713aSLionel Sambuc   -  ``-fsanitize=enum``: Load of a value of an enumerated type which
917*f4a2713aSLionel Sambuc      is not in the range of representable values for that enumerated
918*f4a2713aSLionel Sambuc      type.
919*f4a2713aSLionel Sambuc   -  ``-fsanitize=float-cast-overflow``: Conversion to, from, or
920*f4a2713aSLionel Sambuc      between floating-point types which would overflow the
921*f4a2713aSLionel Sambuc      destination.
922*f4a2713aSLionel Sambuc   -  ``-fsanitize=float-divide-by-zero``: Floating point division by
923*f4a2713aSLionel Sambuc      zero.
924*f4a2713aSLionel Sambuc   -  ``-fsanitize=function``: Indirect call of a function through a
925*f4a2713aSLionel Sambuc      function pointer of the wrong type (Linux, C++ and x86/x86_64 only).
926*f4a2713aSLionel Sambuc   -  ``-fsanitize=integer-divide-by-zero``: Integer division by zero.
927*f4a2713aSLionel Sambuc   -  ``-fsanitize=null``: Use of a null pointer or creation of a null
928*f4a2713aSLionel Sambuc      reference.
929*f4a2713aSLionel Sambuc   -  ``-fsanitize=object-size``: An attempt to use bytes which the
930*f4a2713aSLionel Sambuc      optimizer can determine are not part of the object being
931*f4a2713aSLionel Sambuc      accessed. The sizes of objects are determined using
932*f4a2713aSLionel Sambuc      ``__builtin_object_size``, and consequently may be able to detect
933*f4a2713aSLionel Sambuc      more problems at higher optimization levels.
934*f4a2713aSLionel Sambuc   -  ``-fsanitize=return``: In C++, reaching the end of a
935*f4a2713aSLionel Sambuc      value-returning function without returning a value.
936*f4a2713aSLionel Sambuc   -  ``-fsanitize=shift``: Shift operators where the amount shifted is
937*f4a2713aSLionel Sambuc      greater or equal to the promoted bit-width of the left hand side
938*f4a2713aSLionel Sambuc      or less than zero, or where the left hand side is negative. For a
939*f4a2713aSLionel Sambuc      signed left shift, also checks for signed overflow in C, and for
940*f4a2713aSLionel Sambuc      unsigned overflow in C++.
941*f4a2713aSLionel Sambuc   -  ``-fsanitize=signed-integer-overflow``: Signed integer overflow,
942*f4a2713aSLionel Sambuc      including all the checks added by ``-ftrapv``, and checking for
943*f4a2713aSLionel Sambuc      overflow in signed division (``INT_MIN / -1``).
944*f4a2713aSLionel Sambuc   -  ``-fsanitize=unreachable``: If control flow reaches
945*f4a2713aSLionel Sambuc      ``__builtin_unreachable``.
946*f4a2713aSLionel Sambuc   -  ``-fsanitize=unsigned-integer-overflow``: Unsigned integer
947*f4a2713aSLionel Sambuc      overflows.
948*f4a2713aSLionel Sambuc   -  ``-fsanitize=vla-bound``: A variable-length array whose bound
949*f4a2713aSLionel Sambuc      does not evaluate to a positive value.
950*f4a2713aSLionel Sambuc   -  ``-fsanitize=vptr``: Use of an object whose vptr indicates that
951*f4a2713aSLionel Sambuc      it is of the wrong dynamic type, or that its lifetime has not
952*f4a2713aSLionel Sambuc      begun or has ended. Incompatible with ``-fno-rtti``.
953*f4a2713aSLionel Sambuc
954*f4a2713aSLionel Sambuc   You can turn off or modify checks for certain source files, functions
955*f4a2713aSLionel Sambuc   or even variables by providing a special file:
956*f4a2713aSLionel Sambuc
957*f4a2713aSLionel Sambuc   -  ``-fsanitize-blacklist=/path/to/blacklist/file``: disable or modify
958*f4a2713aSLionel Sambuc      sanitizer checks for objects listed in the file. See
959*f4a2713aSLionel Sambuc      :doc:`SanitizerSpecialCaseList` for file format description.
960*f4a2713aSLionel Sambuc   -  ``-fno-sanitize-blacklist``: don't use blacklist file, if it was
961*f4a2713aSLionel Sambuc      specified earlier in the command line.
962*f4a2713aSLionel Sambuc
963*f4a2713aSLionel Sambuc   Experimental features of AddressSanitizer (not ready for widespread
964*f4a2713aSLionel Sambuc   use, require explicit ``-fsanitize=address``):
965*f4a2713aSLionel Sambuc
966*f4a2713aSLionel Sambuc   -  ``-fsanitize=use-after-return``: Check for use-after-return
967*f4a2713aSLionel Sambuc      errors (accessing local variable after the function exit).
968*f4a2713aSLionel Sambuc   -  ``-fsanitize=use-after-scope``: Check for use-after-scope errors
969*f4a2713aSLionel Sambuc      (accesing local variable after it went out of scope).
970*f4a2713aSLionel Sambuc
971*f4a2713aSLionel Sambuc   Extra features of MemorySanitizer (require explicit
972*f4a2713aSLionel Sambuc   ``-fsanitize=memory``):
973*f4a2713aSLionel Sambuc
974*f4a2713aSLionel Sambuc   -  ``-fsanitize-memory-track-origins``: Enables origin tracking in
975*f4a2713aSLionel Sambuc      MemorySanitizer. Adds a second section to MemorySanitizer
976*f4a2713aSLionel Sambuc      reports pointing to the heap or stack allocation the
977*f4a2713aSLionel Sambuc      uninitialized bits came from. Slows down execution by additional
978*f4a2713aSLionel Sambuc      1.5x-2x.
979*f4a2713aSLionel Sambuc
980*f4a2713aSLionel Sambuc   Extra features of UndefinedBehaviorSanitizer:
981*f4a2713aSLionel Sambuc
982*f4a2713aSLionel Sambuc   -  ``-fno-sanitize-recover``: By default, after a sanitizer diagnoses
983*f4a2713aSLionel Sambuc      an issue, it will attempt to continue executing the program if there
984*f4a2713aSLionel Sambuc      is a reasonable behavior it can give to the faulting operation. This
985*f4a2713aSLionel Sambuc      option causes the program to abort instead.
986*f4a2713aSLionel Sambuc   -  ``-fsanitize-undefined-trap-on-error``: Causes traps to be emitted
987*f4a2713aSLionel Sambuc      rather than calls to runtime libraries when a problem is detected.
988*f4a2713aSLionel Sambuc      This option is intended for use in cases where the sanitizer runtime
989*f4a2713aSLionel Sambuc      cannot be used (for instance, when building libc or a kernel module).
990*f4a2713aSLionel Sambuc      This is only compatible with the sanitizers in the ``undefined-trap``
991*f4a2713aSLionel Sambuc      group.
992*f4a2713aSLionel Sambuc
993*f4a2713aSLionel Sambuc   The ``-fsanitize=`` argument must also be provided when linking, in
994*f4a2713aSLionel Sambuc   order to link to the appropriate runtime library. When using
995*f4a2713aSLionel Sambuc   ``-fsanitize=vptr`` (or a group that includes it, such as
996*f4a2713aSLionel Sambuc   ``-fsanitize=undefined``) with a C++ program, the link must be
997*f4a2713aSLionel Sambuc   performed by ``clang++``, not ``clang``, in order to link against the
998*f4a2713aSLionel Sambuc   C++-specific parts of the runtime library.
999*f4a2713aSLionel Sambuc
1000*f4a2713aSLionel Sambuc   It is not possible to combine more than one of the ``-fsanitize=address``,
1001*f4a2713aSLionel Sambuc   ``-fsanitize=thread``, and ``-fsanitize=memory`` checkers in the same
1002*f4a2713aSLionel Sambuc   program. The ``-fsanitize=undefined`` checks can be combined with other
1003*f4a2713aSLionel Sambuc   sanitizers.
1004*f4a2713aSLionel Sambuc
1005*f4a2713aSLionel Sambuc**-f[no-]address-sanitizer**
1006*f4a2713aSLionel Sambuc   Deprecated synonym for :ref:`-f[no-]sanitize=address
1007*f4a2713aSLionel Sambuc   <opt_fsanitize_address>`.
1008*f4a2713aSLionel Sambuc**-f[no-]thread-sanitizer**
1009*f4a2713aSLionel Sambuc   Deprecated synonym for :ref:`-f[no-]sanitize=thread
1010*f4a2713aSLionel Sambuc   <opt_fsanitize_thread>`.
1011*f4a2713aSLionel Sambuc
1012*f4a2713aSLionel Sambuc.. option:: -fcatch-undefined-behavior
1013*f4a2713aSLionel Sambuc
1014*f4a2713aSLionel Sambuc   Deprecated synonym for :ref:`-fsanitize=undefined
1015*f4a2713aSLionel Sambuc   <opt_fsanitize_undefined>`.
1016*f4a2713aSLionel Sambuc
1017*f4a2713aSLionel Sambuc.. option:: -fno-assume-sane-operator-new
1018*f4a2713aSLionel Sambuc
1019*f4a2713aSLionel Sambuc   Don't assume that the C++'s new operator is sane.
1020*f4a2713aSLionel Sambuc
1021*f4a2713aSLionel Sambuc   This option tells the compiler to do not assume that C++'s global
1022*f4a2713aSLionel Sambuc   new operator will always return a pointer that does not alias any
1023*f4a2713aSLionel Sambuc   other pointer when the function returns.
1024*f4a2713aSLionel Sambuc
1025*f4a2713aSLionel Sambuc.. option:: -ftrap-function=[name]
1026*f4a2713aSLionel Sambuc
1027*f4a2713aSLionel Sambuc   Instruct code generator to emit a function call to the specified
1028*f4a2713aSLionel Sambuc   function name for ``__builtin_trap()``.
1029*f4a2713aSLionel Sambuc
1030*f4a2713aSLionel Sambuc   LLVM code generator translates ``__builtin_trap()`` to a trap
1031*f4a2713aSLionel Sambuc   instruction if it is supported by the target ISA. Otherwise, the
1032*f4a2713aSLionel Sambuc   builtin is translated into a call to ``abort``. If this option is
1033*f4a2713aSLionel Sambuc   set, then the code generator will always lower the builtin to a call
1034*f4a2713aSLionel Sambuc   to the specified function regardless of whether the target ISA has a
1035*f4a2713aSLionel Sambuc   trap instruction. This option is useful for environments (e.g.
1036*f4a2713aSLionel Sambuc   deeply embedded) where a trap cannot be properly handled, or when
1037*f4a2713aSLionel Sambuc   some custom behavior is desired.
1038*f4a2713aSLionel Sambuc
1039*f4a2713aSLionel Sambuc.. option:: -ftls-model=[model]
1040*f4a2713aSLionel Sambuc
1041*f4a2713aSLionel Sambuc   Select which TLS model to use.
1042*f4a2713aSLionel Sambuc
1043*f4a2713aSLionel Sambuc   Valid values are: ``global-dynamic``, ``local-dynamic``,
1044*f4a2713aSLionel Sambuc   ``initial-exec`` and ``local-exec``. The default value is
1045*f4a2713aSLionel Sambuc   ``global-dynamic``. The compiler may use a different model if the
1046*f4a2713aSLionel Sambuc   selected model is not supported by the target, or if a more
1047*f4a2713aSLionel Sambuc   efficient model can be used. The TLS model can be overridden per
1048*f4a2713aSLionel Sambuc   variable using the ``tls_model`` attribute.
1049*f4a2713aSLionel Sambuc
1050*f4a2713aSLionel Sambuc.. option:: -mhwdiv=[values]
1051*f4a2713aSLionel Sambuc
1052*f4a2713aSLionel Sambuc   Select the ARM modes (arm or thumb) that support hardware division
1053*f4a2713aSLionel Sambuc   instructions.
1054*f4a2713aSLionel Sambuc
1055*f4a2713aSLionel Sambuc   Valid values are: ``arm``, ``thumb`` and ``arm,thumb``.
1056*f4a2713aSLionel Sambuc   This option is used to indicate which mode (arm or thumb) supports
1057*f4a2713aSLionel Sambuc   hardware division instructions. This only applies to the ARM
1058*f4a2713aSLionel Sambuc   architecture.
1059*f4a2713aSLionel Sambuc
1060*f4a2713aSLionel Sambuc.. option:: -m[no-]crc
1061*f4a2713aSLionel Sambuc
1062*f4a2713aSLionel Sambuc   Enable or disable CRC instructions.
1063*f4a2713aSLionel Sambuc
1064*f4a2713aSLionel Sambuc   This option is used to indicate whether CRC instructions are to
1065*f4a2713aSLionel Sambuc   be generated. This only applies to the ARM architecture.
1066*f4a2713aSLionel Sambuc
1067*f4a2713aSLionel Sambuc   CRC instructions are enabled by default on ARMv8.
1068*f4a2713aSLionel Sambuc
1069*f4a2713aSLionel Sambuc
1070*f4a2713aSLionel SambucControlling Size of Debug Information
1071*f4a2713aSLionel Sambuc-------------------------------------
1072*f4a2713aSLionel Sambuc
1073*f4a2713aSLionel SambucDebug info kind generated by Clang can be set by one of the flags listed
1074*f4a2713aSLionel Sambucbelow. If multiple flags are present, the last one is used.
1075*f4a2713aSLionel Sambuc
1076*f4a2713aSLionel Sambuc.. option:: -g0
1077*f4a2713aSLionel Sambuc
1078*f4a2713aSLionel Sambuc  Don't generate any debug info (default).
1079*f4a2713aSLionel Sambuc
1080*f4a2713aSLionel Sambuc.. option:: -gline-tables-only
1081*f4a2713aSLionel Sambuc
1082*f4a2713aSLionel Sambuc  Generate line number tables only.
1083*f4a2713aSLionel Sambuc
1084*f4a2713aSLionel Sambuc  This kind of debug info allows to obtain stack traces with function names,
1085*f4a2713aSLionel Sambuc  file names and line numbers (by such tools as ``gdb`` or ``addr2line``).  It
1086*f4a2713aSLionel Sambuc  doesn't contain any other data (e.g. description of local variables or
1087*f4a2713aSLionel Sambuc  function parameters).
1088*f4a2713aSLionel Sambuc
1089*f4a2713aSLionel Sambuc.. option:: -g
1090*f4a2713aSLionel Sambuc
1091*f4a2713aSLionel Sambuc  Generate complete debug info.
1092*f4a2713aSLionel Sambuc
1093*f4a2713aSLionel SambucComment Parsing Options
1094*f4a2713aSLionel Sambuc--------------------------
1095*f4a2713aSLionel Sambuc
1096*f4a2713aSLionel SambucClang parses Doxygen and non-Doxygen style documentation comments and attaches
1097*f4a2713aSLionel Sambucthem to the appropriate declaration nodes.  By default, it only parses
1098*f4a2713aSLionel SambucDoxygen-style comments and ignores ordinary comments starting with ``//`` and
1099*f4a2713aSLionel Sambuc``/*``.
1100*f4a2713aSLionel Sambuc
1101*f4a2713aSLionel Sambuc.. option:: -fparse-all-comments
1102*f4a2713aSLionel Sambuc
1103*f4a2713aSLionel Sambuc  Parse all comments as documentation comments (including ordinary comments
1104*f4a2713aSLionel Sambuc  starting with ``//`` and ``/*``).
1105*f4a2713aSLionel Sambuc
1106*f4a2713aSLionel Sambuc.. _c:
1107*f4a2713aSLionel Sambuc
1108*f4a2713aSLionel SambucC Language Features
1109*f4a2713aSLionel Sambuc===================
1110*f4a2713aSLionel Sambuc
1111*f4a2713aSLionel SambucThe support for standard C in clang is feature-complete except for the
1112*f4a2713aSLionel SambucC99 floating-point pragmas.
1113*f4a2713aSLionel Sambuc
1114*f4a2713aSLionel SambucExtensions supported by clang
1115*f4a2713aSLionel Sambuc-----------------------------
1116*f4a2713aSLionel Sambuc
1117*f4a2713aSLionel SambucSee :doc:`LanguageExtensions`.
1118*f4a2713aSLionel Sambuc
1119*f4a2713aSLionel SambucDifferences between various standard modes
1120*f4a2713aSLionel Sambuc------------------------------------------
1121*f4a2713aSLionel Sambuc
1122*f4a2713aSLionel Sambucclang supports the -std option, which changes what language mode clang
1123*f4a2713aSLionel Sambucuses. The supported modes for C are c89, gnu89, c94, c99, gnu99 and
1124*f4a2713aSLionel Sambucvarious aliases for those modes. If no -std option is specified, clang
1125*f4a2713aSLionel Sambucdefaults to gnu99 mode.
1126*f4a2713aSLionel Sambuc
1127*f4a2713aSLionel SambucDifferences between all ``c*`` and ``gnu*`` modes:
1128*f4a2713aSLionel Sambuc
1129*f4a2713aSLionel Sambuc-  ``c*`` modes define "``__STRICT_ANSI__``".
1130*f4a2713aSLionel Sambuc-  Target-specific defines not prefixed by underscores, like "linux",
1131*f4a2713aSLionel Sambuc   are defined in ``gnu*`` modes.
1132*f4a2713aSLionel Sambuc-  Trigraphs default to being off in ``gnu*`` modes; they can be enabled by
1133*f4a2713aSLionel Sambuc   the -trigraphs option.
1134*f4a2713aSLionel Sambuc-  The parser recognizes "asm" and "typeof" as keywords in ``gnu*`` modes;
1135*f4a2713aSLionel Sambuc   the variants "``__asm__``" and "``__typeof__``" are recognized in all
1136*f4a2713aSLionel Sambuc   modes.
1137*f4a2713aSLionel Sambuc-  The Apple "blocks" extension is recognized by default in ``gnu*`` modes
1138*f4a2713aSLionel Sambuc   on some platforms; it can be enabled in any mode with the "-fblocks"
1139*f4a2713aSLionel Sambuc   option.
1140*f4a2713aSLionel Sambuc-  Arrays that are VLA's according to the standard, but which can be
1141*f4a2713aSLionel Sambuc   constant folded by the frontend are treated as fixed size arrays.
1142*f4a2713aSLionel Sambuc   This occurs for things like "int X[(1, 2)];", which is technically a
1143*f4a2713aSLionel Sambuc   VLA. ``c*`` modes are strictly compliant and treat these as VLAs.
1144*f4a2713aSLionel Sambuc
1145*f4a2713aSLionel SambucDifferences between ``*89`` and ``*99`` modes:
1146*f4a2713aSLionel Sambuc
1147*f4a2713aSLionel Sambuc-  The ``*99`` modes default to implementing "inline" as specified in C99,
1148*f4a2713aSLionel Sambuc   while the ``*89`` modes implement the GNU version. This can be
1149*f4a2713aSLionel Sambuc   overridden for individual functions with the ``__gnu_inline__``
1150*f4a2713aSLionel Sambuc   attribute.
1151*f4a2713aSLionel Sambuc-  Digraphs are not recognized in c89 mode.
1152*f4a2713aSLionel Sambuc-  The scope of names defined inside a "for", "if", "switch", "while",
1153*f4a2713aSLionel Sambuc   or "do" statement is different. (example: "``if ((struct x {int
1154*f4a2713aSLionel Sambuc   x;}*)0) {}``".)
1155*f4a2713aSLionel Sambuc-  ``__STDC_VERSION__`` is not defined in ``*89`` modes.
1156*f4a2713aSLionel Sambuc-  "inline" is not recognized as a keyword in c89 mode.
1157*f4a2713aSLionel Sambuc-  "restrict" is not recognized as a keyword in ``*89`` modes.
1158*f4a2713aSLionel Sambuc-  Commas are allowed in integer constant expressions in ``*99`` modes.
1159*f4a2713aSLionel Sambuc-  Arrays which are not lvalues are not implicitly promoted to pointers
1160*f4a2713aSLionel Sambuc   in ``*89`` modes.
1161*f4a2713aSLionel Sambuc-  Some warnings are different.
1162*f4a2713aSLionel Sambuc
1163*f4a2713aSLionel Sambucc94 mode is identical to c89 mode except that digraphs are enabled in
1164*f4a2713aSLionel Sambucc94 mode (FIXME: And ``__STDC_VERSION__`` should be defined!).
1165*f4a2713aSLionel Sambuc
1166*f4a2713aSLionel SambucGCC extensions not implemented yet
1167*f4a2713aSLionel Sambuc----------------------------------
1168*f4a2713aSLionel Sambuc
1169*f4a2713aSLionel Sambucclang tries to be compatible with gcc as much as possible, but some gcc
1170*f4a2713aSLionel Sambucextensions are not implemented yet:
1171*f4a2713aSLionel Sambuc
1172*f4a2713aSLionel Sambuc-  clang does not support #pragma weak (`bug
1173*f4a2713aSLionel Sambuc   3679 <http://llvm.org/bugs/show_bug.cgi?id=3679>`_). Due to the uses
1174*f4a2713aSLionel Sambuc   described in the bug, this is likely to be implemented at some point,
1175*f4a2713aSLionel Sambuc   at least partially.
1176*f4a2713aSLionel Sambuc-  clang does not support decimal floating point types (``_Decimal32`` and
1177*f4a2713aSLionel Sambuc   friends) or fixed-point types (``_Fract`` and friends); nobody has
1178*f4a2713aSLionel Sambuc   expressed interest in these features yet, so it's hard to say when
1179*f4a2713aSLionel Sambuc   they will be implemented.
1180*f4a2713aSLionel Sambuc-  clang does not support nested functions; this is a complex feature
1181*f4a2713aSLionel Sambuc   which is infrequently used, so it is unlikely to be implemented
1182*f4a2713aSLionel Sambuc   anytime soon. In C++11 it can be emulated by assigning lambda
1183*f4a2713aSLionel Sambuc   functions to local variables, e.g:
1184*f4a2713aSLionel Sambuc
1185*f4a2713aSLionel Sambuc   .. code-block:: cpp
1186*f4a2713aSLionel Sambuc
1187*f4a2713aSLionel Sambuc     auto const local_function = [&](int parameter) {
1188*f4a2713aSLionel Sambuc       // Do something
1189*f4a2713aSLionel Sambuc     };
1190*f4a2713aSLionel Sambuc     ...
1191*f4a2713aSLionel Sambuc     local_function(1);
1192*f4a2713aSLionel Sambuc
1193*f4a2713aSLionel Sambuc-  clang does not support global register variables; this is unlikely to
1194*f4a2713aSLionel Sambuc   be implemented soon because it requires additional LLVM backend
1195*f4a2713aSLionel Sambuc   support.
1196*f4a2713aSLionel Sambuc-  clang does not support static initialization of flexible array
1197*f4a2713aSLionel Sambuc   members. This appears to be a rarely used extension, but could be
1198*f4a2713aSLionel Sambuc   implemented pending user demand.
1199*f4a2713aSLionel Sambuc-  clang does not support
1200*f4a2713aSLionel Sambuc   ``__builtin_va_arg_pack``/``__builtin_va_arg_pack_len``. This is
1201*f4a2713aSLionel Sambuc   used rarely, but in some potentially interesting places, like the
1202*f4a2713aSLionel Sambuc   glibc headers, so it may be implemented pending user demand. Note
1203*f4a2713aSLionel Sambuc   that because clang pretends to be like GCC 4.2, and this extension
1204*f4a2713aSLionel Sambuc   was introduced in 4.3, the glibc headers will not try to use this
1205*f4a2713aSLionel Sambuc   extension with clang at the moment.
1206*f4a2713aSLionel Sambuc-  clang does not support the gcc extension for forward-declaring
1207*f4a2713aSLionel Sambuc   function parameters; this has not shown up in any real-world code
1208*f4a2713aSLionel Sambuc   yet, though, so it might never be implemented.
1209*f4a2713aSLionel Sambuc
1210*f4a2713aSLionel SambucThis is not a complete list; if you find an unsupported extension
1211*f4a2713aSLionel Sambucmissing from this list, please send an e-mail to cfe-dev. This list
1212*f4a2713aSLionel Sambuccurrently excludes C++; see :ref:`C++ Language Features <cxx>`. Also, this
1213*f4a2713aSLionel Sambuclist does not include bugs in mostly-implemented features; please see
1214*f4a2713aSLionel Sambucthe `bug
1215*f4a2713aSLionel Sambuctracker <http://llvm.org/bugs/buglist.cgi?quicksearch=product%3Aclang+component%3A-New%2BBugs%2CAST%2CBasic%2CDriver%2CHeaders%2CLLVM%2BCodeGen%2Cparser%2Cpreprocessor%2CSemantic%2BAnalyzer>`_
1216*f4a2713aSLionel Sambucfor known existing bugs (FIXME: Is there a section for bug-reporting
1217*f4a2713aSLionel Sambucguidelines somewhere?).
1218*f4a2713aSLionel Sambuc
1219*f4a2713aSLionel SambucIntentionally unsupported GCC extensions
1220*f4a2713aSLionel Sambuc----------------------------------------
1221*f4a2713aSLionel Sambuc
1222*f4a2713aSLionel Sambuc-  clang does not support the gcc extension that allows variable-length
1223*f4a2713aSLionel Sambuc   arrays in structures. This is for a few reasons: one, it is tricky to
1224*f4a2713aSLionel Sambuc   implement, two, the extension is completely undocumented, and three,
1225*f4a2713aSLionel Sambuc   the extension appears to be rarely used. Note that clang *does*
1226*f4a2713aSLionel Sambuc   support flexible array members (arrays with a zero or unspecified
1227*f4a2713aSLionel Sambuc   size at the end of a structure).
1228*f4a2713aSLionel Sambuc-  clang does not have an equivalent to gcc's "fold"; this means that
1229*f4a2713aSLionel Sambuc   clang doesn't accept some constructs gcc might accept in contexts
1230*f4a2713aSLionel Sambuc   where a constant expression is required, like "x-x" where x is a
1231*f4a2713aSLionel Sambuc   variable.
1232*f4a2713aSLionel Sambuc-  clang does not support ``__builtin_apply`` and friends; this extension
1233*f4a2713aSLionel Sambuc   is extremely obscure and difficult to implement reliably.
1234*f4a2713aSLionel Sambuc
1235*f4a2713aSLionel Sambuc.. _c_ms:
1236*f4a2713aSLionel Sambuc
1237*f4a2713aSLionel SambucMicrosoft extensions
1238*f4a2713aSLionel Sambuc--------------------
1239*f4a2713aSLionel Sambuc
1240*f4a2713aSLionel Sambucclang has some experimental support for extensions from Microsoft Visual
1241*f4a2713aSLionel SambucC++; to enable it, use the -fms-extensions command-line option. This is
1242*f4a2713aSLionel Sambucthe default for Windows targets. Note that the support is incomplete.
1243*f4a2713aSLionel SambucSome constructs such as dllexport on classes are ignored with a warning,
1244*f4a2713aSLionel Sambucand others such as `Microsoft IDL annotations
1245*f4a2713aSLionel Sambuc<http://msdn.microsoft.com/en-us/library/8tesw2eh.aspx>`_ are silently
1246*f4a2713aSLionel Sambucignored.
1247*f4a2713aSLionel Sambuc
1248*f4a2713aSLionel Sambucclang has a -fms-compatibility flag that makes clang accept enough
1249*f4a2713aSLionel Sambucinvalid C++ to be able to parse most Microsoft headers. For example, it
1250*f4a2713aSLionel Sambucallows `unqualified lookup of dependent base class members
1251*f4a2713aSLionel Sambuc<http://clang.llvm.org/compatibility.html#dep_lookup_bases>`_, which is
1252*f4a2713aSLionel Sambuca common compatibility issue with clang. This flag is enabled by default
1253*f4a2713aSLionel Sambucfor Windows targets.
1254*f4a2713aSLionel Sambuc
1255*f4a2713aSLionel Sambuc-fdelayed-template-parsing lets clang delay all template instantiation
1256*f4a2713aSLionel Sambucuntil the end of a translation unit. This flag is enabled by default for
1257*f4a2713aSLionel SambucWindows targets.
1258*f4a2713aSLionel Sambuc
1259*f4a2713aSLionel Sambuc-  clang allows setting ``_MSC_VER`` with ``-fmsc-version=``. It defaults to
1260*f4a2713aSLionel Sambuc   1700 which is the same as Visual C/C++ 2012. Any number is supported
1261*f4a2713aSLionel Sambuc   and can greatly affect what Windows SDK and c++stdlib headers clang
1262*f4a2713aSLionel Sambuc   can compile.
1263*f4a2713aSLionel Sambuc-  clang does not support the Microsoft extension where anonymous record
1264*f4a2713aSLionel Sambuc   members can be declared using user defined typedefs.
1265*f4a2713aSLionel Sambuc-  clang supports the Microsoft ``#pragma pack`` feature for controlling
1266*f4a2713aSLionel Sambuc   record layout. GCC also contains support for this feature, however
1267*f4a2713aSLionel Sambuc   where MSVC and GCC are incompatible clang follows the MSVC
1268*f4a2713aSLionel Sambuc   definition.
1269*f4a2713aSLionel Sambuc-  clang supports the Microsoft ``#pragma comment(lib, "foo.lib")`` feature for
1270*f4a2713aSLionel Sambuc   automatically linking against the specified library.  Currently this feature
1271*f4a2713aSLionel Sambuc   only works with the Visual C++ linker.
1272*f4a2713aSLionel Sambuc-  clang supports the Microsoft ``#pragma comment(linker, "/flag:foo")`` feature
1273*f4a2713aSLionel Sambuc   for adding linker flags to COFF object files.  The user is responsible for
1274*f4a2713aSLionel Sambuc   ensuring that the linker understands the flags.
1275*f4a2713aSLionel Sambuc-  clang defaults to C++11 for Windows targets.
1276*f4a2713aSLionel Sambuc
1277*f4a2713aSLionel Sambuc.. _cxx:
1278*f4a2713aSLionel Sambuc
1279*f4a2713aSLionel SambucC++ Language Features
1280*f4a2713aSLionel Sambuc=====================
1281*f4a2713aSLionel Sambuc
1282*f4a2713aSLionel Sambucclang fully implements all of standard C++98 except for exported
1283*f4a2713aSLionel Sambuctemplates (which were removed in C++11), and `many C++11
1284*f4a2713aSLionel Sambucfeatures <http://clang.llvm.org/cxx_status.html>`_ are also implemented.
1285*f4a2713aSLionel Sambuc
1286*f4a2713aSLionel SambucControlling implementation limits
1287*f4a2713aSLionel Sambuc---------------------------------
1288*f4a2713aSLionel Sambuc
1289*f4a2713aSLionel Sambuc.. option:: -fbracket-depth=N
1290*f4a2713aSLionel Sambuc
1291*f4a2713aSLionel Sambuc  Sets the limit for nested parentheses, brackets, and braces to N.  The
1292*f4a2713aSLionel Sambuc  default is 256.
1293*f4a2713aSLionel Sambuc
1294*f4a2713aSLionel Sambuc.. option:: -fconstexpr-depth=N
1295*f4a2713aSLionel Sambuc
1296*f4a2713aSLionel Sambuc  Sets the limit for recursive constexpr function invocations to N.  The
1297*f4a2713aSLionel Sambuc  default is 512.
1298*f4a2713aSLionel Sambuc
1299*f4a2713aSLionel Sambuc.. option:: -ftemplate-depth=N
1300*f4a2713aSLionel Sambuc
1301*f4a2713aSLionel Sambuc  Sets the limit for recursively nested template instantiations to N.  The
1302*f4a2713aSLionel Sambuc  default is 256.
1303*f4a2713aSLionel Sambuc
1304*f4a2713aSLionel Sambuc.. option:: -foperator-arrow-depth=N
1305*f4a2713aSLionel Sambuc
1306*f4a2713aSLionel Sambuc  Sets the limit for iterative calls to 'operator->' functions to N.  The
1307*f4a2713aSLionel Sambuc  default is 256.
1308*f4a2713aSLionel Sambuc
1309*f4a2713aSLionel Sambuc.. _objc:
1310*f4a2713aSLionel Sambuc
1311*f4a2713aSLionel SambucObjective-C Language Features
1312*f4a2713aSLionel Sambuc=============================
1313*f4a2713aSLionel Sambuc
1314*f4a2713aSLionel Sambuc.. _objcxx:
1315*f4a2713aSLionel Sambuc
1316*f4a2713aSLionel SambucObjective-C++ Language Features
1317*f4a2713aSLionel Sambuc===============================
1318*f4a2713aSLionel Sambuc
1319*f4a2713aSLionel Sambuc
1320*f4a2713aSLionel Sambuc.. _target_features:
1321*f4a2713aSLionel Sambuc
1322*f4a2713aSLionel SambucTarget-Specific Features and Limitations
1323*f4a2713aSLionel Sambuc========================================
1324*f4a2713aSLionel Sambuc
1325*f4a2713aSLionel SambucCPU Architectures Features and Limitations
1326*f4a2713aSLionel Sambuc------------------------------------------
1327*f4a2713aSLionel Sambuc
1328*f4a2713aSLionel SambucX86
1329*f4a2713aSLionel Sambuc^^^
1330*f4a2713aSLionel Sambuc
1331*f4a2713aSLionel SambucThe support for X86 (both 32-bit and 64-bit) is considered stable on
1332*f4a2713aSLionel SambucDarwin (Mac OS/X), Linux, FreeBSD, and Dragonfly BSD: it has been tested
1333*f4a2713aSLionel Sambucto correctly compile many large C, C++, Objective-C, and Objective-C++
1334*f4a2713aSLionel Sambuccodebases.
1335*f4a2713aSLionel Sambuc
1336*f4a2713aSLionel SambucOn ``x86_64-mingw32``, passing i128(by value) is incompatible to Microsoft
1337*f4a2713aSLionel Sambucx64 calling conversion. You might need to tweak
1338*f4a2713aSLionel Sambuc``WinX86_64ABIInfo::classify()`` in lib/CodeGen/TargetInfo.cpp.
1339*f4a2713aSLionel Sambuc
1340*f4a2713aSLionel SambucARM
1341*f4a2713aSLionel Sambuc^^^
1342*f4a2713aSLionel Sambuc
1343*f4a2713aSLionel SambucThe support for ARM (specifically ARMv6 and ARMv7) is considered stable
1344*f4a2713aSLionel Sambucon Darwin (iOS): it has been tested to correctly compile many large C,
1345*f4a2713aSLionel SambucC++, Objective-C, and Objective-C++ codebases. Clang only supports a
1346*f4a2713aSLionel Sambuclimited number of ARM architectures. It does not yet fully support
1347*f4a2713aSLionel SambucARMv5, for example.
1348*f4a2713aSLionel Sambuc
1349*f4a2713aSLionel SambucPowerPC
1350*f4a2713aSLionel Sambuc^^^^^^^
1351*f4a2713aSLionel Sambuc
1352*f4a2713aSLionel SambucThe support for PowerPC (especially PowerPC64) is considered stable
1353*f4a2713aSLionel Sambucon Linux and FreeBSD: it has been tested to correctly compile many
1354*f4a2713aSLionel Sambuclarge C and C++ codebases. PowerPC (32bit) is still missing certain
1355*f4a2713aSLionel Sambucfeatures (e.g. PIC code on ELF platforms).
1356*f4a2713aSLionel Sambuc
1357*f4a2713aSLionel SambucOther platforms
1358*f4a2713aSLionel Sambuc^^^^^^^^^^^^^^^
1359*f4a2713aSLionel Sambuc
1360*f4a2713aSLionel Sambucclang currently contains some support for other architectures (e.g. Sparc);
1361*f4a2713aSLionel Sambuchowever, significant pieces of code generation are still missing, and they
1362*f4a2713aSLionel Sambuchaven't undergone significant testing.
1363*f4a2713aSLionel Sambuc
1364*f4a2713aSLionel Sambucclang contains limited support for the MSP430 embedded processor, but
1365*f4a2713aSLionel Sambucboth the clang support and the LLVM backend support are highly
1366*f4a2713aSLionel Sambucexperimental.
1367*f4a2713aSLionel Sambuc
1368*f4a2713aSLionel SambucOther platforms are completely unsupported at the moment. Adding the
1369*f4a2713aSLionel Sambucminimal support needed for parsing and semantic analysis on a new
1370*f4a2713aSLionel Sambucplatform is quite easy; see ``lib/Basic/Targets.cpp`` in the clang source
1371*f4a2713aSLionel Sambuctree. This level of support is also sufficient for conversion to LLVM IR
1372*f4a2713aSLionel Sambucfor simple programs. Proper support for conversion to LLVM IR requires
1373*f4a2713aSLionel Sambucadding code to ``lib/CodeGen/CGCall.cpp`` at the moment; this is likely to
1374*f4a2713aSLionel Sambucchange soon, though. Generating assembly requires a suitable LLVM
1375*f4a2713aSLionel Sambucbackend.
1376*f4a2713aSLionel Sambuc
1377*f4a2713aSLionel SambucOperating System Features and Limitations
1378*f4a2713aSLionel Sambuc-----------------------------------------
1379*f4a2713aSLionel Sambuc
1380*f4a2713aSLionel SambucDarwin (Mac OS/X)
1381*f4a2713aSLionel Sambuc^^^^^^^^^^^^^^^^^
1382*f4a2713aSLionel Sambuc
1383*f4a2713aSLionel SambucNone
1384*f4a2713aSLionel Sambuc
1385*f4a2713aSLionel SambucWindows
1386*f4a2713aSLionel Sambuc^^^^^^^
1387*f4a2713aSLionel Sambuc
1388*f4a2713aSLionel SambucExperimental supports are on Cygming.
1389*f4a2713aSLionel Sambuc
1390*f4a2713aSLionel SambucSee also :ref:`Microsoft Extensions <c_ms>`.
1391*f4a2713aSLionel Sambuc
1392*f4a2713aSLionel SambucCygwin
1393*f4a2713aSLionel Sambuc""""""
1394*f4a2713aSLionel Sambuc
1395*f4a2713aSLionel SambucClang works on Cygwin-1.7.
1396*f4a2713aSLionel Sambuc
1397*f4a2713aSLionel SambucMinGW32
1398*f4a2713aSLionel Sambuc"""""""
1399*f4a2713aSLionel Sambuc
1400*f4a2713aSLionel SambucClang works on some mingw32 distributions. Clang assumes directories as
1401*f4a2713aSLionel Sambucbelow;
1402*f4a2713aSLionel Sambuc
1403*f4a2713aSLionel Sambuc-  ``C:/mingw/include``
1404*f4a2713aSLionel Sambuc-  ``C:/mingw/lib``
1405*f4a2713aSLionel Sambuc-  ``C:/mingw/lib/gcc/mingw32/4.[3-5].0/include/c++``
1406*f4a2713aSLionel Sambuc
1407*f4a2713aSLionel SambucOn MSYS, a few tests might fail.
1408*f4a2713aSLionel Sambuc
1409*f4a2713aSLionel SambucMinGW-w64
1410*f4a2713aSLionel Sambuc"""""""""
1411*f4a2713aSLionel Sambuc
1412*f4a2713aSLionel SambucFor 32-bit (i686-w64-mingw32), and 64-bit (x86\_64-w64-mingw32), Clang
1413*f4a2713aSLionel Sambucassumes as below;
1414*f4a2713aSLionel Sambuc
1415*f4a2713aSLionel Sambuc-  ``GCC versions 4.5.0 to 4.5.3, 4.6.0 to 4.6.2, or 4.7.0 (for the C++ header search path)``
1416*f4a2713aSLionel Sambuc-  ``some_directory/bin/gcc.exe``
1417*f4a2713aSLionel Sambuc-  ``some_directory/bin/clang.exe``
1418*f4a2713aSLionel Sambuc-  ``some_directory/bin/clang++.exe``
1419*f4a2713aSLionel Sambuc-  ``some_directory/bin/../include/c++/GCC_version``
1420*f4a2713aSLionel Sambuc-  ``some_directory/bin/../include/c++/GCC_version/x86_64-w64-mingw32``
1421*f4a2713aSLionel Sambuc-  ``some_directory/bin/../include/c++/GCC_version/i686-w64-mingw32``
1422*f4a2713aSLionel Sambuc-  ``some_directory/bin/../include/c++/GCC_version/backward``
1423*f4a2713aSLionel Sambuc-  ``some_directory/bin/../x86_64-w64-mingw32/include``
1424*f4a2713aSLionel Sambuc-  ``some_directory/bin/../i686-w64-mingw32/include``
1425*f4a2713aSLionel Sambuc-  ``some_directory/bin/../include``
1426*f4a2713aSLionel Sambuc
1427*f4a2713aSLionel SambucThis directory layout is standard for any toolchain you will find on the
1428*f4a2713aSLionel Sambucofficial `MinGW-w64 website <http://mingw-w64.sourceforge.net>`_.
1429*f4a2713aSLionel Sambuc
1430*f4a2713aSLionel SambucClang expects the GCC executable "gcc.exe" compiled for
1431*f4a2713aSLionel Sambuc``i686-w64-mingw32`` (or ``x86_64-w64-mingw32``) to be present on PATH.
1432*f4a2713aSLionel Sambuc
1433*f4a2713aSLionel Sambuc`Some tests might fail <http://llvm.org/bugs/show_bug.cgi?id=9072>`_ on
1434*f4a2713aSLionel Sambuc``x86_64-w64-mingw32``.
1435*f4a2713aSLionel Sambuc
1436*f4a2713aSLionel Sambuc.. _clang-cl:
1437*f4a2713aSLionel Sambuc
1438*f4a2713aSLionel Sambucclang-cl
1439*f4a2713aSLionel Sambuc========
1440*f4a2713aSLionel Sambuc
1441*f4a2713aSLionel Sambucclang-cl is an alternative command-line interface to Clang driver, designed for
1442*f4a2713aSLionel Sambuccompatibility with the Visual C++ compiler, cl.exe.
1443*f4a2713aSLionel Sambuc
1444*f4a2713aSLionel SambucTo enable clang-cl to find system headers, libraries, and the linker when run
1445*f4a2713aSLionel Sambucfrom the command-line, it should be executed inside a Visual Studio Native Tools
1446*f4a2713aSLionel SambucCommand Prompt or a regular Command Prompt where the environment has been set
1447*f4a2713aSLionel Sambucup using e.g. `vcvars32.bat <http://msdn.microsoft.com/en-us/library/f2ccy3wt.aspx>`_.
1448*f4a2713aSLionel Sambuc
1449*f4a2713aSLionel Sambucclang-cl can also be used from inside Visual Studio  by using an LLVM Platform
1450*f4a2713aSLionel SambucToolset.
1451*f4a2713aSLionel Sambuc
1452*f4a2713aSLionel SambucCommand-Line Options
1453*f4a2713aSLionel Sambuc--------------------
1454*f4a2713aSLionel Sambuc
1455*f4a2713aSLionel SambucTo be compatible with cl.exe, clang-cl supports most of the same command-line
1456*f4a2713aSLionel Sambucoptions. Those options can start with either ``/`` or ``-``. It also supports
1457*f4a2713aSLionel Sambucsome of Clang's core options, such as the ``-W`` options.
1458*f4a2713aSLionel Sambuc
1459*f4a2713aSLionel SambucOptions that are known to clang-cl, but not currently supported, are ignored
1460*f4a2713aSLionel Sambucwith a warning. For example:
1461*f4a2713aSLionel Sambuc
1462*f4a2713aSLionel Sambuc  ::
1463*f4a2713aSLionel Sambuc
1464*f4a2713aSLionel Sambuc    clang-cl.exe: warning: argument unused during compilation: '/Zi'
1465*f4a2713aSLionel Sambuc
1466*f4a2713aSLionel SambucTo suppress warnings about unused arguments, use the ``-Qunused-arguments`` option.
1467*f4a2713aSLionel Sambuc
1468*f4a2713aSLionel SambucOptions that are not known to clang-cl will cause errors. If they are spelled with a
1469*f4a2713aSLionel Sambucleading ``/``, they will be mistaken for a filename:
1470*f4a2713aSLionel Sambuc
1471*f4a2713aSLionel Sambuc  ::
1472*f4a2713aSLionel Sambuc
1473*f4a2713aSLionel Sambuc    clang-cl.exe: error: no such file or directory: '/foobar'
1474*f4a2713aSLionel Sambuc
1475*f4a2713aSLionel SambucPlease `file a bug <http://llvm.org/bugs/enter_bug.cgi?product=clang&component=Driver>`_
1476*f4a2713aSLionel Sambucfor any valid cl.exe flags that clang-cl does not understand.
1477*f4a2713aSLionel Sambuc
1478*f4a2713aSLionel SambucExecute ``clang-cl /?`` to see a list of supported options:
1479*f4a2713aSLionel Sambuc
1480*f4a2713aSLionel Sambuc  ::
1481*f4a2713aSLionel Sambuc
1482*f4a2713aSLionel Sambuc    /?                     Display available options
1483*f4a2713aSLionel Sambuc    /c                     Compile only
1484*f4a2713aSLionel Sambuc    /D <macro[=value]>     Define macro
1485*f4a2713aSLionel Sambuc    /fallback              Fall back to cl.exe if clang-cl fails to compile
1486*f4a2713aSLionel Sambuc    /FA                    Output assembly code file during compilation
1487*f4a2713aSLionel Sambuc    /Fa<file or directory> Output assembly code to this file during compilation
1488*f4a2713aSLionel Sambuc    /Fe<file or directory> Set output executable file or directory (ends in / or \)
1489*f4a2713aSLionel Sambuc    /FI<value>             Include file before parsing
1490*f4a2713aSLionel Sambuc    /Fo<file or directory> Set output object file, or directory (ends in / or \)
1491*f4a2713aSLionel Sambuc    /GF-                   Disable string pooling
1492*f4a2713aSLionel Sambuc    /GR-                   Disable RTTI
1493*f4a2713aSLionel Sambuc    /GR                    Enable RTTI
1494*f4a2713aSLionel Sambuc    /help                  Display available options
1495*f4a2713aSLionel Sambuc    /I <dir>               Add directory to include search path
1496*f4a2713aSLionel Sambuc    /J                     Make char type unsigned
1497*f4a2713aSLionel Sambuc    /LDd                   Create debug DLL
1498*f4a2713aSLionel Sambuc    /LD                    Create DLL
1499*f4a2713aSLionel Sambuc    /link <options>        Forward options to the linker
1500*f4a2713aSLionel Sambuc    /MDd                   Use DLL debug run-time
1501*f4a2713aSLionel Sambuc    /MD                    Use DLL run-time
1502*f4a2713aSLionel Sambuc    /MTd                   Use static debug run-time
1503*f4a2713aSLionel Sambuc    /MT                    Use static run-time
1504*f4a2713aSLionel Sambuc    /Ob0                   Disable inlining
1505*f4a2713aSLionel Sambuc    /Od                    Disable optimization
1506*f4a2713aSLionel Sambuc    /Oi-                   Disable use of builtin functions
1507*f4a2713aSLionel Sambuc    /Oi                    Enable use of builtin functions
1508*f4a2713aSLionel Sambuc    /Os                    Optimize for size
1509*f4a2713aSLionel Sambuc    /Ot                    Optimize for speed
1510*f4a2713aSLionel Sambuc    /Ox                    Maximum optimization
1511*f4a2713aSLionel Sambuc    /Oy-                   Disable frame pointer omission
1512*f4a2713aSLionel Sambuc    /Oy                    Enable frame pointer omission
1513*f4a2713aSLionel Sambuc    /O<n>                  Optimization level
1514*f4a2713aSLionel Sambuc    /P                     Only run the preprocessor
1515*f4a2713aSLionel Sambuc    /showIncludes          Print info about included files to stderr
1516*f4a2713aSLionel Sambuc    /TC                    Treat all source files as C
1517*f4a2713aSLionel Sambuc    /Tc <filename>         Specify a C source file
1518*f4a2713aSLionel Sambuc    /TP                    Treat all source files as C++
1519*f4a2713aSLionel Sambuc    /Tp <filename>         Specify a C++ source file
1520*f4a2713aSLionel Sambuc    /U <macro>             Undefine macro
1521*f4a2713aSLionel Sambuc    /W0                    Disable all warnings
1522*f4a2713aSLionel Sambuc    /W1                    Enable -Wall
1523*f4a2713aSLionel Sambuc    /W2                    Enable -Wall
1524*f4a2713aSLionel Sambuc    /W3                    Enable -Wall
1525*f4a2713aSLionel Sambuc    /W4                    Enable -Wall
1526*f4a2713aSLionel Sambuc    /Wall                  Enable -Wall
1527*f4a2713aSLionel Sambuc    /WX-                   Do not treat warnings as errors
1528*f4a2713aSLionel Sambuc    /WX                    Treat warnings as errors
1529*f4a2713aSLionel Sambuc    /w                     Disable all warnings
1530*f4a2713aSLionel Sambuc    /Zs                    Syntax-check only
1531*f4a2713aSLionel Sambuc
1532*f4a2713aSLionel SambucThe /fallback Option
1533*f4a2713aSLionel Sambuc^^^^^^^^^^^^^^^^^^^^
1534*f4a2713aSLionel Sambuc
1535*f4a2713aSLionel SambucWhen clang-cl is run with the ``/fallback`` option, it will first try to
1536*f4a2713aSLionel Sambuccompile files itself. For any file that it fails to compile, it will fall back
1537*f4a2713aSLionel Sambucand try to compile the file by invoking cl.exe.
1538*f4a2713aSLionel Sambuc
1539*f4a2713aSLionel SambucThis option is intended to be used as a temporary means to build projects where
1540*f4a2713aSLionel Sambucclang-cl cannot successfully compile all the files. clang-cl may fail to compile
1541*f4a2713aSLionel Sambuca file either because it cannot generate code for some C++ feature, or because
1542*f4a2713aSLionel Sambucit cannot parse some Microsoft language extension.
1543