CLANG(1)

πŸ“¦ version 23.1.3, in centos-stream 9

πŸ‘‘ CLANG(1) β€” the Clang C, C++, and Objective-C compiler πŸ‘‘

okay bestie, sit down, grab a lil snack πŸ“ β€” this is the clang manual page, part of the Clang manual, and it's a big one. But it's literally just your compiler, and your compiler is iconic, so let's go πŸ’…

✨ NAME ✨

clang β€” the Clang C, C++, and Objective-C compiler. that's it, that's the vibe 🫢

🌸 SYNOPSIS 🌸

clang [options] filename ...

πŸ’– DESCRIPTION πŸ’–

so clang is a C, C++, and Objective-C compiler, and it's giving full stack β€” it encompasses preprocessing, parsing, optimization, code generation, assembly, and linking, all in one πŸ’« Depending on which high-level mode setting you pass, Clang will stop before doing a full link. And like, even though Clang is highly integrated (main character energy), it's genuinely important to understand the stages of compilation so you know how to invoke it properly. The stages are:

πŸš— Driver

the clang executable is actually just a small driver that controls the overall execution of other tools β€” the compiler, the assembler, the linker, all of them. Typically you don't need to interact with the driver directly, but you transparently use it to run the other tools. it's the manager, not the intern, iykyk.

πŸ” Preprocessing

this stage handles tokenization of the input source file, macro expansion, #include expansion, and handling of other preprocessor directives. The output of this stage is typically called a ".i" (for C), ".ii" (for C++), ".mi" (for Objective-C), or ".mii" (for Objective-C++) file. so many lil extensions, we love a naming convention 🌈

🧠 Parsing and Semantic Analysis

this stage parses the input file, translating preprocessor tokens into a parse tree. Once it's in the form of a parse tree, it applies semantic analysis to compute types for expressions as well as determine whether the code is well formed. This stage is responsible for generating most of the compiler warnings as well as parse errors. The output of this stage is an "Abstract Syntax Tree" (AST). yes bestie, the AST β€” the moment your code becomes a whole tree 🌳

⚑ Code Generation and Optimization

this stage translates an AST into low-level intermediate code (known as "LLVM IR") and ultimately to machine code. This phase is responsible for optimizing the generated code and handling target-specific code generation. The output of this stage is typically called a ".s" file or "assembly" file.

Clang also supports the use of an integrated assembler, in which the code generator produces object files directly. This avoids the overhead of generating the ".s" file and of calling the target assembler. lowkey a flex πŸ”₯

πŸ”§ Assembler

this stage runs the target assembler to translate the output of the compiler into a target object file. The output of this stage is typically called a ".o" file or "object" file.

πŸ”— Linker

this stage runs the target linker to merge multiple object files into an executable or dynamic library. The output of this stage is typically called an "a.out", ".dylib" or ".so" file.

πŸ•΅οΈ Clang Static Analyzer

The Clang Static Analyzer is a tool that scans source code to try to find bugs through code analysis. This tool uses many parts of Clang and is built into the same driver. Please see https://clang-analyzer.llvm.org for more details on how to use the static analyzer. it's giving detective energy, we stan πŸ•΅οΈβ€β™€οΈ


πŸŽ€ OPTIONS πŸŽ€

πŸ›‘ Stage Selection Options

like, how far do you wanna go down the pipeline? pick your stop bestie 🚏

  • -E β€” Run the preprocessor stage.
  • -fsyntax-only β€” Run the preprocessor, parser and semantic analysis stages.
  • -S β€” Run the previous stages as well as LLVM generation and optimization stages and target-specific code generation, producing an assembly file.
  • -c β€” Run all of the above, plus the assembler, generating a target ".o" object file.
  • no stage selection option β€” If no stage selection option is specified, all stages above are run, and the linker is run to combine the results into an executable or shared library. the full send πŸš€

