blob: 0c1ab574d5353cb6245d9663d9af2982107d7f00 [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
Daniel Dunbar073190d2010-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 Lattnerb5f6e802009-05-06 02:47:51 +000060
Chris Lattner9b081c62009-05-06 17:22:08 +000061=item B<Assembler>
Chris Lattnerb5f6e802009-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 Lattner482c6822009-05-11 22:45:37 +000065file or "object" file.
Chris Lattnerb5f6e802009-05-06 02:47:51 +000066
Chris Lattner9b081c62009-05-06 17:22:08 +000067=item B<Linker>
Chris Lattnerb5f6e802009-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 Lattner482c6822009-05-11 22:45:37 +000076stages. In addition to compilation of code, Clang also supports other tools:
Chris Lattner9b081c62009-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 Lattnerb5f6e802009-05-06 02:47:51 +000084
85=head1 OPTIONS
86
Chris Lattnerb5f6e802009-05-06 02:47:51 +000087=head2 Stage Selection Options
88
89=over
Daniel Dunbardbec0332009-04-29 01:00:32 +000090
Daniel Dunbardbec0332009-04-29 01:00:32 +000091=item B<-E>
92
Chris Lattner9b081c62009-05-06 17:22:08 +000093Run the preprocessor stage.
Daniel Dunbardbec0332009-04-29 01:00:32 +000094
Chris Lattner9b081c62009-05-06 17:22:08 +000095=item B<-fsyntax-only>
Chris Lattnerb5f6e802009-05-06 02:47:51 +000096
Chris Lattner9b081c62009-05-06 17:22:08 +000097Run the preprocessor, parser and type checking stages.
Chris Lattnerb5f6e802009-05-06 02:47:51 +000098
Chris Lattner9b081c62009-05-06 17:22:08 +000099=item B<-S>
Chris Lattnerb5f6e802009-05-06 02:47:51 +0000100
Daniel Dunbar94f497b2009-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 Lattnerb5f6e802009-05-06 02:47:51 +0000103
Chris Lattner9b081c62009-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 Lattnerb5f6e802009-05-06 02:47:51 +0000116
117=back
118
119
120
Chris Lattner04005dd2009-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 Dunbar94f497b2009-05-18 21:34:46 +0000139Treat source input files as Objective-C++ inputs.
Chris Lattner04005dd2009-05-12 00:01:32 +0000140
141=item B<-ObjC>
142
Daniel Dunbar94f497b2009-05-18 21:34:46 +0000143Treat source input files as Objective-C inputs.
Chris Lattner04005dd2009-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
171=item B<-fwritable-strings>
172
173Make all string literals default to writable. This disables uniquing of
174strings and other optimizations.
175
176=item B<-flax-vector-conversions>
177
178Allow loose type checking rules for implicit vector conversions.
179
180=item B<-fblocks>
181
182Enable the "Blocks" language feature.
183
184
185=item B<-fobjc-gc-only>
186
187Indicate that Objective-C code should be compiled in GC-only mode, which only
188works when Objective-C Garbage Collection is enabled.
189
190=item B<-fobjc-gc>
191
192Indicate that Objective-C code should be compiled in hybrid-GC mode, which works
193with both GC and non-GC mode.
194
195=back
196
197
198
199=head2 Target Selection Options
200
Daniel Dunbar94f497b2009-05-18 21:34:46 +0000201Clang fully supports cross compilation as an inherent part of its design.
Chris Lattner04005dd2009-05-12 00:01:32 +0000202Depending on how your version of Clang is configured, it may have support for
Daniel Dunbar94f497b2009-05-18 21:34:46 +0000203a number of cross compilers, or may only support a native target.
Chris Lattner04005dd2009-05-12 00:01:32 +0000204
205=over
206
Chris Lattner04005dd2009-05-12 00:01:32 +0000207=item B<-arch> I<architecture>
208
209Specify the architecture to build for.
210
211=item B<-mmacosx-version-min>=I<version>
212
213When building for Mac OS/X, specify the minimum version supported by your
214application.
215
216=item B<-miphoneos-version-min>
217
218When building for iPhone OS, specify the minimum version supported by your
219application.
220
221
222=item B<-march>=I<cpu>
223
224Specify that Clang should generate code for a specific processor family member
225and later. For example, if you specify -march=i486, the compiler is allowed to
226generate instructions that are valid on i486 and later processors, but which
227may not exist on earlier ones.
228
229=back
230
231
232=head2 Code Generation Options
233
234=over
235
236=item B<-O0> B<-O1> B<-O2> B<-Os> B<-O3> B<-O4>
237
238Specify which optimization level to use. B<-O0> means "no optimization": this
Daniel Dunbar94f497b2009-05-18 21:34:46 +0000239level compiles the fastest and generates the most debuggable code. B<-O2> is a
240moderate level of optimization which enables most optimizations. B<-Os> is like
241B<-O2> with extra optimizations to reduce code size. B<-O3> is like B<-O2>,
242except that it enables optimizations that take longer to perform or that may
243generate larger code (in an attempt to make the program run faster). On
244supported platforms, B<-O4> enables link-time optimization; object files are
245stored in the LLVM bitcode file format and whole program optimization is done at
246link time. B<-O1> is somewhere between B<-O0> and B<-O2>.
Chris Lattner04005dd2009-05-12 00:01:32 +0000247
248=item B<-g>
249
250Generate debug information. Note that Clang debug information works best at
251B<-O0>. At higher optimization levels, only line number information is
252currently available.
253
254=item B<-fexceptions>
255
256Enable generation of unwind information, this allows exceptions to be thrown
257through Clang compiled stack frames. This is on by default in x86-64.
258
259=item B<-ftrapv>
260
261Generate code to catch integer overflow errors. Signed integer overflow is
262undefined in C, with this flag, extra code is generated to detect this and abort
263when it happens.
264
265
266=item B<-fvisibility>
267
268This flag sets the default visibility level.
269
270=item B<-fcommon>
271
272This flag specifies that variables without initializers get common linkage. It
273can be disabled with B<-fno-common>.
274
Daniel Dunbar94f497b2009-05-18 21:34:46 +0000275=item B<-flto> B<-emit-llvm>
276
277Generate output files in LLVM formats, suitable for link time optimization. When
278used with B<-S> this generates LLVM intermediate language assembly files,
279otherwise this generates LLVM bitcode format object files (which may be passed
280to the linker depending on the stage selection options).
281
Chris Lattner04005dd2009-05-12 00:01:32 +0000282=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
Daniel Dunbar073190d2010-05-21 00:28:14 +0000331Pass I<arg> to the clang compiler frontend.
Daniel Dunbardbec0332009-04-29 01:00:32 +0000332
333=item B<-Xlinker> I<arg>
334
335Pass I<arg> to the linker.
336
Daniel Dunbar073190d2010-05-21 00:28:14 +0000337=item B<-mllvm> I<arg>
338
339Pass I<arg> to the LLVM backend.
340
Daniel Dunbardbec0332009-04-29 01:00:32 +0000341=item B<-Xpreprocessor> I<arg>
342
343Pass I<arg> to the preprocessor.
344
Daniel Dunbar073190d2010-05-21 00:28:14 +0000345=item B<-o> I<file>
Daniel Dunbardbec0332009-04-29 01:00:32 +0000346
347Write output to I<file>.
348
Daniel Dunbardbec0332009-04-29 01:00:32 +0000349=item B<-print-file-name>=I<file>
350
351Print the full library path of I<file>.
352
353=item B<-print-libgcc-file-name>
354
355Print the library path for "libgcc.a".
356
357=item B<-print-prog-name>=I<name>
358
359Print the full program path of I<name>.
360
361=item B<-print-search-dirs>
362
363Print the paths used for finding libraries and programs.
364
365=item B<-save-temps>
366
367Save intermediate compilation results.
368
Daniel Dunbar073190d2010-05-21 00:28:14 +0000369=item B<-integrated-as> B<-no-integrated-as>
370
371Used to enable and disable, respectively, the use of the integrated
372assembler. Whether the integrated assembler is on by default is target
373dependent.
374
Daniel Dunbardbec0332009-04-29 01:00:32 +0000375=item B<-time>
376
377Time individual commands.
378
Chris Lattner482c6822009-05-11 22:45:37 +0000379=item B<-ftime-report>
380
381Print timing summary of each stage of compilation.
382
Daniel Dunbardbec0332009-04-29 01:00:32 +0000383=item B<-v>
384
385Show commands to run and use verbose output.
386
Chris Lattner482c6822009-05-11 22:45:37 +0000387=back
Daniel Dunbardbec0332009-04-29 01:00:32 +0000388
Chris Lattner482c6822009-05-11 22:45:37 +0000389
Chris Lattner482c6822009-05-11 22:45:37 +0000390=head2 Diagnostics Options
391
392=over
393
Daniel Dunbar0a2329a2009-09-13 02:21:55 +0000394=item B<-fshow-column>
Chris Lattner04005dd2009-05-12 00:01:32 +0000395B<-fshow-source-location>
396B<-fcaret-diagnostics>
397B<-fdiagnostics-fixit-info>
398B<-fdiagnostics-print-source-range-info>
399B<-fprint-source-range-info>
400B<-fdiagnostics-show-option>
401B<-fmessage-length>
Chris Lattner482c6822009-05-11 22:45:37 +0000402
Chris Lattner04005dd2009-05-12 00:01:32 +0000403These options control how Clang prints out information about diagnostics (errors
404and warnings). Please see the Clang User's Manual for more information.
Chris Lattner482c6822009-05-11 22:45:37 +0000405
406=back
Chris Lattner9b081c62009-05-06 17:22:08 +0000407
408
409=head2 Preprocessor Options
410
411=over
412
Chris Lattner06ab0442009-05-12 00:47:40 +0000413=item B<-D>I<macroname=value>
Chris Lattner482c6822009-05-11 22:45:37 +0000414
Chris Lattner06ab0442009-05-12 00:47:40 +0000415Adds an implicit #define into the predefines buffer which is read before the
416source file is preprocessed.
Chris Lattner482c6822009-05-11 22:45:37 +0000417
Chris Lattner06ab0442009-05-12 00:47:40 +0000418=item B<-U>I<macroname>
Chris Lattner482c6822009-05-11 22:45:37 +0000419
Chris Lattner06ab0442009-05-12 00:47:40 +0000420Adds an implicit #undef into the predefines buffer which is read before the
421source file is preprocessed.
Chris Lattner482c6822009-05-11 22:45:37 +0000422
Chris Lattner06ab0442009-05-12 00:47:40 +0000423=item B<-include> I<filename>
Chris Lattner482c6822009-05-11 22:45:37 +0000424
Chris Lattner06ab0442009-05-12 00:47:40 +0000425Adds an implicit #include into the predefines buffer which is read before the
426source file is preprocessed.
Chris Lattner482c6822009-05-11 22:45:37 +0000427
Chris Lattner06ab0442009-05-12 00:47:40 +0000428=item B<-I>I<directory>
Chris Lattner482c6822009-05-11 22:45:37 +0000429
Chris Lattner06ab0442009-05-12 00:47:40 +0000430Add the specified directory to the search path for include files.
431
432=item B<-F>I<directory>
433
434Add the specified directory to the search path for framework include files.
435
436=item B<-nostdinc>
437
438Do not search the standard system directories for include files.
439
Rafael Espindola4c8e6112009-10-27 00:29:40 +0000440=item B<-nobuiltininc>
441
442Do not search clang's builtin directory for include files.
443
Chris Lattner06ab0442009-05-12 00:47:40 +0000444=cut
445
446## TODO, but do we really want people using this stuff?
Daniel Dunbar0a2329a2009-09-13 02:21:55 +0000447#=item B<-idirafter>I<directory>
448#=item B<-iquote>I<directory>
449#=item B<-isystem>I<directory>
450#=item B<-iprefix>I<directory>
451#=item B<-iwithprefix>I<directory>
452#=item B<-iwithprefixbefore>I<directory>
453#=item B<-isysroot>
454
Chris Lattner06ab0442009-05-12 00:47:40 +0000455=pod
Chris Lattner482c6822009-05-11 22:45:37 +0000456
457
Chris Lattner9b081c62009-05-06 17:22:08 +0000458=back
459
460
461
Chris Lattner06ab0442009-05-12 00:47:40 +0000462=cut
Chris Lattner9b081c62009-05-06 17:22:08 +0000463
Chris Lattner06ab0442009-05-12 00:47:40 +0000464### TODO someday.
Daniel Dunbar0a2329a2009-09-13 02:21:55 +0000465#=head2 Warning Control Options
466#=over
467#=back
468#=head2 Code Generation and Optimization Options
469#=over
470#=back
471#=head2 Assembler Options
472#=over
473#=back
474#=head2 Linker Options
475#=over
476#=back
477#=head2 Static Analyzer Options
478#=over
479#=back
Chris Lattner482c6822009-05-11 22:45:37 +0000480
Chris Lattner06ab0442009-05-12 00:47:40 +0000481=pod
Chris Lattner482c6822009-05-11 22:45:37 +0000482
483
Daniel Dunbardbec0332009-04-29 01:00:32 +0000484=head1 ENVIRONMENT
485
Daniel Dunbare58c9432009-05-06 19:18:09 +0000486=over
487
488=item B<TMPDIR>, B<TEMP>, B<TMP>
489
490These environment variables are checked, in order, for the location to
491write temporary files used during the compilation process.
492
493=item B<CPATH>
494
495If this environment variable is present, it is treated as a delimited
496list of paths to be added to the default system include path list. The
497delimiter is the platform dependent delimitor, as used in the I<PATH>
498environment variable.
499
500Empty components in the environment variable are ignored.
501
502=item B<C_INCLUDE_PATH>, B<OBJC_INCLUDE_PATH>, B<CPLUS_INCLUDE_PATH>,
503B<OBJCPLUS_INCLUDE_PATH>
504
505These environment variables specify additional paths, as for CPATH,
506which are only used when processing the appropriate language.
507
Chris Lattner482c6822009-05-11 22:45:37 +0000508=item B<MACOSX_DEPLOYMENT_TARGET>
Daniel Dunbare58c9432009-05-06 19:18:09 +0000509
510If -mmacosx-version-min is unspecified, the default deployment target
Chris Lattner482c6822009-05-11 22:45:37 +0000511is read from this environment variable. This option only affects darwin
512targets.
Daniel Dunbare58c9432009-05-06 19:18:09 +0000513
514=back
Daniel Dunbardbec0332009-04-29 01:00:32 +0000515
516=head1 BUGS
517
Chris Lattner9b081c62009-05-06 17:22:08 +0000518Clang currently does not have C++ support, and this manual page is incomplete.
519To report bugs, please visit L<http://llvm.org/bugs/>. Most bug reports should
Daniel Dunbare58c9432009-05-06 19:18:09 +0000520include preprocessed source files (use the B<-E> option) and the full output of
521the compiler, along with information to reproduce.
Daniel Dunbardbec0332009-04-29 01:00:32 +0000522
523=head1 SEE ALSO
524
Chris Lattner482c6822009-05-11 22:45:37 +0000525 as(1), ld(1)
Daniel Dunbardbec0332009-04-29 01:00:32 +0000526
527=head1 AUTHOR
528
529Maintained by the Clang / LLVM Team (L<http://clang.llvm.org>).
530
531=cut