blob: 7be5a230640d4779e6ef049965cd7413d05cbe62 [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
96=item B<-emit-llvm>
97
Chris Lattner9b081c62009-05-06 17:22:08 +000098Run the preprocessor, parser, type checking stages, LLVM generation and
99optimization stages.
Chris Lattnerb5f6e802009-05-06 02:47:51 +0000100
Chris Lattner9b081c62009-05-06 17:22:08 +0000101=item B<-S>
Chris Lattnerb5f6e802009-05-06 02:47:51 +0000102
Chris Lattner9b081c62009-05-06 17:22:08 +0000103Run all of the above, plus target-specific code generation, producing an
104assembly file.
Chris Lattnerb5f6e802009-05-06 02:47:51 +0000105
Chris Lattner9b081c62009-05-06 17:22:08 +0000106=item B<-c>
107
108Run all of the above, plus the assembler, generating a target ".o" object file.
109
110=item B<no stage selection option>
111
112If no stage selection option is specified, all stages above are run, and the
113linker is run to combine the results into an executable or shared library.
114
115=item B<--analyze>
116
117Run the Clang Static Analyzer.
Chris Lattnerb5f6e802009-05-06 02:47:51 +0000118
119=back
120
121
122
Chris Lattner9b081c62009-05-06 17:22:08 +0000123=head2 Driver Options
Chris Lattnerb5f6e802009-05-06 02:47:51 +0000124
125=over
126
Chris Lattner9b081c62009-05-06 17:22:08 +0000127=item B<-###>
Chris Lattnerb5f6e802009-05-06 02:47:51 +0000128
Chris Lattner9b081c62009-05-06 17:22:08 +0000129Print the commands to run for this compilation.
130
131=item B<--help>
132
133Display available options.
134
Daniel Dunbardbec0332009-04-29 01:00:32 +0000135=item B<-Qunused-arguments>
136
137Don't emit warning for unused driver arguments.
138
Daniel Dunbardbec0332009-04-29 01:00:32 +0000139=item B<-Wa,>I<args>
140
141Pass the comma separated arguments in I<args> to the assembler.
142
143=item B<-Wl,>I<args>
144
145Pass the comma separated arguments in I<args> to the linker.
146
147=item B<-Wp,>I<args>
148
149Pass the comma separated arguments in I<args> to the preprocessor.
150
151=item B<-Xanalyzer> I<arg>
152
153Pass I<arg> to the static analyzer.
154
155=item B<-Xassembler> I<arg>
156
157Pass I<arg> to the assembler.
158
159=item B<-Xclang> I<arg>
160
161Pass I<arg> to the clang compiler.
162
163=item B<-Xlinker> I<arg>
164
165Pass I<arg> to the linker.
166
167=item B<-Xpreprocessor> I<arg>
168
169Pass I<arg> to the preprocessor.
170
Daniel Dunbardbec0332009-04-29 01:00:32 +0000171=item B<-o> I<file>
172
173Write output to I<file>.
174
Daniel Dunbardbec0332009-04-29 01:00:32 +0000175=item B<-print-file-name>=I<file>
176
177Print the full library path of I<file>.
178
179=item B<-print-libgcc-file-name>
180
181Print the library path for "libgcc.a".
182
183=item B<-print-prog-name>=I<name>
184
185Print the full program path of I<name>.
186
187=item B<-print-search-dirs>
188
189Print the paths used for finding libraries and programs.
190
191=item B<-save-temps>
192
193Save intermediate compilation results.
194
195=item B<-time>
196
197Time individual commands.
198
Chris Lattner482c6822009-05-11 22:45:37 +0000199=item B<-ftime-report>
200
201Print timing summary of each stage of compilation.
202
Daniel Dunbardbec0332009-04-29 01:00:32 +0000203=item B<-v>
204
205Show commands to run and use verbose output.
206
Chris Lattner482c6822009-05-11 22:45:37 +0000207=back
Daniel Dunbardbec0332009-04-29 01:00:32 +0000208
Chris Lattner482c6822009-05-11 22:45:37 +0000209
210
211=head2 Target Selection Options
212
213=over
214
215-triple
216-arch
217-mmacosx-version-min=10.3.9
218-miphoneos-version-min
Daniel Dunbardbec0332009-04-29 01:00:32 +0000219
Chris Lattner9b081c62009-05-06 17:22:08 +0000220
Daniel Dunbardbec0332009-04-29 01:00:32 +0000221=back
222
Chris Lattner9b081c62009-05-06 17:22:08 +0000223
224
Chris Lattner482c6822009-05-11 22:45:37 +0000225=head2 Language Selection and Mode Options
226
227=over
228
229=item B<-x> I<language>
230
231Treat subsequent input files as having type I<language>.
232
233=item B<-ObjC++>
234
235Treat source input files as Objective-C++ inputs.
236
237=item B<-ObjC>
238
239Treat source input files as Objective-C inputs.
240
241B<-std>=I<language>
242
243
244-ffreestanding
245-fno-builtin
246-fmath-errno
247-fobjc-gc-only
248-fobjc-gc
249-fpascal-strings
250-fms-extensions
251-fwritable-strings
252-fno-lax-vector-conversions
253-fblocks
254-trigraphs
255
256
257=back
258
259
260
261=head2 Code Generation Options
262
263=over
264
265-fexceptions
266-fobjc-nonfragile-abi
267-fgnu-runtime
268-fnext-runtime
269-ftrapv
270-fvisibility
271-Os, O0, O1, O2, O3, O4
272-fno-common
273-g
274-mcpu
275
276=back
277
278
279
280
281=head2 Diagnostics Options
282
283=over
284
285-fshow-column
286-fshow-source-location
287-fcaret-diagnostics
288-fdiagnostics-fixit-info
289-fdiagnostics-print-source-range-info
290-fprint-source-range-info
291-fdiagnostics-show-option
292-fmessage-length
293
294
295=back
Chris Lattner9b081c62009-05-06 17:22:08 +0000296
297
298=head2 Preprocessor Options
299
300=over
301
Chris Lattner482c6822009-05-11 22:45:37 +0000302=item B<-xyz>
303
304Frob
305
306-D
307-U
308-include
309-imacros
310
311
312
313-nostdinc
314-F
315-I
316-idirafter
317-iquote
318-isystem
319-iprefix
320-iwithprefix
321-iwithprefixbefore
322-isysroot
323
324
325
326
Chris Lattner9b081c62009-05-06 17:22:08 +0000327=back
328
329
330
331
332=head2 Parser and Semantic Analysis Options
333
334=over
335
336=back
337
338
339
Chris Lattner482c6822009-05-11 22:45:37 +0000340
341
Chris Lattner9b081c62009-05-06 17:22:08 +0000342=head2 Code Generation and Optimization Options
343
344=over
345
346=back
347
348
Chris Lattner482c6822009-05-11 22:45:37 +0000349
350
351
352
Chris Lattner9b081c62009-05-06 17:22:08 +0000353=head2 Assembler Options
354
355=over
356
357=back
358
359
Chris Lattner482c6822009-05-11 22:45:37 +0000360
361
362
363
Chris Lattner9b081c62009-05-06 17:22:08 +0000364=head2 Linker Options
365
366=over
367
368=back
369
370
Chris Lattner482c6822009-05-11 22:45:37 +0000371
372
373
374=head2 Static Analyzer Options
375
376=over
377
378=back
379
380
381
Daniel Dunbardbec0332009-04-29 01:00:32 +0000382=head1 ENVIRONMENT
383
Daniel Dunbare58c9432009-05-06 19:18:09 +0000384=over
385
386=item B<TMPDIR>, B<TEMP>, B<TMP>
387
388These environment variables are checked, in order, for the location to
389write temporary files used during the compilation process.
390
391=item B<CPATH>
392
393If this environment variable is present, it is treated as a delimited
394list of paths to be added to the default system include path list. The
395delimiter is the platform dependent delimitor, as used in the I<PATH>
396environment variable.
397
398Empty components in the environment variable are ignored.
399
400=item B<C_INCLUDE_PATH>, B<OBJC_INCLUDE_PATH>, B<CPLUS_INCLUDE_PATH>,
401B<OBJCPLUS_INCLUDE_PATH>
402
403These environment variables specify additional paths, as for CPATH,
404which are only used when processing the appropriate language.
405
Chris Lattner482c6822009-05-11 22:45:37 +0000406=item B<MACOSX_DEPLOYMENT_TARGET>
Daniel Dunbare58c9432009-05-06 19:18:09 +0000407
408If -mmacosx-version-min is unspecified, the default deployment target
Chris Lattner482c6822009-05-11 22:45:37 +0000409is read from this environment variable. This option only affects darwin
410targets.
Daniel Dunbare58c9432009-05-06 19:18:09 +0000411
412=back
Daniel Dunbardbec0332009-04-29 01:00:32 +0000413
414=head1 BUGS
415
Chris Lattner9b081c62009-05-06 17:22:08 +0000416Clang currently does not have C++ support, and this manual page is incomplete.
417To report bugs, please visit L<http://llvm.org/bugs/>. Most bug reports should
Daniel Dunbare58c9432009-05-06 19:18:09 +0000418include preprocessed source files (use the B<-E> option) and the full output of
419the compiler, along with information to reproduce.
Daniel Dunbardbec0332009-04-29 01:00:32 +0000420
421=head1 SEE ALSO
422
Chris Lattner482c6822009-05-11 22:45:37 +0000423 as(1), ld(1)
Daniel Dunbardbec0332009-04-29 01:00:32 +0000424
425=head1 AUTHOR
426
427Maintained by the Clang / LLVM Team (L<http://clang.llvm.org>).
428
429=cut