blob: 032efcfcabc5fccdadbdf234e6fe43f9cd25f7ce [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>
17 I<input-filenames>
Daniel Dunbarc1b16582009-04-29 01:00:32 +000018
19=head1 DESCRIPTION
20
Chris Lattner20807872009-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 Dunbarc1b16582009-04-29 01:00:32 +000026
27=over
28
Chris Lattner20807872009-05-06 02:47:51 +000029=item B<Driver>
Daniel Dunbarc1b16582009-04-29 01:00:32 +000030
Chris Lattner20807872009-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 Dunbarc1b16582009-04-29 01:00:32 +000035
Chris Lattner20807872009-05-06 02:47:51 +000036=item B<Preprocessing>
Daniel Dunbarc1b16582009-04-29 01:00:32 +000037
Chris Lattner20807872009-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 Lattnere3c3f402009-05-11 22:45:37 +000052This stage translates an AST into low-level intermediate code (known as "LLVM
Daniel Dunbar95dff812010-05-21 00:28:14 +000053IR") and ultimately to machine code. This phase is responsible for optimizing
54the generated code and handling target-specfic code generation. The output of
55this stage is typically called a ".s" file or "assembly" file.
56
57Clang also supports the use of an integrated assembler, in which the code
58generator produces object files directly. This avoids the overhead of generating
59the ".s" file and of calling the target assembler.
Chris Lattner20807872009-05-06 02:47:51 +000060
Chris Lattner164ac102009-05-06 17:22:08 +000061=item B<Assembler>
Chris Lattner20807872009-05-06 02:47:51 +000062
63This stage runs the target assembler to translate the output of the compiler
64into a target object file. The output of this stage is typically called a ".o"
Chris Lattnere3c3f402009-05-11 22:45:37 +000065file or "object" file.
Chris Lattner20807872009-05-06 02:47:51 +000066
Chris Lattner164ac102009-05-06 17:22:08 +000067=item B<Linker>
Chris Lattner20807872009-05-06 02:47:51 +000068
69This stage runs the target linker to merge multiple object files into an
70executable or dynamic library. The output of this stage is typically called an
71"a.out", ".dylib" or ".so" file.
72
73=back
74
75The Clang compiler supports a large number of options to control each of these
Chris Lattnere3c3f402009-05-11 22:45:37 +000076stages. In addition to compilation of code, Clang also supports other tools:
Chris Lattner164ac102009-05-06 17:22:08 +000077
78B<Clang Static Analyzer>
79
80The Clang Static Analyzer is a tool that scans source code to try to find bugs
81though code analysis. This tool uses many parts of Clang and is built into the
82same driver.
83
Chris Lattner20807872009-05-06 02:47:51 +000084
85=head1 OPTIONS
86
Chris Lattner20807872009-05-06 02:47:51 +000087=head2 Stage Selection Options
88
89=over
Daniel Dunbarc1b16582009-04-29 01:00:32 +000090
Daniel Dunbarc1b16582009-04-29 01:00:32 +000091=item B<-E>
92
Chris Lattner164ac102009-05-06 17:22:08 +000093Run the preprocessor stage.
Daniel Dunbarc1b16582009-04-29 01:00:32 +000094
Chris Lattner164ac102009-05-06 17:22:08 +000095=item B<-fsyntax-only>
Chris Lattner20807872009-05-06 02:47:51 +000096
Chris Lattner164ac102009-05-06 17:22:08 +000097Run the preprocessor, parser and type checking stages.
Chris Lattner20807872009-05-06 02:47:51 +000098
Chris Lattner164ac102009-05-06 17:22:08 +000099=item B<-S>
Chris Lattner20807872009-05-06 02:47:51 +0000100
Daniel Dunbarf7a24e12009-05-18 21:34:46 +0000101Run the previous stages as well as LLVM generation and optimization stages and
102target-specific code generation, producing an assembly file.
Chris Lattner20807872009-05-06 02:47:51 +0000103
Chris Lattner164ac102009-05-06 17:22:08 +0000104=item B<-c>
105
106Run all of the above, plus the assembler, generating a target ".o" object file.
107
108=item B<no stage selection option>
109
110If no stage selection option is specified, all stages above are run, and the
111linker is run to combine the results into an executable or shared library.
112
113=item B<--analyze>
114
115Run the Clang Static Analyzer.
Chris Lattner20807872009-05-06 02:47:51 +0000116
117=back
118
119
120
Chris Lattner66c64f92009-05-12 00:01:32 +0000121=head2 Language Selection and Mode Options
122
123=over
124
125=item B<-x> I<language>
126
127Treat subsequent input files as having type I<language>.
128
129=item B<-std>=I<language>
130
131Specify the language standard to compile for.
132
133=item B<-ansi>
134
135Same as B<-std=c89>.
136
137=item B<-ObjC++>
138
Daniel Dunbarf7a24e12009-05-18 21:34:46 +0000139Treat source input files as Objective-C++ inputs.
Chris Lattner66c64f92009-05-12 00:01:32 +0000140
141=item B<-ObjC>
142
Daniel Dunbarf7a24e12009-05-18 21:34:46 +0000143Treat source input files as Objective-C inputs.
Chris Lattner66c64f92009-05-12 00:01:32 +0000144
145=item B<-trigraphs>
146
147Enable trigraphs.
148
149=item B<-ffreestanding>
150
151Indicate that the file should be compiled for a freestanding, not a hosted,
152environment.
153
154=item B<-fno-builtin>
155
156Disable special handling and optimizations of builtin functions like strlen and
157malloc.
158
159=item B<-fmath-errno>
160
161Indicate that math functions should be treated as updating errno.
162
163=item B<-fpascal-strings>
164
165Enable support for Pascal-style strings with "\pfoo".
166
167=item B<-fms-extensions>
168
169Enable support for Microsoft extensions.
170
Dawn Perchik68bb1b42010-09-02 23:59:25 +0000171=item B<-fborland-extensions>
172
173Enable support for Borland extensions.
174
Chris Lattner66c64f92009-05-12 00:01:32 +0000175=item B<-fwritable-strings>
176
177Make all string literals default to writable. This disables uniquing of
178strings and other optimizations.
179
180=item B<-flax-vector-conversions>
181
182Allow loose type checking rules for implicit vector conversions.
183
184=item B<-fblocks>
185
186Enable the "Blocks" language feature.
187
188
189=item B<-fobjc-gc-only>
190
191Indicate that Objective-C code should be compiled in GC-only mode, which only
192works when Objective-C Garbage Collection is enabled.
193
194=item B<-fobjc-gc>
195
196Indicate that Objective-C code should be compiled in hybrid-GC mode, which works
197with both GC and non-GC mode.
198
199=back
200
201
202
203=head2 Target Selection Options
204
Daniel Dunbarf7a24e12009-05-18 21:34:46 +0000205Clang fully supports cross compilation as an inherent part of its design.
Chris Lattner66c64f92009-05-12 00:01:32 +0000206Depending on how your version of Clang is configured, it may have support for
Daniel Dunbarf7a24e12009-05-18 21:34:46 +0000207a number of cross compilers, or may only support a native target.
Chris Lattner66c64f92009-05-12 00:01:32 +0000208
209=over
210
Chris Lattner66c64f92009-05-12 00:01:32 +0000211=item B<-arch> I<architecture>
212
213Specify the architecture to build for.
214
215=item B<-mmacosx-version-min>=I<version>
216
217When building for Mac OS/X, specify the minimum version supported by your
218application.
219
220=item B<-miphoneos-version-min>
221
222When building for iPhone OS, specify the minimum version supported by your
223application.
224
225
226=item B<-march>=I<cpu>
227
228Specify that Clang should generate code for a specific processor family member
229and later. For example, if you specify -march=i486, the compiler is allowed to
230generate instructions that are valid on i486 and later processors, but which
231may not exist on earlier ones.
232
233=back
234
235
236=head2 Code Generation Options
237
238=over
239
240=item B<-O0> B<-O1> B<-O2> B<-Os> B<-O3> B<-O4>
241
242Specify which optimization level to use. B<-O0> means "no optimization": this
Daniel Dunbarf7a24e12009-05-18 21:34:46 +0000243level compiles the fastest and generates the most debuggable code. B<-O2> is a
244moderate level of optimization which enables most optimizations. B<-Os> is like
245B<-O2> with extra optimizations to reduce code size. B<-O3> is like B<-O2>,
246except that it enables optimizations that take longer to perform or that may
247generate larger code (in an attempt to make the program run faster). On
248supported platforms, B<-O4> enables link-time optimization; object files are
249stored in the LLVM bitcode file format and whole program optimization is done at
250link time. B<-O1> is somewhere between B<-O0> and B<-O2>.
Chris Lattner66c64f92009-05-12 00:01:32 +0000251
252=item B<-g>
253
254Generate debug information. Note that Clang debug information works best at
255B<-O0>. At higher optimization levels, only line number information is
256currently available.
257
258=item B<-fexceptions>
259
260Enable generation of unwind information, this allows exceptions to be thrown
261through Clang compiled stack frames. This is on by default in x86-64.
262
263=item B<-ftrapv>
264
265Generate code to catch integer overflow errors. Signed integer overflow is
266undefined in C, with this flag, extra code is generated to detect this and abort
267when it happens.
268
269
270=item B<-fvisibility>
271
272This flag sets the default visibility level.
273
274=item B<-fcommon>
275
276This flag specifies that variables without initializers get common linkage. It
277can be disabled with B<-fno-common>.
278
Daniel Dunbarf7a24e12009-05-18 21:34:46 +0000279=item B<-flto> B<-emit-llvm>
280
281Generate output files in LLVM formats, suitable for link time optimization. When
282used with B<-S> this generates LLVM intermediate language assembly files,
283otherwise this generates LLVM bitcode format object files (which may be passed
284to the linker depending on the stage selection options).
285
Chris Lattner66c64f92009-05-12 00:01:32 +0000286=cut
287
288##=item B<-fnext-runtime> B<-fobjc-nonfragile-abi> B<-fgnu-runtime>
289##These options specify which Objective-C runtime the code generator should
290##target. FIXME: we don't want people poking these generally.
291
292=pod
293
294=back
295
296
Chris Lattner164ac102009-05-06 17:22:08 +0000297=head2 Driver Options
Chris Lattner20807872009-05-06 02:47:51 +0000298
299=over
300
Chris Lattner164ac102009-05-06 17:22:08 +0000301=item B<-###>
Chris Lattner20807872009-05-06 02:47:51 +0000302
Chris Lattner164ac102009-05-06 17:22:08 +0000303Print the commands to run for this compilation.
304
305=item B<--help>
306
307Display available options.
308
Daniel Dunbarc1b16582009-04-29 01:00:32 +0000309=item B<-Qunused-arguments>
310
311Don't emit warning for unused driver arguments.
312
Daniel Dunbarc1b16582009-04-29 01:00:32 +0000313=item B<-Wa,>I<args>
314
315Pass the comma separated arguments in I<args> to the assembler.
316
317=item B<-Wl,>I<args>
318
319Pass the comma separated arguments in I<args> to the linker.
320
321=item B<-Wp,>I<args>
322
323Pass the comma separated arguments in I<args> to the preprocessor.
324
325=item B<-Xanalyzer> I<arg>
326
327Pass I<arg> to the static analyzer.
328
329=item B<-Xassembler> I<arg>
330
331Pass I<arg> to the assembler.
332
333=item B<-Xclang> I<arg>
334
Daniel Dunbar95dff812010-05-21 00:28:14 +0000335Pass I<arg> to the clang compiler frontend.
Daniel Dunbarc1b16582009-04-29 01:00:32 +0000336
337=item B<-Xlinker> I<arg>
338
339Pass I<arg> to the linker.
340
Daniel Dunbar95dff812010-05-21 00:28:14 +0000341=item B<-mllvm> I<arg>
342
343Pass I<arg> to the LLVM backend.
344
Daniel Dunbarc1b16582009-04-29 01:00:32 +0000345=item B<-Xpreprocessor> I<arg>
346
347Pass I<arg> to the preprocessor.
348
Daniel Dunbar95dff812010-05-21 00:28:14 +0000349=item B<-o> I<file>
Daniel Dunbarc1b16582009-04-29 01:00:32 +0000350
351Write output to I<file>.
352
Daniel Dunbarc1b16582009-04-29 01:00:32 +0000353=item B<-print-file-name>=I<file>
354
355Print the full library path of I<file>.
356
357=item B<-print-libgcc-file-name>
358
359Print the library path for "libgcc.a".
360
361=item B<-print-prog-name>=I<name>
362
363Print the full program path of I<name>.
364
365=item B<-print-search-dirs>
366
367Print the paths used for finding libraries and programs.
368
369=item B<-save-temps>
370
371Save intermediate compilation results.
372
Daniel Dunbar95dff812010-05-21 00:28:14 +0000373=item B<-integrated-as> B<-no-integrated-as>
374
375Used to enable and disable, respectively, the use of the integrated
376assembler. Whether the integrated assembler is on by default is target
377dependent.
378
Daniel Dunbarc1b16582009-04-29 01:00:32 +0000379=item B<-time>
380
381Time individual commands.
382
Chris Lattnere3c3f402009-05-11 22:45:37 +0000383=item B<-ftime-report>
384
385Print timing summary of each stage of compilation.
386
Daniel Dunbarc1b16582009-04-29 01:00:32 +0000387=item B<-v>
388
389Show commands to run and use verbose output.
390
Chris Lattnere3c3f402009-05-11 22:45:37 +0000391=back
Daniel Dunbarc1b16582009-04-29 01:00:32 +0000392
Chris Lattnere3c3f402009-05-11 22:45:37 +0000393
Chris Lattnere3c3f402009-05-11 22:45:37 +0000394=head2 Diagnostics Options
395
396=over
397
Daniel Dunbar5e2de9f2009-09-13 02:21:55 +0000398=item B<-fshow-column>
Chris Lattner66c64f92009-05-12 00:01:32 +0000399B<-fshow-source-location>
400B<-fcaret-diagnostics>
401B<-fdiagnostics-fixit-info>
Douglas Gregoreec975c2010-08-19 20:24:43 +0000402B<-fdiagnostics-parseable-fixits>
Chris Lattner66c64f92009-05-12 00:01:32 +0000403B<-fdiagnostics-print-source-range-info>
404B<-fprint-source-range-info>
405B<-fdiagnostics-show-option>
406B<-fmessage-length>
Chris Lattnere3c3f402009-05-11 22:45:37 +0000407
Chris Lattner66c64f92009-05-12 00:01:32 +0000408These options control how Clang prints out information about diagnostics (errors
409and warnings). Please see the Clang User's Manual for more information.
Chris Lattnere3c3f402009-05-11 22:45:37 +0000410
411=back
Chris Lattner164ac102009-05-06 17:22:08 +0000412
413
414=head2 Preprocessor Options
415
416=over
417
Chris Lattner32efff62009-05-12 00:47:40 +0000418=item B<-D>I<macroname=value>
Chris Lattnere3c3f402009-05-11 22:45:37 +0000419
Chris Lattner32efff62009-05-12 00:47:40 +0000420Adds an implicit #define into the predefines buffer which is read before the
421source file is preprocessed.
Chris Lattnere3c3f402009-05-11 22:45:37 +0000422
Chris Lattner32efff62009-05-12 00:47:40 +0000423=item B<-U>I<macroname>
Chris Lattnere3c3f402009-05-11 22:45:37 +0000424
Chris Lattner32efff62009-05-12 00:47:40 +0000425Adds an implicit #undef into the predefines buffer which is read before the
426source file is preprocessed.
Chris Lattnere3c3f402009-05-11 22:45:37 +0000427
Chris Lattner32efff62009-05-12 00:47:40 +0000428=item B<-include> I<filename>
Chris Lattnere3c3f402009-05-11 22:45:37 +0000429
Chris Lattner32efff62009-05-12 00:47:40 +0000430Adds an implicit #include into the predefines buffer which is read before the
431source file is preprocessed.
Chris Lattnere3c3f402009-05-11 22:45:37 +0000432
Chris Lattner32efff62009-05-12 00:47:40 +0000433=item B<-I>I<directory>
Chris Lattnere3c3f402009-05-11 22:45:37 +0000434
Chris Lattner32efff62009-05-12 00:47:40 +0000435Add the specified directory to the search path for include files.
436
437=item B<-F>I<directory>
438
439Add the specified directory to the search path for framework include files.
440
441=item B<-nostdinc>
442
443Do not search the standard system directories for include files.
444
Rafael Espindolabb85c262009-10-27 00:29:40 +0000445=item B<-nobuiltininc>
446
447Do not search clang's builtin directory for include files.
448
Chris Lattner32efff62009-05-12 00:47:40 +0000449=cut
450
451## TODO, but do we really want people using this stuff?
Daniel Dunbar5e2de9f2009-09-13 02:21:55 +0000452#=item B<-idirafter>I<directory>
453#=item B<-iquote>I<directory>
454#=item B<-isystem>I<directory>
455#=item B<-iprefix>I<directory>
456#=item B<-iwithprefix>I<directory>
457#=item B<-iwithprefixbefore>I<directory>
458#=item B<-isysroot>
459
Chris Lattner32efff62009-05-12 00:47:40 +0000460=pod
Chris Lattnere3c3f402009-05-11 22:45:37 +0000461
462
Chris Lattner164ac102009-05-06 17:22:08 +0000463=back
464
465
466
Chris Lattner32efff62009-05-12 00:47:40 +0000467=cut
Chris Lattner164ac102009-05-06 17:22:08 +0000468
Chris Lattner32efff62009-05-12 00:47:40 +0000469### TODO someday.
Daniel Dunbar5e2de9f2009-09-13 02:21:55 +0000470#=head2 Warning Control Options
471#=over
472#=back
473#=head2 Code Generation and Optimization Options
474#=over
475#=back
476#=head2 Assembler Options
477#=over
478#=back
479#=head2 Linker Options
480#=over
481#=back
482#=head2 Static Analyzer Options
483#=over
484#=back
Chris Lattnere3c3f402009-05-11 22:45:37 +0000485
Chris Lattner32efff62009-05-12 00:47:40 +0000486=pod
Chris Lattnere3c3f402009-05-11 22:45:37 +0000487
488
Daniel Dunbarc1b16582009-04-29 01:00:32 +0000489=head1 ENVIRONMENT
490
Daniel Dunbar16af4762009-05-06 19:18:09 +0000491=over
492
493=item B<TMPDIR>, B<TEMP>, B<TMP>
494
495These environment variables are checked, in order, for the location to
496write temporary files used during the compilation process.
497
498=item B<CPATH>
499
500If this environment variable is present, it is treated as a delimited
501list of paths to be added to the default system include path list. The
502delimiter is the platform dependent delimitor, as used in the I<PATH>
503environment variable.
504
505Empty components in the environment variable are ignored.
506
507=item B<C_INCLUDE_PATH>, B<OBJC_INCLUDE_PATH>, B<CPLUS_INCLUDE_PATH>,
508B<OBJCPLUS_INCLUDE_PATH>
509
510These environment variables specify additional paths, as for CPATH,
511which are only used when processing the appropriate language.
512
Chris Lattnere3c3f402009-05-11 22:45:37 +0000513=item B<MACOSX_DEPLOYMENT_TARGET>
Daniel Dunbar16af4762009-05-06 19:18:09 +0000514
515If -mmacosx-version-min is unspecified, the default deployment target
Chris Lattnere3c3f402009-05-11 22:45:37 +0000516is read from this environment variable. This option only affects darwin
517targets.
Daniel Dunbar16af4762009-05-06 19:18:09 +0000518
519=back
Daniel Dunbarc1b16582009-04-29 01:00:32 +0000520
521=head1 BUGS
522
Chris Lattner164ac102009-05-06 17:22:08 +0000523To report bugs, please visit L<http://llvm.org/bugs/>. Most bug reports should
Daniel Dunbar16af4762009-05-06 19:18:09 +0000524include preprocessed source files (use the B<-E> option) and the full output of
525the compiler, along with information to reproduce.
Daniel Dunbarc1b16582009-04-29 01:00:32 +0000526
527=head1 SEE ALSO
528
Chris Lattnere3c3f402009-05-11 22:45:37 +0000529 as(1), ld(1)
Daniel Dunbarc1b16582009-04-29 01:00:32 +0000530
531=head1 AUTHOR
532
533Maintained by the Clang / LLVM Team (L<http://clang.llvm.org>).
534
535=cut