blob: 9f7a4483019ec3be738a7e256a8effe2f05806c9 [file] [log] [blame]
Daniel Dunbardbec0332009-04-29 01:00:32 +00001=pod
2
3=head1 NAME
4
Douglas Gregor51c7a782010-09-24 17:26:14 +00005clang - the Clang C, 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>
Daniel Dunbar3f16c952010-09-14 23:12:40 +000017 B<-stdlib=>I<library>
Chris Lattnerb5f6e802009-05-06 02:47:51 +000018 I<input-filenames>
Daniel Dunbardbec0332009-04-29 01:00:32 +000019
20=head1 DESCRIPTION
21
Douglas Gregor51c7a782010-09-24 17:26:14 +000022B<clang> is a C, C++, and Objective-C compiler which encompasses preprocessing,
Chris Lattnerb5f6e802009-05-06 02:47:51 +000023parsing, 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 Dunbardbec0332009-04-29 01:00:32 +000027
28=over
29
Chris Lattnerb5f6e802009-05-06 02:47:51 +000030=item B<Driver>
Daniel Dunbardbec0332009-04-29 01:00:32 +000031
Chris Lattnerb5f6e802009-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 Dunbardbec0332009-04-29 01:00:32 +000036
Chris Lattnerb5f6e802009-05-06 02:47:51 +000037=item B<Preprocessing>
Daniel Dunbardbec0332009-04-29 01:00:32 +000038
Chris Lattnerb5f6e802009-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
Douglas Gregor51c7a782010-09-24 17:26:14 +000041this stage is typically called a ".i" (for C), ".ii" (for C++), ".mi" (for
42Objective-C) , or ".mii" (for Objective-C++) file.
Chris Lattnerb5f6e802009-05-06 02:47:51 +000043
44=item B<Parsing and Semantic Analysis>
45
46This stage parses the input file, translating preprocessor tokens into a parse
47tree. Once in the form of a parser tree, it applies semantic analysis to compute
48types for expressions as well and determine whether the code is well formed. This
49stage is responsible for generating most of the compiler warnings as well as
50parse errors. The output of this stage is an "Abstract Syntax Tree" (AST).
51
52=item B<Code Generation and Optimization>
53
Chris Lattner482c6822009-05-11 22:45:37 +000054This stage translates an AST into low-level intermediate code (known as "LLVM
Daniel Dunbar073190d2010-05-21 00:28:14 +000055IR") and ultimately to machine code. This phase is responsible for optimizing
56the generated code and handling target-specfic code generation. The output of
57this stage is typically called a ".s" file or "assembly" file.
58
59Clang also supports the use of an integrated assembler, in which the code
60generator produces object files directly. This avoids the overhead of generating
61the ".s" file and of calling the target assembler.
Chris Lattnerb5f6e802009-05-06 02:47:51 +000062
Chris Lattner9b081c62009-05-06 17:22:08 +000063=item B<Assembler>
Chris Lattnerb5f6e802009-05-06 02:47:51 +000064
65This stage runs the target assembler to translate the output of the compiler
66into a target object file. The output of this stage is typically called a ".o"
Chris Lattner482c6822009-05-11 22:45:37 +000067file or "object" file.
Chris Lattnerb5f6e802009-05-06 02:47:51 +000068
Chris Lattner9b081c62009-05-06 17:22:08 +000069=item B<Linker>
Chris Lattnerb5f6e802009-05-06 02:47:51 +000070
71This stage runs the target linker to merge multiple object files into an
72executable or dynamic library. The output of this stage is typically called an
73"a.out", ".dylib" or ".so" file.
74
75=back
76
77The Clang compiler supports a large number of options to control each of these
Chris Lattner482c6822009-05-11 22:45:37 +000078stages. In addition to compilation of code, Clang also supports other tools:
Chris Lattner9b081c62009-05-06 17:22:08 +000079
80B<Clang Static Analyzer>
81
82The Clang Static Analyzer is a tool that scans source code to try to find bugs
Douglas Gregor77809812010-10-08 21:03:07 +000083through code analysis. This tool uses many parts of Clang and is built into the
Chris Lattner9b081c62009-05-06 17:22:08 +000084same driver.
85
Chris Lattnerb5f6e802009-05-06 02:47:51 +000086
87=head1 OPTIONS
88
Chris Lattnerb5f6e802009-05-06 02:47:51 +000089=head2 Stage Selection Options
90
91=over
Daniel Dunbardbec0332009-04-29 01:00:32 +000092
Daniel Dunbardbec0332009-04-29 01:00:32 +000093=item B<-E>
94
Chris Lattner9b081c62009-05-06 17:22:08 +000095Run the preprocessor stage.
Daniel Dunbardbec0332009-04-29 01:00:32 +000096
Chris Lattner9b081c62009-05-06 17:22:08 +000097=item B<-fsyntax-only>
Chris Lattnerb5f6e802009-05-06 02:47:51 +000098
Chris Lattner9b081c62009-05-06 17:22:08 +000099Run the preprocessor, parser and type checking 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
Daniel Dunbar94f497b2009-05-18 21:34:46 +0000103Run the previous stages as well as LLVM generation and optimization stages and
104target-specific code generation, producing an assembly 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
Daniel Dunbar3f16c952010-09-14 23:12:40 +0000135=item B<-stdlib>=I<language>
136
137Specify the C++ standard library to use; supported options are libstdc++ and
138libc++.
139
Chris Lattner04005dd2009-05-12 00:01:32 +0000140=item B<-ansi>
141
142Same as B<-std=c89>.
143
144=item B<-ObjC++>
145
Daniel Dunbar94f497b2009-05-18 21:34:46 +0000146Treat source input files as Objective-C++ inputs.
Chris Lattner04005dd2009-05-12 00:01:32 +0000147
148=item B<-ObjC>
149
Daniel Dunbar94f497b2009-05-18 21:34:46 +0000150Treat source input files as Objective-C inputs.
Chris Lattner04005dd2009-05-12 00:01:32 +0000151
152=item B<-trigraphs>
153
154Enable trigraphs.
155
156=item B<-ffreestanding>
157
158Indicate that the file should be compiled for a freestanding, not a hosted,
159environment.
160
161=item B<-fno-builtin>
162
163Disable special handling and optimizations of builtin functions like strlen and
164malloc.
165
166=item B<-fmath-errno>
167
168Indicate that math functions should be treated as updating errno.
169
170=item B<-fpascal-strings>
171
172Enable support for Pascal-style strings with "\pfoo".
173
174=item B<-fms-extensions>
175
176Enable support for Microsoft extensions.
177
Michael J. Spencerdae4ac42010-10-21 05:21:48 +0000178=item B<-fmsc-version=>
179
180Set _MSC_VER. Defaults to 1300 on Windows. Not set otherwise.
181
Dawn Perchik400b6072010-09-02 23:59:25 +0000182=item B<-fborland-extensions>
183
184Enable support for Borland extensions.
185
Chris Lattner04005dd2009-05-12 00:01:32 +0000186=item B<-fwritable-strings>
187
188Make all string literals default to writable. This disables uniquing of
189strings and other optimizations.
190
191=item B<-flax-vector-conversions>
192
193Allow loose type checking rules for implicit vector conversions.
194
195=item B<-fblocks>
196
197Enable the "Blocks" language feature.
198
Chris Lattner04005dd2009-05-12 00:01:32 +0000199=item B<-fobjc-gc-only>
200
201Indicate that Objective-C code should be compiled in GC-only mode, which only
202works when Objective-C Garbage Collection is enabled.
203
204=item B<-fobjc-gc>
205
206Indicate that Objective-C code should be compiled in hybrid-GC mode, which works
207with both GC and non-GC mode.
208
Daniel Dunbardea63132010-09-20 18:19:55 +0000209=item B<-fobjc-abi-version>=I<version>
210
211Select the Objective-C ABI version to use. Available versions are 1 (legacy
212"fragile" ABI), 2 (non-fragile ABI 1), and 3 (non-fragile ABI 2).
213
214=item B<-fobjc-nonfragile-abi-version>=I<version>
215
216Select the Objective-C non-fragile ABI version to use by default. This will only
217be used as the Objective-C ABI when the non-fragile ABI is enabled (either via
218-fobjc-nonfragile-abi, or because it is the platform default).
219
220=item B<-fobjc-nonfragile-abi>
221
222Enable use of the Objective-C non-fragile ABI. On platforms for which this is
223the default ABI, it can be disabled with B<-fno-objc-nonfragile-abi>.
224
Chris Lattner04005dd2009-05-12 00:01:32 +0000225=back
226
227
228
229=head2 Target Selection Options
230
Daniel Dunbar94f497b2009-05-18 21:34:46 +0000231Clang fully supports cross compilation as an inherent part of its design.
Chris Lattner04005dd2009-05-12 00:01:32 +0000232Depending on how your version of Clang is configured, it may have support for
Daniel Dunbar94f497b2009-05-18 21:34:46 +0000233a number of cross compilers, or may only support a native target.
Chris Lattner04005dd2009-05-12 00:01:32 +0000234
235=over
236
Chris Lattner04005dd2009-05-12 00:01:32 +0000237=item B<-arch> I<architecture>
238
239Specify the architecture to build for.
240
241=item B<-mmacosx-version-min>=I<version>
242
243When building for Mac OS/X, specify the minimum version supported by your
244application.
245
246=item B<-miphoneos-version-min>
247
248When building for iPhone OS, specify the minimum version supported by your
249application.
250
251
252=item B<-march>=I<cpu>
253
254Specify that Clang should generate code for a specific processor family member
255and later. For example, if you specify -march=i486, the compiler is allowed to
256generate instructions that are valid on i486 and later processors, but which
257may not exist on earlier ones.
258
259=back
260
261
262=head2 Code Generation Options
263
264=over
265
266=item B<-O0> B<-O1> B<-O2> B<-Os> B<-O3> B<-O4>
267
268Specify which optimization level to use. B<-O0> means "no optimization": this
Daniel Dunbar94f497b2009-05-18 21:34:46 +0000269level compiles the fastest and generates the most debuggable code. B<-O2> is a
270moderate level of optimization which enables most optimizations. B<-Os> is like
271B<-O2> with extra optimizations to reduce code size. B<-O3> is like B<-O2>,
272except that it enables optimizations that take longer to perform or that may
273generate larger code (in an attempt to make the program run faster). On
274supported platforms, B<-O4> enables link-time optimization; object files are
275stored in the LLVM bitcode file format and whole program optimization is done at
276link time. B<-O1> is somewhere between B<-O0> and B<-O2>.
Chris Lattner04005dd2009-05-12 00:01:32 +0000277
278=item B<-g>
279
280Generate debug information. Note that Clang debug information works best at
281B<-O0>. At higher optimization levels, only line number information is
282currently available.
283
284=item B<-fexceptions>
285
286Enable generation of unwind information, this allows exceptions to be thrown
287through Clang compiled stack frames. This is on by default in x86-64.
288
289=item B<-ftrapv>
290
291Generate code to catch integer overflow errors. Signed integer overflow is
292undefined in C, with this flag, extra code is generated to detect this and abort
293when it happens.
294
295
296=item B<-fvisibility>
297
298This flag sets the default visibility level.
299
300=item B<-fcommon>
301
302This flag specifies that variables without initializers get common linkage. It
303can be disabled with B<-fno-common>.
304
Daniel Dunbar94f497b2009-05-18 21:34:46 +0000305=item B<-flto> B<-emit-llvm>
306
307Generate output files in LLVM formats, suitable for link time optimization. When
308used with B<-S> this generates LLVM intermediate language assembly files,
309otherwise this generates LLVM bitcode format object files (which may be passed
310to the linker depending on the stage selection options).
311
Chris Lattner04005dd2009-05-12 00:01:32 +0000312=cut
313
314##=item B<-fnext-runtime> B<-fobjc-nonfragile-abi> B<-fgnu-runtime>
315##These options specify which Objective-C runtime the code generator should
316##target. FIXME: we don't want people poking these generally.
317
318=pod
319
320=back
321
322
Chris Lattner9b081c62009-05-06 17:22:08 +0000323=head2 Driver Options
Chris Lattnerb5f6e802009-05-06 02:47:51 +0000324
325=over
326
Chris Lattner9b081c62009-05-06 17:22:08 +0000327=item B<-###>
Chris Lattnerb5f6e802009-05-06 02:47:51 +0000328
Chris Lattner9b081c62009-05-06 17:22:08 +0000329Print the commands to run for this compilation.
330
331=item B<--help>
332
333Display available options.
334
Daniel Dunbardbec0332009-04-29 01:00:32 +0000335=item B<-Qunused-arguments>
336
337Don't emit warning for unused driver arguments.
338
Daniel Dunbardbec0332009-04-29 01:00:32 +0000339=item B<-Wa,>I<args>
340
341Pass the comma separated arguments in I<args> to the assembler.
342
343=item B<-Wl,>I<args>
344
345Pass the comma separated arguments in I<args> to the linker.
346
347=item B<-Wp,>I<args>
348
349Pass the comma separated arguments in I<args> to the preprocessor.
350
351=item B<-Xanalyzer> I<arg>
352
353Pass I<arg> to the static analyzer.
354
355=item B<-Xassembler> I<arg>
356
357Pass I<arg> to the assembler.
358
359=item B<-Xclang> I<arg>
360
Daniel Dunbar073190d2010-05-21 00:28:14 +0000361Pass I<arg> to the clang compiler frontend.
Daniel Dunbardbec0332009-04-29 01:00:32 +0000362
363=item B<-Xlinker> I<arg>
364
365Pass I<arg> to the linker.
366
Daniel Dunbar073190d2010-05-21 00:28:14 +0000367=item B<-mllvm> I<arg>
368
369Pass I<arg> to the LLVM backend.
370
Daniel Dunbardbec0332009-04-29 01:00:32 +0000371=item B<-Xpreprocessor> I<arg>
372
373Pass I<arg> to the preprocessor.
374
Daniel Dunbar073190d2010-05-21 00:28:14 +0000375=item B<-o> I<file>
Daniel Dunbardbec0332009-04-29 01:00:32 +0000376
377Write output to I<file>.
378
Daniel Dunbardbec0332009-04-29 01:00:32 +0000379=item B<-print-file-name>=I<file>
380
381Print the full library path of I<file>.
382
383=item B<-print-libgcc-file-name>
384
385Print the library path for "libgcc.a".
386
387=item B<-print-prog-name>=I<name>
388
389Print the full program path of I<name>.
390
391=item B<-print-search-dirs>
392
393Print the paths used for finding libraries and programs.
394
395=item B<-save-temps>
396
397Save intermediate compilation results.
398
Daniel Dunbar073190d2010-05-21 00:28:14 +0000399=item B<-integrated-as> B<-no-integrated-as>
400
401Used to enable and disable, respectively, the use of the integrated
402assembler. Whether the integrated assembler is on by default is target
403dependent.
404
Daniel Dunbardbec0332009-04-29 01:00:32 +0000405=item B<-time>
406
407Time individual commands.
408
Chris Lattner482c6822009-05-11 22:45:37 +0000409=item B<-ftime-report>
410
411Print timing summary of each stage of compilation.
412
Daniel Dunbardbec0332009-04-29 01:00:32 +0000413=item B<-v>
414
415Show commands to run and use verbose output.
416
Chris Lattner482c6822009-05-11 22:45:37 +0000417=back
Daniel Dunbardbec0332009-04-29 01:00:32 +0000418
Chris Lattner482c6822009-05-11 22:45:37 +0000419
Chris Lattner482c6822009-05-11 22:45:37 +0000420=head2 Diagnostics Options
421
422=over
423
Daniel Dunbar0a2329a2009-09-13 02:21:55 +0000424=item B<-fshow-column>
Chris Lattner04005dd2009-05-12 00:01:32 +0000425B<-fshow-source-location>
426B<-fcaret-diagnostics>
427B<-fdiagnostics-fixit-info>
Douglas Gregor4786c152010-08-19 20:24:43 +0000428B<-fdiagnostics-parseable-fixits>
Chris Lattner04005dd2009-05-12 00:01:32 +0000429B<-fdiagnostics-print-source-range-info>
430B<-fprint-source-range-info>
431B<-fdiagnostics-show-option>
432B<-fmessage-length>
Chris Lattner482c6822009-05-11 22:45:37 +0000433
Chris Lattner04005dd2009-05-12 00:01:32 +0000434These options control how Clang prints out information about diagnostics (errors
435and warnings). Please see the Clang User's Manual for more information.
Chris Lattner482c6822009-05-11 22:45:37 +0000436
437=back
Chris Lattner9b081c62009-05-06 17:22:08 +0000438
439
440=head2 Preprocessor Options
441
442=over
443
Chris Lattner06ab0442009-05-12 00:47:40 +0000444=item B<-D>I<macroname=value>
Chris Lattner482c6822009-05-11 22:45:37 +0000445
Chris Lattner06ab0442009-05-12 00:47:40 +0000446Adds an implicit #define into the predefines buffer which is read before the
447source file is preprocessed.
Chris Lattner482c6822009-05-11 22:45:37 +0000448
Chris Lattner06ab0442009-05-12 00:47:40 +0000449=item B<-U>I<macroname>
Chris Lattner482c6822009-05-11 22:45:37 +0000450
Chris Lattner06ab0442009-05-12 00:47:40 +0000451Adds an implicit #undef into the predefines buffer which is read before the
452source file is preprocessed.
Chris Lattner482c6822009-05-11 22:45:37 +0000453
Chris Lattner06ab0442009-05-12 00:47:40 +0000454=item B<-include> I<filename>
Chris Lattner482c6822009-05-11 22:45:37 +0000455
Chris Lattner06ab0442009-05-12 00:47:40 +0000456Adds an implicit #include into the predefines buffer which is read before the
457source file is preprocessed.
Chris Lattner482c6822009-05-11 22:45:37 +0000458
Chris Lattner06ab0442009-05-12 00:47:40 +0000459=item B<-I>I<directory>
Chris Lattner482c6822009-05-11 22:45:37 +0000460
Chris Lattner06ab0442009-05-12 00:47:40 +0000461Add the specified directory to the search path for include files.
462
463=item B<-F>I<directory>
464
465Add the specified directory to the search path for framework include files.
466
467=item B<-nostdinc>
468
469Do not search the standard system directories for include files.
470
Rafael Espindola4c8e6112009-10-27 00:29:40 +0000471=item B<-nobuiltininc>
472
473Do not search clang's builtin directory for include files.
474
Chris Lattner06ab0442009-05-12 00:47:40 +0000475=cut
476
477## TODO, but do we really want people using this stuff?
Daniel Dunbar0a2329a2009-09-13 02:21:55 +0000478#=item B<-idirafter>I<directory>
479#=item B<-iquote>I<directory>
480#=item B<-isystem>I<directory>
481#=item B<-iprefix>I<directory>
482#=item B<-iwithprefix>I<directory>
483#=item B<-iwithprefixbefore>I<directory>
484#=item B<-isysroot>
485
Chris Lattner06ab0442009-05-12 00:47:40 +0000486=pod
Chris Lattner482c6822009-05-11 22:45:37 +0000487
488
Chris Lattner9b081c62009-05-06 17:22:08 +0000489=back
490
491
492
Chris Lattner06ab0442009-05-12 00:47:40 +0000493=cut
Chris Lattner9b081c62009-05-06 17:22:08 +0000494
Chris Lattner06ab0442009-05-12 00:47:40 +0000495### TODO someday.
Daniel Dunbar0a2329a2009-09-13 02:21:55 +0000496#=head2 Warning Control Options
497#=over
498#=back
499#=head2 Code Generation and Optimization Options
500#=over
501#=back
502#=head2 Assembler Options
503#=over
504#=back
505#=head2 Linker Options
506#=over
507#=back
508#=head2 Static Analyzer Options
509#=over
510#=back
Chris Lattner482c6822009-05-11 22:45:37 +0000511
Chris Lattner06ab0442009-05-12 00:47:40 +0000512=pod
Chris Lattner482c6822009-05-11 22:45:37 +0000513
514
Daniel Dunbardbec0332009-04-29 01:00:32 +0000515=head1 ENVIRONMENT
516
Daniel Dunbare58c9432009-05-06 19:18:09 +0000517=over
518
519=item B<TMPDIR>, B<TEMP>, B<TMP>
520
521These environment variables are checked, in order, for the location to
522write temporary files used during the compilation process.
523
524=item B<CPATH>
525
526If this environment variable is present, it is treated as a delimited
527list of paths to be added to the default system include path list. The
528delimiter is the platform dependent delimitor, as used in the I<PATH>
529environment variable.
530
531Empty components in the environment variable are ignored.
532
533=item B<C_INCLUDE_PATH>, B<OBJC_INCLUDE_PATH>, B<CPLUS_INCLUDE_PATH>,
534B<OBJCPLUS_INCLUDE_PATH>
535
536These environment variables specify additional paths, as for CPATH,
537which are only used when processing the appropriate language.
538
Chris Lattner482c6822009-05-11 22:45:37 +0000539=item B<MACOSX_DEPLOYMENT_TARGET>
Daniel Dunbare58c9432009-05-06 19:18:09 +0000540
541If -mmacosx-version-min is unspecified, the default deployment target
Chris Lattner482c6822009-05-11 22:45:37 +0000542is read from this environment variable. This option only affects darwin
543targets.
Daniel Dunbare58c9432009-05-06 19:18:09 +0000544
545=back
Daniel Dunbardbec0332009-04-29 01:00:32 +0000546
547=head1 BUGS
548
Chris Lattner9b081c62009-05-06 17:22:08 +0000549To report bugs, please visit L<http://llvm.org/bugs/>. Most bug reports should
Daniel Dunbare58c9432009-05-06 19:18:09 +0000550include preprocessed source files (use the B<-E> option) and the full output of
551the compiler, along with information to reproduce.
Daniel Dunbardbec0332009-04-29 01:00:32 +0000552
553=head1 SEE ALSO
554
Chris Lattner482c6822009-05-11 22:45:37 +0000555 as(1), ld(1)
Daniel Dunbardbec0332009-04-29 01:00:32 +0000556
557=head1 AUTHOR
558
559Maintained by the Clang / LLVM Team (L<http://clang.llvm.org>).
560
561=cut