CLANG(1)

๐Ÿ“ฆ
version 19.1.7 ยท 5 versions
, in fedora 43

๐Ÿ’… CLANG(1) โ€” the Clang compiler, but make it a group chat

okay bestie, sit down, hydrate, because clang(1) is the moment. this is the manual page for the Clang C, C++, and Objective-C compiler, and yes we are going through all of it. no skimming. no cap. ๐Ÿ’–


โœจ NAME โœจ

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


๐ŸŒธ SYNOPSIS ๐ŸŒธ

clang [options] filename ...

๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

so like, clang is a C, C++, and Objective-C compiler, and she does everything: preprocessing, parsing, optimization, code generation, assembly, and linking. all of it. she's booked and busy. ๐Ÿ’…

depending on which high-level mode setting you pass, Clang will stop before doing a full link. and listen โ€” even though Clang is super integrated, you gotta understand the stages of compilation to understand how to invoke her. it's giving "know your queen". these are the stages:

  • Driver โ€” the clang executable is actually just a lil 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 all those other tools. she's the manager 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 parse-tree form, it applies semantic analysis to compute types for expressions as well as to 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). ๐ŸŒณ
  • 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 queen. โœจ

  • 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's a detective, your honor. ๐Ÿ•ต๏ธโ€โ™€๏ธ


๐Ÿ’– OPTIONS ๐Ÿ’–

๐ŸŽ€ Stage Selection Options ๐ŸŽ€

  • -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 you don't specify any stage selection option, all the stages above get run, and then the linker is run to combine the results into an executable or shared library. 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.

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

the default C language standard is gnu17, except on PS4, where it is gnu99. (PS4 girlies stay winning, i guess ๐ŸŽฎ)

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

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, the platform default will be used.
  • -rtlib=<library> โ€” specify the compiler runtime library to use; supported options are libgcc and compiler-rt. if not specified, the 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 it is assumed that a freestanding environment will additionally provide memcpy, memmove, memset and memcmp implementations, as these are needed for efficient codegen for many programs. so like, you gotta bring your own snacks. ๐Ÿ“
  • -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.
  • -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. she's versatile like that. ๐Ÿงš

  • -arch <architecture> โ€” specify the architecture to build for (Mac OS X specific).
  • -target <architecture> โ€” specify the architecture to build for (all platforms).
  • -mmacos-version-min=<version> โ€” when building for macOS, specify the minimum version supported by your application.
  • -miphoneos-version-min โ€” when building for iPhone OS, specify the minimum version supported by your application.
  • --print-supported-cpus โ€” drops a whole list of supported processors for whatever target you're repping (say it with --target=<architecture> or -arch <architecture>). No target? Then it just uses your system default target. easy.
  • -mcpu=?, -mtune=? โ€” literally just an alias for --print-supported-cpus. same energy.
  • -mcpu=help, -mtune=help โ€” also an alias for --print-supported-cpus. yes bestie, all roads lead there.
  • -march=<cpu> โ€” tells Clang to generate code for a specific processor family member and later. so if you say -march=i486, the compiler is allowed to spit out instructions that are valid on i486 and everything after it โ€” but those instructions might not exist on earlier processors. iykyk.
  • --print-enabled-extensions โ€” prints the list of extensions that are turned on for the target you built out of the --target, -march, and -mcpu values combined. ngl, rn this one only works on AArch64 and RISC-V. on RISC-V it also prints the ISA string of the enabled extensions. slay.
  • --print-supported-extensions โ€” prints the list of all the extensions supported for every CPU target of an architecture (you specify it with --target=<architecture> or -arch <architecture>). no target given? system default target steps in. again, only supported on AArch64 and RISC-V for now.

โœจ Code Generation Options โœจ

  • -O0, -O1, -O2, -O3, -Ofast, -Os, -Oz, -Og, -O, -O4 โ€” pick your optimization level, bestie. here's the tea:
    • -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 is deprecated in Clang 19 and a warning gets emitted saying that -O3 in combination with -ffast-math should be used instead if the request for non-standard math behavior is intended. there's 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. ๐Ÿ’€ so like, be careful.
    • -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 like -O1. in future versions, this option might disable different optimizations in order to improve debuggability.
    • -O is equivalent to -O1.
    • -O4 and higher: currently equivalent to -O3.
  • -g, -gline-tables-only, -gmodules โ€” these control debug information output. heads up: Clang debug information works best at -O0. when more than one option starting with -g is specified, the last one wins (last one standing, periodt):
    • -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.
