• Home
  • Raw
  • Download

Lines Matching +full:clang +full:- +full:format +full:- +full:3

2 Clang Compiler User's Manual
11 The Clang Compiler is an open-source compiler for the C family of
13 these languages. Clang builds on the LLVM optimizer and code generator,
14 allowing it to provide high-quality optimization and code generation
16 `Clang Web Site <http://clang.llvm.org>`_ or the `LLVM Web
19 This document describes important notes about using Clang as a compiler
20 for an end-user, documenting the supported features, command line
21 options, etc. If you are interested in using Clang to build a tool that
23 `Clang Static Analyzer <http://clang-analyzer.llvm.org>`_, please see its web
26 Clang is designed to support the C family of programming languages,
27 which includes :ref:`C <c>`, :ref:`Objective-C <objc>`, :ref:`C++ <cxx>`, and
28 :ref:`Objective-C++ <objcxx>` as well as many dialects of those. For
29 language-specific information, please see the corresponding language
32 - :ref:`C Language <c>`: K&R C, ANSI C89, ISO C90, ISO C94 (C89+AMD1), ISO
34 - :ref:`Objective-C Language <objc>`: ObjC 1, ObjC 2, ObjC 2.1, plus
36 - :ref:`C++ Language <cxx>`
37 - :ref:`Objective C++ Language <objcxx>`
39 In addition to these base languages and their dialects, Clang supports a
43 as to improve functionality through Clang-specific features. The Clang
46 migration from GCC to Clang. In most cases, code "just works".
47 Clang also provides an alternative driver, :ref:`clang-cl`, that is designed
50 In addition to language specific features, Clang has a variety of
52 being compiled for. Please see the :ref:`Target-Specific Features and
57 contains a basic :ref:`introduction to using Clang <basicusage>` as a
63 -----------
71 -----------
85 options like :option:`-c`, :option:`-g`, etc.
88 ---------------------------------------------
90 .. option:: -Werror
95 .. -Werror, and Sphinx complains.
97 ``-Werror=foo``
101 .. option:: -Wno-error=foo
103 Turn warning "foo" into an warning even if :option:`-Werror` is specified.
105 .. option:: -Wfoo
109 .. option:: -Wno-foo
113 .. option:: -w
117 .. option:: -Weverything
121 .. option:: -pedantic
125 .. option:: -pedantic-errors
129 .. option:: -Wsystem-headers
133 .. option:: -ferror-limit=123
136 20, and the error limit can be disabled with `-ferror-limit=0`.
138 .. option:: -ftemplate-backtrace-limit=123
142 the limit can be disabled with `-ftemplate-backtrace-limit=0`.
149 Clang aims to produce beautiful diagnostics by default, particularly for
150 new users that first come to Clang. However, different people have
151 different preferences, and sometimes Clang is driven not by a human,
153 these cases, Clang provides a wide range of options to control the exact
154 output format of the diagnostics that it generates.
156 .. _opt_fshow-column:
158 **-f[no-]show-column**
161 This option, which defaults to on, controls whether or not Clang
163 enabled, Clang will print something like:
167 test.c:28:8: warning: extra tokens at end of #endif directive [-Wextra-tokens]
172 When this is disabled, Clang will print "test.c:28: warning..." with
178 .. _opt_fshow-source-location:
180 **-f[no-]show-source-location**
183 This option, which defaults to on, controls whether or not Clang
185 For example, when this is enabled, Clang will print something like:
189 test.c:28:8: warning: extra tokens at end of #endif directive [-Wextra-tokens]
194 When this is disabled, Clang will not print the "test.c:28:8: "
197 .. _opt_fcaret-diagnostics:
199 **-f[no-]caret-diagnostics**
201 This option, which defaults to on, controls whether or not Clang
203 diagnostic. For example, when this is enabled, Clang will print
208 test.c:28:8: warning: extra tokens at end of #endif directive [-Wextra-tokens]
213 **-f[no-]color-diagnostics**
214 This option, which defaults to on when a color-capable terminal is
215 detected, controls whether or not Clang prints diagnostics in color.
217 When this option is enabled, Clang will use colors to highlight
225 …"color:magenta">warning</span>: extra tokens at end of #endif directive [-Wextra-tokens]</span></b>
231 When this is disabled, Clang will just print:
235 test.c:2:8: warning: extra tokens at end of #endif directive [-Wextra-tokens]
240 **-fansi-escape-codes**
245 .. option:: -fdiagnostics-format=clang/msvc/vi
247 Changes diagnostic output format to better match IDEs and command line tools.
249 This option controls the output format of the filename, line number,
253 **clang** (default)
256 t.c:3:11: warning: conversion specifies type 'char *' but the argument has type 'int'
261 t.c(3,11) : warning: conversion specifies type 'char *' but the argument has type 'int'
266 t.c +3:11: warning: conversion specifies type 'char *' but the argument has type 'int'
268 .. _opt_fdiagnostics-show-option:
270 **-f[no-]diagnostics-show-option**
271 Enable ``[-Woption]`` information in diagnostic line.
273 This option, which defaults to on, controls whether or not Clang
280 test.c:28:8: warning: extra tokens at end of #endif directive [-Wextra-tokens]
285 Passing **-fno-diagnostics-show-option** will prevent Clang from
286 printing the [:ref:`-Wextra-tokens <opt_Wextra-tokens>`] information in
291 .. _opt_fdiagnostics-show-category:
293 .. option:: -fdiagnostics-show-category=none/id/name
297 This option, which defaults to "none", controls whether or not Clang
303 For example, a format string warning will produce these three
308 … t.c:3:11: warning: conversion specifies type 'char *' but the argument has type 'int' [-Wformat]
309 … t.c:3:11: warning: conversion specifies type 'char *' but the argument has type 'int' [-Wformat,1]
310 …t.c:3:11: warning: conversion specifies type 'char *' but the argument has type 'int' [-Wformat,Fo…
316 .. _opt_fdiagnostics-fixit-info:
318 **-f[no-]diagnostics-fixit-info**
321 This option, which defaults to on, controls whether or not Clang
327 test.c:28:8: warning: extra tokens at end of #endif directive [-Wextra-tokens]
332 Passing **-fno-diagnostics-fixit-info** will prevent Clang from
337 .. _opt_fdiagnostics-print-source-range-info:
339 **-fdiagnostics-print-source-range-info**
341 This option makes Clang print information about source ranges in a machine
342 parsable format after the file/line/column number information. The
348 …exprs.c:47:15:{47:8-47:14}{47:17-47:24}: error: invalid operands to binary expression ('int *' and…
349 P = (P-42) + Gamma*4;
352 The {}'s are generated by -fdiagnostics-print-source-range-info.
357 .. option:: -fdiagnostics-parseable-fixits
359 Print Fix-Its in a machine parseable form.
361 This option makes Clang print available Fix-Its in a machine
362 parseable format at the end of diagnostics. The following example
363 illustrates the format:
367 fix-it:"t.cpp":{7:25-7:29}:"Gamma"
369 The range printed is a half-open range, so in this example the
376 non-printable characters (as octal "\\xxx").
381 .. option:: -fno-elide-type
397 -fno-elide-type:
403 .. option:: -fdiagnostics-show-template-tree
407 For diffing large templated types, this option will cause Clang to
410 -fno-elide-type.
418 With :option:`-fdiagnostics-show-template-tree`:
437 .. _opt_wextra-tokens:
439 .. option:: -Wextra-tokens
448 test.c:28:8: warning: extra tokens at end of #endif directive [-Wextra-tokens]
455 .. option:: -Wambiguous-member-template
476 because it's hard to work around, Clang downgrades it to a warning
479 .. option:: -Wbind-to-temporary-copy
515 Options to Control Clang Crash Diagnostics
516 ------------------------------------------
518 As unbelievable as it may sound, Clang does crash from time to time.
520 edge <http://llvm.org/releases/download.html#svn>`_. Clang goes to great
521 lengths to assist you in filing a bug report. Specifically, Clang
527 .. option:: -fno-crash-diagnostics
529 Disable auto-generation of preprocessed source files during a clang crash.
531 The -fno-crash-diagnostics flag can be helpful for speeding the process
535 ------------------------------------
537 Optimization reports trace, at a high-level, all the major decisions
543 Clang offers a family of flags which the optimizers can use to emit
546 1. When the pass makes a transformation (:option:`-Rpass`).
548 2. When the pass fails to make a transformation (:option:`-Rpass-missed`).
550 3. When the pass determines whether or not to make a transformation
551 (:option:`-Rpass-analysis`).
553 NOTE: Although the discussion below focuses on :option:`-Rpass`, the exact
554 same options apply to :option:`-Rpass-missed` and :option:`-Rpass-analysis`.
561 .. code-block:: console
563 $ clang -O2 -Rpass=inline code.cc -o code
564 code.cc:4:25: remark: foo inlined into bar [-Rpass=inline]
565 int bar(int j) { return foo(j, j - 2); }
568 Note that remarks from the inliner are identified with `[-Rpass=inline]`.
570 :option:`-Rpass=.*` (in fact, you can use any valid POSIX regular
588 expansions). However, the locations used by :option:`-Rpass` are
593 -------------
594 Clang options that that don't fit neatly into other categories.
596 .. option:: -MV
599 for NMake or Jom. Ignored unless another option causes Clang to emit a
602 When Clang emits a dependency file (e.g., you supplied the -M option)
606 is actually part of the filename. Normally Clang uses backslash to "escape"
607 a special character, which is the convention used by GNU Make. The -MV
608 option tells Clang to put double-quotes around the entire filename, which
612 Language and Target-Independent Features
616 -------------------------------
618 Clang provides a number of ways to control which code constructs cause
622 Controlling How Clang Displays Diagnostics
625 When Clang emits a diagnostic, it includes rich information in the
626 output, and gives you fine-grain control over which information is
627 printed. Clang has the ability to print this information, and these are
631 occurs in your code [:ref:`-fshow-column <opt_fshow-column>`,
632 :ref:`-fshow-source-location <opt_fshow-source-location>`].
638 [:ref:`-fdiagnostics-show-option <opt_fdiagnostics-show-option>`].
639 #. A :ref:`high-level category <diagnostics_categories>` for the diagnostic
642 [:ref:`-fdiagnostics-show-category <opt_fdiagnostics-show-category>`].
645 [:ref:`-fcaret-diagnostics <opt_fcaret-diagnostics>`].
647 problem (when Clang is certain it knows)
648 [:ref:`-fdiagnostics-fixit-info <opt_fdiagnostics-fixit-info>`].
649 #. A machine-parsable representation of the ranges involved (off by
651 [:ref:`-fdiagnostics-print-source-range-info <opt_fdiagnostics-print-source-range-info>`].
661 - Ignored
662 - Note
663 - Remark
664 - Warning
665 - Error
666 - Fatal
674 high-level category. This category is intended to make it possible to
679 :ref:`-fdiagnostics-show-category <opt_fdiagnostics-show-category>` option.
683 by running '``clang --print-diagnostic-categories``'.
688 TODO: -W flags, -pedantic, etc
695 Clang can also control what diagnostics are enabled through the use of
697 warnings in a section of source code. Clang supports GCC's pragma for
702 following example code will tell Clang or GCC to ignore the -Wall
705 .. code-block:: c
707 #pragma GCC diagnostic ignored "-Wall"
709 In addition to all of the functionality provided by GCC's pragma, Clang
714 In the below example :option:`-Wextra-tokens` is ignored for only a single line
718 .. code-block:: c
723 #pragma clang diagnostic ignored "-Wextra-tokens"
728 #pragma clang diagnostic pop
732 possible to use push and pop around GCC compatible diagnostics and Clang
734 and pops as unknown pragmas. It should be noted that while Clang
735 supports the GCC pragma, Clang and GCC do not support the exact same set
743 .. code-block:: c
756 .. code-block:: c
769 include path specified by ``-isystem``, but this can be overridden in
776 .. code-block:: c
781 #pragma clang system_header
786 The :option:`--system-header-prefix=` and :option:`--no-system-header-prefix=`
787 command-line arguments can be used to override whether subsets of an include
791 command-line which matches the specified header name takes precedence.
794 .. code-block:: console
796 $ clang -Ifoo -isystem bar --system-header-prefix=x/ \
797 --no-system-header-prefix=x/y/
813 In addition to the traditional ``-W`` flags, one can enable **all**
814 diagnostics by passing :option:`-Weverything`. This works as expected
816 :option:`-Werror`, and also includes the warnings from :option:`-pedantic`.
818 Note that when combined with :option:`-w` (which disables all warnings), that
824 While not strictly part of the compiler, the diagnostics from Clang's
825 `static analyzer <http://clang-analyzer.llvm.org>`_ can also be
827 `annotations <http://clang-analyzer.llvm.org/annotations.html>`_ and the
829 page <http://clang-analyzer.llvm.org/faq.html#exclude_code>`_ for more
832 .. _usersmanual-precompiled-headers:
835 -------------------
845 on-disk cache that contains the vital information necessary to reduce
854 To generate a PCH file using Clang, one invokes Clang with the
855 :option:`-x <language>-header` option. This mirrors the interface in GCC
858 .. code-block:: console
860 $ gcc -x c-header test.h -o test.h.gch
861 $ clang -x c-header test.h -o test.h.pch
866 A PCH file can then be used as a prefix header when a :option:`-include`
867 option is passed to ``clang``:
869 .. code-block:: console
871 $ clang -include test.h test.c -o test
873 The ``clang`` driver will first check if a PCH file for ``test.h`` is
875 will be processed from the PCH file. Otherwise, Clang falls back to
881 Clang does *not* automatically use PCH files for headers that are directly
884 .. code-block:: console
886 $ clang -x c-header test.h -o test.h.pch
889 $ clang test.c -o test
891 In this example, ``clang`` will not automatically use the PCH file for
893 specified on the command line using :option:`-include`.
901 meant to be installed alongside the headers. Clang permits the creation
916 arguments. First, pass the ``--relocatable-pch`` flag to indicate that
918 :option:`-isysroot /path/to/build`, which makes all includes for your library
921 .. code-block:: console
923 # clang -x c-header --relocatable-pch -isysroot /path/to/build /path/to/build/mylib.h mylib.h.pch
928 in some other system root, the :option:`-isysroot` option can be used provide
930 example, :option:`-isysroot /Developer/SDKs/MacOSX10.4u.sdk` will look for
938 .. _controlling-code-generation:
941 ---------------------------
943 Clang provides a number of ways to control code generation. The options
946 **-f[no-]sanitize=check1,check2,...**
950 This option controls whether Clang adds runtime checks for various
955 - .. _opt_fsanitize_address:
957 ``-fsanitize=address``:
960 - .. _opt_fsanitize_thread:
962 ``-fsanitize=thread``: :doc:`ThreadSanitizer`, a data race detector.
963 - .. _opt_fsanitize_memory:
965 ``-fsanitize=memory``: :doc:`MemorySanitizer`,
968 - .. _opt_fsanitize_undefined:
970 ``-fsanitize=undefined``: :doc:`UndefinedBehaviorSanitizer`,
973 - ``-fsanitize=dataflow``: :doc:`DataFlowSanitizer`, a general data
975 - ``-fsanitize=cfi``: :doc:`control flow integrity <ControlFlowIntegrity>`
976 checks. Requires ``-flto``.
977 - ``-fsanitize=safe-stack``: :doc:`safe stack <SafeStack>`
978 protection against stack-based memory corruption errors.
980 There are more fine-grained checks available: see
981 the :ref:`list <ubsan-checks>` of specific kinds of
982 undefined behavior that can be detected and the :ref:`list <cfi-schemes>`
985 The ``-fsanitize=`` argument must also be provided when linking, in
988 It is not possible to combine more than one of the ``-fsanitize=address``,
989 ``-fsanitize=thread``, and ``-fsanitize=memory`` checkers in the same
992 **-f[no-]sanitize-recover=check1,check2,...**
994 **-f[no-]sanitize-recover=all**
996 Controls which checks enabled by ``-fsanitize=`` flag are non-fatal.
1000 By default, non-fatal checks are those enabled by
1002 except for ``-fsanitize=return`` and ``-fsanitize=unreachable``. Some
1007 Note that the ``-fsanitize-trap`` flag has precedence over this flag.
1011 ``-fno-sanitize-trap``.
1013 For example, if a command line contains the flags ``-fsanitize=undefined
1014 -fsanitize-trap=undefined``, the flag ``-fsanitize-recover=alignment``
1016 ``-fno-sanitize-trap=alignment``.
1018 **-f[no-]sanitize-trap=check1,check2,...**
1020 Controls which checks enabled by the ``-fsanitize=`` flag trap. This
1028 is supplied together with ``-fsanitize=undefined``, the ``vptr`` sanitizer
1033 .. option:: -fsanitize-blacklist=/path/to/blacklist/file
1037 :doc:`SanitizerSpecialCaseList` for file format description.
1039 .. option:: -fno-sanitize-blacklist
1043 **-f[no-]sanitize-coverage=[type,features,...]**
1048 **-f[no-]sanitize-stats**
1053 .. option:: -fsanitize-undefined-trap-on-error
1055 Deprecated alias for ``-fsanitize-trap=undefined``.
1057 .. option:: -fsanitize-cfi-cross-dso
1059 Enable cross-DSO control flow integrity checks. This flag modifies
1061 of cross-DSO virtual and indirect calls.
1063 .. option:: -ffast-math
1065 Enable fast-math mode. This defines the ``__FAST_MATH__`` preprocessor
1066 macro, and lets the compiler make aggressive, potentially-lossy assumptions
1067 about floating-point math. These include:
1069 * Floating-point math obeys regular algebraic rules for real numbers (e.g.
1072 * operands to floating-point operations are not equal to ``NaN`` and
1074 * ``+0`` and ``-0`` are interchangeable.
1076 .. option:: -fwhole-program-vtables
1078 Enable whole-program vtable optimizations, such as single-implementation
1080 :doc:`hidden LTO visibility <LTOVisibility>`. Requires ``-flto``.
1082 .. option:: -fno-assume-sane-operator-new
1090 .. option:: -ftrap-function=[name]
1104 .. option:: -ftls-model=[model]
1108 Valid values are: ``global-dynamic``, ``local-dynamic``,
1109 ``initial-exec`` and ``local-exec``. The default value is
1110 ``global-dynamic``. The compiler may use a different model if the
1115 .. option:: -femulated-tls
1117 Select emulated TLS model, which overrides all -ftls-model choices.
1122 .. option:: -mhwdiv=[values]
1132 .. option:: -m[no-]crc
1141 .. option:: -mgeneral-regs-only
1148 .. option:: -mcompact-branches=[values]
1158 **-f[no-]max-type-align=[number]**
1166 when working with values of those types, Clang usually wants to use instructions
1168 not promise to return memory that is more than 8-byte or 16-byte-aligned. Use
1175 This option can be overridden on a case-by-case basis by putting an explicit
1178 .. code-block:: console
1181 // Make an aligned typedef of the AVX-512 16-int vector type.
1185 // The compiler may assume that ‘v’ is 64-byte aligned, regardless of the
1186 // value of -fmax-type-align.
1191 ---------------------------
1198 Clang supports profile guided optimization with two different kinds of
1219 via ``-fprofile-instr-generate`` must be used with ``-fprofile-instr-use``.
1221 converted and used with ``-fprofile-sample-use``.
1226 3. Sampling profiles can only be used for optimization. They cannot be used for
1228 sampling profiles for code coverage, sample-based profiles are too
1229 coarse-grained for code coverage purposes; it would yield poor results.
1232 generated by that tool must then be converted into a format that can be read
1253 requirement is that you add ``-gline-tables-only`` or ``-g`` to the
1257 .. code-block:: console
1259 $ clang++ -O2 -gline-tables-only code.cc -o code
1263 into the format that the LLVM optimizer understands. Currently, there
1268 .. code-block:: console
1270 $ perf record -b ./code
1272 Note the use of the ``-b`` flag. This tells Perf to use the Last Branch
1277 3. Convert the collected profile data to LLVM's sample profile format.
1283 .. code-block:: console
1285 $ create_llvm_prof --binary=./code --out=code.prof
1289 without the ``-b`` flag, you need to use ``--use_lbr=false`` when
1297 with ``-gline-tables-only`` and ``-fprofile-sample-use``.
1299 .. code-block:: console
1301 $ clang++ -O2 -gline-tables-only -fprofile-sample-use=code.prof code.cc -o code
1308 the data generated by the profiler must be converted into a format that can be
1313 information. The format is described below. It can also be generated from
1314 the binary or gcov formats using the ``llvm-profdata`` tool.
1317 profile files. This is the format generated by the ``create_llvm_prof`` tool
1320 3. GCC encoding. This is based on the gcov format, which is accepted by GCC. It
1321 is only interesting in environments where GCC and Clang co-exist. This
1324 ``llvm-profdata``, but it cannot be generated by either.
1329 profiler's native format into one of these three.
1332 Sample Profile Text Format
1335 This section describes the ASCII text format for sampling profiles. It is,
1340 .. code-block:: console
1374 - Sampled line represents the profile information of a source location.
1377 - Callsite line represents the profile information of an inlined callsite.
1425 .. code-block:: console
1427 130: 7 foo:3 bar:2 baz:7
1433 As an example, consider a program with the call chain ``main -> foo -> bar``.
1438 .. code-block:: console
1455 Clang also supports profiling via instrumentation. This requires building a
1465 ``-fprofile-instr-generate`` option.
1467 .. code-block:: console
1469 $ clang++ -O2 -fprofile-instr-generate code.cc -o code
1479 .. code-block:: console
1481 $ LLVM_PROFILE_FILE="code-%p.profraw" ./code
1483 3. Combine profiles from multiple runs and convert the "raw" profile format to
1484 the input expected by clang. Use the ``merge`` command of the
1485 ``llvm-profdata`` tool to do this.
1487 .. code-block:: console
1489 $ llvm-profdata merge -output=code.profdata code-*.profraw
1492 since the merge operation also changes the file format.
1494 4. Build the code again using the ``-fprofile-instr-use`` option to specify the
1497 .. code-block:: console
1499 $ clang++ -O2 -fprofile-instr-use=code.profdata code.cc -o code
1502 profile. As you make changes to your code, clang may no longer be able to
1505 Profile generation and use can also be controlled by the GCC-compatible flags
1506 ``-fprofile-generate`` and ``-fprofile-use``. Although these flags are
1508 GCC-compatible profiles. They are only meant to implement GCC's semantics
1511 .. option:: -fprofile-generate[=<dirname>]
1513 Without any other arguments, ``-fprofile-generate`` behaves identically to
1514 ``-fprofile-instr-generate``. When given a directory name, it generates the
1520 .. code-block:: console
1522 $ clang++ -O2 -fprofile-generate=yyy/zzz code.cc -o code
1528 .. code-block:: console
1537 .. option:: -fprofile-use[=<pathname>]
1539 Without any other arguments, ``-fprofile-use`` behaves identically to
1540 ``-fprofile-instr-use``. Otherwise, if ``pathname`` is the full path to a
1551 In these cases, you can use the flag ``-fno-profile-instr-generate`` (or
1552 ``-fno-profile-generate``) to disable profile generation, and
1553 ``-fno-profile-instr-use`` (or ``-fno-profile-use``) to disable profile use.
1559 -----------------------------
1564 Debug info kind generated by Clang can be set by one of the flags listed
1567 .. option:: -g0
1571 .. option:: -gline-tables-only
1580 .. option:: -fstandalone-debug
1582 Clang supports a number of optimizations to reduce the size of debug
1585 compilation units. For instance, Clang will not emit type
1587 replaced with a forward declaration. Further, Clang will only emit
1591 The **-fstandalone-debug** option turns off these optimizations.
1592 This is useful when working with 3rd-party libraries that don't come
1593 with debug information. Note that Clang will never emit type
1596 .. option:: -fno-standalone-debug
1598 On Darwin **-fstandalone-debug** is enabled by default. The
1599 **-fno-standalone-debug** option can be used to get to turn on the
1600 vtable-based optimization described above.
1602 .. option:: -g
1609 While Clang generally emits standard DWARF debug info (http://dwarfstd.org),
1613 .. option:: -ggdb, -glldb, -gsce
1616 debugger, respectively. Each of these options implies **-g**. (Therefore, if
1617 you want both **-gline-tables-only** and debugger tuning, the tuning option
1622 -----------------------
1624 Clang parses Doxygen and non-Doxygen style documentation comments and attaches
1626 Doxygen-style comments and ignores ordinary comments starting with ``//`` and
1629 .. option:: -Wdocumentation
1638 .. option:: -Wno-documentation-unknown-command
1642 .. option:: -fparse-all-comments
1647 .. option:: -fcomment-block-commands=[commands]
1649 Define custom documentation commands as block commands. This allows Clang to
1652 *without trailing space*; e.g. ``-fcomment-block-commands=foo,bar`` defines
1655 It is also possible to use ``-fcomment-block-commands`` several times; e.g.
1656 ``-fcomment-block-commands=foo -fcomment-block-commands=bar`` does the same
1664 The support for standard C in clang is feature-complete except for the
1665 C99 floating-point pragmas.
1667 Extensions supported by clang
1668 -----------------------------
1673 ------------------------------------------
1675 clang supports the -std option, which changes what language mode clang
1677 gnu11, and various aliases for those modes. If no -std option is
1678 specified, clang defaults to gnu11 mode. Many C99 and C11 features are
1680 ``-pedantic-errors`` to request an error if a feature from a later standard
1685 - ``c*`` modes define "``__STRICT_ANSI__``".
1686 - Target-specific defines not prefixed by underscores, like "linux",
1688 - Trigraphs default to being off in ``gnu*`` modes; they can be enabled by
1689 the -trigraphs option.
1690 - The parser recognizes "asm" and "typeof" as keywords in ``gnu*`` modes;
1693 - The Apple "blocks" extension is recognized by default in ``gnu*`` modes
1694 on some platforms; it can be enabled in any mode with the "-fblocks"
1696 - Arrays that are VLA's according to the standard, but which can be
1703 - The ``*99`` modes default to implementing "inline" as specified in C99,
1707 - Digraphs are not recognized in c89 mode.
1708 - The scope of names defined inside a "for", "if", "switch", "while",
1711 - ``__STDC_VERSION__`` is not defined in ``*89`` modes.
1712 - "inline" is not recognized as a keyword in c89 mode.
1713 - "restrict" is not recognized as a keyword in ``*89`` modes.
1714 - Commas are allowed in integer constant expressions in ``*99`` modes.
1715 - Arrays which are not lvalues are not implicitly promoted to pointers
1717 - Some warnings are different.
1721 - Warnings for use of C11 features are disabled.
1722 - ``__STDC_VERSION__`` is defined to ``201112L`` rather than ``199901L``.
1728 ----------------------------------
1730 clang tries to be compatible with gcc as much as possible, but some gcc
1733 - clang does not support decimal floating point types (``_Decimal32`` and
1734 friends) or fixed-point types (``_Fract`` and friends); nobody has
1737 - clang does not support nested functions; this is a complex feature
1742 .. code-block:: cpp
1750 - clang does not support static initialization of flexible array
1753 - clang does not support
1757 that because clang pretends to be like GCC 4.2, and this extension
1759 extension with clang at the moment.
1760 - clang does not support the gcc extension for forward-declaring
1761 function parameters; this has not shown up in any real-world code
1765 missing from this list, please send an e-mail to cfe-dev. This list
1767 list does not include bugs in mostly-implemented features; please see
1769 tracker <http://llvm.org/bugs/buglist.cgi?quicksearch=product%3Aclang+component%3A-New%2BBugs%2CAST…
1770 for known existing bugs (FIXME: Is there a section for bug-reporting
1774 ----------------------------------------
1776 - clang does not support the gcc extension that allows variable-length
1779 the extension appears to be rarely used. Note that clang *does*
1782 - clang does not have an equivalent to gcc's "fold"; this means that
1783 clang doesn't accept some constructs gcc might accept in contexts
1784 where a constant expression is required, like "x-x" where x is a
1786 - clang does not support ``__builtin_apply`` and friends; this extension
1792 --------------------
1794 clang has support for many extensions from Microsoft Visual C++. To enable these
1795 extensions, use the ``-fms-extensions`` command-line option. This is the default
1796 for Windows targets. Clang does not implement every pragma or declspec provided
1800 clang has a ``-fms-compatibility`` flag that makes clang accept enough
1803 <http://clang.llvm.org/compatibility.html#dep_lookup_bases>`_, which is
1804 a common compatibility issue with clang. This flag is enabled by default
1807 ``-fdelayed-template-parsing`` lets clang delay parsing of function template
1811 For compatibility with existing code that compiles with MSVC, clang defines the
1813 and 180000000 respectively, making clang look like an early release of Visual
1814 C++ 2013. The ``-fms-compatibility-version=`` flag overrides these values. It
1816 compatibility version makes clang behave more like that version of MSVC. For
1817 example, ``-fms-compatibility-version=19`` will enable C++14 features and define
1825 clang fully implements all of standard C++98 except for exported
1830 ---------------------------------
1832 .. option:: -fbracket-depth=N
1837 .. option:: -fconstexpr-depth=N
1842 .. option:: -ftemplate-depth=N
1847 .. option:: -foperator-arrow-depth=N
1849 Sets the limit for iterative calls to 'operator->' functions to N. The
1854 Objective-C Language Features
1859 Objective-C++ Language Features
1867 Clang supports all OpenMP 3.1 directives and clauses. In addition, some
1870 set of atomic constructs, ``proc_bind`` clause for all parallel-based
1875 Use :option:`-fopenmp` to enable OpenMP. Support for OpenMP can be disabled with
1876 :option:`-fno-openmp`.
1879 ---------------------------------
1881 .. option:: -fopenmp-use-tls
1885 local variables, using TLS support. If :option:`-fno-openmp-use-tls`
1891 Target-Specific Features and Limitations
1895 ------------------------------------------
1900 The support for X86 (both 32-bit and 64-bit) is considered stable on
1902 to correctly compile many large C, C++, Objective-C, and Objective-C++
1905 On ``x86_64-mingw32``, passing i128(by value) is incompatible with the
1909 For the X86 target, clang supports the :option:`-m16` command line
1910 argument which enables 16-bit code output. This is broadly similar to
1912 and the ABI remains 32-bit but the assembler emits instructions
1913 appropriate for a CPU running in 16-bit mode, with address-size and
1914 operand-size prefixes to enable 32-bit addressing and operations.
1921 C++, Objective-C, and Objective-C++ codebases. Clang only supports a
1936 clang currently contains some support for other architectures (e.g. Sparc);
1940 clang contains limited support for the MSP430 embedded processor, but
1941 both the clang support and the LLVM backend support are highly
1946 platform is quite easy; see ``lib/Basic/Targets.cpp`` in the clang source
1954 -----------------------------------------
1964 Clang has experimental support for targeting "Cygming" (Cygwin / MinGW)
1972 Clang works on Cygwin-1.7.
1977 Clang works on some mingw32 distributions. Clang assumes directories as
1980 - ``C:/mingw/include``
1981 - ``C:/mingw/lib``
1982 - ``C:/mingw/lib/gcc/mingw32/4.[3-5].0/include/c++``
1986 MinGW-w64
1989 For 32-bit (i686-w64-mingw32), and 64-bit (x86\_64-w64-mingw32), Clang
1992 - ``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)``
1993 - ``some_directory/bin/gcc.exe``
1994 - ``some_directory/bin/clang.exe``
1995 - ``some_directory/bin/clang++.exe``
1996 - ``some_directory/bin/../include/c++/GCC_version``
1997 - ``some_directory/bin/../include/c++/GCC_version/x86_64-w64-mingw32``
1998 - ``some_directory/bin/../include/c++/GCC_version/i686-w64-mingw32``
1999 - ``some_directory/bin/../include/c++/GCC_version/backward``
2000 - ``some_directory/bin/../x86_64-w64-mingw32/include``
2001 - ``some_directory/bin/../i686-w64-mingw32/include``
2002 - ``some_directory/bin/../include``
2005 official `MinGW-w64 website <http://mingw-w64.sourceforge.net>`_.
2007 Clang expects the GCC executable "gcc.exe" compiled for
2008 ``i686-w64-mingw32`` (or ``x86_64-w64-mingw32``) to be present on PATH.
2011 ``x86_64-w64-mingw32``.
2013 .. _clang-cl:
2015 clang-cl
2018 clang-cl is an alternative command-line interface to Clang driver, designed for
2021 To enable clang-cl to find system headers, libraries, and the linker when run
2022 from the command-line, it should be executed inside a Visual Studio Native Tools
2024 up using e.g. `vcvars32.bat <http://msdn.microsoft.com/en-us/library/f2ccy3wt.aspx>`_.
2026 clang-cl can also be used from inside Visual Studio by using an LLVM Platform
2029 Command-Line Options
2030 --------------------
2032 To be compatible with cl.exe, clang-cl supports most of the same command-line
2033 options. Those options can start with either ``/`` or ``-``. It also supports
2034 some of Clang's core options, such as the ``-W`` options.
2036 Options that are known to clang-cl, but not currently supported, are ignored
2041 clang-cl.exe: warning: argument unused during compilation: '/AI'
2043 To suppress warnings about unused arguments, use the ``-Qunused-arguments`` option.
2045 Options that are not known to clang-cl will be ignored by default. Use the
2046 ``-Werror=unknown-argument`` option in order to treat them as errors. If these
2051 clang-cl.exe: error: no such file or directory: '/foobar'
2053 Please `file a bug <http://llvm.org/bugs/enter_bug.cgi?product=clang&component=Driver>`_
2054 for any valid cl.exe flags that clang-cl does not understand.
2056 Execute ``clang-cl /?`` to see a list of supported options:
2063 /Brepro- Emit an object file which cannot be reproduced over time
2071 /fallback Fall back to cl.exe if clang-cl fails to compile
2078 /fp:except-
2083 /GA Assume thread-local variables are defined in the executable
2084 /GF- Disable string pooling
2085 /GR- Disable emission of RTTI data
2088 /Gw- Don't put each data item in its own section
2090 /Gy- Don't put each function in its own section
2098 /MDd Use DLL debug run-time
2099 /MD Use DLL run-time
2100 /MTd Use static debug run-time
2101 /MT Use static run-time
2104 /Oi- Disable use of builtin functions
2111 /Qvec- Disable the loop vectorization passes
2120 /vmb Use a best-case representation method for member pointers
2121 /vmg Use a most-general representation for member pointers
2122 /vmm Set the default most-general representation to multiple inheritance
2123 /vms Set the default most-general representation to single inheritance
2124 /vmv Set the default most-general representation to virtual inheritance
2128 /W1 Enable -Wall
2129 /W2 Enable -Wall
2130 /W3 Enable -Wall
2131 /W4 Enable -Wall and -Wextra
2132 /Wall Enable -Wall and -Wextra
2133 /WX- Do not treat warnings as errors
2137 /Zc:sizedDealloc- Disable C++14 sized global deallocation functions
2140 /Zc:threadSafeInit- Disable thread-safe initialization of static variables
2141 /Zc:threadSafeInit Enable thread-safe initialization of static variables
2142 /Zc:trigraphs- Disable trigraphs (default)
2148 /Zs Syntax-check only
2151 -### Print (but do not run) the commands to run for this compilation
2152 --analyze Run the static analyzer
2153 -fansi-escape-codes Use ANSI escape codes for diagnostics
2154 -fcolor-diagnostics Use colors in diagnostics
2155 -fdiagnostics-parseable-fixits
2156 Print fix-its in machine parseable form
2157 -fms-compatibility-version=<value>
2158 Dot-separated value representing the Microsoft compiler version
2160 -fms-compatibility Enable full Microsoft Visual C++ compatibility
2161-fms-extensions Accept some non-standard constructs supported by the Microsoft compiler
2162 -fmsc-version=<value> Microsoft compiler version number to report in _MSC_VER
2164 -fno-sanitize-coverage=<value>
2166 -fno-sanitize-recover=<value>
2168 -fno-sanitize-trap=<value>
2170 -fsanitize-blacklist=<value>
2172 -fsanitize-coverage=<value>
2174 -fsanitize-recover=<value>
2176 -fsanitize-trap=<value> Enable trapping for specified sanitizers
2177 -fsanitize=<check> Turn on runtime checks for various forms of undefined or suspicious
2179 -gcodeview Generate CodeView debug information
2180 -mllvm <value> Additional arguments to forward to LLVM's option processing
2181 -Qunused-arguments Don't emit warning for unused driver arguments
2182 -R<remark> Enable the specified remark
2183 --target=<value> Generate code for the given target
2184 -v Show commands to run and use verbose output
2185 -W<warning> Enable the specified warning
2186 -Xclang <arg> Pass <arg> to the clang compiler
2191 When clang-cl is run with the ``/fallback`` option, it will first try to
2196 clang-cl cannot successfully compile all the files. clang-cl may fail to compile