🌍 Language Selection and Mode Options

  • -x <language> β€” Treat subsequent input files as having type language.
  • -std=<standard> β€” Specify the language standard to compile for. okay this one is a whole buffet, let's break it down πŸ‘‡

Supported values for the C language are:

  • c89, c90, iso9899:1990 β€” ISO C 1990
  • iso9899:199409 β€” ISO C 1990 with amendment 1
  • gnu89, gnu90 β€” ISO C 1990 with GNU extensions
  • c99, iso9899:1999 β€” ISO C 1999
  • gnu99 β€” ISO C 1999 with GNU extensions
  • c11, iso9899:2011 β€” ISO C 2011
  • gnu11 β€” ISO C 2011 with GNU extensions
  • c17, iso9899:2017 β€” ISO C 2017
  • gnu17 β€” ISO C 2017 with GNU extensions
  • c23, iso9899:2024 β€” ISO C 2023
  • gnu23 β€” ISO C 2023 with GNU extensions
  • c2y β€” ISO C 202y
  • gnu2y β€” ISO C 202y with GNU extensions

The default C language standard is gnu17, except on PS4, where it is gnu99. (PS4 bestie living in the past, no judgement πŸ’€)

Supported values for the C++ language are:

  • c++98, c++03 β€” ISO C++ 1998 with amendments
  • gnu++98, gnu++03 β€” ISO C++ 1998 with amendments and GNU extensions
  • c++11 β€” ISO C++ 2011 with amendments
  • gnu++11 β€” ISO C++ 2011 with amendments and GNU extensions
  • c++14 β€” ISO C++ 2014 with amendments
  • gnu++14 β€” ISO C++ 2014 with amendments and GNU extensions
  • c++17 β€” ISO C++ 2017 with amendments
  • gnu++17 β€” ISO C++ 2017 with amendments and GNU extensions
  • c++20 β€” ISO C++ 2020 with amendments
  • gnu++20 β€” ISO C++ 2020 with amendments and GNU extensions
  • c++23 β€” ISO C++ 2023 with amendments
  • gnu++23 β€” ISO C++ 2023 with amendments and GNU extensions
  • c++2c β€” Working draft for C++2c
  • gnu++2c β€” Working draft for C++2c with GNU extensions
  • c++2d β€” Working draft for C++2d
  • gnu++2d β€” Working draft for C++2d with GNU extensions

The default C++ language standard is gnu++17.

Supported values for the OpenCL language are:

  • cl1.0 β€” OpenCL 1.0
  • cl1.1 β€” OpenCL 1.1
  • cl1.2 β€” OpenCL 1.2
  • cl2.0 β€” OpenCL 2.0

The default OpenCL language standard is cl1.0.

Supported values for the CUDA language are:

  • cuda β€” NVIDIA CUDA(tm)
  • -stdlib=<library> β€” Specify the C++ standard library to use; supported options are libstdc++ and libc++. If not specified, platform default will be used. pick your fighter βš”οΈ
  • -rtlib=<library> β€” Specify the compiler runtime library to use; supported options are libgcc and compiler-rt. If not specified, platform default will be used.
  • -ansi β€” Same as -std=c89. retro era ✨
  • -ObjC, -ObjC++ β€” Treat source input files as Objective-C and Object-C++ inputs respectively.
  • -trigraphs β€” Enable trigraphs.
  • -ffreestanding β€” Indicate that the file should be compiled for a freestanding, not a hosted, environment. Note that a freestanding build still requires linking against a C Standard Library which supports the freestanding interfaces for the specified language mode and target environment. This includes functions like memcpy, memmove, and memset. so like, "freestanding" is not "no library at all" bestie, don't get it twisted 🫢
  • -fno-builtin β€” Disable special handling and optimizations of well-known library functions, like strlen() and malloc().
  • -fno-builtin-<function> β€” Disable special handling and optimizations for the specific library function. For example, -fno-builtin-strlen removes any special handling for the strlen() library function.
  • -fno-builtin-std-<function> β€” Disable special handling and optimizations for the specific C++ standard library function in namespace std. For example, -fno-builtin-std-move_if_noexcept removes any special handling for the std::move_if_noexcept() library function.

