xref: /minix3/external/bsd/llvm/dist/clang/docs/tools/clang.pod (revision 0b98e8aad89f2bd4ba80b523d73cf29e9dd82ce1)
1=pod
2
3=head1 NAME
4
5clang - the Clang C, C++, and Objective-C compiler
6
7=head1 SYNOPSIS
8
9B<clang> [B<-c>|B<-S>|B<-E>] B<-std=>I<standard> B<-g>
10  [B<-O0>|B<-O1>|B<-O2>|B<-O3>|B<-Ofast>|B<-Os>|B<-Oz>|B<-O>|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  B<-stdlib=>I<library>
18  I<input-filenames>
19
20=head1 DESCRIPTION
21
22B<clang> is a C, C++, and Objective-C compiler which encompasses preprocessing,
23parsing, 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:
27
28=over
29
30=item B<Driver>
31
32The 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.
36
37=item B<Preprocessing>
38
39This stage handles tokenization of the input source file, macro expansion,
40#include expansion and handling of other preprocessor directives.  The output of
41this stage is typically called a ".i" (for C), ".ii" (for C++), ".mi" (for
42Objective-C) , or ".mii" (for Objective-C++) file.
43
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
54This stage translates an AST into low-level intermediate code (known as "LLVM
55IR") and ultimately to machine code.  This phase is responsible for optimizing
56the generated code and handling target-specific 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.
62
63=item B<Assembler>
64
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"
67file or "object" file.
68
69=item B<Linker>
70
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
78stages.  In addition to compilation of code, Clang also supports other tools:
79
80B<Clang Static Analyzer>
81
82The Clang Static Analyzer is a tool that scans source code to try to find bugs
83through code analysis.  This tool uses many parts of Clang and is built into the
84same driver.  Please see L<http://clang-analyzer.llvm.org> for more details
85on how to use the static analyzer.
86
87
88=head1 OPTIONS
89
90=head2 Stage Selection Options
91
92=over
93
94=item B<-E>
95
96Run the preprocessor stage.
97
98=item B<-fsyntax-only>
99
100Run the preprocessor, parser and type checking stages.
101
102=item B<-S>
103
104Run the previous stages as well as LLVM generation and optimization stages and
105target-specific code generation, producing an assembly file.
106
107=item B<-c>
108
109Run all of the above, plus the assembler, generating a target ".o" object file.
110
111=item B<no stage selection option>
112
113If no stage selection option is specified, all stages above are run, and the
114linker is run to combine the results into an executable or shared library.
115
116=back
117
118
119
120=head2 Language Selection and Mode Options
121
122=over
123
124=item B<-x> I<language>
125
126Treat subsequent input files as having type I<language>.
127
128=item B<-std>=I<language>
129
130Specify the language standard to compile for.
131
132=item B<-stdlib>=I<library>
133
134Specify the C++ standard library to use; supported options are libstdc++ and
135libc++.
136
137=item B<-ansi>
138
139Same as B<-std=c89>.
140
141=item B<-ObjC++>
142
143Treat source input files as Objective-C++ inputs.
144
145=item B<-ObjC>
146
147Treat source input files as Objective-C inputs.
148
149=item B<-trigraphs>
150
151Enable trigraphs.
152
153=item B<-ffreestanding>
154
155Indicate that the file should be compiled for a freestanding, not a hosted,
156environment.
157
158=item B<-fno-builtin>
159
160Disable special handling and optimizations of builtin functions like strlen and
161malloc.
162
163=item B<-fmath-errno>
164
165Indicate that math functions should be treated as updating errno.
166
167=item B<-fpascal-strings>
168
169Enable support for Pascal-style strings with "\pfoo".
170
171=item B<-fms-extensions>
172
173Enable support for Microsoft extensions.
174
175=item B<-fmsc-version=>
176
177Set _MSC_VER. Defaults to 1300 on Windows. Not set otherwise.
178
179=item B<-fborland-extensions>
180
181Enable support for Borland extensions.
182
183=item B<-fwritable-strings>
184
185Make all string literals default to writable.  This disables uniquing of
186strings and other optimizations.
187
188=item B<-flax-vector-conversions>
189
190Allow loose type checking rules for implicit vector conversions.
191
192=item B<-fblocks>
193
194Enable the "Blocks" language feature.
195
196=item B<-fobjc-gc-only>
197
198Indicate that Objective-C code should be compiled in GC-only mode, which only
199works when Objective-C Garbage Collection is enabled.
200
201=item B<-fobjc-gc>
202
203Indicate that Objective-C code should be compiled in hybrid-GC mode, which works
204with both GC and non-GC mode.
205
206=item B<-fobjc-abi-version>=I<version>
207
208Select the Objective-C ABI version to use. Available versions are 1 (legacy
209"fragile" ABI), 2 (non-fragile ABI 1), and 3 (non-fragile ABI 2).
210
211=item B<-fobjc-nonfragile-abi-version>=I<version>
212
213Select the Objective-C non-fragile ABI version to use by default. This will only
214be used as the Objective-C ABI when the non-fragile ABI is enabled (either via
215-fobjc-nonfragile-abi, or because it is the platform default).
216
217=item B<-fobjc-nonfragile-abi>
218
219Enable use of the Objective-C non-fragile ABI. On platforms for which this is
220the default ABI, it can be disabled with B<-fno-objc-nonfragile-abi>.
221
222=back
223
224
225
226=head2 Target Selection Options
227
228Clang fully supports cross compilation as an inherent part of its design.
229Depending on how your version of Clang is configured, it may have support for
230a number of cross compilers, or may only support a native target.
231
232=over
233
234=item B<-arch> I<architecture>
235
236Specify the architecture to build for.
237
238=item B<-mmacosx-version-min>=I<version>
239
240When building for Mac OS/X, specify the minimum version supported by your
241application.
242
243=item B<-miphoneos-version-min>
244
245When building for iPhone OS, specify the minimum version supported by your
246application.
247
248
249=item B<-march>=I<cpu>
250
251Specify that Clang should generate code for a specific processor family member
252and later.  For example, if you specify -march=i486, the compiler is allowed to
253generate instructions that are valid on i486 and later processors, but which
254may not exist on earlier ones.
255
256=back
257
258
259=head2 Code Generation Options
260
261=over
262
263=item B<-O0> B<-O1> B<-O2> B<-O3> B<-Ofast> B<-Os> B<-Oz> B<-O> B<-O4>
264
265Specify which optimization level to use:
266
267=over
268
269=item B<-O0>
270
271Means "no optimization": this level compiles the fastest and
272generates the most debuggable code.
273
274=item B<-O1>
275
276Somewhere between B<-O0> and B<-O2>.
277
278=item B<-O2>
279
280Moderate level of optimization which enables most optimizations.
281
282=item B<-O3>
283
284Like B<-O2>, except that it enables optimizations that take longer to perform
285or that may generate larger code (in an attempt to make the program run faster).
286
287=item B<-Ofast>
288
289Enables all the optimizations from B<-O3> along with other aggressive
290optimizations that may violate strict compliance with language standards.
291
292=item B<-Os>
293
294Like B<-O2> with extra optimizations to reduce code size.
295
296=item B<-Oz>
297
298Like B<-Os> (and thus B<-O2>), but reduces code size further.
299
300=item B<-O>
301
302Equivalent to B<-O2>.
303
304=item B<-O4> and higher
305
306Currently equivalent to B<-O3>
307
308=back
309
310=item B<-g>
311
312Generate debug information.  Note that Clang debug information works best at
313B<-O0>.  At higher optimization levels, only line number information is
314currently available.
315
316=item B<-fexceptions>
317
318Enable generation of unwind information, this allows exceptions to be thrown
319through Clang compiled stack frames.  This is on by default in x86-64.
320
321=item B<-ftrapv>
322
323Generate code to catch integer overflow errors.  Signed integer overflow is
324undefined in C, with this flag, extra code is generated to detect this and abort
325when it happens.
326
327
328=item B<-fvisibility>
329
330This flag sets the default visibility level.
331
332=item B<-fcommon>
333
334This flag specifies that variables without initializers get common linkage.  It
335can be disabled with B<-fno-common>.
336
337=item B<-ftls-model>
338
339Set the default thread-local storage (TLS) model to use for thread-local
340variables. Valid values are: "global-dynamic", "local-dynamic", "initial-exec"
341and "local-exec". The default is "global-dynamic". The default model can be
342overridden with the tls_model attribute. The compiler will try to choose a more
343efficient model if possible.
344
345=item B<-flto> B<-emit-llvm>
346
347Generate output files in LLVM formats, suitable for link time optimization. When
348used with B<-S> this generates LLVM intermediate language assembly files,
349otherwise this generates LLVM bitcode format object files (which may be passed
350to the linker depending on the stage selection options).
351
352=cut
353
354##=item B<-fnext-runtime> B<-fobjc-nonfragile-abi> B<-fgnu-runtime>
355##These options specify which Objective-C runtime the code generator should
356##target.  FIXME: we don't want people poking these generally.
357
358=pod
359
360=back
361
362
363=head2 Driver Options
364
365=over
366
367=item B<-###>
368
369Print the commands to run for this compilation.
370
371=item B<--help>
372
373Display available options.
374
375=item B<-Qunused-arguments>
376
377Don't emit warning for unused driver arguments.
378
379=item B<-Wa,>I<args>
380
381Pass the comma separated arguments in I<args> to the assembler.
382
383=item B<-Wl,>I<args>
384
385Pass the comma separated arguments in I<args> to the linker.
386
387=item B<-Wp,>I<args>
388
389Pass the comma separated arguments in I<args> to the preprocessor.
390
391=item B<-Xanalyzer> I<arg>
392
393Pass I<arg> to the static analyzer.
394
395=item B<-Xassembler> I<arg>
396
397Pass I<arg> to the assembler.
398
399=item B<-Xlinker> I<arg>
400
401Pass I<arg> to the linker.
402
403=item B<-Xpreprocessor> I<arg>
404
405Pass I<arg> to the preprocessor.
406
407=item B<-o> I<file>
408
409Write output to I<file>.
410
411=item B<-print-file-name>=I<file>
412
413Print the full library path of I<file>.
414
415=item B<-print-libgcc-file-name>
416
417Print the library path for "libgcc.a".
418
419=item B<-print-prog-name>=I<name>
420
421Print the full program path of I<name>.
422
423=item B<-print-search-dirs>
424
425Print the paths used for finding libraries and programs.
426
427=item B<-save-temps>
428
429Save intermediate compilation results.
430
431=item B<-integrated-as> B<-no-integrated-as>
432
433Used to enable and disable, respectively, the use of the integrated
434assembler. Whether the integrated assembler is on by default is target
435dependent.
436
437=item B<-time>
438
439Time individual commands.
440
441=item B<-ftime-report>
442
443Print timing summary of each stage of compilation.
444
445=item B<-v>
446
447Show commands to run and use verbose output.
448
449=back
450
451
452=head2 Diagnostics Options
453
454=over
455
456=item B<-fshow-column>
457B<-fshow-source-location>
458B<-fcaret-diagnostics>
459B<-fdiagnostics-fixit-info>
460B<-fdiagnostics-parseable-fixits>
461B<-fdiagnostics-print-source-range-info>
462B<-fprint-source-range-info>
463B<-fdiagnostics-show-option>
464B<-fmessage-length>
465
466These options control how Clang prints out information about diagnostics (errors
467and warnings).  Please see the Clang User's Manual for more information.
468
469=back
470
471
472=head2 Preprocessor Options
473
474=over
475
476=item B<-D>I<macroname=value>
477
478Adds an implicit #define into the predefines buffer which is read before the
479source file is preprocessed.
480
481=item B<-U>I<macroname>
482
483Adds an implicit #undef into the predefines buffer which is read before the
484source file is preprocessed.
485
486=item B<-include> I<filename>
487
488Adds an implicit #include into the predefines buffer which is read before the
489source file is preprocessed.
490
491=item B<-I>I<directory>
492
493Add the specified directory to the search path for include files.
494
495=item B<-F>I<directory>
496
497Add the specified directory to the search path for framework include files.
498
499=item B<-nostdinc>
500
501Do not search the standard system directories or compiler builtin directories
502for include files.
503
504=item B<-nostdlibinc>
505
506Do not search the standard system directories for include files, but do search
507compiler builtin include directories.
508
509=item B<-nobuiltininc>
510
511Do not search clang's builtin directory for include files.
512
513=cut
514
515## TODO, but do we really want people using this stuff?
516#=item B<-idirafter>I<directory>
517#=item B<-iquote>I<directory>
518#=item B<-isystem>I<directory>
519#=item B<-iprefix>I<directory>
520#=item B<-iwithprefix>I<directory>
521#=item B<-iwithprefixbefore>I<directory>
522#=item B<-isysroot>
523
524=pod
525
526
527=back
528
529
530
531=cut
532
533### TODO someday.
534#=head2 Warning Control Options
535#=over
536#=back
537#=head2 Code Generation and Optimization Options
538#=over
539#=back
540#=head2 Assembler Options
541#=over
542#=back
543#=head2 Linker Options
544#=over
545#=back
546#=head2 Static Analyzer Options
547#=over
548#=back
549
550=pod
551
552
553=head1 ENVIRONMENT
554
555=over
556
557=item B<TMPDIR>, B<TEMP>, B<TMP>
558
559These environment variables are checked, in order, for the location to
560write temporary files used during the compilation process.
561
562=item B<CPATH>
563
564If this environment variable is present, it is treated as a delimited
565list of paths to be added to the default system include path list. The
566delimiter is the platform dependent delimitor, as used in the I<PATH>
567environment variable.
568
569Empty components in the environment variable are ignored.
570
571=item B<C_INCLUDE_PATH>, B<OBJC_INCLUDE_PATH>, B<CPLUS_INCLUDE_PATH>,
572B<OBJCPLUS_INCLUDE_PATH>
573
574These environment variables specify additional paths, as for CPATH,
575which are only used when processing the appropriate language.
576
577=item B<MACOSX_DEPLOYMENT_TARGET>
578
579If -mmacosx-version-min is unspecified, the default deployment target
580is read from this environment variable.  This option only affects darwin
581targets.
582
583=back
584
585=head1 BUGS
586
587To report bugs, please visit L<http://llvm.org/bugs/>.  Most bug reports should
588include preprocessed source files (use the B<-E> option) and the full output of
589the compiler, along with information to reproduce.
590
591=head1 SEE ALSO
592
593 as(1), ld(1)
594
595=head1 AUTHOR
596
597Maintained by the Clang / LLVM Team (L<http://clang.llvm.org>).
598
599=cut
600