1CLANG(1)                             Clang                            CLANG(1)
2
3
4

NAME

6       clang - the Clang C, C++, and Objective-C compiler
7

SYNOPSIS

9       clang [options] filename ...
10

DESCRIPTION

12       clang  is  a C, C++, and Objective-C compiler which encompasses prepro‐
13       cessing, parsing, optimization, code generation, assembly, and linking.
14       Depending  on  which high-level mode setting is passed, Clang will stop
15       before doing a full link.  While Clang  is  highly  integrated,  it  is
16       important to understand the stages of compilation, to understand how to
17       invoke it.  These stages are:
18
19       Driver The clang executable is actually a small driver  which  controls
20              the  overall  execution  of  other  tools  such as the compiler,
21              assembler and linker.  Typically you do  not  need  to  interact
22              with  the  driver, but you transparently use it to run the other
23              tools.
24
25       Preprocessing
26              This stage handles tokenization of the input source file,  macro
27              expansion, #include expansion and handling of other preprocessor
28              directives.  The output of this stage is typically called a ".i"
29              (for  C),  ".ii"  (for  C++), ".mi" (for Objective-C), or ".mii"
30              (for Objective-C++) file.
31
32       Parsing and Semantic Analysis
33              This stage  parses  the  input  file,  translating  preprocessor
34              tokens  into a parse tree.  Once in the form of a parse tree, it
35              applies semantic analysis to compute types  for  expressions  as
36              well  and  determine whether the code is well formed. This stage
37              is responsible for generating most of the compiler  warnings  as
38              well  as  parse errors. The output of this stage is an "Abstract
39              Syntax Tree" (AST).
40
41       Code Generation and Optimization
42              This stage translates an AST into  low-level  intermediate  code
43              (known as "LLVM IR") and ultimately to machine code.  This phase
44              is responsible for optimizing the generated  code  and  handling
45              target-specific  code  generation.   The output of this stage is
46              typically called a ".s" file or "assembly" file.
47
48              Clang also supports the use of an integrated assembler, in which
49              the  code  generator produces object files directly. This avoids
50              the overhead of generating the ".s" file and of calling the tar‐
51              get assembler.
52
53       Assembler
54              This  stage runs the target assembler to translate the output of
55              the compiler into a target object file. The output of this stage
56              is typically called a ".o" file or "object" file.
57
58       Linker This stage runs the target linker to merge multiple object files
59              into an executable or dynamic library. The output of this  stage
60              is typically called an "a.out", ".dylib" or ".so" file.
61
62       Clang Static Analyzer
63
64       The  Clang  Static  Analyzer is a tool that scans source code to try to
65       find bugs through code analysis.  This tool uses many  parts  of  Clang
66       and    is    built    into    the   same   driver.    Please   see   <‐
67       https://clang-analyzer.llvm.org> for more details on  how  to  use  the
68       static analyzer.
69

OPTIONS

