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
clangexecutable 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,
#includeexpansion 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:
c89c90iso9899:1990โ ISO C 1990iso9899:199409โ ISO C 1990 with amendment 1gnu89gnu90โ ISO C 1990 with GNU extensionsc99iso9899:1999โ ISO C 1999gnu99โ ISO C 1999 with GNU extensionsc11iso9899:2011โ ISO C 2011gnu11โ ISO C 2011 with GNU extensionsc17iso9899:2017โ ISO C 2017gnu17โ ISO C 2017 with GNU extensionsc23iso9899:2024โ ISO C 2023gnu23โ ISO C 2023 with GNU extensionsc2yโ ISO C 202ygnu2yโ 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++98c++03โ ISO C++ 1998 with amendmentsgnu++98gnu++03โ ISO C++ 1998 with amendments and GNU extensionsc++11โ ISO C++ 2011 with amendmentsgnu++11โ ISO C++ 2011 with amendments and GNU extensionsc++14โ ISO C++ 2014 with amendmentsgnu++14โ ISO C++ 2014 with amendments and GNU extensionsc++17โ ISO C++ 2017 with amendmentsgnu++17โ ISO C++ 2017 with amendments and GNU extensionsc++20โ ISO C++ 2020 with amendmentsgnu++20โ ISO C++ 2020 with amendments and GNU extensionsc++23โ ISO C++ 2023 with amendmentsgnu++23โ ISO C++ 2023 with amendments and GNU extensionsc++2cโ working draft for C++2cgnu++2cโ working draft for C++2c with GNU extensionsc++2dโ working draft for C++2dgnu++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.0cl1.1โ OpenCL 1.1cl1.2โ OpenCL 1.2cl2.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 arelibstdc++andlibc++. if not specified, platform default will be used.-rtlib=<library>โ specify the compiler runtime library to use; supported options arelibgccandcompiler-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 likememcpy,memmove, andmemset. so like, freestanding but not that freestanding, okurrr ๐-fno-builtinโ disable special handling and optimizations of well-known library functions, likestrlen()andmalloc().-fno-builtin-<function>โ disable special handling and optimizations for the specific library function. for example,-fno-builtin-strlenremoves any special handling for thestrlen()library function.-fno-builtin-std-<function>โ disable special handling and optimizations for the specific C++ standard library function in namespacestd. for example,-fno-builtin-std-move_if_noexceptremoves any special handling for thestd::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 updatingerrno.-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 ofcl.exe, or1933. 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 vectorsinteger: allow implicit bitcasts between integer vectors of the same overall bit-widthall: 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 are1(legacy "fragile" ABI),2(non-fragile ABI 1), and3(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-mcpuvalues. 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-O0and-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-O3along 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-Ofastbecause 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-O2with 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-livenessflag 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.-O4and 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-gis 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-typescan 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 thetls_modelattribute. 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-Sthis 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-fltoalong with-gand compiling and linking in separate steps, you also need to pass-Wl,-object_path_lto,<lto-filename>.oat the linking step to instruct theld64linker 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.dSYMbundle usingdsymutil(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-statstake precedence overCC_PRINT_INTERNAL_STATandCC_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#defineinto the predefines buffer which is read before the source file is preprocessed.-U<macroname>โ adds an implicit#undefinto the predefines buffer which is read before the source file is preprocessed.-include <filename>โ adds an implicit#includeinto 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#includedirective. 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 thePATHenvironment 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 theCPATHenvironment variable.MACOSX_DEPLOYMENT_TARGETโ if-mmacos-version-minis 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>)
ยฉ๏ธ Copyright
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