don't 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. not the vibe for shipping.
  • -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.

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. ok that's the rule, no exceptions.

  • -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, you can use the negation -fno-eliminate-unused-debug-types. flip it and reverse it. ๐Ÿฆ‹
  • -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++. iconic.
  • -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. it's giving safety net.
  • -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. main character energy: it wants the best for you.
  • -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). don't skip this step bestie, fr fr.

๐Ÿš— Driver Options ๐Ÿš—

  • -### โ€” print (but do not run) the commands to run for this compilation. peek but don't touch.
  • --help โ€” display available options.
  • -Qunused-arguments โ€” do not emit any warnings for unused driver arguments. no nagging, we love that.
  • -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-state=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. it's the boss here.
  • -integrated-as, -no-integrated-as โ€” used to enable and disable, respectively, the use of the integrated assembler. whether the integrated assembler is on by default is target dependent.
  • -time โ€” time individual commands. โฑ๏ธ
  • -ftime-report โ€” print timing summary of each stage of compilation.
  • -v โ€” show commands to run and use verbose output.

๐Ÿ” 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 โ€” these options control how Clang prints out information about diagnostics (errors and warnings). please see the Clang User's Manual for more information. โœจ

๐ŸŒธ Preprocessor Options ๐ŸŒธ

  • -D<macroname>=<value> โ€” bestie this sneaks an implicit #define into the predefines buffer, and that buffer gets read before your source file even gets preprocessed. so the macro is just... there. iconic.
  • -U<macroname> โ€” same vibe, opposite direction: adds an implicit #undef into the predefines buffer, read before the source file is preprocessed. undefining before you even defined anything? we love a preemptive strike ๐Ÿ’…
  • -include <filename> โ€” drops an implicit #include into the predefines buffer, and yeah, that buffer is read before your source file gets preprocessed. free include, no code changes.
  • -I<directory> โ€” adds the directory you name to the search path for include files. your headers, your rules ๐ŸŽ€
  • -F<directory> โ€” adds the directory you name to the search path for framework include files.
  • -nostdinc โ€” do not search the standard system directories, and also do not search the compiler builtin directories, for include files. full isolation era.
  • -nostdlibinc โ€” do not search the standard system directories for include files, but do still search compiler builtin include directories. bestie is picking and choosing, honestly valid.
  • -nobuiltininc โ€” do not search clang's builtin directory for include files.
  • -fkeep-system-includes โ€” okay so this one is only usable with -E. Instead of copying the preprocessed content of "system" headers into the output, it preserves the #include directive instead. The way this can greatly reduce the volume of text that -E produces ๐Ÿ˜ญ which is super helpful when you're trying to produce a "small" reproduceable test case.
But listen โ€” this option does not guarantee reproduceability. If the including source defines preprocessor symbols that influence the behavior of system headers (for example, _XOPEN_SOURCE), then -E will remove that definition, and that 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 skipping the vibe check on this one, fr fr.

๐ŸŒˆ ENVIRONMENT ๐ŸŒˆ

  • TMPDIR, TEMP, TMP โ€” these get checked, in order, for the location to write temporary files used during the compilation process. first one wins, so if you're being shady about temp files, they will find out ๐Ÿ‘€
  • CPATH โ€” if this environment variable is present, it's treated as a delimited list of paths to be added to the default system include path list. The delimiter is the platform dependent delimiter, as used in the PATH environment variable.

Empty components in the environment variable are ignored. (shoutout to empty components, they simply do not exist here ๐Ÿ’€)

  • C_INCLUDE_PATH, OBJC_INCLUDE_PATH, CPLUS_INCLUDE_PATH, OBJCPLUS_INCLUDE_PATH โ€” these environment variables specify additional paths, exactly as for CPATH, except they're only used when processing the appropriate language. so C paths for C, ObjC paths for ObjC, etc. each one knows its assignment โœจ
  • 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. Apple girlies only ๐ŸŽ

๐Ÿ’€ 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. like bestie, give us the receipts or we literally cannot help you ๐Ÿ™ˆ


๐Ÿซถ 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 ๐ŸŽ€ that version is from Mar 11, 2026 and it's page 19 of CLANG(1) โ€” slay, go compile something iconic โœจ๐Ÿ’…

๐Ÿ“ฆ where this page comes from