For C standard library functions that the C++ standard library also provides in namespace std, use -fno-builtin-<function> instead. (yes, the other one β€” the non-std flag. we know, it's a lil confusing 😭)

  • -fmath-errno β€” Indicate that math functions should be treated as updating errno.
  • -fpascal-strings β€” Enable support for Pascal-style strings with "\pfoo".
  • -fms-extensions β€” Enable support for Microsoft extensions.
  • -fmsc-version= β€” Set _MSC_VER. When on Windows, this defaults to either the same value as the currently installed version of cl.exe, or 1933. Not set otherwise.
  • -fborland-extensions β€” Enable support for Borland extensions.
  • -fwritable-strings β€” Make all string literals default to writable. This disables uniquing of strings and other optimizations. ⚠️ say bye to those optimizations, she's committing fr
  • -flax-vector-conversions, -flax-vector-conversions=<kind>, -fno-lax-vector-conversions β€” Allow loose type checking rules for implicit vector conversions. Possible values of kind:
    • none: allow no implicit conversions between vectors
    • integer: allow implicit bitcasts between integer vectors of the same overall bit-width
    • all: allow implicit bitcasts between any vectors of the same overall bit-width

kind defaults to integer if unspecified.

  • -fblocks β€” Enable the "Blocks" language feature.
  • -fobjc-abi-version=version β€” Select the Objective-C ABI version to use. Available versions are 1 (legacy "fragile" ABI), 2 (non-fragile ABI 1), and 3 (non-fragile ABI 2).
  • -fobjc-nonfragile-abi-version=<version> β€” Select the Objective-C non-fragile ABI version to use by default. This will only be used as the Objective-C ABI when the non-fragile ABI is enabled (either via -fobjc-nonfragile-abi, or because it is the platform default).
  • -fobjc-nonfragile-abi, -fno-objc-nonfragile-abi β€” Enable use of the Objective-C non-fragile ABI. On platforms for which this is the default ABI, it can be disabled with -fno-objc-nonfragile-abi.

🎯 Target Selection Options

Clang fully supports cross compilation as an inherent part of its design. Depending on how your version of Clang is configured, it may have support for a number of cross compilers, or may only support a native target. so like, depending on your setup you might have a whole roster of targets, or literally just the one πŸ’…

  • -arch <architecture> β€” Specify the architecture to build for (Mac OS X specific).
  • -target <architecture> β€” tells Clang which architecture to build for, on every platform. πŸ’…
  • -mmacos-version-min=<version> β€” when you're building for macOS, this sets the minimum version your app supports. 🍎
  • -miphoneos-version-min β€” when building for iPhone OS, this sets the minimum version your app supports. πŸ“±
  • --print-supported-cpus β€” prints out a list of supported processors for the given target (specified through --target=<architecture> or -arch <architecture>). If no target is specified, the system default target is used. πŸ–¨οΈ
  • -mcpu=?, -mtune=? β€” acts as an alias for --print-supported-cpus. ✨
  • -mcpu=help, -mtune=help β€” also acts as an alias for --print-supported-cpus. ✨
  • -march=<cpu> β€” says Clang should generate code for a specific processor family member and later. For example, if you specify -march=i486, the compiler is allowed to generate instructions that are valid on i486 and later processors, but which may not exist on earlier ones. πŸ”₯
  • --print-enabled-extensions β€” prints the list of extensions that are enabled for the target specified by the combination of --target, -march, and -mcpu values. Currently, this option is only supported on AArch64 and RISC-V. On RISC-V, this option also prints out the ISA string of enabled extensions. 🌈
  • --print-supported-extensions β€” prints the list of all extensions that are supported for every CPU target for an architecture (specified through --target=<architecture> or -arch <architecture>). If no target is specified, the system default target is used. Currently, this option is only supported on AArch64 and RISC-V. 🌸

🧠 Code Generation Options 🧠

  • -O0, -O1, -O2, -O3, -Ofast, -Os, -Oz, -Og, -O, -O4 β€” specify which optimization level to use:
    • -O0 means "no optimization": this level compiles the fastest and generates the most debuggable code. 🐒
    • -O1 is somewhere between -O0 and -O2.
    • -O2 is a moderate level of optimization which enables most optimizations.
    • -O3 is like -O2, except that it enables optimizations that take longer to perform or that may generate larger code (in an attempt to make the program run faster). πŸš€
    • -Ofast enables all the optimizations from -O3 along with other aggressive optimizations that may violate strict compliance with language standards. This has been deprecated since Clang 19. There is no timeline yet for removal; the aim is to discourage use of -Ofast due to the surprising behavior of an optimization flag changing the observable behavior of correct code. 😭 If -Ofast has been specified and is the effective optimization level (i.e. there is no later -O option specified), then the option can be replaced in the option string with -O3 -ffast-math -fstrict-aliasing. (-fstrict-aliasing is the default on non-Windows, non-UEFI platforms). If -Ofast has been specified but is not the effective optimization level, then it can be removed or replaced with -O3.
    • -Os is like -O2 with extra optimizations to reduce code size.
    • -Oz is like -Os (and thus -O2), but reduces code size further.
    • -Og is similar to -O1, but with slightly reduced optimization and better variable visibility. The same optimizations are run as at -O1, but the -fextend-variable-liveness flag is also set, which tries to prevent optimizations from reducing the liveness of user variables, improving their availability when debugging. πŸ”
    • -O is equivalent to -O1.
    • -O4 and higher β€” currently equivalent to -O3.
  • -g, -gline-tables-only, -gmodules β€” control debug information output. Note that Clang debug information works best at -O0. When more than one option starting with -g is specified, the last one wins:
    • -g generates debug information. πŸ›
    • -gline-tables-only generates only line table debug information. This allows for symbolicated backtraces with inlining information, but does not include any information about variables, their locations or types.
    • -gmodules generates debug information that contains external references to types defined in Clang modules or precompiled headers instead of emitting redundant debug type information into every object file. This option transparently switches the Clang module format to object file containers that hold the Clang module together with the debug information. When compiling a program that uses Clang modules or precompiled headers, this option produces complete debug information with faster compile times and much smaller object files. πŸ’Ύ This option should not be used when building static libraries for distribution to other machines because the debug info will contain references to the module cache on the machine the object files in the library were built on. πŸ’€
  • -fstandalone-debug, -fno-standalone-debug β€” Clang supports a number of optimizations to reduce the size of debug information in the binary. They work based on the assumption that the debug type information can be spread out over multiple compilation units. For instance, Clang will not emit type definitions for types that are not needed by a module and could be replaced with a forward declaration. Further, Clang will only emit type info for a dynamic C++ class in the module that contains the vtable for the class. -fstandalone-debug turns off these optimizations. This is useful when working with 3rd-party libraries that don't come with debug information. This is the default on Darwin. Note that Clang will never emit type information for types that are not referenced at all by the program. 🧠
  • -feliminate-unused-debug-types β€” by default, Clang does not emit type information for types that are defined but not used in a program. To retain the debug info for these unused types, the negation -fno-eliminate-unused-debug-types can be used. 🩹
  • -fexceptions β€” allow exceptions to be thrown through Clang compiled stack frames (on many targets, this will enable unwind information for functions that might have an exception thrown through them). For most targets, this is enabled by default for C++. 🎒
  • -ftrapv β€” generate code to catch integer overflow errors. Signed integer overflow is undefined in C. With this flag, extra code is generated to detect this and abort when it happens. 🚨
  • -fvisibility β€” this flag sets the default visibility level. πŸ‘€
  • -fcommon, -fno-common β€” this flag specifies that variables without initializers get common linkage. It can be disabled with -fno-common. 🀝
  • -ftls-model=<model> β€” set the default thread-local storage (TLS) model to use for thread-local variables. Valid values are: "global-dynamic", "local-dynamic", "initial-exec" and "local-exec". The default is "global-dynamic". The default model can be overridden with the tls_model attribute. The compiler will try to choose a more efficient model if possible. 🧡
  • -flto, -flto=full, -flto=thin, -emit-llvm β€” generate output files in LLVM formats, suitable for link time optimization. When used with -S this generates LLVM intermediate language assembly files, otherwise this generates LLVM bitcode format object files (which may be passed to the linker depending on the stage selection options). The default for -flto is "full", in which the LLVM bitcode is suitable for monolithic Link Time Optimization (LTO), where the linker merges all such modules into a single combined module for optimization. With "thin", ThinLTO compilation is invoked instead. πŸ”—
NOTE: On Darwin, when using -flto along with -g and compiling and linking in separate steps, you also need to pass -Wl,-object_path_lto,<lto-filename>.o at the linking step to instruct the ld64 linker not to delete the temporary object file generated during Link Time Optimization (this flag is automatically passed to the linker by Clang if compilation and linking are done in a single step). This allows debugging the executable as well as generating the .dSYM bundle using dsymutil(1). 🫢

πŸš™ Driver Options πŸš™

  • -### β€” print (but do not run) the commands to run for this compilation. πŸ‘€
  • --help β€” display available options. πŸ†˜
  • -Qunused-arguments β€” do not emit any warnings for unused driver arguments. 🀫
  • -Wa,<args> β€” pass the comma separated arguments in args to the assembler. πŸ› οΈ
  • -Wl,<args> β€” pass the comma separated arguments in args to the linker. πŸ”—
  • -Wp,<args> β€” pass the comma separated arguments in args to the preprocessor. πŸ§ͺ
  • -Xanalyzer <arg> β€” pass arg to the static analyzer. πŸ”¬
  • -Xassembler <arg> β€” pass arg to the assembler. βš™οΈ
  • -Xlinker <arg> β€” pass arg to the linker. 🚚
  • -Xpreprocessor <arg> β€” pass arg to the preprocessor. 🧼
  • -o <file> β€” write output to file. πŸ“
  • -print-file-name=<file> β€” print the full library path of file. πŸ“š
  • -print-libgcc-file-name β€” print the library path for the currently used compiler runtime library ("libgcc.a" or "libclang_rt.builtins.*.a"). 🧱
  • -print-prog-name=<name> β€” print the full program path of name. 🧭
  • -print-search-dirs β€” print the paths used for finding libraries and programs. πŸ—ΊοΈ
  • -save-temps β€” save intermediate compilation results. 🧺
  • -save-stats, -save-stats=cwd, -save-stats=obj β€” save internal code generation (LLVM) statistics to a file in the current directory (-save-stats/-save-stats=cwd) or the directory of the output file (-save-stats=obj). πŸ“Š You can also use environment variables to control the statistics reporting. Setting CC_PRINT_INTERNAL_STAT to 1 enables the feature, the report goes to stdout in JSON format. Setting CC_PRINT_INTERNAL_STAT_FILE to a file path makes it report statistics to the given file in the JSON format. Note that -save-stats take precedence over CC_PRINT_INTERNAL_STAT and CC_PRINT_INTERNAL_STAT_FILE. πŸ‘‘
  • -integrated-as, -no-integrated-as β€” turns the integrated assembler on and off respectively. And whether it's already on by default? target dependent, bestie β€” it literally depends on where you're compiling 🎯
  • -time β€” clocks each individual command so you can see where the time went ⏱️
  • -ftime-report β€” prints a lil timing summary for every stage of compilation. receipts for your build πŸ”₯
  • -v β€” shows the commands being run and gives you verbose output. the yapper flag πŸ—£οΈβœ¨

🩺 Diagnostics Options 🩺

  • -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 β€” this whole lil squad controls how Clang prints out information about diagnostics (you know, errors and warnings πŸ’€). For the full tea, the manpage says to check the Clang User's Manual β€” iykyk πŸ“–

🧚 Preprocessor Options 🧚

  • -D<macroname>=<value> β€” sneaks an implicit #define into the predefines buffer, which gets read before your source file is preprocessed. free real estate define πŸ’…
  • -U<macroname> β€” same energy, opposite direction: adds an implicit #undef into the predefines buffer that's read before the source file is preprocessed πŸ™ˆ
  • -include <filename> β€” adds an implicit #include into the predefines buffer, read before the source file is preprocessed. surprise include, but make it intentional πŸŽ€
  • -I<directory> β€” adds the directory you point at to the search path for include files πŸ”
  • -F<directory> β€” adds the directory to the search path for framework include files (yes, frameworks specifically) 🍎
  • -nostdinc β€” do not search the standard system directories or the compiler builtin directories for include files. full isolation era 🚫
  • -nostdlibinc β€” skips the standard system directories for include files, but still does search compiler builtin include directories. so it's picky, not antisocial 🫢
  • -nobuiltininc β€” don't search clang's own builtin directory for include files πŸ βœ–οΈ
  • -nostdinc++ β€” don't search the system C++ standard library directory for include files πŸ¦‹
  • -fkeep-system-includes β€” usable only with -E. It does not copy the preprocessed content of "system" headers into the output; instead it preserves the #include directive. This can massively shrink the volume of text -E produces, which is lowkey helpful when you're trying to make a "small" reproducible test case πŸ“‰
But bestie, hear me: this option does not guarantee reproducibility. If the including source defines preprocessor symbols that influence the behavior of system headers (for example, _XOPEN_SOURCE), the operation of -E will remove that definition and thus can change the semantics of the included header. Also, using a different version of the system headers (especially a different version of the STL) may result in different behavior. Always verify the preprocessed file by compiling it separately. no cap, verify it πŸ’€

🌈 ENVIRONMENT 🌈

  • TMPDIR, TEMP, TMP β€” these environment variables get checked in order for the location to write temporary files used during the compilation process. first one wins, diva behavior πŸ’…
  • CPATH β€” specifies additional (non-system) header search paths used to find included header files. These paths are searched after paths specified with the -I<directory> option, but before any system header search paths. Paths are delimited by the platform dependent delimiter, same as what's used in the PATH environment variable. Empty entries in the delimited path list β€” including ones at the beginning or end of the list β€” are treated as specifying the compiler's current working directory πŸ—‚οΈβœ¨
  • C_INCLUDE_PATH, OBJC_INCLUDE_PATH, CPLUS_INCLUDE_PATH, OBJCPLUS_INCLUDE_PATH β€” these specify additional system header file search paths used when processing the corresponding language. Search paths are delimited just like for the CPATH environment variable πŸ§šβ€β™€οΈ
  • MACOSX_DEPLOYMENT_TARGET β€” if -mmacos-version-min is unspecified, the default deployment target is read from this environment variable. Heads up: this option only affects Darwin targets 🍏

πŸ’€ BUGS πŸ’€

To report bugs, please visit https://github.com/llvm/llvm-project/issues/ β€” that's the spot, bestie.

Most bug reports should include preprocessed source files (use the -E option πŸ‘€) and the full output of the compiler, along with information to reproduce. Give them everything, main character energy, don't make them ask twice 🫢


πŸ‘‘ SEE ALSO πŸ‘‘

as(1), ld(1)


🌸 AUTHOR 🌸

Maintained by the Clang / LLVM Team (http://clang.llvm.org) πŸ’œ


2007-2026, The Clang Team


and that's the whole page, bestie β€” slay, you read all of it πŸŽ‰ this edition is the 23 one, dated Oct 06, 2026, and it's signed CLANG(1). go forth and compile iconic things βœ¨πŸ’…πŸ¦‹

πŸ“¦ where this page comes from