71   Stage Selection Options
72       -E     Run the preprocessor stage.
73
74       -fsyntax-only
75              Run the preprocessor, parser and type checking stages.
76
77       -S     Run the previous stages as well as LLVM generation and optimiza‐
78              tion stages and target-specific code  generation,  producing  an
79              assembly file.
80
81       -c     Run  all  of  the above, plus the assembler, generating a target
82              ".o" object file.
83
84       no stage selection option
85              If no stage selection option is specified, all stages above  are
86              run,  and  the linker is run to combine the results into an exe‐
87              cutable or shared library.
88
89   Language Selection and Mode Options
90       -x <language>
91              Treat subsequent input files as having type language.
92
93       -std=<standard>
94              Specify the language standard to compile for.
95
96              Supported values for the C language are:
97                 c89
98                 c90
99                 iso9899:1990
100
101                     ISO C 1990
102                 iso9899:199409
103
104                     ISO C 1990 with amendment 1
105                 gnu89
106                 gnu90
107
108                     ISO C 1990 with GNU extensions
109                 c99
110                 iso9899:1999
111
112                     ISO C 1999
113                 gnu99
114
115                     ISO C 1999 with GNU extensions
116                 c11
117                 iso9899:2011
118
119                     ISO C 2011
120                 gnu11
121
122                     ISO C 2011 with GNU extensions
123                 c17
124                 iso9899:2017
125
126                     ISO C 2017
127                 gnu17
128
129                     ISO C 2017 with GNU extensions
130
131              The default C language standard is gnu11, except on  PS4,  where
132              it is gnu99.
133
134              Supported values for the C++ language are:
135                 c++98
136                 c++03
137
138                     ISO C++ 1998 with amendments
139                 gnu++98
140                 gnu++03
141
142                     ISO C++ 1998 with amendments and GNU extensions
143                 c++11
144
145                     ISO C++ 2011 with amendments
146                 gnu++11
147
148                     ISO C++ 2011 with amendments and GNU extensions
149                 c++14
150
151                     ISO C++ 2014 with amendments
152                 gnu++14
153
154                     ISO C++ 2014 with amendments and GNU extensions
155                 c++17
156
157                     ISO C++ 2017 with amendments
158                 gnu++17
159
160                     ISO C++ 2017 with amendments and GNU extensions
161                 c++2a
162
163                     Working draft for ISO C++ 2020
164                 gnu++2a
165
166                     Working draft for ISO C++ 2020 with GNU extensions
167
168              The default C++ language standard is gnu++14.
169
170              Supported values for the OpenCL language are:
171                 cl1.0
172
173                     OpenCL 1.0
174                 cl1.1
175
176                     OpenCL 1.1
177                 cl1.2
178
179                     OpenCL 1.2
180                 cl2.0
181
182                     OpenCL 2.0
183
184              The default OpenCL language standard is cl1.0.
185
186              Supported values for the CUDA language are:
187                 cuda
188
189                     NVIDIA CUDA(tm)
190
191       -stdlib=<library>
192              Specify  the  C++ standard library to use; supported options are
193              libstdc++ and libc++. If not specified, platform default will be
194              used.
195
196       -rtlib=<library>
197              Specify  the  compiler runtime library to use; supported options
198              are libgcc and compiler-rt. If not specified,  platform  default
199              will be used.
200
201       -ansi  Same as -std=c89.
202
203       -ObjC, -ObjC++
204              Treat  source  input  files as Objective-C and Object-C++ inputs
205              respectively.
206
207       -trigraphs
208              Enable trigraphs.
209
210       -ffreestanding
211              Indicate that the file should be compiled  for  a  freestanding,
212              not a hosted, environment.
213
214       -fno-builtin
215              Disable  special handling and optimizations of builtin functions
216              like strlen() and malloc().
217
218       -fmath-errno
219              Indicate that math  functions  should  be  treated  as  updating
220              errno.
221
222       -fpascal-strings
223              Enable support for Pascal-style strings with "\pfoo".
224
225       -fms-extensions
226              Enable support for Microsoft extensions.
227
228       -fmsc-version=
229              Set _MSC_VER. Defaults to 1300 on Windows. Not set otherwise.
230
231       -fborland-extensions
232              Enable support for Borland extensions.
233
234       -fwritable-strings
235              Make  all  string  literals  default to writable.  This disables
236              uniquing of strings and other optimizations.
237
238       -flax-vector-conversions,              -flax-vector-conversions=<kind>,
239       -fno-lax-vector-conversions
240              Allow loose type checking rules for implicit vector conversions.
241              Possible values of <kind>:
242
243              · none: allow no implicit conversions between vectors
244
245              · integer: allow implicit bitcasts between  integer  vectors  of
246                the same overall bit-width
247
248              · all:  allow  implicit bitcasts between any vectors of the same
249                overall bit-width
250
251              <kind> defaults to integer if unspecified.
252
253       -fblocks
254              Enable the "Blocks" language feature.
255
256       -fobjc-abi-version=version
257              Select the Objective-C ABI version to  use.  Available  versions
258              are  1  (legacy  "fragile"  ABI),  2  (non-fragile ABI 1), and 3
259              (non-fragile ABI 2).
260
261       -fobjc-nonfragile-abi-version=<version>
262              Select  the  Objective-C  non-fragile  ABI  version  to  use  by
263              default.  This will only be used as the Objective-C ABI when the
264              non-fragile ABI is enabled (either via -fobjc-nonfragile-abi, or
265              because it is the platform default).
266
267       -fobjc-nonfragile-abi, -fno-objc-nonfragile-abi
268              Enable  use of the Objective-C non-fragile ABI. On platforms for
269              which  this  is  the  default  ABI,  it  can  be  disabled  with
270              -fno-objc-nonfragile-abi.
271
272   Target Selection Options
273       Clang  fully  supports  cross  compilation  as  an inherent part of its
274       design.  Depending on how your version of Clang is configured,  it  may
275       have  support  for  a  number of cross compilers, or may only support a
276       native target.
277
278       -arch <architecture>
279              Specify the architecture to build for.
280
281       -mmacosx-version-min=<version>
282              When building for macOS, specify the minimum  version  supported
283              by your application.
284
285       -miphoneos-version-min
286              When  building  for  iPhone OS, specify the minimum version sup‐
287              ported by your application.
288
289       --print-supported-cpus
290              Print out a list of supported processors for  the  given  target
291              (specified  through  --target=<architecture> or -arch <architec‐
292              ture>). If no target is specified,  the  system  default  target
293              will be used.
294
295       -mcpu=?, -mtune=?
296              Aliases of --print-supported-cpus
297
298       -march=<cpu>
299              Specify that Clang should generate code for a specific processor
300              family  member  and  later.   For  example,   if   you   specify
301              -march=i486,  the  compiler  is allowed to generate instructions
302              that are valid on i486 and later processors, but which  may  not
303              exist on earlier ones.
304
305   Code Generation Options
306       -O0, -O1, -O2, -O3, -Ofast, -Os, -Oz, -Og, -O, -O4
307              Specify which optimization level to use:
308                 -O0  Means "no optimization": this level compiles the fastest
309                 and generates the most debuggable code.
310
311                 -O1 Somewhere between -O0 and -O2.
312
313                 -O2 Moderate level of optimization which enables  most  opti‐
314                 mizations.
315
316                 -O3  Like -O2, except that it enables optimizations that take
317                 longer to perform or that may generate  larger  code  (in  an
318                 attempt to make the program run faster).
319
320                 -Ofast  Enables  all  the  optimizations  from -O3 along with
321                 other aggressive optimizations that may violate  strict  com‐
322                 pliance with language standards.
323
324                 -Os Like -O2 with extra optimizations to reduce code size.
325
326                 -Oz Like -Os (and thus -O2), but reduces code size further.
327
328                 -Og  Like  -O1. In future versions, this option might disable
329                 different optimizations in order to improve debuggability.
330
331                 -O Equivalent to -O2.
332
333                 -O4 and higher
334                     Currently equivalent to -O3
335
336       -g, -gline-tables-only, -gmodules
337              Control debug information output.  Note that Clang debug  infor‐
338              mation  works  best  at -O0.  When more than one option starting
339              with -g is specified, the last one wins:
340                 -g Generate debug information.
341
342                 -gline-tables-only Generate only line  table  debug  informa‐
343                 tion.  This  allows for symbolicated backtraces with inlining
344                 information, but does not include any information about vari‐
345                 ables, their locations or types.
346
347                 -gmodules  Generate  debug information that contains external
348                 references to types defined in Clang modules  or  precompiled
349                 headers  instead of emitting redundant debug type information
350                 into every object file.  This option  transparently  switches
351                 the  Clang  module format to object file containers that hold
352                 the Clang module together with the debug  information.   When
353                 compiling  a  program  that uses Clang modules or precompiled
354                 headers, this option produces complete debug information with
355                 faster compile times and much smaller object files.
356
357                 This option should not be used when building static libraries
358                 for distribution to other machines  because  the  debug  info
359                 will  contain  references  to the module cache on the machine
360                 the object files in the library were built on.
361
362       -fstandalone-debug -fno-standalone-debug
363              Clang supports a number of optimizations to reduce the  size  of
364              debug  information in the binary. They work based on the assump‐
365              tion that the debug type information can be spread out over mul‐
366              tiple compilation units.  For instance, Clang will not emit type
367              definitions for types that are not needed by a module and  could
368              be  replaced  with  a  forward declaration.  Further, Clang will
369              only emit type info for a dynamic C++ class in the  module  that
370              contains the vtable for the class.
371
372              The  -fstandalone-debug  option  turns  off these optimizations.
373              This is useful when working with 3rd-party libraries that  don't
374              come  with  debug  information.   This is the default on Darwin.
375              Note that Clang will never emit type information for types  that
376              are not referenced at all by the program.
377
378       -fexceptions
379              Enable  generation of unwind information. This allows exceptions
380              to be thrown through Clang compiled stack frames.  This is on by
381              default in x86-64.
382
383       -ftrapv
384              Generate  code to catch integer overflow errors.  Signed integer
385              overflow is undefined in C. With this flag, extra code is gener‐
386              ated to detect this and abort when it happens.
387
388       -fvisibility
389              This flag sets the default visibility level.
390
391       -fcommon, -fno-common
392              This flag specifies that variables without initializers get com‐
393              mon linkage.  It can be disabled with -fno-common.
394
395       -ftls-model=<model>
396              Set the default thread-local storage  (TLS)  model  to  use  for
397              thread-local  variables.  Valid  values  are:  "global-dynamic",
398              "local-dynamic", "initial-exec" and "local-exec". The default is
399              "global-dynamic".  The  default model can be overridden with the
400              tls_model attribute. The compiler will  try  to  choose  a  more
401              efficient model if possible.
402
403       -flto, -flto=full, -flto=thin, -emit-llvm
404              Generate  output  files  in LLVM formats, suitable for link time
405              optimization.  When used with -S this generates LLVM  intermedi‐
406              ate  language assembly files, otherwise this generates LLVM bit‐
407              code format object files (which may  be  passed  to  the  linker
408              depending on the stage selection options).
409
410              The  default  for  -flto is "full", in which the LLVM bitcode is
411              suitable for monolithic Link Time Optimization (LTO), where  the
412              linker merges all such modules into a single combined module for
413              optimization.  With  "thin",  ThinLTO  compilation  is   invoked
414              instead.
415
416   Driver Options
417       -###   Print (but do not run) the commands to run for this compilation.
418
419       --help Display available options.
420
421       -Qunused-arguments
422              Do not emit any warnings for unused driver arguments.
423
424       -Wa,<args>
425              Pass the comma separated arguments in args to the assembler.
426
427       -Wl,<args>
428              Pass the comma separated arguments in args to the linker.
429
430       -Wp,<args>
431              Pass the comma separated arguments in args to the preprocessor.
432
433       -Xanalyzer <arg>
434              Pass arg to the static analyzer.
435
436       -Xassembler <arg>
437              Pass arg to the assembler.
438
439       -Xlinker <arg>
440              Pass arg to the linker.
441
442       -Xpreprocessor <arg>
443              Pass arg to the preprocessor.
444
445       -o <file>
446              Write output to file.
447
448       -print-file-name=<file>
449              Print the full library path of file.
450
451       -print-libgcc-file-name
452              Print  the  library path for the currently used compiler runtime
453              library ("libgcc.a" or "libclang_rt.builtins.*.a").
454
455       -print-prog-name=<name>
456              Print the full program path of name.
457
458       -print-search-dirs
459              Print the paths used for finding libraries and programs.
460
461       -save-temps
462              Save intermediate compilation results.
463
464       -save-stats, -save-stats=cwd, -save-stats=obj
465              Save internal code generation (LLVM) statistics to a file in the
466              current  directory (-save-stats/"-save-stats=cwd") or the direc‐
467              tory of the output file ("-save-state=obj").
468
469       -integrated-as, -no-integrated-as
470              Used to enable and disable, respectively, the use of  the  inte‐
471              grated  assembler.  Whether  the  integrated  assembler is on by
472              default is target dependent.
473
474       -time  Time individual commands.
475
476       -ftime-report
477              Print timing summary of each stage of compilation.
478
479       -v     Show commands to run and use verbose output.
480
481   Diagnostics Options
482       -fshow-column, -fshow-source-location, -fcaret-diagnostics,  -fdiagnos‐
483       tics-fixit-info,       -fdiagnostics-parseable-fixits,       -fdiagnos‐
484       tics-print-source-range-info,   -fprint-source-range-info,   -fdiagnos‐
485       tics-show-option, -fmessage-length
486              These  options  control  how  Clang prints out information about
487              diagnostics (errors and warnings). Please see the  Clang  User's
488              Manual for more information.
489
490   Preprocessor Options
491       -D<macroname>=<value>
492              Adds  an  implicit  #define  into the predefines buffer which is
493              read before the source file is preprocessed.
494
495       -U<macroname>
496              Adds an implicit #undef into the predefines buffer which is read
497              before the source file is preprocessed.
498
499       -include <filename>
500              Adds  an  implicit  #include into the predefines buffer which is
501              read before the source file is preprocessed.
502
503       -I<directory>
504              Add the specified directory  to  the  search  path  for  include
505              files.
506
507       -F<directory>
508              Add  the  specified  directory  to the search path for framework
509              include files.
510
511       -nostdinc
512              Do not  search  the  standard  system  directories  or  compiler
513              builtin directories for include files.
514
515       -nostdlibinc
516              Do not search the standard system directories for include files,
517              but do search compiler builtin include directories.
518
519       -nobuiltininc
520              Do not search clang's builtin directory for include files.
521

