blob: c520f93997e53ffe4f21315a258f260e4b82c028 [file] [log] [blame]
Daniel Dunbardbec0332009-04-29 01:00:32 +00001=pod
2
3=head1 NAME
4
Chris Lattnerb5f6e802009-05-06 02:47:51 +00005clang - the Clang C and Objective-C compiler
Daniel Dunbardbec0332009-04-29 01:00:32 +00006
7=head1 SYNOPSIS
8
Chris Lattnerb5f6e802009-05-06 02:47:51 +00009B<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...>
13 B<-D>I<macro[=defn]>
14 B<-f>I<feature-option...>
15 B<-m>I<machine-option...>
16 B<-o> I<output-file>
17 I<input-filenames>
Daniel Dunbardbec0332009-04-29 01:00:32 +000018
19=head1 DESCRIPTION
20
Chris Lattnerb5f6e802009-05-06 02:47:51 +000021B<clang> is a C and Objective-C compiler which encompasses preprocessing,
22parsing, optimization, code generation, assembly, and linking. Depending on
23which high-level mode setting is passed, Clang will stop before doing a full
24link. While Clang is highly integrated, it is important to understand the
25stages of compilation, to understand how to invoke it. These stages are:
Daniel Dunbardbec0332009-04-29 01:00:32 +000026
27=over
28
Chris Lattnerb5f6e802009-05-06 02:47:51 +000029=item B<Driver>
Daniel Dunbardbec0332009-04-29 01:00:32 +000030
Chris Lattnerb5f6e802009-05-06 02:47:51 +000031The B<clang> executable is actually a small driver which controls the overall
32execution of other tools such as the compiler, assembler and linker. Typically
33you do not need to interact with the driver, but you transparently use it to run
34the other tools.
Daniel Dunbardbec0332009-04-29 01:00:32 +000035
Chris Lattnerb5f6e802009-05-06 02:47:51 +000036=item B<Preprocessing>
Daniel Dunbardbec0332009-04-29 01:00:32 +000037
Chris Lattnerb5f6e802009-05-06 02:47:51 +000038This stage handles tokenization of the input source file, macro expansion,
39#include expansion and handling of other preprocessor directives. The output of
40this stage is typically called a ".i" (for C) or ".mi" (for Objective-C) file.
41
42=item B<Parsing and Semantic Analysis>
43
44This stage parses the input file, translating preprocessor tokens into a parse
45tree. Once in the form of a parser tree, it applies semantic analysis to compute
46types for expressions as well and determine whether the code is well formed. This
47stage is responsible for generating most of the compiler warnings as well as
48parse errors. The output of this stage is an "Abstract Syntax Tree" (AST).
49
50=item B<Code Generation and Optimization>
51
Chris Lattner482c6822009-05-11 22:45:37 +000052This stage translates an AST into low-level intermediate code (known as "LLVM
53IR") and ultimately to machine code (depending on the optimization level). This
54phase is responsible for optimizing the generated code and handling
55target-specfic code generation. The output of this stage is typically called a
56".s" file or "assembly" file.
Chris Lattnerb5f6e802009-05-06 02:47:51 +000057
Chris Lattner9b081c62009-05-06 17:22:08 +000058=item B<Assembler>
Chris Lattnerb5f6e802009-05-06 02:47:51 +000059
60This stage runs the target assembler to translate the output of the compiler
61into a target object file. The output of this stage is typically called a ".o"
Chris Lattner482c6822009-05-11 22:45:37 +000062file or "object" file.
Chris Lattnerb5f6e802009-05-06 02:47:51 +000063
Chris Lattner9b081c62009-05-06 17:22:08 +000064=item B<Linker>
Chris Lattnerb5f6e802009-05-06 02:47:51 +000065
66This stage runs the target linker to merge multiple object files into an
67executable or dynamic library. The output of this stage is typically called an
68"a.out", ".dylib" or ".so" file.
69
70=back
71
72The Clang compiler supports a large number of options to control each of these
Chris Lattner482c6822009-05-11 22:45:37 +000073stages. In addition to compilation of code, Clang also supports other tools:
Chris Lattner9b081c62009-05-06 17:22:08 +000074
75B<Clang Static Analyzer>
76
77The Clang Static Analyzer is a tool that scans source code to try to find bugs
78though code analysis. This tool uses many parts of Clang and is built into the
79same driver.
80
Chris Lattnerb5f6e802009-05-06 02:47:51 +000081
82=head1 OPTIONS
83
Chris Lattnerb5f6e802009-05-06 02:47:51 +000084=head2 Stage Selection Options
85
86=over
Daniel Dunbardbec0332009-04-29 01:00:32 +000087
Daniel Dunbardbec0332009-04-29 01:00:32 +000088=item B<-E>
89
Chris Lattner9b081c62009-05-06 17:22:08 +000090Run the preprocessor stage.
Daniel Dunbardbec0332009-04-29 01:00:32 +000091
Chris Lattner9b081c62009-05-06 17:22:08 +000092=item B<-fsyntax-only>
Chris Lattnerb5f6e802009-05-06 02:47:51 +000093
Chris Lattner9b081c62009-05-06 17:22:08 +000094Run the preprocessor, parser and type checking stages.
Chris Lattnerb5f6e802009-05-06 02:47:51 +000095
Chris Lattner9b081c62009-05-06 17:22:08 +000096=item B<-S>
Chris Lattnerb5f6e802009-05-06 02:47:51 +000097
Daniel Dunbar94f497b2009-05-18 21:34:46 +000098Run the previous stages as well as LLVM generation and optimization stages and
99target-specific code generation, producing an assembly file.
Chris Lattnerb5f6e802009-05-06 02:47:51 +0000100
Chris Lattner9b081c62009-05-06 17:22:08 +0000101=item B<-c>
102
103Run all of the above, plus the assembler, generating a target ".o" object file.
104
105=item B<no stage selection option>
106
107If no stage selection option is specified, all stages above are run, and the
108linker is run to combine the results into an executable or shared library.
109
110=item B<--analyze>
111
112Run the Clang Static Analyzer.
Chris Lattnerb5f6e802009-05-06 02:47:51 +0000113
114=back
115
116
117
Chris Lattner04005dd2009-05-12 00:01:32 +0000118=head2 Language Selection and Mode Options
119
120=over
121
122=item B<-x> I<language>
123
124Treat subsequent input files as having type I<language>.
125
126=item B<-std>=I<language>
127
128Specify the language standard to compile for.
129
130=item B<-ansi>
131
132Same as B<-std=c89>.
133
134=item B<-ObjC++>
135
Daniel Dunbar94f497b2009-05-18 21:34:46 +0000136Treat source input files as Objective-C++ inputs.
Chris Lattner04005dd2009-05-12 00:01:32 +0000137
138=item B<-ObjC>
139
Daniel Dunbar94f497b2009-05-18 21:34:46 +0000140Treat source input files as Objective-C inputs.
Chris Lattner04005dd2009-05-12 00:01:32 +0000141
142=item B<-trigraphs>
143
144Enable trigraphs.
145
146=item B<-ffreestanding>
147
148Indicate that the file should be compiled for a freestanding, not a hosted,
149environment.
150
151=item B<-fno-builtin>
152
153Disable special handling and optimizations of builtin functions like strlen and
154malloc.
155
156=item B<-fmath-errno>
157
158Indicate that math functions should be treated as updating errno.
159
160=item B<-fpascal-strings>
161
162Enable support for Pascal-style strings with "\pfoo".
163
164=item B<-fms-extensions>
165
166Enable support for Microsoft extensions.
167
168=item B<-fwritable-strings>
169
170Make all string literals default to writable. This disables uniquing of
171strings and other optimizations.
172
173=item B<-flax-vector-conversions>
174
175Allow loose type checking rules for implicit vector conversions.
176
177=item B<-fblocks>
178
179Enable the "Blocks" language feature.
180
181
182=item B<-fobjc-gc-only>
183
184Indicate that Objective-C code should be compiled in GC-only mode, which only
185works when Objective-C Garbage Collection is enabled.
186
187=item B<-fobjc-gc>
188
189Indicate that Objective-C code should be compiled in hybrid-GC mode, which works
190with both GC and non-GC mode.
191
192=back
193
194
195
196=head2 Target Selection Options
197
Daniel Dunbar94f497b2009-05-18 21:34:46 +0000198Clang fully supports cross compilation as an inherent part of its design.
Chris Lattner04005dd2009-05-12 00:01:32 +0000199Depending on how your version of Clang is configured, it may have support for
Daniel Dunbar94f497b2009-05-18 21:34:46 +0000200a number of cross compilers, or may only support a native target.
Chris Lattner04005dd2009-05-12 00:01:32 +0000201
202=over
203
Chris Lattner04005dd2009-05-12 00:01:32 +0000204=item B<-arch> I<architecture>
205
206Specify the architecture to build for.
207
208=item B<-mmacosx-version-min>=I<version>
209
210When building for Mac OS/X, specify the minimum version supported by your
211application.
212
213=item B<-miphoneos-version-min>
214
215When building for iPhone OS, specify the minimum version supported by your
216application.
217
218
219=item B<-march>=I<cpu>
220
221Specify that Clang should generate code for a specific processor family member
222and later. For example, if you specify -march=i486, the compiler is allowed to
223generate instructions that are valid on i486 and later processors, but which
224may not exist on earlier ones.
225
226=back
227
228
229=head2 Code Generation Options
230
231=over
232
233=item B<-O0> B<-O1> B<-O2> B<-Os> B<-O3> B<-O4>
234
235Specify which optimization level to use. B<-O0> means "no optimization": this
Daniel Dunbar94f497b2009-05-18 21:34:46 +0000236level compiles the fastest and generates the most debuggable code. B<-O2> is a
237moderate level of optimization which enables most optimizations. B<-Os> is like
238B<-O2> with extra optimizations to reduce code size. B<-O3> is like B<-O2>,
239except that it enables optimizations that take longer to perform or that may
240generate larger code (in an attempt to make the program run faster). On
241supported platforms, B<-O4> enables link-time optimization; object files are
242stored in the LLVM bitcode file format and whole program optimization is done at
243link time. B<-O1> is somewhere between B<-O0> and B<-O2>.
Chris Lattner04005dd2009-05-12 00:01:32 +0000244
245=item B<-g>
246
247Generate debug information. Note that Clang debug information works best at
248B<-O0>. At higher optimization levels, only line number information is
249currently available.
250
251=item B<-fexceptions>
252
253Enable generation of unwind information, this allows exceptions to be thrown
254through Clang compiled stack frames. This is on by default in x86-64.
255
256=item B<-ftrapv>
257
258Generate code to catch integer overflow errors. Signed integer overflow is
259undefined in C, with this flag, extra code is generated to detect this and abort
260when it happens.
261
262
263=item B<-fvisibility>
264
265This flag sets the default visibility level.
266
267=item B<-fcommon>
268
269This flag specifies that variables without initializers get common linkage. It
270can be disabled with B<-fno-common>.
271
Daniel Dunbar94f497b2009-05-18 21:34:46 +0000272=item B<-flto> B<-emit-llvm>
273
274Generate output files in LLVM formats, suitable for link time optimization. When
275used with B<-S> this generates LLVM intermediate language assembly files,
276otherwise this generates LLVM bitcode format object files (which may be passed
277to the linker depending on the stage selection options).
278
Chris Lattner04005dd2009-05-12 00:01:32 +0000279=cut
280
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.
284
285=pod
286
287=back
288
289
Chris Lattner9b081c62009-05-06 17:22:08 +0000290=head2 Driver Options
Chris Lattnerb5f6e802009-05-06 02:47:51 +0000291
292=over
293
Chris Lattner9b081c62009-05-06 17:22:08 +0000294=item B<-###>
Chris Lattnerb5f6e802009-05-06 02:47:51 +0000295
Chris Lattner9b081c62009-05-06 17:22:08 +0000296Print the commands to run for this compilation.
297
298=item B<--help>
299
300Display available options.
301
Daniel Dunbardbec0332009-04-29 01:00:32 +0000302=item B<-Qunused-arguments>
303
304Don't emit warning for unused driver arguments.
305
Daniel Dunbardbec0332009-04-29 01:00:32 +0000306=item B<-Wa,>I<args>
307
308Pass the comma separated arguments in I<args> to the assembler.
309
310=item B<-Wl,>I<args>
311
312Pass the comma separated arguments in I<args> to the linker.
313
314=item B<-Wp,>I<args>
315
316Pass the comma separated arguments in I<args> to the preprocessor.
317
318=item B<-Xanalyzer> I<arg>
319
320Pass I<arg> to the static analyzer.
321
322=item B<-Xassembler> I<arg>
323
324Pass I<arg> to the assembler.
325
326=item B<-Xclang> I<arg>
327
328Pass I<arg> to the clang compiler.
329
330=item B<-Xlinker> I<arg>
331
332Pass I<arg> to the linker.
333
334=item B<-Xpreprocessor> I<arg>
335
336Pass I<arg> to the preprocessor.
337
Daniel Dunbardbec0332009-04-29 01:00:32 +0000338=item B<-o> I<file>
339
340Write output to I<file>.
341
Daniel Dunbardbec0332009-04-29 01:00:32 +0000342=item B<-print-file-name>=I<file>
343
344Print the full library path of I<file>.
345
346=item B<-print-libgcc-file-name>
347
348Print the library path for "libgcc.a".
349
350=item B<-print-prog-name>=I<name>
351
352Print the full program path of I<name>.
353
354=item B<-print-search-dirs>
355
356Print the paths used for finding libraries and programs.
357
358=item B<-save-temps>
359
360Save intermediate compilation results.
361
362=item B<-time>
363
364Time individual commands.
365
Chris Lattner482c6822009-05-11 22:45:37 +0000366=item B<-ftime-report>
367
368Print timing summary of each stage of compilation.
369
Daniel Dunbardbec0332009-04-29 01:00:32 +0000370=item B<-v>
371
372Show commands to run and use verbose output.
373
Chris Lattner482c6822009-05-11 22:45:37 +0000374=back
Daniel Dunbardbec0332009-04-29 01:00:32 +0000375
Chris Lattner482c6822009-05-11 22:45:37 +0000376
Chris Lattner482c6822009-05-11 22:45:37 +0000377=head2 Diagnostics Options
378
379=over
380
Chris Lattner04005dd2009-05-12 00:01:32 +0000381=item
382B<-fshow-column>
383B<-fshow-source-location>
384B<-fcaret-diagnostics>
385B<-fdiagnostics-fixit-info>
386B<-fdiagnostics-print-source-range-info>
387B<-fprint-source-range-info>
388B<-fdiagnostics-show-option>
389B<-fmessage-length>
Chris Lattner482c6822009-05-11 22:45:37 +0000390
Chris Lattner04005dd2009-05-12 00:01:32 +0000391These options control how Clang prints out information about diagnostics (errors
392and warnings). Please see the Clang User's Manual for more information.
Chris Lattner482c6822009-05-11 22:45:37 +0000393
394=back
Chris Lattner9b081c62009-05-06 17:22:08 +0000395
396
397=head2 Preprocessor Options
398
399=over
400
Chris Lattner06ab0442009-05-12 00:47:40 +0000401=item B<-D>I<macroname=value>
Chris Lattner482c6822009-05-11 22:45:37 +0000402
Chris Lattner06ab0442009-05-12 00:47:40 +0000403Adds an implicit #define into the predefines buffer which is read before the
404source file is preprocessed.
Chris Lattner482c6822009-05-11 22:45:37 +0000405
Chris Lattner06ab0442009-05-12 00:47:40 +0000406=item B<-U>I<macroname>
Chris Lattner482c6822009-05-11 22:45:37 +0000407
Chris Lattner06ab0442009-05-12 00:47:40 +0000408Adds an implicit #undef into the predefines buffer which is read before the
409source file is preprocessed.
Chris Lattner482c6822009-05-11 22:45:37 +0000410
Chris Lattner06ab0442009-05-12 00:47:40 +0000411=item B<-include> I<filename>
Chris Lattner482c6822009-05-11 22:45:37 +0000412
Chris Lattner06ab0442009-05-12 00:47:40 +0000413Adds an implicit #include into the predefines buffer which is read before the
414source file is preprocessed.
Chris Lattner482c6822009-05-11 22:45:37 +0000415
Chris Lattner06ab0442009-05-12 00:47:40 +0000416=item B<-I>I<directory>
Chris Lattner482c6822009-05-11 22:45:37 +0000417
Chris Lattner06ab0442009-05-12 00:47:40 +0000418Add the specified directory to the search path for include files.
419
420=item B<-F>I<directory>
421
422Add the specified directory to the search path for framework include files.
423
424=item B<-nostdinc>
425
426Do not search the standard system directories for include files.
427
428=cut
429
430## TODO, but do we really want people using this stuff?
431=item B<-idirafter>I<directory>
432=item B<-iquote>I<directory>
433=item B<-isystem>I<directory>
434=item B<-iprefix>I<directory>
435=item B<-iwithprefix>I<directory>
436=item B<-iwithprefixbefore>I<directory>
437=item B<-isysroot>
438=pod
Chris Lattner482c6822009-05-11 22:45:37 +0000439
440
Chris Lattner9b081c62009-05-06 17:22:08 +0000441=back
442
443
444
Chris Lattner06ab0442009-05-12 00:47:40 +0000445=cut
Chris Lattner9b081c62009-05-06 17:22:08 +0000446
Chris Lattner06ab0442009-05-12 00:47:40 +0000447### TODO someday.
448=head2 Warning Control Options
Chris Lattner9b081c62009-05-06 17:22:08 +0000449=over
Chris Lattner9b081c62009-05-06 17:22:08 +0000450=back
Chris Lattner9b081c62009-05-06 17:22:08 +0000451=head2 Code Generation and Optimization Options
Chris Lattner9b081c62009-05-06 17:22:08 +0000452=over
Chris Lattner9b081c62009-05-06 17:22:08 +0000453=back
Chris Lattner9b081c62009-05-06 17:22:08 +0000454=head2 Assembler Options
Chris Lattner9b081c62009-05-06 17:22:08 +0000455=over
Chris Lattner9b081c62009-05-06 17:22:08 +0000456=back
Chris Lattner9b081c62009-05-06 17:22:08 +0000457=head2 Linker Options
Chris Lattner9b081c62009-05-06 17:22:08 +0000458=over
Chris Lattner9b081c62009-05-06 17:22:08 +0000459=back
Chris Lattner482c6822009-05-11 22:45:37 +0000460=head2 Static Analyzer Options
Chris Lattner482c6822009-05-11 22:45:37 +0000461=over
Chris Lattner482c6822009-05-11 22:45:37 +0000462=back
463
Chris Lattner06ab0442009-05-12 00:47:40 +0000464=pod
Chris Lattner482c6822009-05-11 22:45:37 +0000465
466
Daniel Dunbardbec0332009-04-29 01:00:32 +0000467=head1 ENVIRONMENT
468
Daniel Dunbare58c9432009-05-06 19:18:09 +0000469=over
470
471=item B<TMPDIR>, B<TEMP>, B<TMP>
472
473These environment variables are checked, in order, for the location to
474write temporary files used during the compilation process.
475
476=item B<CPATH>
477
478If this environment variable is present, it is treated as a delimited
479list of paths to be added to the default system include path list. The
480delimiter is the platform dependent delimitor, as used in the I<PATH>
481environment variable.
482
483Empty components in the environment variable are ignored.
484
485=item B<C_INCLUDE_PATH>, B<OBJC_INCLUDE_PATH>, B<CPLUS_INCLUDE_PATH>,
486B<OBJCPLUS_INCLUDE_PATH>
487
488These environment variables specify additional paths, as for CPATH,
489which are only used when processing the appropriate language.
490
Chris Lattner482c6822009-05-11 22:45:37 +0000491=item B<MACOSX_DEPLOYMENT_TARGET>
Daniel Dunbare58c9432009-05-06 19:18:09 +0000492
493If -mmacosx-version-min is unspecified, the default deployment target
Chris Lattner482c6822009-05-11 22:45:37 +0000494is read from this environment variable. This option only affects darwin
495targets.
Daniel Dunbare58c9432009-05-06 19:18:09 +0000496
497=back
Daniel Dunbardbec0332009-04-29 01:00:32 +0000498
499=head1 BUGS
500
Chris Lattner9b081c62009-05-06 17:22:08 +0000501Clang currently does not have C++ support, and this manual page is incomplete.
502To report bugs, please visit L<http://llvm.org/bugs/>. Most bug reports should
Daniel Dunbare58c9432009-05-06 19:18:09 +0000503include preprocessed source files (use the B<-E> option) and the full output of
504the compiler, along with information to reproduce.
Daniel Dunbardbec0332009-04-29 01:00:32 +0000505
506=head1 SEE ALSO
507
Chris Lattner482c6822009-05-11 22:45:37 +0000508 as(1), ld(1)
Daniel Dunbardbec0332009-04-29 01:00:32 +0000509
510=head1 AUTHOR
511
512Maintained by the Clang / LLVM Team (L<http://clang.llvm.org>).
513
514=cut