Development/Clang

    From The Document Foundation Wiki

    Clang Compiler

    Clang [1] is a C++ compiler that can be used for building LibreOffice and/or for additional analysis of the code.

    Advantages/disadvantages

    Clang, at least on Linux, seems to produce somewhat slower binaries (5-20%), so there is no advantage in using it for production binaries. (On macOS it is the only alternative (unless you intentionally try to use some obsolete SDK, Apple has phased out GCC from their toolchain.)

    There are advantages when using for development:

    • Better diagnostics (more expressive, colored, quote source including pointing out the exact place, typedef preservation, suggestions on how to fix the error, etc.), see this page for details.
    • Somewhat faster compilation, although not significantly (5-20%). Support for precompiled headers (PCH) further improves this.
    • Clang is a newer modular codebase written in C++, which is easier to read (in case of looking for compiler bugs) or reuse (libclang allows writing other tools or extending the compiler).

    Disadvantages:

    • Debug support is unusable with optimizing (i.e. -g does not work with any -O option except for -O0), at least on Linux. Not a big problem for developer builds though.

    Building with Clang

    See Development/Building LibreOffice with Clang for how to build LibreOffice with Clang instead of GCC, including the possible necessary setup.

    Additional compilation warnings

    LibreOffice includes a Clang plugin that produces additional warnings during compilation. These require LLVM/Clang development headers/libraries and are enabled automatically by --enable-dbgutil or forced using --enable-compiler-plugins. See Clang plugins for further information, including development information.

    Source rewriting

    LibreOffice includes a Clang plugin that can be also used to do source code changes. Again, this requires LLVM/Clang development headers/libraries, must be enabled by --enable-dbgutil or forced using --enable-compiler-plugins. See Clang plugins for further information, including development information.

    Static Code Analysis

    See Development/Clang Code Analysis.