ENVIRONMENT

523       TMPDIR, TEMP, TMP
524              These environment variables are checked, in order, for the loca‐
525              tion  to  write  temporary  files  used  during  the compilation
526              process.
527
528       CPATH  If this environment variable is present,  it  is  treated  as  a
529              delimited  list  of  paths  to  be  added  to the default system
530              include path list.  The  delimiter  is  the  platform  dependent
531              delimiter, as used in the PATH environment variable.
532
533              Empty components in the environment variable are ignored.
534
535       C_INCLUDE_PATH,     OBJC_INCLUDE_PATH,     CPLUS_INCLUDE_PATH,    OBJC‐
536       PLUS_INCLUDE_PATH
537              These environment variables specify  additional  paths,  as  for
538              CPATH,  which are only used when processing the appropriate lan‐
539              guage.
540
541       MACOSX_DEPLOYMENT_TARGET
542              If -mmacosx-version-min is unspecified, the  default  deployment
543              target  is read from this environment variable. This option only
544              affects Darwin targets.
545

BUGS

547       To  report  bugs,  please  visit  <https://bugs.llvm.org/>.   Most  bug
548       reports  should  include  preprocessed source files (use the -E option)
549       and the full output of the compiler, along with information  to  repro‐
550       duce.
551

SEE ALSO

553       as(1), ld(1)
554

AUTHOR

556       Maintained by the Clang / LLVM Team (<http://clang.llvm.org>)
557
559       2007-2020, The Clang Team
560
561
562
563
56410                               Apr 03, 2020                         CLANG(1)
Impressum