xref: /openbsd-src/gnu/llvm/clang/docs/CommandGuide/clang.rst (revision 7a9b00ce7716f522d49aa36666c74a71cd12203a)
1adae0cfdSpatrickclang, clang++, clang-cpp - the Clang C, C++, and Objective-C compiler
2adae0cfdSpatrick======================================================================
3e5dd7070Spatrick
4e5dd7070SpatrickSYNOPSIS
5e5dd7070Spatrick--------
6e5dd7070Spatrick
7e5dd7070Spatrick:program:`clang` [*options*] *filename ...*
8e5dd7070Spatrick
9e5dd7070SpatrickDESCRIPTION
10e5dd7070Spatrick-----------
11e5dd7070Spatrick
12e5dd7070Spatrick:program:`clang` is a C, C++, and Objective-C compiler which encompasses
13e5dd7070Spatrickpreprocessing, parsing, optimization, code generation, assembly, and linking.
14e5dd7070SpatrickDepending on which high-level mode setting is passed, Clang will stop before
15e5dd7070Spatrickdoing a full link.  While Clang is highly integrated, it is important to
16e5dd7070Spatrickunderstand the stages of compilation, to understand how to invoke it.  These
17e5dd7070Spatrickstages are:
18e5dd7070Spatrick
19e5dd7070SpatrickDriver
20e5dd7070Spatrick    The clang executable is actually a small driver which controls the overall
21e5dd7070Spatrick    execution of other tools such as the compiler, assembler and linker.
22e5dd7070Spatrick    Typically you do not need to interact with the driver, but you
23e5dd7070Spatrick    transparently use it to run the other tools.
24e5dd7070Spatrick
25e5dd7070SpatrickPreprocessing
26e5dd7070Spatrick    This stage handles tokenization of the input source file, macro expansion,
27e5dd7070Spatrick    #include expansion and handling of other preprocessor directives.  The
28e5dd7070Spatrick    output of this stage is typically called a ".i" (for C), ".ii" (for C++),
29e5dd7070Spatrick    ".mi" (for Objective-C), or ".mii" (for Objective-C++) file.
30e5dd7070Spatrick
31e5dd7070SpatrickParsing and Semantic Analysis
32e5dd7070Spatrick    This stage parses the input file, translating preprocessor tokens into a
33e5dd7070Spatrick    parse tree.  Once in the form of a parse tree, it applies semantic
34e5dd7070Spatrick    analysis to compute types for expressions as well and determine whether
35e5dd7070Spatrick    the code is well formed. This stage is responsible for generating most of
36e5dd7070Spatrick    the compiler warnings as well as parse errors. The output of this stage is
37e5dd7070Spatrick    an "Abstract Syntax Tree" (AST).
38e5dd7070Spatrick
39e5dd7070SpatrickCode Generation and Optimization
40e5dd7070Spatrick    This stage translates an AST into low-level intermediate code (known as
41e5dd7070Spatrick    "LLVM IR") and ultimately to machine code.  This phase is responsible for
42e5dd7070Spatrick    optimizing the generated code and handling target-specific code generation.
43e5dd7070Spatrick    The output of this stage is typically called a ".s" file or "assembly" file.
44e5dd7070Spatrick
45e5dd7070Spatrick    Clang also supports the use of an integrated assembler, in which the code
46e5dd7070Spatrick    generator produces object files directly. This avoids the overhead of
47e5dd7070Spatrick    generating the ".s" file and of calling the target assembler.
48e5dd7070Spatrick
49e5dd7070SpatrickAssembler
50e5dd7070Spatrick    This stage runs the target assembler to translate the output of the
51e5dd7070Spatrick    compiler into a target object file. The output of this stage is typically
52e5dd7070Spatrick    called a ".o" file or "object" file.
53e5dd7070Spatrick
54e5dd7070SpatrickLinker
55e5dd7070Spatrick    This stage runs the target linker to merge multiple object files into an
56e5dd7070Spatrick    executable or dynamic library. The output of this stage is typically called
57e5dd7070Spatrick    an "a.out", ".dylib" or ".so" file.
58e5dd7070Spatrick
59e5dd7070Spatrick:program:`Clang Static Analyzer`
60e5dd7070Spatrick
61e5dd7070SpatrickThe Clang Static Analyzer is a tool that scans source code to try to find bugs
62e5dd7070Spatrickthrough code analysis.  This tool uses many parts of Clang and is built into
63e5dd7070Spatrickthe same driver.  Please see <https://clang-analyzer.llvm.org> for more details
64e5dd7070Spatrickon how to use the static analyzer.
65e5dd7070Spatrick
66e5dd7070SpatrickOPTIONS
67e5dd7070Spatrick-------
68e5dd7070Spatrick
69e5dd7070SpatrickStage Selection Options
70e5dd7070Spatrick~~~~~~~~~~~~~~~~~~~~~~~
71e5dd7070Spatrick
72e5dd7070Spatrick.. option:: -E
73e5dd7070Spatrick
74e5dd7070Spatrick Run the preprocessor stage.
75e5dd7070Spatrick
76e5dd7070Spatrick.. option:: -fsyntax-only
77e5dd7070Spatrick
78*7a9b00ceSrobert Run the preprocessor, parser and semantic analysis stages.
79e5dd7070Spatrick
80e5dd7070Spatrick.. option:: -S
81e5dd7070Spatrick
82e5dd7070Spatrick Run the previous stages as well as LLVM generation and optimization stages
83e5dd7070Spatrick and target-specific code generation, producing an assembly file.
84e5dd7070Spatrick
85e5dd7070Spatrick.. option:: -c
86e5dd7070Spatrick
87e5dd7070Spatrick Run all of the above, plus the assembler, generating a target ".o" object file.
88e5dd7070Spatrick
89e5dd7070Spatrick.. option:: no stage selection option
90e5dd7070Spatrick
91e5dd7070Spatrick If no stage selection option is specified, all stages above are run, and the
92e5dd7070Spatrick linker is run to combine the results into an executable or shared library.
93e5dd7070Spatrick
94e5dd7070SpatrickLanguage Selection and Mode Options
95e5dd7070Spatrick~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
96e5dd7070Spatrick
97e5dd7070Spatrick.. option:: -x <language>
98e5dd7070Spatrick
99e5dd7070Spatrick Treat subsequent input files as having type language.
100e5dd7070Spatrick
101e5dd7070Spatrick.. option:: -std=<standard>
102e5dd7070Spatrick
103e5dd7070Spatrick Specify the language standard to compile for.
104e5dd7070Spatrick
105e5dd7070Spatrick Supported values for the C language are:
106e5dd7070Spatrick
107e5dd7070Spatrick  | ``c89``
108e5dd7070Spatrick  | ``c90``
109e5dd7070Spatrick  | ``iso9899:1990``
110e5dd7070Spatrick
111e5dd7070Spatrick   ISO C 1990
112e5dd7070Spatrick
113e5dd7070Spatrick  | ``iso9899:199409``
114e5dd7070Spatrick
115e5dd7070Spatrick   ISO C 1990 with amendment 1
116e5dd7070Spatrick
117e5dd7070Spatrick  | ``gnu89``
118e5dd7070Spatrick  | ``gnu90``
119e5dd7070Spatrick
120e5dd7070Spatrick   ISO C 1990 with GNU extensions
121e5dd7070Spatrick
122e5dd7070Spatrick  | ``c99``
123e5dd7070Spatrick  | ``iso9899:1999``
124e5dd7070Spatrick
125e5dd7070Spatrick   ISO C 1999
126e5dd7070Spatrick
127e5dd7070Spatrick  | ``gnu99``
128e5dd7070Spatrick
129e5dd7070Spatrick   ISO C 1999 with GNU extensions
130e5dd7070Spatrick
131e5dd7070Spatrick  | ``c11``
132e5dd7070Spatrick  | ``iso9899:2011``
133e5dd7070Spatrick
134e5dd7070Spatrick   ISO C 2011
135e5dd7070Spatrick
136e5dd7070Spatrick  | ``gnu11``
137e5dd7070Spatrick
138e5dd7070Spatrick   ISO C 2011 with GNU extensions
139e5dd7070Spatrick
140e5dd7070Spatrick  | ``c17``
141e5dd7070Spatrick  | ``iso9899:2017``
142e5dd7070Spatrick
143e5dd7070Spatrick   ISO C 2017
144e5dd7070Spatrick
145e5dd7070Spatrick  | ``gnu17``
146e5dd7070Spatrick
147e5dd7070Spatrick   ISO C 2017 with GNU extensions
148e5dd7070Spatrick
149ec727ea7Spatrick The default C language standard is ``gnu17``, except on PS4, where it is
150e5dd7070Spatrick ``gnu99``.
151e5dd7070Spatrick
152e5dd7070Spatrick Supported values for the C++ language are:
153e5dd7070Spatrick
154e5dd7070Spatrick  | ``c++98``
155e5dd7070Spatrick  | ``c++03``
156e5dd7070Spatrick
157e5dd7070Spatrick   ISO C++ 1998 with amendments
158e5dd7070Spatrick
159e5dd7070Spatrick  | ``gnu++98``
160e5dd7070Spatrick  | ``gnu++03``
161e5dd7070Spatrick
162e5dd7070Spatrick   ISO C++ 1998 with amendments and GNU extensions
163e5dd7070Spatrick
164e5dd7070Spatrick  | ``c++11``
165e5dd7070Spatrick
166e5dd7070Spatrick   ISO C++ 2011 with amendments
167e5dd7070Spatrick
168e5dd7070Spatrick  | ``gnu++11``
169e5dd7070Spatrick
170e5dd7070Spatrick    ISO C++ 2011 with amendments and GNU extensions
171e5dd7070Spatrick
172e5dd7070Spatrick  | ``c++14``
173e5dd7070Spatrick
174e5dd7070Spatrick   ISO C++ 2014 with amendments
175e5dd7070Spatrick
176e5dd7070Spatrick  | ``gnu++14``
177e5dd7070Spatrick
178e5dd7070Spatrick   ISO C++ 2014 with amendments and GNU extensions
179e5dd7070Spatrick
180e5dd7070Spatrick  | ``c++17``
181e5dd7070Spatrick
182e5dd7070Spatrick   ISO C++ 2017 with amendments
183e5dd7070Spatrick
184e5dd7070Spatrick  | ``gnu++17``
185e5dd7070Spatrick
186e5dd7070Spatrick   ISO C++ 2017 with amendments and GNU extensions
187e5dd7070Spatrick
188*7a9b00ceSrobert  | ``c++20``
189e5dd7070Spatrick
190*7a9b00ceSrobert   ISO C++ 2020 with amendments
191e5dd7070Spatrick
192*7a9b00ceSrobert  | ``gnu++20``
193e5dd7070Spatrick
194*7a9b00ceSrobert   ISO C++ 2020 with amendments and GNU extensions
195e5dd7070Spatrick
196*7a9b00ceSrobert  | ``c++2b``
197*7a9b00ceSrobert
198*7a9b00ceSrobert   Working draft for ISO C++ 2023
199*7a9b00ceSrobert
200*7a9b00ceSrobert  | ``gnu++2b``
201*7a9b00ceSrobert
202*7a9b00ceSrobert   Working draft for ISO C++ 2023 with GNU extensions
203*7a9b00ceSrobert
204*7a9b00ceSrobert The default C++ language standard is ``gnu++17``.
205e5dd7070Spatrick
206e5dd7070Spatrick Supported values for the OpenCL language are:
207e5dd7070Spatrick
208e5dd7070Spatrick  | ``cl1.0``
209e5dd7070Spatrick
210e5dd7070Spatrick   OpenCL 1.0
211e5dd7070Spatrick
212e5dd7070Spatrick  | ``cl1.1``
213e5dd7070Spatrick
214e5dd7070Spatrick   OpenCL 1.1
215e5dd7070Spatrick
216e5dd7070Spatrick  | ``cl1.2``
217e5dd7070Spatrick
218e5dd7070Spatrick   OpenCL 1.2
219e5dd7070Spatrick
220e5dd7070Spatrick  | ``cl2.0``
221e5dd7070Spatrick
222e5dd7070Spatrick   OpenCL 2.0
223e5dd7070Spatrick
224e5dd7070Spatrick The default OpenCL language standard is ``cl1.0``.
225e5dd7070Spatrick
226e5dd7070Spatrick Supported values for the CUDA language are:
227e5dd7070Spatrick
228e5dd7070Spatrick  | ``cuda``
229e5dd7070Spatrick
230e5dd7070Spatrick   NVIDIA CUDA(tm)
231e5dd7070Spatrick
232e5dd7070Spatrick.. option:: -stdlib=<library>
233e5dd7070Spatrick
234e5dd7070Spatrick Specify the C++ standard library to use; supported options are libstdc++ and
235e5dd7070Spatrick libc++. If not specified, platform default will be used.
236e5dd7070Spatrick
237e5dd7070Spatrick.. option:: -rtlib=<library>
238e5dd7070Spatrick
239e5dd7070Spatrick Specify the compiler runtime library to use; supported options are libgcc and
240e5dd7070Spatrick compiler-rt. If not specified, platform default will be used.
241e5dd7070Spatrick
242e5dd7070Spatrick.. option:: -ansi
243e5dd7070Spatrick
244e5dd7070Spatrick Same as -std=c89.
245e5dd7070Spatrick
246e5dd7070Spatrick.. option:: -ObjC, -ObjC++
247e5dd7070Spatrick
248e5dd7070Spatrick Treat source input files as Objective-C and Object-C++ inputs respectively.
249e5dd7070Spatrick
250e5dd7070Spatrick.. option:: -trigraphs
251e5dd7070Spatrick
252e5dd7070Spatrick Enable trigraphs.
253e5dd7070Spatrick
254e5dd7070Spatrick.. option:: -ffreestanding
255e5dd7070Spatrick
256e5dd7070Spatrick Indicate that the file should be compiled for a freestanding, not a hosted,
257ec727ea7Spatrick environment. Note that it is assumed that a freestanding environment will
258ec727ea7Spatrick additionally provide `memcpy`, `memmove`, `memset` and `memcmp`
259ec727ea7Spatrick implementations, as these are needed for efficient codegen for many programs.
260e5dd7070Spatrick
261e5dd7070Spatrick.. option:: -fno-builtin
262e5dd7070Spatrick
263*7a9b00ceSrobert Disable special handling and optimizations of well-known library functions,
264*7a9b00ceSrobert like :c:func:`strlen` and :c:func:`malloc`.
265*7a9b00ceSrobert
266*7a9b00ceSrobert.. option:: -fno-builtin-<function>
267*7a9b00ceSrobert
268*7a9b00ceSrobert Disable special handling and optimizations for the specific library function.
269*7a9b00ceSrobert For example, ``-fno-builtin-strlen`` removes any special handling for the
270*7a9b00ceSrobert :c:func:`strlen` library function.
271*7a9b00ceSrobert
272*7a9b00ceSrobert.. option:: -fno-builtin-std-<function>
273*7a9b00ceSrobert
274*7a9b00ceSrobert Disable special handling and optimizations for the specific C++ standard
275*7a9b00ceSrobert library function in namespace ``std``. For example,
276*7a9b00ceSrobert ``-fno-builtin-std-move_if_noexcept`` removes any special handling for the
277*7a9b00ceSrobert :cpp:func:`std::move_if_noexcept` library function.
278*7a9b00ceSrobert
279*7a9b00ceSrobert For C standard library functions that the C++ standard library also provides
280*7a9b00ceSrobert in namespace ``std``, use :option:`-fno-builtin-\<function\>` instead.
281e5dd7070Spatrick
282e5dd7070Spatrick.. option:: -fmath-errno
283e5dd7070Spatrick
284e5dd7070Spatrick Indicate that math functions should be treated as updating :c:data:`errno`.
285e5dd7070Spatrick
286e5dd7070Spatrick.. option:: -fpascal-strings
287e5dd7070Spatrick
288e5dd7070Spatrick Enable support for Pascal-style strings with "\\pfoo".
289e5dd7070Spatrick
290e5dd7070Spatrick.. option:: -fms-extensions
291e5dd7070Spatrick
292e5dd7070Spatrick Enable support for Microsoft extensions.
293e5dd7070Spatrick
294e5dd7070Spatrick.. option:: -fmsc-version=
295e5dd7070Spatrick
296e5dd7070Spatrick Set _MSC_VER. Defaults to 1300 on Windows. Not set otherwise.
297e5dd7070Spatrick
298e5dd7070Spatrick.. option:: -fborland-extensions
299e5dd7070Spatrick
300e5dd7070Spatrick Enable support for Borland extensions.
301e5dd7070Spatrick
302e5dd7070Spatrick.. option:: -fwritable-strings
303e5dd7070Spatrick
304e5dd7070Spatrick Make all string literals default to writable.  This disables uniquing of
305e5dd7070Spatrick strings and other optimizations.
306e5dd7070Spatrick
307e5dd7070Spatrick.. option:: -flax-vector-conversions, -flax-vector-conversions=<kind>, -fno-lax-vector-conversions
308e5dd7070Spatrick
309e5dd7070Spatrick Allow loose type checking rules for implicit vector conversions.
310e5dd7070Spatrick Possible values of <kind>:
311e5dd7070Spatrick
312e5dd7070Spatrick - ``none``: allow no implicit conversions between vectors
313e5dd7070Spatrick - ``integer``: allow implicit bitcasts between integer vectors of the same
314e5dd7070Spatrick   overall bit-width
315e5dd7070Spatrick - ``all``: allow implicit bitcasts between any vectors of the same
316e5dd7070Spatrick   overall bit-width
317e5dd7070Spatrick
318e5dd7070Spatrick <kind> defaults to ``integer`` if unspecified.
319e5dd7070Spatrick
320e5dd7070Spatrick.. option:: -fblocks
321e5dd7070Spatrick
322e5dd7070Spatrick Enable the "Blocks" language feature.
323e5dd7070Spatrick
324e5dd7070Spatrick.. option:: -fobjc-abi-version=version
325e5dd7070Spatrick
326e5dd7070Spatrick Select the Objective-C ABI version to use. Available versions are 1 (legacy
327e5dd7070Spatrick "fragile" ABI), 2 (non-fragile ABI 1), and 3 (non-fragile ABI 2).
328e5dd7070Spatrick
329e5dd7070Spatrick.. option:: -fobjc-nonfragile-abi-version=<version>
330e5dd7070Spatrick
331e5dd7070Spatrick Select the Objective-C non-fragile ABI version to use by default. This will
332e5dd7070Spatrick only be used as the Objective-C ABI when the non-fragile ABI is enabled
333e5dd7070Spatrick (either via :option:`-fobjc-nonfragile-abi`, or because it is the platform
334e5dd7070Spatrick default).
335e5dd7070Spatrick
336e5dd7070Spatrick.. option:: -fobjc-nonfragile-abi, -fno-objc-nonfragile-abi
337e5dd7070Spatrick
338e5dd7070Spatrick Enable use of the Objective-C non-fragile ABI. On platforms for which this is
339e5dd7070Spatrick the default ABI, it can be disabled with :option:`-fno-objc-nonfragile-abi`.
340e5dd7070Spatrick
341e5dd7070SpatrickTarget Selection Options
342e5dd7070Spatrick~~~~~~~~~~~~~~~~~~~~~~~~
343e5dd7070Spatrick
344e5dd7070SpatrickClang fully supports cross compilation as an inherent part of its design.
345e5dd7070SpatrickDepending on how your version of Clang is configured, it may have support for a
346e5dd7070Spatricknumber of cross compilers, or may only support a native target.
347e5dd7070Spatrick
348e5dd7070Spatrick.. option:: -arch <architecture>
349e5dd7070Spatrick
350*7a9b00ceSrobert  Specify the architecture to build for (Mac OS X specific).
351*7a9b00ceSrobert
352*7a9b00ceSrobert.. option:: -target <architecture>
353*7a9b00ceSrobert
354*7a9b00ceSrobert  Specify the architecture to build for (all platforms).
355e5dd7070Spatrick
356e5dd7070Spatrick.. option:: -mmacosx-version-min=<version>
357e5dd7070Spatrick
358e5dd7070Spatrick  When building for macOS, specify the minimum version supported by your
359e5dd7070Spatrick  application.
360e5dd7070Spatrick
361e5dd7070Spatrick.. option:: -miphoneos-version-min
362e5dd7070Spatrick
363e5dd7070Spatrick  When building for iPhone OS, specify the minimum version supported by your
364e5dd7070Spatrick  application.
365e5dd7070Spatrick
366e5dd7070Spatrick.. option:: --print-supported-cpus
367e5dd7070Spatrick
368e5dd7070Spatrick  Print out a list of supported processors for the given target (specified
369a0747c9fSpatrick  through ``--target=<architecture>`` or :option:`-arch` ``<architecture>``). If no
370a0747c9fSpatrick  target is specified, the system default target will be used.
371e5dd7070Spatrick
372e5dd7070Spatrick.. option:: -mcpu=?, -mtune=?
373e5dd7070Spatrick
374a0747c9fSpatrick  Acts as an alias for :option:`--print-supported-cpus`.
375e5dd7070Spatrick
376e5dd7070Spatrick.. option:: -march=<cpu>
377e5dd7070Spatrick
378e5dd7070Spatrick  Specify that Clang should generate code for a specific processor family
379e5dd7070Spatrick  member and later.  For example, if you specify -march=i486, the compiler is
380e5dd7070Spatrick  allowed to generate instructions that are valid on i486 and later processors,
381e5dd7070Spatrick  but which may not exist on earlier ones.
382e5dd7070Spatrick
383e5dd7070Spatrick
384e5dd7070SpatrickCode Generation Options
385e5dd7070Spatrick~~~~~~~~~~~~~~~~~~~~~~~
386e5dd7070Spatrick
387e5dd7070Spatrick.. option:: -O0, -O1, -O2, -O3, -Ofast, -Os, -Oz, -Og, -O, -O4
388e5dd7070Spatrick
389e5dd7070Spatrick  Specify which optimization level to use:
390e5dd7070Spatrick
391e5dd7070Spatrick    :option:`-O0` Means "no optimization": this level compiles the fastest and
392e5dd7070Spatrick    generates the most debuggable code.
393e5dd7070Spatrick
394e5dd7070Spatrick    :option:`-O1` Somewhere between :option:`-O0` and :option:`-O2`.
395e5dd7070Spatrick
396e5dd7070Spatrick    :option:`-O2` Moderate level of optimization which enables most
397e5dd7070Spatrick    optimizations.
398e5dd7070Spatrick
399e5dd7070Spatrick    :option:`-O3` Like :option:`-O2`, except that it enables optimizations that
400e5dd7070Spatrick    take longer to perform or that may generate larger code (in an attempt to
401e5dd7070Spatrick    make the program run faster).
402e5dd7070Spatrick
403e5dd7070Spatrick    :option:`-Ofast` Enables all the optimizations from :option:`-O3` along
404e5dd7070Spatrick    with other aggressive optimizations that may violate strict compliance with
405e5dd7070Spatrick    language standards.
406e5dd7070Spatrick
407e5dd7070Spatrick    :option:`-Os` Like :option:`-O2` with extra optimizations to reduce code
408e5dd7070Spatrick    size.
409e5dd7070Spatrick
410e5dd7070Spatrick    :option:`-Oz` Like :option:`-Os` (and thus :option:`-O2`), but reduces code
411e5dd7070Spatrick    size further.
412e5dd7070Spatrick
413e5dd7070Spatrick    :option:`-Og` Like :option:`-O1`. In future versions, this option might
414e5dd7070Spatrick    disable different optimizations in order to improve debuggability.
415e5dd7070Spatrick
416ec727ea7Spatrick    :option:`-O` Equivalent to :option:`-O1`.
417e5dd7070Spatrick
418e5dd7070Spatrick    :option:`-O4` and higher
419e5dd7070Spatrick
420e5dd7070Spatrick      Currently equivalent to :option:`-O3`
421e5dd7070Spatrick
422e5dd7070Spatrick.. option:: -g, -gline-tables-only, -gmodules
423e5dd7070Spatrick
424e5dd7070Spatrick  Control debug information output.  Note that Clang debug information works
425e5dd7070Spatrick  best at :option:`-O0`.  When more than one option starting with `-g` is
426e5dd7070Spatrick  specified, the last one wins:
427e5dd7070Spatrick
428e5dd7070Spatrick    :option:`-g` Generate debug information.
429e5dd7070Spatrick
430e5dd7070Spatrick    :option:`-gline-tables-only` Generate only line table debug information. This
431e5dd7070Spatrick    allows for symbolicated backtraces with inlining information, but does not
432e5dd7070Spatrick    include any information about variables, their locations or types.
433e5dd7070Spatrick
434e5dd7070Spatrick    :option:`-gmodules` Generate debug information that contains external
435e5dd7070Spatrick    references to types defined in Clang modules or precompiled headers instead
436e5dd7070Spatrick    of emitting redundant debug type information into every object file.  This
437e5dd7070Spatrick    option transparently switches the Clang module format to object file
438e5dd7070Spatrick    containers that hold the Clang module together with the debug information.
439e5dd7070Spatrick    When compiling a program that uses Clang modules or precompiled headers,
440e5dd7070Spatrick    this option produces complete debug information with faster compile
441e5dd7070Spatrick    times and much smaller object files.
442e5dd7070Spatrick
443e5dd7070Spatrick    This option should not be used when building static libraries for
444e5dd7070Spatrick    distribution to other machines because the debug info will contain
445e5dd7070Spatrick    references to the module cache on the machine the object files in the
446e5dd7070Spatrick    library were built on.
447e5dd7070Spatrick
448e5dd7070Spatrick.. option:: -fstandalone-debug -fno-standalone-debug
449e5dd7070Spatrick
450e5dd7070Spatrick  Clang supports a number of optimizations to reduce the size of debug
451e5dd7070Spatrick  information in the binary. They work based on the assumption that the
452e5dd7070Spatrick  debug type information can be spread out over multiple compilation units.
453e5dd7070Spatrick  For instance, Clang will not emit type definitions for types that are not
454e5dd7070Spatrick  needed by a module and could be replaced with a forward declaration.
455e5dd7070Spatrick  Further, Clang will only emit type info for a dynamic C++ class in the
456e5dd7070Spatrick  module that contains the vtable for the class.
457e5dd7070Spatrick
458e5dd7070Spatrick  The :option:`-fstandalone-debug` option turns off these optimizations.
459e5dd7070Spatrick  This is useful when working with 3rd-party libraries that don't come with
460e5dd7070Spatrick  debug information.  This is the default on Darwin.  Note that Clang will
461e5dd7070Spatrick  never emit type information for types that are not referenced at all by the
462e5dd7070Spatrick  program.
463e5dd7070Spatrick
464a0747c9fSpatrick.. option:: -feliminate-unused-debug-types
465a0747c9fSpatrick
466a0747c9fSpatrick  By default, Clang does not emit type information for types that are defined
467a0747c9fSpatrick  but not used in a program. To retain the debug info for these unused types,
468a0747c9fSpatrick  the negation **-fno-eliminate-unused-debug-types** can be used.
469a0747c9fSpatrick
470e5dd7070Spatrick.. option:: -fexceptions
471e5dd7070Spatrick
472e5dd7070Spatrick  Enable generation of unwind information. This allows exceptions to be thrown
473e5dd7070Spatrick  through Clang compiled stack frames.  This is on by default in x86-64.
474e5dd7070Spatrick
475e5dd7070Spatrick.. option:: -ftrapv
476e5dd7070Spatrick
477e5dd7070Spatrick  Generate code to catch integer overflow errors.  Signed integer overflow is
478e5dd7070Spatrick  undefined in C. With this flag, extra code is generated to detect this and
479e5dd7070Spatrick  abort when it happens.
480e5dd7070Spatrick
481e5dd7070Spatrick.. option:: -fvisibility
482e5dd7070Spatrick
483e5dd7070Spatrick  This flag sets the default visibility level.
484e5dd7070Spatrick
485e5dd7070Spatrick.. option:: -fcommon, -fno-common
486e5dd7070Spatrick
487e5dd7070Spatrick  This flag specifies that variables without initializers get common linkage.
488e5dd7070Spatrick  It can be disabled with :option:`-fno-common`.
489e5dd7070Spatrick
490e5dd7070Spatrick.. option:: -ftls-model=<model>
491e5dd7070Spatrick
492e5dd7070Spatrick  Set the default thread-local storage (TLS) model to use for thread-local
493e5dd7070Spatrick  variables. Valid values are: "global-dynamic", "local-dynamic",
494e5dd7070Spatrick  "initial-exec" and "local-exec". The default is "global-dynamic". The default
495e5dd7070Spatrick  model can be overridden with the tls_model attribute. The compiler will try
496e5dd7070Spatrick  to choose a more efficient model if possible.
497e5dd7070Spatrick
498e5dd7070Spatrick.. option:: -flto, -flto=full, -flto=thin, -emit-llvm
499e5dd7070Spatrick
500e5dd7070Spatrick  Generate output files in LLVM formats, suitable for link time optimization.
501e5dd7070Spatrick  When used with :option:`-S` this generates LLVM intermediate language
502e5dd7070Spatrick  assembly files, otherwise this generates LLVM bitcode format object files
503e5dd7070Spatrick  (which may be passed to the linker depending on the stage selection options).
504e5dd7070Spatrick
505e5dd7070Spatrick  The default for :option:`-flto` is "full", in which the
506e5dd7070Spatrick  LLVM bitcode is suitable for monolithic Link Time Optimization (LTO), where
507e5dd7070Spatrick  the linker merges all such modules into a single combined module for
508e5dd7070Spatrick  optimization. With "thin", :doc:`ThinLTO <../ThinLTO>`
509e5dd7070Spatrick  compilation is invoked instead.
510e5dd7070Spatrick
511ec727ea7Spatrick  .. note::
512ec727ea7Spatrick
513ec727ea7Spatrick     On Darwin, when using :option:`-flto` along with :option:`-g` and
514ec727ea7Spatrick     compiling and linking in separate steps, you also need to pass
515ec727ea7Spatrick     ``-Wl,-object_path_lto,<lto-filename>.o`` at the linking step to instruct the
516ec727ea7Spatrick     ld64 linker not to delete the temporary object file generated during Link
517ec727ea7Spatrick     Time Optimization (this flag is automatically passed to the linker by Clang
518ec727ea7Spatrick     if compilation and linking are done in a single step). This allows debugging
519ec727ea7Spatrick     the executable as well as generating the ``.dSYM`` bundle using :manpage:`dsymutil(1)`.
520ec727ea7Spatrick
521e5dd7070SpatrickDriver Options
522e5dd7070Spatrick~~~~~~~~~~~~~~
523e5dd7070Spatrick
524e5dd7070Spatrick.. option:: -###
525e5dd7070Spatrick
526e5dd7070Spatrick  Print (but do not run) the commands to run for this compilation.
527e5dd7070Spatrick
528e5dd7070Spatrick.. option:: --help
529e5dd7070Spatrick
530e5dd7070Spatrick  Display available options.
531e5dd7070Spatrick
532e5dd7070Spatrick.. option:: -Qunused-arguments
533e5dd7070Spatrick
534e5dd7070Spatrick  Do not emit any warnings for unused driver arguments.
535e5dd7070Spatrick
536e5dd7070Spatrick.. option:: -Wa,<args>
537e5dd7070Spatrick
538e5dd7070Spatrick  Pass the comma separated arguments in args to the assembler.
539e5dd7070Spatrick
540e5dd7070Spatrick.. option:: -Wl,<args>
541e5dd7070Spatrick
542e5dd7070Spatrick  Pass the comma separated arguments in args to the linker.
543e5dd7070Spatrick
544e5dd7070Spatrick.. option:: -Wp,<args>
545e5dd7070Spatrick
546e5dd7070Spatrick  Pass the comma separated arguments in args to the preprocessor.
547e5dd7070Spatrick
548e5dd7070Spatrick.. option:: -Xanalyzer <arg>
549e5dd7070Spatrick
550e5dd7070Spatrick  Pass arg to the static analyzer.
551e5dd7070Spatrick
552e5dd7070Spatrick.. option:: -Xassembler <arg>
553e5dd7070Spatrick
554e5dd7070Spatrick  Pass arg to the assembler.
555e5dd7070Spatrick
556e5dd7070Spatrick.. option:: -Xlinker <arg>
557e5dd7070Spatrick
558e5dd7070Spatrick  Pass arg to the linker.
559e5dd7070Spatrick
560e5dd7070Spatrick.. option:: -Xpreprocessor <arg>
561e5dd7070Spatrick
562e5dd7070Spatrick  Pass arg to the preprocessor.
563e5dd7070Spatrick
564e5dd7070Spatrick.. option:: -o <file>
565e5dd7070Spatrick
566e5dd7070Spatrick  Write output to file.
567e5dd7070Spatrick
568e5dd7070Spatrick.. option:: -print-file-name=<file>
569e5dd7070Spatrick
570e5dd7070Spatrick  Print the full library path of file.
571e5dd7070Spatrick
572e5dd7070Spatrick.. option:: -print-libgcc-file-name
573e5dd7070Spatrick
574e5dd7070Spatrick  Print the library path for the currently used compiler runtime library
575e5dd7070Spatrick  ("libgcc.a" or "libclang_rt.builtins.*.a").
576e5dd7070Spatrick
577e5dd7070Spatrick.. option:: -print-prog-name=<name>
578e5dd7070Spatrick
579e5dd7070Spatrick  Print the full program path of name.
580e5dd7070Spatrick
581e5dd7070Spatrick.. option:: -print-search-dirs
582e5dd7070Spatrick
583e5dd7070Spatrick  Print the paths used for finding libraries and programs.
584e5dd7070Spatrick
585e5dd7070Spatrick.. option:: -save-temps
586e5dd7070Spatrick
587e5dd7070Spatrick  Save intermediate compilation results.
588e5dd7070Spatrick
589e5dd7070Spatrick.. option:: -save-stats, -save-stats=cwd, -save-stats=obj
590e5dd7070Spatrick
591e5dd7070Spatrick  Save internal code generation (LLVM) statistics to a file in the current
592e5dd7070Spatrick  directory (:option:`-save-stats`/"-save-stats=cwd") or the directory
593e5dd7070Spatrick  of the output file ("-save-state=obj").
594e5dd7070Spatrick
595e5dd7070Spatrick.. option:: -integrated-as, -no-integrated-as
596e5dd7070Spatrick
597e5dd7070Spatrick  Used to enable and disable, respectively, the use of the integrated
598e5dd7070Spatrick  assembler. Whether the integrated assembler is on by default is target
599e5dd7070Spatrick  dependent.
600e5dd7070Spatrick
601e5dd7070Spatrick.. option:: -time
602e5dd7070Spatrick
603e5dd7070Spatrick  Time individual commands.
604e5dd7070Spatrick
605e5dd7070Spatrick.. option:: -ftime-report
606e5dd7070Spatrick
607e5dd7070Spatrick  Print timing summary of each stage of compilation.
608e5dd7070Spatrick
609e5dd7070Spatrick.. option:: -v
610e5dd7070Spatrick
611e5dd7070Spatrick  Show commands to run and use verbose output.
612e5dd7070Spatrick
613e5dd7070Spatrick
614e5dd7070SpatrickDiagnostics Options
615e5dd7070Spatrick~~~~~~~~~~~~~~~~~~~
616e5dd7070Spatrick
617e5dd7070Spatrick.. option:: -fshow-column, -fshow-source-location, -fcaret-diagnostics, -fdiagnostics-fixit-info, -fdiagnostics-parseable-fixits, -fdiagnostics-print-source-range-info, -fprint-source-range-info, -fdiagnostics-show-option, -fmessage-length
618e5dd7070Spatrick
619e5dd7070Spatrick  These options control how Clang prints out information about diagnostics
620e5dd7070Spatrick  (errors and warnings). Please see the Clang User's Manual for more information.
621e5dd7070Spatrick
622e5dd7070SpatrickPreprocessor Options
623e5dd7070Spatrick~~~~~~~~~~~~~~~~~~~~
624e5dd7070Spatrick
625e5dd7070Spatrick.. option:: -D<macroname>=<value>
626e5dd7070Spatrick
627e5dd7070Spatrick  Adds an implicit #define into the predefines buffer which is read before the
628e5dd7070Spatrick  source file is preprocessed.
629e5dd7070Spatrick
630e5dd7070Spatrick.. option:: -U<macroname>
631e5dd7070Spatrick
632e5dd7070Spatrick  Adds an implicit #undef into the predefines buffer which is read before the
633e5dd7070Spatrick  source file is preprocessed.
634e5dd7070Spatrick
635e5dd7070Spatrick.. option:: -include <filename>
636e5dd7070Spatrick
637e5dd7070Spatrick  Adds an implicit #include into the predefines buffer which is read before the
638e5dd7070Spatrick  source file is preprocessed.
639e5dd7070Spatrick
640e5dd7070Spatrick.. option:: -I<directory>
641e5dd7070Spatrick
642e5dd7070Spatrick  Add the specified directory to the search path for include files.
643e5dd7070Spatrick
644e5dd7070Spatrick.. option:: -F<directory>
645e5dd7070Spatrick
646e5dd7070Spatrick  Add the specified directory to the search path for framework include files.
647e5dd7070Spatrick
648e5dd7070Spatrick.. option:: -nostdinc
649e5dd7070Spatrick
650e5dd7070Spatrick  Do not search the standard system directories or compiler builtin directories
651e5dd7070Spatrick  for include files.
652e5dd7070Spatrick
653e5dd7070Spatrick.. option:: -nostdlibinc
654e5dd7070Spatrick
655e5dd7070Spatrick  Do not search the standard system directories for include files, but do
656e5dd7070Spatrick  search compiler builtin include directories.
657e5dd7070Spatrick
658e5dd7070Spatrick.. option:: -nobuiltininc
659e5dd7070Spatrick
660e5dd7070Spatrick  Do not search clang's builtin directory for include files.
661e5dd7070Spatrick
662e5dd7070Spatrick
663e5dd7070SpatrickENVIRONMENT
664e5dd7070Spatrick-----------
665e5dd7070Spatrick
666e5dd7070Spatrick.. envvar:: TMPDIR, TEMP, TMP
667e5dd7070Spatrick
668e5dd7070Spatrick  These environment variables are checked, in order, for the location to write
669e5dd7070Spatrick  temporary files used during the compilation process.
670e5dd7070Spatrick
671e5dd7070Spatrick.. envvar:: CPATH
672e5dd7070Spatrick
673e5dd7070Spatrick  If this environment variable is present, it is treated as a delimited list of
674e5dd7070Spatrick  paths to be added to the default system include path list. The delimiter is
675e5dd7070Spatrick  the platform dependent delimiter, as used in the PATH environment variable.
676e5dd7070Spatrick
677e5dd7070Spatrick  Empty components in the environment variable are ignored.
678e5dd7070Spatrick
679e5dd7070Spatrick.. envvar:: C_INCLUDE_PATH, OBJC_INCLUDE_PATH, CPLUS_INCLUDE_PATH, OBJCPLUS_INCLUDE_PATH
680e5dd7070Spatrick
681e5dd7070Spatrick  These environment variables specify additional paths, as for :envvar:`CPATH`, which are
682e5dd7070Spatrick  only used when processing the appropriate language.
683e5dd7070Spatrick
684e5dd7070Spatrick.. envvar:: MACOSX_DEPLOYMENT_TARGET
685e5dd7070Spatrick
686e5dd7070Spatrick  If :option:`-mmacosx-version-min` is unspecified, the default deployment
687e5dd7070Spatrick  target is read from this environment variable. This option only affects
688e5dd7070Spatrick  Darwin targets.
689e5dd7070Spatrick
690e5dd7070SpatrickBUGS
691e5dd7070Spatrick----
692e5dd7070Spatrick
693*7a9b00ceSrobertTo report bugs, please visit <https://github.com/llvm/llvm-project/issues/>.  Most bug reports should
694e5dd7070Spatrickinclude preprocessed source files (use the :option:`-E` option) and the full
695e5dd7070Spatrickoutput of the compiler, along with information to reproduce.
696e5dd7070Spatrick
697e5dd7070SpatrickSEE ALSO
698e5dd7070Spatrick--------
699e5dd7070Spatrick
700adae0cfdSpatrick:manpage:`as(1)`, :manpage:`clang-local(1)`, :manpage:`ld(1)`
701