5 clang - the Clang C, C++, and Objective-C compiler
9 B<clang> [B<-c>|B<-S>|B<-E>] B<-std=>I<standard> B<-g>
10 [B<-O0>|B<-O1>|B<-O2>|B<-O3>|B<-Ofast>|B<-Os>|B<-Oz>|B<-O>|B<-O4>]
11 B<-W>I<warnings...> B<-pedantic>
12 B<-I>I<dir...> B<-L>I<dir...>
14 B<-f>I<feature-option...>
15 B<-m>I<machine-option...>
22 B<clang> is a C, C++, and Objective-C compiler which encompasses preprocessing,
23 parsing, optimization, code generation, assembly, and linking. Depending on
24 which high-level mode setting is passed, Clang will stop before doing a full
25 link. While Clang is highly integrated, it is important to understand the
26 stages of compilation, to understand how to invoke it. These stages are:
32 The B<clang> executable is actually a small driver which controls the overall
33 execution of other tools such as the compiler, assembler and linker. Typically
34 you do not need to interact with the driver, but you transparently use it to run
37 =item B<Preprocessing>
39 This stage handles tokenization of the input source file, macro expansion,
40 #include expansion and handling of other preprocessor directives. The output of
41 this stage is typically called a ".i" (for C), ".ii" (for C++), ".mi" (for
42 Objective-C) , or ".mii" (for Objective-C++) file.
44 =item B<Parsing and Semantic Analysis>
46 This stage parses the input file, translating preprocessor tokens into a parse
47 tree. Once in the form of a parser tree, it applies semantic analysis to compute
48 types for expressions as well and determine whether the code is well formed. This
49 stage is responsible for generating most of the compiler warnings as well as
50 parse errors. The output of this stage is an "Abstract Syntax Tree" (AST).
52 =item B<Code Generation and Optimization>
54 This stage translates an AST into low-level intermediate code (known as "LLVM
55 IR") and ultimately to machine code. This phase is responsible for optimizing
56 the generated code and handling target-specific code generation. The output of
57 this stage is typically called a ".s" file or "assembly" file.
59 Clang also supports the use of an integrated assembler, in which the code
60 generator produces object files directly. This avoids the overhead of generating
61 the ".s" file and of calling the target assembler.
65 This stage runs the target assembler to translate the output of the compiler
66 into a target object file. The output of this stage is typically called a ".o"
67 file or "object" file.
71 This stage runs the target linker to merge multiple object files into an
72 executable or dynamic library. The output of this stage is typically called an
73 "a.out", ".dylib" or ".so" file.
77 The Clang compiler supports a large number of options to control each of these
78 stages. In addition to compilation of code, Clang also supports other tools:
80 B<Clang Static Analyzer>
82 The Clang Static Analyzer is a tool that scans source code to try to find bugs
83 through code analysis. This tool uses many parts of Clang and is built into the
84 same driver. Please see L<http://clang-analyzer.llvm.org> for more details
85 on how to use the static analyzer.
90 =head2 Stage Selection Options
96 Run the preprocessor stage.
98 =item B<-fsyntax-only>
100 Run the preprocessor, parser and type checking stages.
104 Run the previous stages as well as LLVM generation and optimization stages and
105 target-specific code generation, producing an assembly file.
109 Run all of the above, plus the assembler, generating a target ".o" object file.
111 =item B<no stage selection option>
113 If no stage selection option is specified, all stages above are run, and the
114 linker is run to combine the results into an executable or shared library.
120 =head2 Language Selection and Mode Options
124 =item B<-x> I<language>
126 Treat subsequent input files as having type I<language>.
128 =item B<-std>=I<language>
130 Specify the language standard to compile for.
132 =item B<-stdlib>=I<library>
134 Specify the C++ standard library to use; supported options are libstdc++ and
143 Treat source input files as Objective-C++ inputs.
147 Treat source input files as Objective-C inputs.
153 =item B<-ffreestanding>
155 Indicate that the file should be compiled for a freestanding, not a hosted,
158 =item B<-fno-builtin>
160 Disable special handling and optimizations of builtin functions like strlen and
163 =item B<-fmath-errno>
165 Indicate that math functions should be treated as updating errno.
167 =item B<-fpascal-strings>
169 Enable support for Pascal-style strings with "\pfoo".
171 =item B<-fms-extensions>
173 Enable support for Microsoft extensions.
175 =item B<-fmsc-version=>
177 Set _MSC_VER. Defaults to 1300 on Windows. Not set otherwise.
179 =item B<-fborland-extensions>
181 Enable support for Borland extensions.
183 =item B<-fwritable-strings>
185 Make all string literals default to writable. This disables uniquing of
186 strings and other optimizations.
188 =item B<-flax-vector-conversions>
190 Allow loose type checking rules for implicit vector conversions.
194 Enable the "Blocks" language feature.
196 =item B<-fobjc-gc-only>
198 Indicate that Objective-C code should be compiled in GC-only mode, which only
199 works when Objective-C Garbage Collection is enabled.
203 Indicate that Objective-C code should be compiled in hybrid-GC mode, which works
204 with both GC and non-GC mode.
206 =item B<-fobjc-abi-version>=I<version>
208 Select the Objective-C ABI version to use. Available versions are 1 (legacy
209 "fragile" ABI), 2 (non-fragile ABI 1), and 3 (non-fragile ABI 2).
211 =item B<-fobjc-nonfragile-abi-version>=I<version>
213 Select the Objective-C non-fragile ABI version to use by default. This will only
214 be used as the Objective-C ABI when the non-fragile ABI is enabled (either via
215 -fobjc-nonfragile-abi, or because it is the platform default).
217 =item B<-fobjc-nonfragile-abi>
219 Enable use of the Objective-C non-fragile ABI. On platforms for which this is
220 the default ABI, it can be disabled with B<-fno-objc-nonfragile-abi>.
226 =head2 Target Selection Options
228 Clang fully supports cross compilation as an inherent part of its design.
229 Depending on how your version of Clang is configured, it may have support for
230 a number of cross compilers, or may only support a native target.
234 =item B<-arch> I<architecture>
236 Specify the architecture to build for.
238 =item B<-mmacosx-version-min>=I<version>
240 When building for Mac OS X, specify the minimum version supported by your
243 =item B<-miphoneos-version-min>
245 When building for iPhone OS, specify the minimum version supported by your
249 =item B<-march>=I<cpu>
251 Specify that Clang should generate code for a specific processor family member
252 and later. For example, if you specify -march=i486, the compiler is allowed to
253 generate instructions that are valid on i486 and later processors, but which
254 may not exist on earlier ones.
259 =head2 Code Generation Options
263 =item B<-O0> B<-O1> B<-O2> B<-O3> B<-Ofast> B<-Os> B<-Oz> B<-O> B<-O4>
265 Specify which optimization level to use:
271 Means "no optimization": this level compiles the fastest and
272 generates the most debuggable code.
276 Somewhere between B<-O0> and B<-O2>.
280 Moderate level of optimization which enables most optimizations.
284 Like B<-O2>, except that it enables optimizations that take longer to perform
285 or that may generate larger code (in an attempt to make the program run faster).
289 Enables all the optimizations from B<-O3> along with other aggressive
290 optimizations that may violate strict compliance with language standards.
294 Like B<-O2> with extra optimizations to reduce code size.
298 Like B<-Os> (and thus B<-O2>), but reduces code size further.
302 Equivalent to B<-O2>.
304 =item B<-O4> and higher
306 Currently equivalent to B<-O3>
312 Generate debug information. Note that Clang debug information works best at
315 =item B<-fstandalone-debug> B<-fno-standalone-debug>
317 Clang supports a number of optimizations to reduce the size of debug
318 information in the binary. They work based on the assumption that the
319 debug type information can be spread out over multiple compilation
320 units. For instance, Clang will not emit type definitions for types
321 that are not needed by a module and could be replaced with a forward
322 declaration. Further, Clang will only emit type info for a dynamic
323 C++ class in the module that contains the vtable for the class.
325 The B<-fstandalone-debug> option turns off these optimizations. This
326 is useful when working with 3rd-party libraries that don't come with
327 debug information. This is the default on Darwin. Note that Clang
328 will never emit type information for types that are not referenced at
331 =item B<-fexceptions>
333 Enable generation of unwind information, this allows exceptions to be thrown
334 through Clang compiled stack frames. This is on by default in x86-64.
338 Generate code to catch integer overflow errors. Signed integer overflow is
339 undefined in C, with this flag, extra code is generated to detect this and abort
343 =item B<-fvisibility>
345 This flag sets the default visibility level.
349 This flag specifies that variables without initializers get common linkage. It
350 can be disabled with B<-fno-common>.
354 Set the default thread-local storage (TLS) model to use for thread-local
355 variables. Valid values are: "global-dynamic", "local-dynamic", "initial-exec"
356 and "local-exec". The default is "global-dynamic". The default model can be
357 overridden with the tls_model attribute. The compiler will try to choose a more
358 efficient model if possible.
360 =item B<-flto> B<-emit-llvm>
362 Generate output files in LLVM formats, suitable for link time optimization. When
363 used with B<-S> this generates LLVM intermediate language assembly files,
364 otherwise this generates LLVM bitcode format object files (which may be passed
365 to the linker depending on the stage selection options).
369 ##=item B<-fnext-runtime> B<-fobjc-nonfragile-abi> B<-fgnu-runtime>
370 ##These options specify which Objective-C runtime the code generator should
371 ##target. FIXME: we don't want people poking these generally.
378 =head2 Driver Options
384 Print (but do not run) the commands to run for this compilation.
388 Display available options.
390 =item B<-Qunused-arguments>
392 Don't emit warning for unused driver arguments.
396 Pass the comma separated arguments in I<args> to the assembler.
400 Pass the comma separated arguments in I<args> to the linker.
404 Pass the comma separated arguments in I<args> to the preprocessor.
406 =item B<-Xanalyzer> I<arg>
408 Pass I<arg> to the static analyzer.
410 =item B<-Xassembler> I<arg>
412 Pass I<arg> to the assembler.
414 =item B<-Xlinker> I<arg>
416 Pass I<arg> to the linker.
418 =item B<-Xpreprocessor> I<arg>
420 Pass I<arg> to the preprocessor.
424 Write output to I<file>.
426 =item B<-print-file-name>=I<file>
428 Print the full library path of I<file>.
430 =item B<-print-libgcc-file-name>
432 Print the library path for "libgcc.a".
434 =item B<-print-prog-name>=I<name>
436 Print the full program path of I<name>.
438 =item B<-print-search-dirs>
440 Print the paths used for finding libraries and programs.
444 Save intermediate compilation results.
446 =item B<-integrated-as> B<-no-integrated-as>
448 Used to enable and disable, respectively, the use of the integrated
449 assembler. Whether the integrated assembler is on by default is target
454 Time individual commands.
456 =item B<-ftime-report>
458 Print timing summary of each stage of compilation.
462 Show commands to run and use verbose output.
467 =head2 Diagnostics Options
471 =item B<-fshow-column>
472 B<-fshow-source-location>
473 B<-fcaret-diagnostics>
474 B<-fdiagnostics-fixit-info>
475 B<-fdiagnostics-parseable-fixits>
476 B<-fdiagnostics-print-source-range-info>
477 B<-fprint-source-range-info>
478 B<-fdiagnostics-show-option>
481 These options control how Clang prints out information about diagnostics (errors
482 and warnings). Please see the Clang User's Manual for more information.
487 =head2 Preprocessor Options
491 =item B<-D>I<macroname=value>
493 Adds an implicit #define into the predefines buffer which is read before the
494 source file is preprocessed.
496 =item B<-U>I<macroname>
498 Adds an implicit #undef into the predefines buffer which is read before the
499 source file is preprocessed.
501 =item B<-include> I<filename>
503 Adds an implicit #include into the predefines buffer which is read before the
504 source file is preprocessed.
506 =item B<-I>I<directory>
508 Add the specified directory to the search path for include files.
510 =item B<-F>I<directory>
512 Add the specified directory to the search path for framework include files.
516 Do not search the standard system directories or compiler builtin directories
519 =item B<-nostdlibinc>
521 Do not search the standard system directories for include files, but do search
522 compiler builtin include directories.
524 =item B<-nobuiltininc>
526 Do not search clang's builtin directory for include files.
530 ## TODO, but do we really want people using this stuff?
531 #=item B<-idirafter>I<directory>
532 #=item B<-iquote>I<directory>
533 #=item B<-isystem>I<directory>
534 #=item B<-iprefix>I<directory>
535 #=item B<-iwithprefix>I<directory>
536 #=item B<-iwithprefixbefore>I<directory>
549 #=head2 Warning Control Options
552 #=head2 Code Generation and Optimization Options
555 #=head2 Assembler Options
558 #=head2 Linker Options
561 #=head2 Static Analyzer Options
572 =item B<TMPDIR>, B<TEMP>, B<TMP>
574 These environment variables are checked, in order, for the location to
575 write temporary files used during the compilation process.
579 If this environment variable is present, it is treated as a delimited
580 list of paths to be added to the default system include path list. The
581 delimiter is the platform dependent delimitor, as used in the I<PATH>
582 environment variable.
584 Empty components in the environment variable are ignored.
586 =item B<C_INCLUDE_PATH>, B<OBJC_INCLUDE_PATH>, B<CPLUS_INCLUDE_PATH>,
587 B<OBJCPLUS_INCLUDE_PATH>
589 These environment variables specify additional paths, as for CPATH,
590 which are only used when processing the appropriate language.
592 =item B<MACOSX_DEPLOYMENT_TARGET>
594 If -mmacosx-version-min is unspecified, the default deployment target
595 is read from this environment variable. This option only affects darwin
602 To report bugs, please visit L<http://llvm.org/bugs/>. Most bug reports should
603 include preprocessed source files (use the B<-E> option) and the full output of
604 the compiler, along with information to reproduce.
612 Maintained by the Clang / LLVM Team (L<http://clang.llvm.org>).