5 clang - the Clang 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<-Os>|B<-O3>|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...>
21 B<clang> is a C and Objective-C compiler which encompasses preprocessing,
22 parsing, optimization, code generation, assembly, and linking. Depending on
23 which high-level mode setting is passed, Clang will stop before doing a full
24 link. While Clang is highly integrated, it is important to understand the
25 stages of compilation, to understand how to invoke it. These stages are:
31 The B<clang> executable is actually a small driver which controls the overall
32 execution of other tools such as the compiler, assembler and linker. Typically
33 you do not need to interact with the driver, but you transparently use it to run
36 =item B<Preprocessing>
38 This stage handles tokenization of the input source file, macro expansion,
39 #include expansion and handling of other preprocessor directives. The output of
40 this stage is typically called a ".i" (for C) or ".mi" (for Objective-C) file.
42 =item B<Parsing and Semantic Analysis>
44 This stage parses the input file, translating preprocessor tokens into a parse
45 tree. Once in the form of a parser tree, it applies semantic analysis to compute
46 types for expressions as well and determine whether the code is well formed. This
47 stage is responsible for generating most of the compiler warnings as well as
48 parse errors. The output of this stage is an "Abstract Syntax Tree" (AST).
50 =item B<Code Generation and Optimization>
52 This stage translates an AST into low-level intermediate code (known as "LLVM
53 IR") and ultimately to machine code (depending on the optimization level). This
54 phase is responsible for optimizing the generated code and handling
55 target-specfic code generation. The output of this stage is typically called a
56 ".s" file or "assembly" file.
60 This stage runs the target assembler to translate the output of the compiler
61 into a target object file. The output of this stage is typically called a ".o"
62 file or "object" file.
66 This stage runs the target linker to merge multiple object files into an
67 executable or dynamic library. The output of this stage is typically called an
68 "a.out", ".dylib" or ".so" file.
72 The Clang compiler supports a large number of options to control each of these
73 stages. In addition to compilation of code, Clang also supports other tools:
75 B<Clang Static Analyzer>
77 The Clang Static Analyzer is a tool that scans source code to try to find bugs
78 though code analysis. This tool uses many parts of Clang and is built into the
84 =head2 Stage Selection Options
90 Run the preprocessor stage.
92 =item B<-fsyntax-only>
94 Run the preprocessor, parser and type checking stages.
98 Run the previous stages as well as LLVM generation and optimization stages and
99 target-specific code generation, producing an assembly file.
103 Run all of the above, plus the assembler, generating a target ".o" object file.
105 =item B<no stage selection option>
107 If no stage selection option is specified, all stages above are run, and the
108 linker is run to combine the results into an executable or shared library.
112 Run the Clang Static Analyzer.
118 =head2 Language Selection and Mode Options
122 =item B<-x> I<language>
124 Treat subsequent input files as having type I<language>.
126 =item B<-std>=I<language>
128 Specify the language standard to compile for.
136 Treat source input files as Objective-C++ inputs.
140 Treat source input files as Objective-C inputs.
146 =item B<-ffreestanding>
148 Indicate that the file should be compiled for a freestanding, not a hosted,
151 =item B<-fno-builtin>
153 Disable special handling and optimizations of builtin functions like strlen and
156 =item B<-fmath-errno>
158 Indicate that math functions should be treated as updating errno.
160 =item B<-fpascal-strings>
162 Enable support for Pascal-style strings with "\pfoo".
164 =item B<-fms-extensions>
166 Enable support for Microsoft extensions.
168 =item B<-fwritable-strings>
170 Make all string literals default to writable. This disables uniquing of
171 strings and other optimizations.
173 =item B<-flax-vector-conversions>
175 Allow loose type checking rules for implicit vector conversions.
179 Enable the "Blocks" language feature.
182 =item B<-fobjc-gc-only>
184 Indicate that Objective-C code should be compiled in GC-only mode, which only
185 works when Objective-C Garbage Collection is enabled.
189 Indicate that Objective-C code should be compiled in hybrid-GC mode, which works
190 with both GC and non-GC mode.
196 =head2 Target Selection Options
198 Clang fully supports cross compilation as an inherent part of its design.
199 Depending on how your version of Clang is configured, it may have support for
200 a number of cross compilers, or may only support a native target.
204 =item B<-arch> I<architecture>
206 Specify the architecture to build for.
208 =item B<-mmacosx-version-min>=I<version>
210 When building for Mac OS/X, specify the minimum version supported by your
213 =item B<-miphoneos-version-min>
215 When building for iPhone OS, specify the minimum version supported by your
219 =item B<-march>=I<cpu>
221 Specify that Clang should generate code for a specific processor family member
222 and later. For example, if you specify -march=i486, the compiler is allowed to
223 generate instructions that are valid on i486 and later processors, but which
224 may not exist on earlier ones.
229 =head2 Code Generation Options
233 =item B<-O0> B<-O1> B<-O2> B<-Os> B<-O3> B<-O4>
235 Specify which optimization level to use. B<-O0> means "no optimization": this
236 level compiles the fastest and generates the most debuggable code. B<-O2> is a
237 moderate level of optimization which enables most optimizations. B<-Os> is like
238 B<-O2> with extra optimizations to reduce code size. B<-O3> is like B<-O2>,
239 except that it enables optimizations that take longer to perform or that may
240 generate larger code (in an attempt to make the program run faster). On
241 supported platforms, B<-O4> enables link-time optimization; object files are
242 stored in the LLVM bitcode file format and whole program optimization is done at
243 link time. B<-O1> is somewhere between B<-O0> and B<-O2>.
247 Generate debug information. Note that Clang debug information works best at
248 B<-O0>. At higher optimization levels, only line number information is
251 =item B<-fexceptions>
253 Enable generation of unwind information, this allows exceptions to be thrown
254 through Clang compiled stack frames. This is on by default in x86-64.
258 Generate code to catch integer overflow errors. Signed integer overflow is
259 undefined in C, with this flag, extra code is generated to detect this and abort
263 =item B<-fvisibility>
265 This flag sets the default visibility level.
269 This flag specifies that variables without initializers get common linkage. It
270 can be disabled with B<-fno-common>.
272 =item B<-flto> B<-emit-llvm>
274 Generate output files in LLVM formats, suitable for link time optimization. When
275 used with B<-S> this generates LLVM intermediate language assembly files,
276 otherwise this generates LLVM bitcode format object files (which may be passed
277 to the linker depending on the stage selection options).
281 ##=item B<-fnext-runtime> B<-fobjc-nonfragile-abi> B<-fgnu-runtime>
282 ##These options specify which Objective-C runtime the code generator should
283 ##target. FIXME: we don't want people poking these generally.
290 =head2 Driver Options
296 Print the commands to run for this compilation.
300 Display available options.
302 =item B<-Qunused-arguments>
304 Don't emit warning for unused driver arguments.
308 Pass the comma separated arguments in I<args> to the assembler.
312 Pass the comma separated arguments in I<args> to the linker.
316 Pass the comma separated arguments in I<args> to the preprocessor.
318 =item B<-Xanalyzer> I<arg>
320 Pass I<arg> to the static analyzer.
322 =item B<-Xassembler> I<arg>
324 Pass I<arg> to the assembler.
326 =item B<-Xclang> I<arg>
328 Pass I<arg> to the clang compiler.
330 =item B<-Xlinker> I<arg>
332 Pass I<arg> to the linker.
334 =item B<-Xpreprocessor> I<arg>
336 Pass I<arg> to the preprocessor.
340 Write output to I<file>.
342 =item B<-print-file-name>=I<file>
344 Print the full library path of I<file>.
346 =item B<-print-libgcc-file-name>
348 Print the library path for "libgcc.a".
350 =item B<-print-prog-name>=I<name>
352 Print the full program path of I<name>.
354 =item B<-print-search-dirs>
356 Print the paths used for finding libraries and programs.
360 Save intermediate compilation results.
364 Time individual commands.
366 =item B<-ftime-report>
368 Print timing summary of each stage of compilation.
372 Show commands to run and use verbose output.
377 =head2 Diagnostics Options
381 =item B<-fshow-column>
382 B<-fshow-source-location>
383 B<-fcaret-diagnostics>
384 B<-fdiagnostics-fixit-info>
385 B<-fdiagnostics-print-source-range-info>
386 B<-fprint-source-range-info>
387 B<-fdiagnostics-show-option>
390 These options control how Clang prints out information about diagnostics (errors
391 and warnings). Please see the Clang User's Manual for more information.
396 =head2 Preprocessor Options
400 =item B<-D>I<macroname=value>
402 Adds an implicit #define into the predefines buffer which is read before the
403 source file is preprocessed.
405 =item B<-U>I<macroname>
407 Adds an implicit #undef into the predefines buffer which is read before the
408 source file is preprocessed.
410 =item B<-include> I<filename>
412 Adds an implicit #include into the predefines buffer which is read before the
413 source file is preprocessed.
415 =item B<-I>I<directory>
417 Add the specified directory to the search path for include files.
419 =item B<-F>I<directory>
421 Add the specified directory to the search path for framework include files.
425 Do not search the standard system directories for include files.
427 =item B<-nobuiltininc>
429 Do not search clang's builtin directory for include files.
433 ## TODO, but do we really want people using this stuff?
434 #=item B<-idirafter>I<directory>
435 #=item B<-iquote>I<directory>
436 #=item B<-isystem>I<directory>
437 #=item B<-iprefix>I<directory>
438 #=item B<-iwithprefix>I<directory>
439 #=item B<-iwithprefixbefore>I<directory>
452 #=head2 Warning Control Options
455 #=head2 Code Generation and Optimization Options
458 #=head2 Assembler Options
461 #=head2 Linker Options
464 #=head2 Static Analyzer Options
475 =item B<TMPDIR>, B<TEMP>, B<TMP>
477 These environment variables are checked, in order, for the location to
478 write temporary files used during the compilation process.
482 If this environment variable is present, it is treated as a delimited
483 list of paths to be added to the default system include path list. The
484 delimiter is the platform dependent delimitor, as used in the I<PATH>
485 environment variable.
487 Empty components in the environment variable are ignored.
489 =item B<C_INCLUDE_PATH>, B<OBJC_INCLUDE_PATH>, B<CPLUS_INCLUDE_PATH>,
490 B<OBJCPLUS_INCLUDE_PATH>
492 These environment variables specify additional paths, as for CPATH,
493 which are only used when processing the appropriate language.
495 =item B<MACOSX_DEPLOYMENT_TARGET>
497 If -mmacosx-version-min is unspecified, the default deployment target
498 is read from this environment variable. This option only affects darwin
505 Clang currently does not have C++ support, and this manual page is incomplete.
506 To report bugs, please visit L<http://llvm.org/bugs/>. Most bug reports should
507 include preprocessed source files (use the B<-E> option) and the full output of
508 the compiler, along with information to reproduce.
516 Maintained by the Clang / LLVM Team (L<http://clang.llvm.org>).