blob: 4adf57faf2b1a0077dd1c488abc67e1b74ff8a7a [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 Lattner04005dd2009-05-12 00:01:32 +0000123=head2 Language Selection and Mode Options
124
125=over
126
127=item B<-x> I<language>
128
129Treat subsequent input files as having type I<language>.
130
131=item B<-std>=I<language>
132
133Specify the language standard to compile for.
134
135=item B<-ansi>
136
137Same as B<-std=c89>.
138
139=item B<-ObjC++>
140
141Treat subsequent source input files as Objective-C++ inputs.
142
143=item B<-ObjC>
144
145Treat subsequent source input files as Objective-C inputs.
146
147=item B<-trigraphs>
148
149Enable trigraphs.
150
151=item B<-ffreestanding>
152
153Indicate that the file should be compiled for a freestanding, not a hosted,
154environment.
155
156=item B<-fno-builtin>
157
158Disable special handling and optimizations of builtin functions like strlen and
159malloc.
160
161=item B<-fmath-errno>
162
163Indicate that math functions should be treated as updating errno.
164
165=item B<-fpascal-strings>
166
167Enable support for Pascal-style strings with "\pfoo".
168
169=item B<-fms-extensions>
170
171Enable support for Microsoft extensions.
172
173=item B<-fwritable-strings>
174
175Make all string literals default to writable. This disables uniquing of
176strings and other optimizations.
177
178=item B<-flax-vector-conversions>
179
180Allow loose type checking rules for implicit vector conversions.
181
182=item B<-fblocks>
183
184Enable the "Blocks" language feature.
185
186
187=item B<-fobjc-gc-only>
188
189Indicate that Objective-C code should be compiled in GC-only mode, which only
190works when Objective-C Garbage Collection is enabled.
191
192=item B<-fobjc-gc>
193
194Indicate that Objective-C code should be compiled in hybrid-GC mode, which works
195with both GC and non-GC mode.
196
197=back
198
199
200
201=head2 Target Selection Options
202
203Clang fully supports cross compilation and an inherent part of its design.
204Depending on how your version of Clang is configured, it may have support for
205a number of cross compilers, or may just support a native target.
206
207=over
208
209=cut
210######
211######=item B<-triple>=I<target triple>
212######
213=pod
214
215
216=item B<-arch> I<architecture>
217
218Specify the architecture to build for.
219
220=item B<-mmacosx-version-min>=I<version>
221
222When building for Mac OS/X, specify the minimum version supported by your
223application.
224
225=item B<-miphoneos-version-min>
226
227When building for iPhone OS, specify the minimum version supported by your
228application.
229
230
231=item B<-march>=I<cpu>
232
233Specify that Clang should generate code for a specific processor family member
234and later. For example, if you specify -march=i486, the compiler is allowed to
235generate instructions that are valid on i486 and later processors, but which
236may not exist on earlier ones.
237
238=back
239
240
241=head2 Code Generation Options
242
243=over
244
245=item B<-O0> B<-O1> B<-O2> B<-Os> B<-O3> B<-O4>
246
247Specify which optimization level to use. B<-O0> means "no optimization": this
248level compiles the fastest and generates the most debuggable code. B<-O2> is
249a moderate level of debugging which enables most optimizations. B<-Os> is like
250B<-O2> but it does extra optimizations to reduce code size. B<-O3> is like
251B<-O2>, except that it enables optimizations that take longer to perform or that
252may generate larger code (in an attempt to make the program run faster). B<-O1>
253is somewhere between B<-O0> and B<-O1>.
254
255=item B<-g>
256
257Generate debug information. Note that Clang debug information works best at
258B<-O0>. At higher optimization levels, only line number information is
259currently available.
260
261=item B<-fexceptions>
262
263Enable generation of unwind information, this allows exceptions to be thrown
264through Clang compiled stack frames. This is on by default in x86-64.
265
266=item B<-ftrapv>
267
268Generate code to catch integer overflow errors. Signed integer overflow is
269undefined in C, with this flag, extra code is generated to detect this and abort
270when it happens.
271
272
273=item B<-fvisibility>
274
275This flag sets the default visibility level.
276
277=item B<-fcommon>
278
279This flag specifies that variables without initializers get common linkage. It
280can be disabled with B<-fno-common>.
281
282=cut
283
284##=item B<-fnext-runtime> B<-fobjc-nonfragile-abi> B<-fgnu-runtime>
285##These options specify which Objective-C runtime the code generator should
286##target. FIXME: we don't want people poking these generally.
287
288=pod
289
290=back
291
292
Chris Lattner9b081c62009-05-06 17:22:08 +0000293=head2 Driver Options
Chris Lattnerb5f6e802009-05-06 02:47:51 +0000294
295=over
296
Chris Lattner9b081c62009-05-06 17:22:08 +0000297=item B<-###>
Chris Lattnerb5f6e802009-05-06 02:47:51 +0000298
Chris Lattner9b081c62009-05-06 17:22:08 +0000299Print the commands to run for this compilation.
300
301=item B<--help>
302
303Display available options.
304
Daniel Dunbardbec0332009-04-29 01:00:32 +0000305=item B<-Qunused-arguments>
306
307Don't emit warning for unused driver arguments.
308
Daniel Dunbardbec0332009-04-29 01:00:32 +0000309=item B<-Wa,>I<args>
310
311Pass the comma separated arguments in I<args> to the assembler.
312
313=item B<-Wl,>I<args>
314
315Pass the comma separated arguments in I<args> to the linker.
316
317=item B<-Wp,>I<args>
318
319Pass the comma separated arguments in I<args> to the preprocessor.
320
321=item B<-Xanalyzer> I<arg>
322
323Pass I<arg> to the static analyzer.
324
325=item B<-Xassembler> I<arg>
326
327Pass I<arg> to the assembler.
328
329=item B<-Xclang> I<arg>
330
331Pass I<arg> to the clang compiler.
332
333=item B<-Xlinker> I<arg>
334
335Pass I<arg> to the linker.
336
337=item B<-Xpreprocessor> I<arg>
338
339Pass I<arg> to the preprocessor.
340
Daniel Dunbardbec0332009-04-29 01:00:32 +0000341=item B<-o> I<file>
342
343Write output to I<file>.
344
Daniel Dunbardbec0332009-04-29 01:00:32 +0000345=item B<-print-file-name>=I<file>
346
347Print the full library path of I<file>.
348
349=item B<-print-libgcc-file-name>
350
351Print the library path for "libgcc.a".
352
353=item B<-print-prog-name>=I<name>
354
355Print the full program path of I<name>.
356
357=item B<-print-search-dirs>
358
359Print the paths used for finding libraries and programs.
360
361=item B<-save-temps>
362
363Save intermediate compilation results.
364
365=item B<-time>
366
367Time individual commands.
368
Chris Lattner482c6822009-05-11 22:45:37 +0000369=item B<-ftime-report>
370
371Print timing summary of each stage of compilation.
372
Daniel Dunbardbec0332009-04-29 01:00:32 +0000373=item B<-v>
374
375Show commands to run and use verbose output.
376
Chris Lattner482c6822009-05-11 22:45:37 +0000377=back
Daniel Dunbardbec0332009-04-29 01:00:32 +0000378
Chris Lattner482c6822009-05-11 22:45:37 +0000379
Chris Lattner482c6822009-05-11 22:45:37 +0000380=head2 Diagnostics Options
381
382=over
383
Chris Lattner04005dd2009-05-12 00:01:32 +0000384=item
385B<-fshow-column>
386B<-fshow-source-location>
387B<-fcaret-diagnostics>
388B<-fdiagnostics-fixit-info>
389B<-fdiagnostics-print-source-range-info>
390B<-fprint-source-range-info>
391B<-fdiagnostics-show-option>
392B<-fmessage-length>
Chris Lattner482c6822009-05-11 22:45:37 +0000393
Chris Lattner04005dd2009-05-12 00:01:32 +0000394These options control how Clang prints out information about diagnostics (errors
395and warnings). Please see the Clang User's Manual for more information.
Chris Lattner482c6822009-05-11 22:45:37 +0000396
397=back
Chris Lattner9b081c62009-05-06 17:22:08 +0000398
399
400=head2 Preprocessor Options
401
402=over
403
Chris Lattner06ab0442009-05-12 00:47:40 +0000404=item B<-D>I<macroname=value>
Chris Lattner482c6822009-05-11 22:45:37 +0000405
Chris Lattner06ab0442009-05-12 00:47:40 +0000406Adds an implicit #define into the predefines buffer which is read before the
407source file is preprocessed.
Chris Lattner482c6822009-05-11 22:45:37 +0000408
Chris Lattner06ab0442009-05-12 00:47:40 +0000409=item B<-U>I<macroname>
Chris Lattner482c6822009-05-11 22:45:37 +0000410
Chris Lattner06ab0442009-05-12 00:47:40 +0000411Adds an implicit #undef into the predefines buffer which is read before the
412source file is preprocessed.
Chris Lattner482c6822009-05-11 22:45:37 +0000413
Chris Lattner06ab0442009-05-12 00:47:40 +0000414=item B<-include> I<filename>
Chris Lattner482c6822009-05-11 22:45:37 +0000415
Chris Lattner06ab0442009-05-12 00:47:40 +0000416Adds an implicit #include into the predefines buffer which is read before the
417source file is preprocessed.
Chris Lattner482c6822009-05-11 22:45:37 +0000418
Chris Lattner06ab0442009-05-12 00:47:40 +0000419=item B<-I>I<directory>
Chris Lattner482c6822009-05-11 22:45:37 +0000420
Chris Lattner06ab0442009-05-12 00:47:40 +0000421Add the specified directory to the search path for include files.
422
423=item B<-F>I<directory>
424
425Add the specified directory to the search path for framework include files.
426
427=item B<-nostdinc>
428
429Do not search the standard system directories for include files.
430
431=cut
432
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>
440=item B<-isysroot>
441=pod
Chris Lattner482c6822009-05-11 22:45:37 +0000442
443
Chris Lattner9b081c62009-05-06 17:22:08 +0000444=back
445
446
447
Chris Lattner06ab0442009-05-12 00:47:40 +0000448=cut
Chris Lattner9b081c62009-05-06 17:22:08 +0000449
Chris Lattner06ab0442009-05-12 00:47:40 +0000450### TODO someday.
451=head2 Warning Control 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 Code Generation and Optimization 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 Assembler Options
Chris Lattner9b081c62009-05-06 17:22:08 +0000458=over
Chris Lattner9b081c62009-05-06 17:22:08 +0000459=back
Chris Lattner9b081c62009-05-06 17:22:08 +0000460=head2 Linker Options
Chris Lattner9b081c62009-05-06 17:22:08 +0000461=over
Chris Lattner9b081c62009-05-06 17:22:08 +0000462=back
Chris Lattner482c6822009-05-11 22:45:37 +0000463=head2 Static Analyzer Options
Chris Lattner482c6822009-05-11 22:45:37 +0000464=over
Chris Lattner482c6822009-05-11 22:45:37 +0000465=back
466
Chris Lattner06ab0442009-05-12 00:47:40 +0000467=pod
Chris Lattner482c6822009-05-11 22:45:37 +0000468
469
Daniel Dunbardbec0332009-04-29 01:00:32 +0000470=head1 ENVIRONMENT
471
Daniel Dunbare58c9432009-05-06 19:18:09 +0000472=over
473
474=item B<TMPDIR>, B<TEMP>, B<TMP>
475
476These environment variables are checked, in order, for the location to
477write temporary files used during the compilation process.
478
479=item B<CPATH>
480
481If this environment variable is present, it is treated as a delimited
482list of paths to be added to the default system include path list. The
483delimiter is the platform dependent delimitor, as used in the I<PATH>
484environment variable.
485
486Empty components in the environment variable are ignored.
487
488=item B<C_INCLUDE_PATH>, B<OBJC_INCLUDE_PATH>, B<CPLUS_INCLUDE_PATH>,
489B<OBJCPLUS_INCLUDE_PATH>
490
491These environment variables specify additional paths, as for CPATH,
492which are only used when processing the appropriate language.
493
Chris Lattner482c6822009-05-11 22:45:37 +0000494=item B<MACOSX_DEPLOYMENT_TARGET>
Daniel Dunbare58c9432009-05-06 19:18:09 +0000495
496If -mmacosx-version-min is unspecified, the default deployment target
Chris Lattner482c6822009-05-11 22:45:37 +0000497is read from this environment variable. This option only affects darwin
498targets.
Daniel Dunbare58c9432009-05-06 19:18:09 +0000499
500=back
Daniel Dunbardbec0332009-04-29 01:00:32 +0000501
502=head1 BUGS
503
Chris Lattner9b081c62009-05-06 17:22:08 +0000504Clang currently does not have C++ support, and this manual page is incomplete.
505To report bugs, please visit L<http://llvm.org/bugs/>. Most bug reports should
Daniel Dunbare58c9432009-05-06 19:18:09 +0000506include preprocessed source files (use the B<-E> option) and the full output of
507the compiler, along with information to reproduce.
Daniel Dunbardbec0332009-04-29 01:00:32 +0000508
509=head1 SEE ALSO
510
Chris Lattner482c6822009-05-11 22:45:37 +0000511 as(1), ld(1)
Daniel Dunbardbec0332009-04-29 01:00:32 +0000512
513=head1 AUTHOR
514
515Maintained by the Clang / LLVM Team (L<http://clang.llvm.org>).
516
517=cut