]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.bin/clang/clang/clang.1
MFV r329799, r329800:
[FreeBSD/FreeBSD.git] / usr.bin / clang / clang / clang.1
1 .\" $FreeBSD$
2 .\" Man page generated from reStructuredText.
3 .
4 .TH "CLANG" "1" "Dec 24, 2017" "6" "Clang"
5 .SH NAME
6 clang \- the Clang C, C++, and Objective-C compiler
7 .
8 .nr rst2man-indent-level 0
9 .
10 .de1 rstReportMargin
11 \\$1 \\n[an-margin]
12 level \\n[rst2man-indent-level]
13 level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
14 -
15 \\n[rst2man-indent0]
16 \\n[rst2man-indent1]
17 \\n[rst2man-indent2]
18 ..
19 .de1 INDENT
20 .\" .rstReportMargin pre:
21 . RS \\$1
22 . nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
23 . nr rst2man-indent-level +1
24 .\" .rstReportMargin post:
25 ..
26 .de UNINDENT
27 . RE
28 .\" indent \\n[an-margin]
29 .\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
30 .nr rst2man-indent-level -1
31 .\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
32 .in \\n[rst2man-indent\\n[rst2man-indent-level]]u
33 ..
34 .SH SYNOPSIS
35 .sp
36 \fBclang\fP [\fIoptions\fP] \fIfilename ...\fP
37 .SH DESCRIPTION
38 .sp
39 \fBclang\fP is a C, C++, and Objective\-C compiler which encompasses
40 preprocessing, parsing, optimization, code generation, assembly, and linking.
41 Depending on which high\-level mode setting is passed, Clang will stop before
42 doing a full link.  While Clang is highly integrated, it is important to
43 understand the stages of compilation, to understand how to invoke it.  These
44 stages are:
45 .INDENT 0.0
46 .TP
47 .B Driver
48 The clang executable is actually a small driver which controls the overall
49 execution of other tools such as the compiler, assembler and linker.
50 Typically you do not need to interact with the driver, but you
51 transparently use it to run the other tools.
52 .TP
53 .B Preprocessing
54 This stage handles tokenization of the input source file, macro expansion,
55 #include expansion and handling of other preprocessor directives.  The
56 output of this stage is typically called a ".i" (for C), ".ii" (for C++),
57 ".mi" (for Objective\-C), or ".mii" (for Objective\-C++) file.
58 .TP
59 .B Parsing and Semantic Analysis
60 This stage parses the input file, translating preprocessor tokens into a
61 parse tree.  Once in the form of a parse tree, it applies semantic
62 analysis to compute types for expressions as well and determine whether
63 the code is well formed. This stage is responsible for generating most of
64 the compiler warnings as well as parse errors. The output of this stage is
65 an "Abstract Syntax Tree" (AST).
66 .TP
67 .B Code Generation and Optimization
68 This stage translates an AST into low\-level intermediate code (known as
69 "LLVM IR") and ultimately to machine code.  This phase is responsible for
70 optimizing the generated code and handling target\-specific code generation.
71 The output of this stage is typically called a ".s" file or "assembly" file.
72 .sp
73 Clang also supports the use of an integrated assembler, in which the code
74 generator produces object files directly. This avoids the overhead of
75 generating the ".s" file and of calling the target assembler.
76 .TP
77 .B Assembler
78 This stage runs the target assembler to translate the output of the
79 compiler into a target object file. The output of this stage is typically
80 called a ".o" file or "object" file.
81 .TP
82 .B Linker
83 This stage runs the target linker to merge multiple object files into an
84 executable or dynamic library. The output of this stage is typically called
85 an "a.out", ".dylib" or ".so" file.
86 .UNINDENT
87 .sp
88 \fBClang Static Analyzer\fP
89 .sp
90 The Clang Static Analyzer is a tool that scans source code to try to find bugs
91 through code analysis.  This tool uses many parts of Clang and is built into
92 the same driver.  Please see <\fI\%http://clang\-analyzer.llvm.org\fP> for more details
93 on how to use the static analyzer.
94 .SH OPTIONS
95 .SS Stage Selection Options
96 .INDENT 0.0
97 .TP
98 .B \-E
99 Run the preprocessor stage.
100 .UNINDENT
101 .INDENT 0.0
102 .TP
103 .B \-fsyntax\-only
104 Run the preprocessor, parser and type checking stages.
105 .UNINDENT
106 .INDENT 0.0
107 .TP
108 .B \-S
109 Run the previous stages as well as LLVM generation and optimization stages
110 and target\-specific code generation, producing an assembly file.
111 .UNINDENT
112 .INDENT 0.0
113 .TP
114 .B \-c
115 Run all of the above, plus the assembler, generating a target ".o" object file.
116 .UNINDENT
117 .INDENT 0.0
118 .TP
119 .B no stage selection option
120 If no stage selection option is specified, all stages above are run, and the
121 linker is run to combine the results into an executable or shared library.
122 .UNINDENT
123 .SS Language Selection and Mode Options
124 .INDENT 0.0
125 .TP
126 .B \-x <language>
127 Treat subsequent input files as having type language.
128 .UNINDENT
129 .INDENT 0.0
130 .TP
131 .B \-std=<language>
132 Specify the language standard to compile for.
133 .UNINDENT
134 .INDENT 0.0
135 .TP
136 .B \-stdlib=<library>
137 Specify the C++ standard library to use; supported options are libstdc++ and
138 libc++. If not specified, platform default will be used.
139 .UNINDENT
140 .INDENT 0.0
141 .TP
142 .B \-rtlib=<library>
143 Specify the compiler runtime library to use; supported options are libgcc and
144 compiler\-rt. If not specified, platform default will be used.
145 .UNINDENT
146 .INDENT 0.0
147 .TP
148 .B \-ansi
149 Same as \-std=c89.
150 .UNINDENT
151 .INDENT 0.0
152 .TP
153 .B \-ObjC, \-ObjC++
154 Treat source input files as Objective\-C and Object\-C++ inputs respectively.
155 .UNINDENT
156 .INDENT 0.0
157 .TP
158 .B \-trigraphs
159 Enable trigraphs.
160 .UNINDENT
161 .INDENT 0.0
162 .TP
163 .B \-ffreestanding
164 Indicate that the file should be compiled for a freestanding, not a hosted,
165 environment.
166 .UNINDENT
167 .INDENT 0.0
168 .TP
169 .B \-fno\-builtin
170 Disable special handling and optimizations of builtin functions like
171 \fBstrlen()\fP and \fBmalloc()\fP\&.
172 .UNINDENT
173 .INDENT 0.0
174 .TP
175 .B \-fmath\-errno
176 Indicate that math functions should be treated as updating \fBerrno\fP\&.
177 .UNINDENT
178 .INDENT 0.0
179 .TP
180 .B \-fpascal\-strings
181 Enable support for Pascal\-style strings with "\epfoo".
182 .UNINDENT
183 .INDENT 0.0
184 .TP
185 .B \-fms\-extensions
186 Enable support for Microsoft extensions.
187 .UNINDENT
188 .INDENT 0.0
189 .TP
190 .B \-fmsc\-version=
191 Set _MSC_VER. Defaults to 1300 on Windows. Not set otherwise.
192 .UNINDENT
193 .INDENT 0.0
194 .TP
195 .B \-fborland\-extensions
196 Enable support for Borland extensions.
197 .UNINDENT
198 .INDENT 0.0
199 .TP
200 .B \-fwritable\-strings
201 Make all string literals default to writable.  This disables uniquing of
202 strings and other optimizations.
203 .UNINDENT
204 .INDENT 0.0
205 .TP
206 .B \-flax\-vector\-conversions
207 Allow loose type checking rules for implicit vector conversions.
208 .UNINDENT
209 .INDENT 0.0
210 .TP
211 .B \-fblocks
212 Enable the "Blocks" language feature.
213 .UNINDENT
214 .INDENT 0.0
215 .TP
216 .B \-fobjc\-abi\-version=version
217 Select the Objective\-C ABI version to use. Available versions are 1 (legacy
218 "fragile" ABI), 2 (non\-fragile ABI 1), and 3 (non\-fragile ABI 2).
219 .UNINDENT
220 .INDENT 0.0
221 .TP
222 .B \-fobjc\-nonfragile\-abi\-version=<version>
223 Select the Objective\-C non\-fragile ABI version to use by default. This will
224 only be used as the Objective\-C ABI when the non\-fragile ABI is enabled
225 (either via \fI\%\-fobjc\-nonfragile\-abi\fP, or because it is the platform
226 default).
227 .UNINDENT
228 .INDENT 0.0
229 .TP
230 .B \-fobjc\-nonfragile\-abi, \-fno\-objc\-nonfragile\-abi
231 Enable use of the Objective\-C non\-fragile ABI. On platforms for which this is
232 the default ABI, it can be disabled with \fI\%\-fno\-objc\-nonfragile\-abi\fP\&.
233 .UNINDENT
234 .SS Target Selection Options
235 .sp
236 Clang fully supports cross compilation as an inherent part of its design.
237 Depending on how your version of Clang is configured, it may have support for a
238 number of cross compilers, or may only support a native target.
239 .INDENT 0.0
240 .TP
241 .B \-arch <architecture>
242 Specify the architecture to build for.
243 .UNINDENT
244 .INDENT 0.0
245 .TP
246 .B \-mmacosx\-version\-min=<version>
247 When building for Mac OS X, specify the minimum version supported by your
248 application.
249 .UNINDENT
250 .INDENT 0.0
251 .TP
252 .B \-miphoneos\-version\-min
253 When building for iPhone OS, specify the minimum version supported by your
254 application.
255 .UNINDENT
256 .INDENT 0.0
257 .TP
258 .B \-march=<cpu>
259 Specify that Clang should generate code for a specific processor family
260 member and later.  For example, if you specify \-march=i486, the compiler is
261 allowed to generate instructions that are valid on i486 and later processors,
262 but which may not exist on earlier ones.
263 .UNINDENT
264 .SS Code Generation Options
265 .INDENT 0.0
266 .TP
267 .B \-O0, \-O1, \-O2, \-O3, \-Ofast, \-Os, \-Oz, \-Og, \-O, \-O4
268 Specify which optimization level to use:
269 .INDENT 7.0
270 .INDENT 3.5
271 \fI\%\-O0\fP Means "no optimization": this level compiles the fastest and
272 generates the most debuggable code.
273 .sp
274 \fI\%\-O1\fP Somewhere between \fI\%\-O0\fP and \fI\%\-O2\fP\&.
275 .sp
276 \fI\%\-O2\fP Moderate level of optimization which enables most
277 optimizations.
278 .sp
279 \fI\%\-O3\fP Like \fI\%\-O2\fP, except that it enables optimizations that
280 take longer to perform or that may generate larger code (in an attempt to
281 make the program run faster).
282 .sp
283 \fI\%\-Ofast\fP Enables all the optimizations from \fI\%\-O3\fP along
284 with other aggressive optimizations that may violate strict compliance with
285 language standards.
286 .sp
287 \fI\%\-Os\fP Like \fI\%\-O2\fP with extra optimizations to reduce code
288 size.
289 .sp
290 \fI\%\-Oz\fP Like \fI\%\-Os\fP (and thus \fI\%\-O2\fP), but reduces code
291 size further.
292 .sp
293 \fI\%\-Og\fP Like \fI\%\-O1\fP\&. In future versions, this option might
294 disable different optimizations in order to improve debuggability.
295 .sp
296 \fI\%\-O\fP Equivalent to \fI\%\-O2\fP\&.
297 .sp
298 \fI\%\-O4\fP and higher
299 .INDENT 0.0
300 .INDENT 3.5
301 Currently equivalent to \fI\%\-O3\fP
302 .UNINDENT
303 .UNINDENT
304 .UNINDENT
305 .UNINDENT
306 .UNINDENT
307 .INDENT 0.0
308 .TP
309 .B \-g, \-gline\-tables\-only, \-gmodules
310 Control debug information output.  Note that Clang debug information works
311 best at \fI\%\-O0\fP\&.  When more than one option starting with \fI\-g\fP is
312 specified, the last one wins:
313 .INDENT 7.0
314 .INDENT 3.5
315 \fB\-g\fP Generate debug information.
316 .sp
317 \fB\-gline\-tables\-only\fP Generate only line table debug information. This
318 allows for symbolicated backtraces with inlining information, but does not
319 include any information about variables, their locations or types.
320 .sp
321 \fI\%\-gmodules\fP Generate debug information that contains external
322 references to types defined in Clang modules or precompiled headers instead
323 of emitting redundant debug type information into every object file.  This
324 option transparently switches the Clang module format to object file
325 containers that hold the Clang module together with the debug information.
326 When compiling a program that uses Clang modules or precompiled headers,
327 this option produces complete debug information with faster compile
328 times and much smaller object files.
329 .sp
330 This option should not be used when building static libraries for
331 distribution to other machines because the debug info will contain
332 references to the module cache on the machine the object files in the
333 library were built on.
334 .UNINDENT
335 .UNINDENT
336 .UNINDENT
337 .INDENT 0.0
338 .TP
339 .B \-fstandalone\-debug \-fno\-standalone\-debug
340 Clang supports a number of optimizations to reduce the size of debug
341 information in the binary. They work based on the assumption that the
342 debug type information can be spread out over multiple compilation units.
343 For instance, Clang will not emit type definitions for types that are not
344 needed by a module and could be replaced with a forward declaration.
345 Further, Clang will only emit type info for a dynamic C++ class in the
346 module that contains the vtable for the class.
347 .sp
348 The \fB\-fstandalone\-debug\fP option turns off these optimizations.
349 This is useful when working with 3rd\-party libraries that don\(aqt come with
350 debug information.  This is the default on Darwin.  Note that Clang will
351 never emit type information for types that are not referenced at all by the
352 program.
353 .UNINDENT
354 .INDENT 0.0
355 .TP
356 .B \-fexceptions
357 Enable generation of unwind information. This allows exceptions to be thrown
358 through Clang compiled stack frames.  This is on by default in x86\-64.
359 .UNINDENT
360 .INDENT 0.0
361 .TP
362 .B \-ftrapv
363 Generate code to catch integer overflow errors.  Signed integer overflow is
364 undefined in C. With this flag, extra code is generated to detect this and
365 abort when it happens.
366 .UNINDENT
367 .INDENT 0.0
368 .TP
369 .B \-fvisibility
370 This flag sets the default visibility level.
371 .UNINDENT
372 .INDENT 0.0
373 .TP
374 .B \-fcommon, \-fno\-common
375 This flag specifies that variables without initializers get common linkage.
376 It can be disabled with \fI\%\-fno\-common\fP\&.
377 .UNINDENT
378 .INDENT 0.0
379 .TP
380 .B \-ftls\-model=<model>
381 Set the default thread\-local storage (TLS) model to use for thread\-local
382 variables. Valid values are: "global\-dynamic", "local\-dynamic",
383 "initial\-exec" and "local\-exec". The default is "global\-dynamic". The default
384 model can be overridden with the tls_model attribute. The compiler will try
385 to choose a more efficient model if possible.
386 .UNINDENT
387 .INDENT 0.0
388 .TP
389 .B \-flto, \-flto=full, \-flto=thin, \-emit\-llvm
390 Generate output files in LLVM formats, suitable for link time optimization.
391 When used with \fI\%\-S\fP this generates LLVM intermediate language
392 assembly files, otherwise this generates LLVM bitcode format object files
393 (which may be passed to the linker depending on the stage selection options).
394 .sp
395 The default for \fI\%\-flto\fP is "full", in which the
396 LLVM bitcode is suitable for monolithic Link Time Optimization (LTO), where
397 the linker merges all such modules into a single combined module for
398 optimization. With "thin", ThinLTO
399 compilation is invoked instead.
400 .UNINDENT
401 .SS Driver Options
402 .INDENT 0.0
403 .TP
404 .B \-###
405 Print (but do not run) the commands to run for this compilation.
406 .UNINDENT
407 .INDENT 0.0
408 .TP
409 .B \-\-help
410 Display available options.
411 .UNINDENT
412 .INDENT 0.0
413 .TP
414 .B \-Qunused\-arguments
415 Do not emit any warnings for unused driver arguments.
416 .UNINDENT
417 .INDENT 0.0
418 .TP
419 .B \-Wa,<args>
420 Pass the comma separated arguments in args to the assembler.
421 .UNINDENT
422 .INDENT 0.0
423 .TP
424 .B \-Wl,<args>
425 Pass the comma separated arguments in args to the linker.
426 .UNINDENT
427 .INDENT 0.0
428 .TP
429 .B \-Wp,<args>
430 Pass the comma separated arguments in args to the preprocessor.
431 .UNINDENT
432 .INDENT 0.0
433 .TP
434 .B \-Xanalyzer <arg>
435 Pass arg to the static analyzer.
436 .UNINDENT
437 .INDENT 0.0
438 .TP
439 .B \-Xassembler <arg>
440 Pass arg to the assembler.
441 .UNINDENT
442 .INDENT 0.0
443 .TP
444 .B \-Xlinker <arg>
445 Pass arg to the linker.
446 .UNINDENT
447 .INDENT 0.0
448 .TP
449 .B \-Xpreprocessor <arg>
450 Pass arg to the preprocessor.
451 .UNINDENT
452 .INDENT 0.0
453 .TP
454 .B \-o <file>
455 Write output to file.
456 .UNINDENT
457 .INDENT 0.0
458 .TP
459 .B \-print\-file\-name=<file>
460 Print the full library path of file.
461 .UNINDENT
462 .INDENT 0.0
463 .TP
464 .B \-print\-libgcc\-file\-name
465 Print the library path for the currently used compiler runtime library
466 ("libgcc.a" or "libclang_rt.builtins.*.a").
467 .UNINDENT
468 .INDENT 0.0
469 .TP
470 .B \-print\-prog\-name=<name>
471 Print the full program path of name.
472 .UNINDENT
473 .INDENT 0.0
474 .TP
475 .B \-print\-search\-dirs
476 Print the paths used for finding libraries and programs.
477 .UNINDENT
478 .INDENT 0.0
479 .TP
480 .B \-save\-temps
481 Save intermediate compilation results.
482 .UNINDENT
483 .INDENT 0.0
484 .TP
485 .B \-save\-stats, \-save\-stats=cwd, \-save\-stats=obj
486 Save internal code generation (LLVM) statistics to a file in the current
487 directory (\fI\%\-save\-stats\fP/"\-save\-stats=cwd") or the directory
488 of the output file ("\-save\-state=obj").
489 .UNINDENT
490 .INDENT 0.0
491 .TP
492 .B \-integrated\-as, \-no\-integrated\-as
493 Used to enable and disable, respectively, the use of the integrated
494 assembler. Whether the integrated assembler is on by default is target
495 dependent.
496 .UNINDENT
497 .INDENT 0.0
498 .TP
499 .B \-time
500 Time individual commands.
501 .UNINDENT
502 .INDENT 0.0
503 .TP
504 .B \-ftime\-report
505 Print timing summary of each stage of compilation.
506 .UNINDENT
507 .INDENT 0.0
508 .TP
509 .B \-v
510 Show commands to run and use verbose output.
511 .UNINDENT
512 .SS Diagnostics Options
513 .INDENT 0.0
514 .TP
515 .B \-fshow\-column, \-fshow\-source\-location, \-fcaret\-diagnostics, \-fdiagnostics\-fixit\-info, \-fdiagnostics\-parseable\-fixits, \-fdiagnostics\-print\-source\-range\-info, \-fprint\-source\-range\-info, \-fdiagnostics\-show\-option, \-fmessage\-length
516 These options control how Clang prints out information about diagnostics
517 (errors and warnings). Please see the Clang User\(aqs Manual for more information.
518 .UNINDENT
519 .SS Preprocessor Options
520 .INDENT 0.0
521 .TP
522 .B \-D<macroname>=<value>
523 Adds an implicit #define into the predefines buffer which is read before the
524 source file is preprocessed.
525 .UNINDENT
526 .INDENT 0.0
527 .TP
528 .B \-U<macroname>
529 Adds an implicit #undef into the predefines buffer which is read before the
530 source file is preprocessed.
531 .UNINDENT
532 .INDENT 0.0
533 .TP
534 .B \-include <filename>
535 Adds an implicit #include into the predefines buffer which is read before the
536 source file is preprocessed.
537 .UNINDENT
538 .INDENT 0.0
539 .TP
540 .B \-I<directory>
541 Add the specified directory to the search path for include files.
542 .UNINDENT
543 .INDENT 0.0
544 .TP
545 .B \-F<directory>
546 Add the specified directory to the search path for framework include files.
547 .UNINDENT
548 .INDENT 0.0
549 .TP
550 .B \-nostdinc
551 Do not search the standard system directories or compiler builtin directories
552 for include files.
553 .UNINDENT
554 .INDENT 0.0
555 .TP
556 .B \-nostdlibinc
557 Do not search the standard system directories for include files, but do
558 search compiler builtin include directories.
559 .UNINDENT
560 .INDENT 0.0
561 .TP
562 .B \-nobuiltininc
563 Do not search clang\(aqs builtin directory for include files.
564 .UNINDENT
565 .SH ENVIRONMENT
566 .INDENT 0.0
567 .TP
568 .B TMPDIR, TEMP, TMP
569 These environment variables are checked, in order, for the location to write
570 temporary files used during the compilation process.
571 .UNINDENT
572 .INDENT 0.0
573 .TP
574 .B CPATH
575 If this environment variable is present, it is treated as a delimited list of
576 paths to be added to the default system include path list. The delimiter is
577 the platform dependent delimiter, as used in the PATH environment variable.
578 .sp
579 Empty components in the environment variable are ignored.
580 .UNINDENT
581 .INDENT 0.0
582 .TP
583 .B C_INCLUDE_PATH, OBJC_INCLUDE_PATH, CPLUS_INCLUDE_PATH, OBJCPLUS_INCLUDE_PATH
584 These environment variables specify additional paths, as for \fI\%CPATH\fP, which are
585 only used when processing the appropriate language.
586 .UNINDENT
587 .INDENT 0.0
588 .TP
589 .B MACOSX_DEPLOYMENT_TARGET
590 If \fI\%\-mmacosx\-version\-min\fP is unspecified, the default deployment
591 target is read from this environment variable. This option only affects
592 Darwin targets.
593 .UNINDENT
594 .SH BUGS
595 .sp
596 To report bugs, please visit <\fI\%http://llvm.org/bugs/\fP>.  Most bug reports should
597 include preprocessed source files (use the \fI\%\-E\fP option) and the full
598 output of the compiler, along with information to reproduce.
599 .SH SEE ALSO
600 .sp
601 \fBas(1)\fP, \fBld(1)\fP
602 .SH AUTHOR
603 Maintained by the Clang / LLVM Team (<http://clang.llvm.org>)
604 .SH COPYRIGHT
605 2007-2017, The Clang Team
606 .\" Generated by docutils manpage writer.
607 .