blob: 8284d319e7b1e393e0a2a229393efb2ac76edd1f [file] [log] [blame]
Daniel Dunbarc1b16582009-04-29 01:00:32 +00001=pod
2
3=head1 NAME
4
Chris Lattner20807872009-05-06 02:47:51 +00005clang - the Clang C and Objective-C compiler
Daniel Dunbarc1b16582009-04-29 01:00:32 +00006
7=head1 SYNOPSIS
8
Chris Lattner20807872009-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>
Daniel Dunbar092b6fb2010-09-14 23:12:40 +000017 B<-stdlib=>I<library>
Chris Lattner20807872009-05-06 02:47:51 +000018 I<input-filenames>
Daniel Dunbarc1b16582009-04-29 01:00:32 +000019
20=head1 DESCRIPTION
21
Chris Lattner20807872009-05-06 02:47:51 +000022B<clang> is a C and Objective-C compiler which encompasses preprocessing,
23parsing, optimization, code generation, assembly, and linking. Depending on
24which high-level mode setting is passed, Clang will stop before doing a full
25link. While Clang is highly integrated, it is important to understand the
26stages of compilation, to understand how to invoke it. These stages are:
Daniel Dunbarc1b16582009-04-29 01:00:32 +000027
28=over
29
Chris Lattner20807872009-05-06 02:47:51 +000030=item B<Driver>
Daniel Dunbarc1b16582009-04-29 01:00:32 +000031
Chris Lattner20807872009-05-06 02:47:51 +000032The B<clang> executable is actually a small driver which controls the overall
33execution of other tools such as the compiler, assembler and linker. Typically
34you do not need to interact with the driver, but you transparently use it to run
35the other tools.
Daniel Dunbarc1b16582009-04-29 01:00:32 +000036
Chris Lattner20807872009-05-06 02:47:51 +000037=item B<Preprocessing>
Daniel Dunbarc1b16582009-04-29 01:00:32 +000038
Chris Lattner20807872009-05-06 02:47:51 +000039This stage handles tokenization of the input source file, macro expansion,
40#include expansion and handling of other preprocessor directives. The output of
41this stage is typically called a ".i" (for C) or ".mi" (for Objective-C) file.
42
43=item B<Parsing and Semantic Analysis>
44
45This stage parses the input file, translating preprocessor tokens into a parse
46tree. Once in the form of a parser tree, it applies semantic analysis to compute
47types for expressions as well and determine whether the code is well formed. This
48stage is responsible for generating most of the compiler warnings as well as
49parse errors. The output of this stage is an "Abstract Syntax Tree" (AST).
50
51=item B<Code Generation and Optimization>
52
Chris Lattnere3c3f402009-05-11 22:45:37 +000053This stage translates an AST into low-level intermediate code (known as "LLVM
Daniel Dunbar95dff812010-05-21 00:28:14 +000054IR") and ultimately to machine code. This phase is responsible for optimizing
55the generated code and handling target-specfic code generation. The output of
56this stage is typically called a ".s" file or "assembly" file.
57
58Clang also supports the use of an integrated assembler, in which the code
59generator produces object files directly. This avoids the overhead of generating
60the ".s" file and of calling the target assembler.
Chris Lattner20807872009-05-06 02:47:51 +000061
Chris Lattner164ac102009-05-06 17:22:08 +000062=item B<Assembler>
Chris Lattner20807872009-05-06 02:47:51 +000063
64This stage runs the target assembler to translate the output of the compiler
65into a target object file. The output of this stage is typically called a ".o"
Chris Lattnere3c3f402009-05-11 22:45:37 +000066file or "object" file.
Chris Lattner20807872009-05-06 02:47:51 +000067
Chris Lattner164ac102009-05-06 17:22:08 +000068=item B<Linker>
Chris Lattner20807872009-05-06 02:47:51 +000069
70This stage runs the target linker to merge multiple object files into an
71executable or dynamic library. The output of this stage is typically called an
72"a.out", ".dylib" or ".so" file.
73
74=back
75
76The Clang compiler supports a large number of options to control each of these
Chris Lattnere3c3f402009-05-11 22:45:37 +000077stages. In addition to compilation of code, Clang also supports other tools:
Chris Lattner164ac102009-05-06 17:22:08 +000078
79B<Clang Static Analyzer>
80
81The Clang Static Analyzer is a tool that scans source code to try to find bugs
82though code analysis. This tool uses many parts of Clang and is built into the
83same driver.
84
Chris Lattner20807872009-05-06 02:47:51 +000085
86=head1 OPTIONS
87
Chris Lattner20807872009-05-06 02:47:51 +000088=head2 Stage Selection Options
89
90=over
Daniel Dunbarc1b16582009-04-29 01:00:32 +000091
Daniel Dunbarc1b16582009-04-29 01:00:32 +000092=item B<-E>
93
Chris Lattner164ac102009-05-06 17:22:08 +000094Run the preprocessor stage.
Daniel Dunbarc1b16582009-04-29 01:00:32 +000095
Chris Lattner164ac102009-05-06 17:22:08 +000096=item B<-fsyntax-only>
Chris Lattner20807872009-05-06 02:47:51 +000097
Chris Lattner164ac102009-05-06 17:22:08 +000098Run the preprocessor, parser and type checking stages.
Chris Lattner20807872009-05-06 02:47:51 +000099
Chris Lattner164ac102009-05-06 17:22:08 +0000100=item B<-S>
Chris Lattner20807872009-05-06 02:47:51 +0000101
Daniel Dunbarf7a24e12009-05-18 21:34:46 +0000102Run the previous stages as well as LLVM generation and optimization stages and
103target-specific code generation, producing an assembly file.
Chris Lattner20807872009-05-06 02:47:51 +0000104
Chris Lattner164ac102009-05-06 17:22:08 +0000105=item B<-c>
106
107Run all of the above, plus the assembler, generating a target ".o" object file.
108
109=item B<no stage selection option>
110
111If no stage selection option is specified, all stages above are run, and the
112linker is run to combine the results into an executable or shared library.
113
114=item B<--analyze>
115
116Run the Clang Static Analyzer.
Chris Lattner20807872009-05-06 02:47:51 +0000117
118=back
119
120
121
Chris Lattner66c64f92009-05-12 00:01:32 +0000122=head2 Language Selection and Mode Options
123
124=over
125
126=item B<-x> I<language>
127
128Treat subsequent input files as having type I<language>.
129
130=item B<-std>=I<language>
131
132Specify the language standard to compile for.
133
Daniel Dunbar092b6fb2010-09-14 23:12:40 +0000134=item B<-stdlib>=I<language>
135
136Specify the C++ standard library to use; supported options are libstdc++ and
137libc++.
138
Chris Lattner66c64f92009-05-12 00:01:32 +0000139=item B<-ansi>
140
141Same as B<-std=c89>.
142
143=item B<-ObjC++>
144
Daniel Dunbarf7a24e12009-05-18 21:34:46 +0000145Treat source input files as Objective-C++ inputs.
Chris Lattner66c64f92009-05-12 00:01:32 +0000146
147=item B<-ObjC>
148
Daniel Dunbarf7a24e12009-05-18 21:34:46 +0000149Treat source input files as Objective-C inputs.
Chris Lattner66c64f92009-05-12 00:01:32 +0000150
151=item B<-trigraphs>
152
153Enable trigraphs.
154
155=item B<-ffreestanding>
156
157Indicate that the file should be compiled for a freestanding, not a hosted,
158environment.
159
160=item B<-fno-builtin>
161
162Disable special handling and optimizations of builtin functions like strlen and
163malloc.
164
165=item B<-fmath-errno>
166
167Indicate that math functions should be treated as updating errno.
168
169=item B<-fpascal-strings>
170
171Enable support for Pascal-style strings with "\pfoo".
172
173=item B<-fms-extensions>
174
175Enable support for Microsoft extensions.
176
Dawn Perchik68bb1b42010-09-02 23:59:25 +0000177=item B<-fborland-extensions>
178
179Enable support for Borland extensions.
180
Chris Lattner66c64f92009-05-12 00:01:32 +0000181=item B<-fwritable-strings>
182
183Make all string literals default to writable. This disables uniquing of
184strings and other optimizations.
185
186=item B<-flax-vector-conversions>
187
188Allow loose type checking rules for implicit vector conversions.
189
190=item B<-fblocks>
191
192Enable the "Blocks" language feature.
193
194
195=item B<-fobjc-gc-only>
196
197Indicate that Objective-C code should be compiled in GC-only mode, which only
198works when Objective-C Garbage Collection is enabled.
199
200=item B<-fobjc-gc>
201
202Indicate that Objective-C code should be compiled in hybrid-GC mode, which works
203with both GC and non-GC mode.
204
205=back
206
207
208
209=head2 Target Selection Options
210
Daniel Dunbarf7a24e12009-05-18 21:34:46 +0000211Clang fully supports cross compilation as an inherent part of its design.
Chris Lattner66c64f92009-05-12 00:01:32 +0000212Depending on how your version of Clang is configured, it may have support for
Daniel Dunbarf7a24e12009-05-18 21:34:46 +0000213a number of cross compilers, or may only support a native target.
Chris Lattner66c64f92009-05-12 00:01:32 +0000214
215=over
216
Chris Lattner66c64f92009-05-12 00:01:32 +0000217=item B<-arch> I<architecture>
218
219Specify the architecture to build for.
220
221=item B<-mmacosx-version-min>=I<version>
222
223When building for Mac OS/X, specify the minimum version supported by your
224application.
225
226=item B<-miphoneos-version-min>
227
228When building for iPhone OS, specify the minimum version supported by your
229application.
230
231
232=item B<-march>=I<cpu>
233
234Specify that Clang should generate code for a specific processor family member
235and later. For example, if you specify -march=i486, the compiler is allowed to
236generate instructions that are valid on i486 and later processors, but which
237may not exist on earlier ones.
238
239=back
240
241
242=head2 Code Generation Options
243
244=over
245
246=item B<-O0> B<-O1> B<-O2> B<-Os> B<-O3> B<-O4>
247
248Specify which optimization level to use. B<-O0> means "no optimization": this
Daniel Dunbarf7a24e12009-05-18 21:34:46 +0000249level compiles the fastest and generates the most debuggable code. B<-O2> is a
250moderate level of optimization which enables most optimizations. B<-Os> is like
251B<-O2> with extra optimizations to reduce code size. B<-O3> is like B<-O2>,
252except that it enables optimizations that take longer to perform or that may
253generate larger code (in an attempt to make the program run faster). On
254supported platforms, B<-O4> enables link-time optimization; object files are
255stored in the LLVM bitcode file format and whole program optimization is done at
256link time. B<-O1> is somewhere between B<-O0> and B<-O2>.
Chris Lattner66c64f92009-05-12 00:01:32 +0000257
258=item B<-g>
259
260Generate debug information. Note that Clang debug information works best at
261B<-O0>. At higher optimization levels, only line number information is
262currently available.
263
264=item B<-fexceptions>
265
266Enable generation of unwind information, this allows exceptions to be thrown
267through Clang compiled stack frames. This is on by default in x86-64.
268
269=item B<-ftrapv>
270
271Generate code to catch integer overflow errors. Signed integer overflow is
272undefined in C, with this flag, extra code is generated to detect this and abort
273when it happens.
274
275
276=item B<-fvisibility>
277
278This flag sets the default visibility level.
279
280=item B<-fcommon>
281
282This flag specifies that variables without initializers get common linkage. It
283can be disabled with B<-fno-common>.
284
Daniel Dunbarf7a24e12009-05-18 21:34:46 +0000285=item B<-flto> B<-emit-llvm>
286
287Generate output files in LLVM formats, suitable for link time optimization. When
288used with B<-S> this generates LLVM intermediate language assembly files,
289otherwise this generates LLVM bitcode format object files (which may be passed
290to the linker depending on the stage selection options).
291
Chris Lattner66c64f92009-05-12 00:01:32 +0000292=cut
293
294##=item B<-fnext-runtime> B<-fobjc-nonfragile-abi> B<-fgnu-runtime>
295##These options specify which Objective-C runtime the code generator should
296##target. FIXME: we don't want people poking these generally.
297
298=pod
299
300=back
301
302
Chris Lattner164ac102009-05-06 17:22:08 +0000303=head2 Driver Options
Chris Lattner20807872009-05-06 02:47:51 +0000304
305=over
306
Chris Lattner164ac102009-05-06 17:22:08 +0000307=item B<-###>
Chris Lattner20807872009-05-06 02:47:51 +0000308
Chris Lattner164ac102009-05-06 17:22:08 +0000309Print the commands to run for this compilation.
310
311=item B<--help>
312
313Display available options.
314
Daniel Dunbarc1b16582009-04-29 01:00:32 +0000315=item B<-Qunused-arguments>
316
317Don't emit warning for unused driver arguments.
318
Daniel Dunbarc1b16582009-04-29 01:00:32 +0000319=item B<-Wa,>I<args>
320
321Pass the comma separated arguments in I<args> to the assembler.
322
323=item B<-Wl,>I<args>
324
325Pass the comma separated arguments in I<args> to the linker.
326
327=item B<-Wp,>I<args>
328
329Pass the comma separated arguments in I<args> to the preprocessor.
330
331=item B<-Xanalyzer> I<arg>
332
333Pass I<arg> to the static analyzer.
334
335=item B<-Xassembler> I<arg>
336
337Pass I<arg> to the assembler.
338
339=item B<-Xclang> I<arg>
340
Daniel Dunbar95dff812010-05-21 00:28:14 +0000341Pass I<arg> to the clang compiler frontend.
Daniel Dunbarc1b16582009-04-29 01:00:32 +0000342
343=item B<-Xlinker> I<arg>
344
345Pass I<arg> to the linker.
346
Daniel Dunbar95dff812010-05-21 00:28:14 +0000347=item B<-mllvm> I<arg>
348
349Pass I<arg> to the LLVM backend.
350
Daniel Dunbarc1b16582009-04-29 01:00:32 +0000351=item B<-Xpreprocessor> I<arg>
352
353Pass I<arg> to the preprocessor.
354
Daniel Dunbar95dff812010-05-21 00:28:14 +0000355=item B<-o> I<file>
Daniel Dunbarc1b16582009-04-29 01:00:32 +0000356
357Write output to I<file>.
358
Daniel Dunbarc1b16582009-04-29 01:00:32 +0000359=item B<-print-file-name>=I<file>
360
361Print the full library path of I<file>.
362
363=item B<-print-libgcc-file-name>
364
365Print the library path for "libgcc.a".
366
367=item B<-print-prog-name>=I<name>
368
369Print the full program path of I<name>.
370
371=item B<-print-search-dirs>
372
373Print the paths used for finding libraries and programs.
374
375=item B<-save-temps>
376
377Save intermediate compilation results.
378
Daniel Dunbar95dff812010-05-21 00:28:14 +0000379=item B<-integrated-as> B<-no-integrated-as>
380
381Used to enable and disable, respectively, the use of the integrated
382assembler. Whether the integrated assembler is on by default is target
383dependent.
384
Daniel Dunbarc1b16582009-04-29 01:00:32 +0000385=item B<-time>
386
387Time individual commands.
388
Chris Lattnere3c3f402009-05-11 22:45:37 +0000389=item B<-ftime-report>
390
391Print timing summary of each stage of compilation.
392
Daniel Dunbarc1b16582009-04-29 01:00:32 +0000393=item B<-v>
394
395Show commands to run and use verbose output.
396
Chris Lattnere3c3f402009-05-11 22:45:37 +0000397=back
Daniel Dunbarc1b16582009-04-29 01:00:32 +0000398
Chris Lattnere3c3f402009-05-11 22:45:37 +0000399
Chris Lattnere3c3f402009-05-11 22:45:37 +0000400=head2 Diagnostics Options
401
402=over
403
Daniel Dunbar5e2de9f2009-09-13 02:21:55 +0000404=item B<-fshow-column>
Chris Lattner66c64f92009-05-12 00:01:32 +0000405B<-fshow-source-location>
406B<-fcaret-diagnostics>
407B<-fdiagnostics-fixit-info>
Douglas Gregoreec975c2010-08-19 20:24:43 +0000408B<-fdiagnostics-parseable-fixits>
Chris Lattner66c64f92009-05-12 00:01:32 +0000409B<-fdiagnostics-print-source-range-info>
410B<-fprint-source-range-info>
411B<-fdiagnostics-show-option>
412B<-fmessage-length>
Chris Lattnere3c3f402009-05-11 22:45:37 +0000413
Chris Lattner66c64f92009-05-12 00:01:32 +0000414These options control how Clang prints out information about diagnostics (errors
415and warnings). Please see the Clang User's Manual for more information.
Chris Lattnere3c3f402009-05-11 22:45:37 +0000416
417=back
Chris Lattner164ac102009-05-06 17:22:08 +0000418
419
420=head2 Preprocessor Options
421
422=over
423
Chris Lattner32efff62009-05-12 00:47:40 +0000424=item B<-D>I<macroname=value>
Chris Lattnere3c3f402009-05-11 22:45:37 +0000425
Chris Lattner32efff62009-05-12 00:47:40 +0000426Adds an implicit #define into the predefines buffer which is read before the
427source file is preprocessed.
Chris Lattnere3c3f402009-05-11 22:45:37 +0000428
Chris Lattner32efff62009-05-12 00:47:40 +0000429=item B<-U>I<macroname>
Chris Lattnere3c3f402009-05-11 22:45:37 +0000430
Chris Lattner32efff62009-05-12 00:47:40 +0000431Adds an implicit #undef into the predefines buffer which is read before the
432source file is preprocessed.
Chris Lattnere3c3f402009-05-11 22:45:37 +0000433
Chris Lattner32efff62009-05-12 00:47:40 +0000434=item B<-include> I<filename>
Chris Lattnere3c3f402009-05-11 22:45:37 +0000435
Chris Lattner32efff62009-05-12 00:47:40 +0000436Adds an implicit #include into the predefines buffer which is read before the
437source file is preprocessed.
Chris Lattnere3c3f402009-05-11 22:45:37 +0000438
Chris Lattner32efff62009-05-12 00:47:40 +0000439=item B<-I>I<directory>
Chris Lattnere3c3f402009-05-11 22:45:37 +0000440
Chris Lattner32efff62009-05-12 00:47:40 +0000441Add the specified directory to the search path for include files.
442
443=item B<-F>I<directory>
444
445Add the specified directory to the search path for framework include files.
446
447=item B<-nostdinc>
448
449Do not search the standard system directories for include files.
450
Rafael Espindolabb85c262009-10-27 00:29:40 +0000451=item B<-nobuiltininc>
452
453Do not search clang's builtin directory for include files.
454
Chris Lattner32efff62009-05-12 00:47:40 +0000455=cut
456
457## TODO, but do we really want people using this stuff?
Daniel Dunbar5e2de9f2009-09-13 02:21:55 +0000458#=item B<-idirafter>I<directory>
459#=item B<-iquote>I<directory>
460#=item B<-isystem>I<directory>
461#=item B<-iprefix>I<directory>
462#=item B<-iwithprefix>I<directory>
463#=item B<-iwithprefixbefore>I<directory>
464#=item B<-isysroot>
465
Chris Lattner32efff62009-05-12 00:47:40 +0000466=pod
Chris Lattnere3c3f402009-05-11 22:45:37 +0000467
468
Chris Lattner164ac102009-05-06 17:22:08 +0000469=back
470
471
472
Chris Lattner32efff62009-05-12 00:47:40 +0000473=cut
Chris Lattner164ac102009-05-06 17:22:08 +0000474
Chris Lattner32efff62009-05-12 00:47:40 +0000475### TODO someday.
Daniel Dunbar5e2de9f2009-09-13 02:21:55 +0000476#=head2 Warning Control Options
477#=over
478#=back
479#=head2 Code Generation and Optimization Options
480#=over
481#=back
482#=head2 Assembler Options
483#=over
484#=back
485#=head2 Linker Options
486#=over
487#=back
488#=head2 Static Analyzer Options
489#=over
490#=back
Chris Lattnere3c3f402009-05-11 22:45:37 +0000491
Chris Lattner32efff62009-05-12 00:47:40 +0000492=pod
Chris Lattnere3c3f402009-05-11 22:45:37 +0000493
494
Daniel Dunbarc1b16582009-04-29 01:00:32 +0000495=head1 ENVIRONMENT
496
Daniel Dunbar16af4762009-05-06 19:18:09 +0000497=over
498
499=item B<TMPDIR>, B<TEMP>, B<TMP>
500
501These environment variables are checked, in order, for the location to
502write temporary files used during the compilation process.
503
504=item B<CPATH>
505
506If this environment variable is present, it is treated as a delimited
507list of paths to be added to the default system include path list. The
508delimiter is the platform dependent delimitor, as used in the I<PATH>
509environment variable.
510
511Empty components in the environment variable are ignored.
512
513=item B<C_INCLUDE_PATH>, B<OBJC_INCLUDE_PATH>, B<CPLUS_INCLUDE_PATH>,
514B<OBJCPLUS_INCLUDE_PATH>
515
516These environment variables specify additional paths, as for CPATH,
517which are only used when processing the appropriate language.
518
Chris Lattnere3c3f402009-05-11 22:45:37 +0000519=item B<MACOSX_DEPLOYMENT_TARGET>
Daniel Dunbar16af4762009-05-06 19:18:09 +0000520
521If -mmacosx-version-min is unspecified, the default deployment target
Chris Lattnere3c3f402009-05-11 22:45:37 +0000522is read from this environment variable. This option only affects darwin
523targets.
Daniel Dunbar16af4762009-05-06 19:18:09 +0000524
525=back
Daniel Dunbarc1b16582009-04-29 01:00:32 +0000526
527=head1 BUGS
528
Chris Lattner164ac102009-05-06 17:22:08 +0000529To report bugs, please visit L<http://llvm.org/bugs/>. Most bug reports should
Daniel Dunbar16af4762009-05-06 19:18:09 +0000530include preprocessed source files (use the B<-E> option) and the full output of
531the compiler, along with information to reproduce.
Daniel Dunbarc1b16582009-04-29 01:00:32 +0000532
533=head1 SEE ALSO
534
Chris Lattnere3c3f402009-05-11 22:45:37 +0000535 as(1), ld(1)
Daniel Dunbarc1b16582009-04-29 01:00:32 +0000536
537=head1 AUTHOR
538
539Maintained by the Clang / LLVM Team (L<http://clang.llvm.org>).
540
541=cut