============================
Clang Compiler User's Manual
============================
.. contents::
:local:
Introduction
============
The Clang Compiler is an open-source compiler for the C family of
programming languages, aiming to be the best in class implementation of
these languages. Clang builds on the LLVM optimizer and code generator,
allowing it to provide high-quality optimization and code generation
support for many targets. For more general information, please see the
`Clang Web Site <http://clang.llvm.org>`_ or the `LLVM Web
Site <http://llvm.org>`_.
This document describes important notes about using Clang as a compiler
for an end-user, documenting the supported features, command line
options, etc. If you are interested in using Clang to build a tool that
processes code, please see :doc:`InternalsManual`. If you are interested in the
`Clang Static Analyzer <http://clang-analyzer.llvm.org>`_, please see its web
page.
Clang is designed to support the C family of programming languages,
which includes :ref:`C <c>`, :ref:`Objective-C <objc>`, :ref:`C++ <cxx>`, and
:ref:`Objective-C++ <objcxx>` as well as many dialects of those. For
language-specific information, please see the corresponding language
specific section:
- :ref:`C Language <c>`: K&R C, ANSI C89, ISO C90, ISO C94 (C89+AMD1), ISO
C99 (+TC1, TC2, TC3).
- :ref:`Objective-C Language <objc>`: ObjC 1, ObjC 2, ObjC 2.1, plus
variants depending on base language.
- :ref:`C++ Language <cxx>`
- :ref:`Objective C++ Language <objcxx>`
In addition to these base languages and their dialects, Clang supports a
broad variety of language extensions, which are documented in the
corresponding language section. These extensions are provided to be
compatible with the GCC, Microsoft, and other popular compilers as well
as to improve functionality through Clang-specific features. The Clang
driver and language features are intentionally designed to be as
compatible with the GNU GCC compiler as reasonably possible, easing
migration from GCC to Clang. In most cases, code "just works".
In addition to language specific features, Clang has a variety of
features that depend on what CPU architecture or operating system is
being compiled for. Please see the :ref:`Target-Specific Features and
Limitations <target_features>` section for more details.
The rest of the introduction introduces some basic :ref:`compiler
terminology <terminology>` that is used throughout this manual and
contains a basic :ref:`introduction to using Clang <basicusage>` as a
command line compiler.
.. _terminology:
Terminology
-----------
Front end, parser, backend, preprocessor, undefined behavior,
diagnostic, optimizer
.. _basicusage:
Basic Usage
-----------
Intro to how to use a C compiler for newbies.
compile + link compile then link debug info enabling optimizations
picking a language to use, defaults to C99 by default. Autosenses based
on extension. using a makefile
Command Line Options
====================
This section is generally an index into other sections. It does not go
into depth on the ones that are covered by other sections. However, the
first part introduces the language selection and other high level
options like :option:`-c`, :option:`-g`, etc.
Options to Control Error and Warning Messages
---------------------------------------------
.. option:: -Werror
Turn warnings into errors.
.. This is in plain monospaced font because it generates the same label as
.. -Werror, and Sphinx complains.
``-Werror=foo``
Turn warning "foo" into an error.
.. option:: -Wno-error=foo
Turn warning "foo" into an warning even if :option:`-Werror` is specified.
.. option:: -Wfoo
Enable warning "foo".
.. option:: -Wno-foo
Disable warning "foo".
.. option:: -w
Disable all warnings.
.. option:: -Weverything
:ref:`Enable all warnings. <diagnostics_enable_everything>`
.. option:: -pedantic
Warn on language extensions.
.. option:: -pedantic-errors
Error on language extensions.
.. option:: -Wsystem-headers
Enable warnings from system headers.
.. option:: -ferror-limit=123
Stop emitting diagnostics after 123 errors have been produced. The default is
20, and the error limit can be disabled with :option:`-ferror-limit=0`.
.. option:: -ftemplate-backtrace-limit=123
Only emit up to 123 template instantiation notes within the template
instantiation backtrace for a single warning or error. The default is 10, and
the limit can be disabled with :option:`-ftemplate-backtrace-limit=0`.
.. _cl_diag_formatting:
Formatting of Diagnostics
^^^^^^^^^^^^^^^^^^^^^^^^^
Clang aims to produce beautiful diagnostics by default, particularly for
new users that first come to Clang. However, different people have
different preferences, and sometimes Clang is driven by another program
that wants to parse simple and consistent output, not a person. For
these cases, Clang provides a wide range of options to control the exact
output format of the diagnostics that it generates.
.. _opt_fshow-column:
**-f[no-]show-column**
Print column number in diagnostic.
This option, which defaults to on, controls whether or not Clang
prints the column number of a diagnostic. For example, when this is
enabled, Clang will print something like:
::
test.c:28:8: warning: extra tokens at end of #endif directive [-Wextra-tokens]
#endif bad
^
//
When this is disabled, Clang will print "test.c:28: warning..." with
no column number.
The printed column numbers count bytes from the beginning of the
line; take care if your source contains multibyte characters.
.. _opt_fshow-source-location:
**-f[no-]show-source-location**
Print source file/line/column information in diagnostic.
This option, which defaults to on, controls whether or not Clang
prints the filename, line number and column number of a diagnostic.
For example, when this is enabled, Clang will print something like:
::
test.c:28:8: warning: extra tokens at end of #endif directive [-Wextra-tokens]
#endif bad
^
//
When this is disabled, Clang will not print the "test.c:28:8: "
part.
.. _opt_fcaret-diagnostics:
**-f[no-]caret-diagnostics**
Print source line and ranges from source code in diagnostic.
This option, which defaults to on, controls whether or not Clang
prints the source line, source ranges, and caret when emitting a
diagnostic. For example, when this is enabled, Clang will print
something like:
::
test.c:28:8: warning: extra tokens at end of #endif directive [-Wextra-tokens]
#endif bad
^
//
**-f[no-]color-diagnostics**
This option, which defaults to on when a color-capable terminal is
detected, controls whether or not Clang prints diagnostics in color.
When this option is enabled, Clang will use colors to highlight
specific parts of the diagnostic, e.g.,
.. nasty hack to not lose our dignity
.. raw:: html
<pre>