CLANG(1)

๐Ÿ’… clang โ€” the Clang C, C++, and Objective-C compiler

okay bestie, welcome to the clang(1) manual page, Clang edition. this is the whole thing, all of it, no skips. grab a boba, we're going in ๐Ÿง‹โœจ


โœจ NAME โœจ

clang โ€” literally the Clang C, C++, and Objective-C compiler. that's her. that's the whole name. iconic behavior ๐Ÿ‘‘

๐ŸŒธ SYNOPSIS ๐ŸŒธ

clang [options] filename ...

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

so clang is a C, C++, and Objective-C compiler, and she does everything โ€” preprocessing, parsing, optimization, code generation, assembly, and linking, all under one roof ๐Ÿ’… depending on which high-level mode setting you pass, Clang will stop before doing a full link. and like, even though Clang is super highly integrated, it's genuinely important to understand the stages of compilation so you know how to invoke her properly. here are the stages, bestie:

  • Driver โ€” the clang executable is actually just a small driver that controls the overall execution of the other tools like the compiler, assembler and linker. typically you don't need to interact with the driver directly, but you transparently use it to run the other tools. she's the manager fr fr.
  • 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.
  • 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 queen, 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. efficiency slay ๐Ÿ’…
  • 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. she will find your bugs, and honestly? good for her.


โœจ OPTIONS โœจ

๐ŸŽ€ Stage Selection Options

these are the "how far do you want me to go" options. pick your stopping point 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. all gas, no brakes ๐Ÿ”ฅ

