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