๐Ÿฆ‹ Language Selection and Mode Options

  • -x <language> โ€” treat subsequent input files as having type language.
  • -std=<standard> โ€” specify the language standard to compile for.

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. (playstation girlies stay winning ๐ŸŽฎ)

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.
  • -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.
  • -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 but not that freestanding, okurrr ๐Ÿ™ˆ
  • -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. iykyk ๐Ÿ’…

  • -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. (she's giving chaos, but ok ๐Ÿซถ)
  • -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 โ€” it's not a bolted-on afterthought, it's the vibe โœจ 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.

  • -arch <architecture> โ€” specify the architecture to build for (Mac OS X specific).
  • -target <architecture> โ€” tells Clang which architecture to build for, on literally every platform ๐Ÿ’…
  • -mmacos-version-min=<version> โ€” building for macOS? This sets the minimum version your app supports, bestie.
  • -miphoneos-version-min โ€” same vibe, but for iPhone OS: sets the minimum version your app supports.
  • --print-supported-cpus โ€” prints out a whole list of supported processors for the target you're building for (the one you gave via --target=<architecture> or -arch <architecture>). Didn't specify a target? No worries, it just uses the system default target ๐Ÿ’ซ
  • -mcpu=?, -mtune=? โ€” lowkey just an alias for --print-supported-cpus.
  • -mcpu=help, -mtune=help โ€” yep, another alias for --print-supported-cpus. Same energy.
  • -march=<cpu> โ€” this one's saying "generate code for this specific processor family member and later." Like, if you pass -march=i486, the compiler is fully allowed to emit instructions that are valid on i486 and later processors โ€” but which may not exist on earlier ones. Iconic but spicy ๐ŸŒถ๏ธ
  • --print-enabled-extensions โ€” prints the list of extensions that are enabled for the target specified by the combo of your --target, -march, and -mcpu values. Heads up: right now this option is only supported on AArch64 and RISC-V. On RISC-V it also prints out the ISA string of the enabled extensions, which is a cute lil bonus ๐ŸŽ€
  • --print-supported-extensions โ€” prints the list of all the extensions supported for every CPU target for an architecture (that architecture coming from --target=<architecture> or -arch <architecture>). No target specified? System default target steps in. Again: currently only supported on AArch64 and RISC-V ๐Ÿฆ‹

โœจ Code Generation Options โœจ

  • -O0, -O1, -O2, -O3, -Ofast, -Os, -Oz, -Og, -O, -O4 โ€” okay so this is the optimization level lineup, and here's the tea on each one:
    • -O0 โ€” means "no optimization." This level compiles the fastest and generates the most debuggable code. Zero thoughts, just vibes ๐Ÿซง
    • -O1 โ€” somewhere between -O0 and -O2. That's it, that's the description.
    • -O2 โ€” moderate level of optimization which enables most optimizations. The reliable main character ๐Ÿ‘‘
    • -O3 โ€” like -O2, except it also enables optimizations that take longer to perform or that may generate larger code (the whole point being 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. Big warning energy here: this has been deprecated since Clang 19. There is no timeline yet for removal; the aim is to discourage use of -Ofast because of 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 โ€” cross-ref cmdoption-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 โ€” like -O2 with extra optimizations to reduce code size. Slimming down, we love to see it ๐Ÿ’…
  • -Oz โ€” like -Os (and thus -O2), but reduces code size even further.
  • -Og โ€” 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. Debugger girlies stay winning ๐Ÿ”ฅ
  • -O โ€” equivalent to -O1.
  • -O4 and higher โ€” currently equivalent to -O3. That's the whole thing.
  • -g, -gline-tables-only, -gmodules โ€” these control debug information output. Note (fr fr take this in): Clang debug information works best at -O0. And when more than one option starting with -g is specified, the last one wins ๐Ÿ˜ค
    • -g โ€” generate debug information. The classic.
    • -gline-tables-only โ€” generate 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. Like a backtrace with the plot but no character development.
    • -gmodules โ€” generate debug information that contains external references to types defined in Clang modules or precompiled headers instead of emitting redundant debug type information into every single 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. Genuinely obsessed ๐Ÿ’–
โš ๏ธ Do not use this option 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. That's a whole mess you don't want.
  • -fstandalone-debug, -fno-standalone-debug โ€” okay so 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 aren't 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.

The -fstandalone-debug option 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. Periodt.

  • -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. Giving those unused types their moment ๐ŸŒธ
  • -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. Snitches on your overflow ๐Ÿ’€
  • -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> โ€” sets 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). iykyk ๐Ÿงš

๐ŸŒˆ Driver Options ๐ŸŒˆ

  • -### โ€” print (but do not run) the commands to run for this compilation. All talk, no action ๐Ÿ’…
  • --help โ€” display available options.
  • -Qunused-arguments โ€” do not emit any warnings for unused driver arguments. Let it go, bestie.
  • -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. Simple as that ๐ŸŽ€
  • -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. Keep the receipts ๐Ÿงพ
  • -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, and 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. Numbers, but make it a vibe ๐Ÿ“Š

Heads-up: the page literally notes that -save-stats take precedence over CC_PRINT_INTERNAL_STAT and CC_PRINT_INTERNAL_STAT_FILE. ๐Ÿ’…
  • -integrated-as, -no-integrated-as โ€” turn the integrated assembler on and off, respectively. Whether the integrated assembler is on by default is target dependent.
  • -time โ€” time individual commands.
  • -ftime-report โ€” print a timing summary of each stage of compilation.
  • -v โ€” show commands to run and use verbose output.

๐Ÿฉบ Diagnostics Options

These options control how Clang prints out information about diagnostics โ€” a.k.a. errors and warnings, bestie. Please see the Clang User's Manual for more information.

  • -fshow-column โ€” diagnostics-output control; see the Clang User's Manual.
  • -fshow-source-location โ€” diagnostics-output control; see the Clang User's Manual.
  • -fcaret-diagnostics โ€” diagnostics-output control; see the Clang User's Manual.
  • -fdiagnostics-fixit-info โ€” diagnostics-output control; see the Clang User's Manual.
  • -fdiagnostics-parseable-fixits โ€” diagnostics-output control; see the Clang User's Manual.
  • -fdiagnostics-print-source-range-info โ€” diagnostics-output control; see the Clang User's Manual.
  • -fprint-source-range-info โ€” diagnostics-output control; see the Clang User's Manual.
  • -fdiagnostics-show-option โ€” diagnostics-output control; see the Clang User's Manual.
  • -fmessage-length โ€” diagnostics-output control; see the Clang User's Manual.

๐Ÿงช Preprocessor Options

  • -D<macroname>=<value> โ€” adds an implicit #define into the predefines buffer which is read before the source file is preprocessed.
  • -U<macroname> โ€” adds an implicit #undef into the predefines buffer which is read before the source file is preprocessed.
  • -include <filename> โ€” adds an implicit #include into the predefines buffer which is read before the source file is preprocessed.
  • -I<directory> โ€” add the specified directory to the search path for include files.
  • -F<directory> โ€” add the specified directory to the search path for framework include files.
  • -nostdinc โ€” do not search the standard system directories or compiler builtin directories for include files.
  • -nostdlibinc โ€” do not search the standard system directories for include files, but do search compiler builtin include directories.
  • -nobuiltininc โ€” do not search clang's builtin directory for include files.
  • -nostdinc++ โ€” do not search the system C++ standard library directory for include files.
  • -fkeep-system-includes โ€” usable only with -E. Do not copy the preprocessed content of "system" headers to the output; instead, preserve the #include directive. This can greatly reduce the volume of text produced by -E, which can be helpful when trying to produce a "small" reproduceable test case.

Okay but caveat time, because this next bit matters: this option does not guarantee reproduceability, however. 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. ๐Ÿซถ

๐ŸŒ ENVIRONMENT

  • TMPDIR, TEMP, TMP โ€” these environment variables are checked, in order, for the location to write temporary files used during the compilation process.
  • CPATH โ€” this environment variable specifies additional (non-system) header search paths to be 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 as used in the PATH environment variable. Empty entries in the delimited path list, including those 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 environment variables specify additional system header file search paths to be used when processing the corresponding language. Search paths are delimited as for the CPATH environment variable.
  • MACOSX_DEPLOYMENT_TARGET โ€” if -mmacos-version-min is unspecified, the default deployment target is read from this environment variable. This option only affects Darwin targets.

๐Ÿ› BUGS

To report bugs, please visit https://github.com/llvm/llvm-project/issues/. Most bug reports should include preprocessed source files (use the -E option) and the full output of the compiler, along with information to reproduce.

๐Ÿ‘€ SEE ALSO

๐Ÿซถ Author

Maintained by the Clang / LLVM Team (<http://clang.llvm.org>)

2007-2026, The Clang Team


Bye bestie!! That was the whole CLANG(1) page โ€” page 23, dated Oct 20, 2026 โ€” and honestly, she ate. ๐Ÿ’–โœจ๐ŸŽ€

๐Ÿ“ฆ where this page comes from
  • arch rolling: clang 23.1.4-1 ยท Apache-2.0 WITH LLVM-exception
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms