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<-Os>|B<-Oz>|B<-O3>|B<-Ofast>|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. 85 86 87=head1 OPTIONS 88 89=head2 Stage Selection Options 90 91=over 92 93=item B<-E> 94 95Run the preprocessor stage. 96 97=item B<-fsyntax-only> 98 99Run the preprocessor, parser and type checking stages. 100 101=item B<-S> 102 103Run the previous stages as well as LLVM generation and optimization stages and 104target-specific code generation, producing an assembly file. 105 106=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. 118 119=back 120 121 122 123=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 135=item B<-stdlib>=I<library> 136 137Specify the C++ standard library to use; supported options are libstdc++ and 138libc++. 139 140=item B<-ansi> 141 142Same as B<-std=c89>. 143 144=item B<-ObjC++> 145 146Treat source input files as Objective-C++ inputs. 147 148=item B<-ObjC> 149 150Treat source input files as Objective-C inputs. 151 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 178=item B<-fmsc-version=> 179 180Set _MSC_VER. Defaults to 1300 on Windows. Not set otherwise. 181 182=item B<-fborland-extensions> 183 184Enable support for Borland extensions. 185 186=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 199=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 209=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 225=back 226 227 228 229=head2 Target Selection Options 230 231Clang fully supports cross compilation as an inherent part of its design. 232Depending on how your version of Clang is configured, it may have support for 233a number of cross compilers, or may only support a native target. 234 235=over 236 237=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<-Oz> B<-O3> B<-Ofast> B<-O4> 267 268Specify which optimization level to use. B<-O0> means "no optimization": this 269level 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<-Oz> is like B<-Os> 272(and thus B<-O2>), but reduces code size further. B<-O3> is like B<-O2>, 273except that it enables optimizations that take longer to perform or that may 274generate larger code (in an attempt to make the program run faster). 275B<-Ofast> enables all the optimizations from B<-O3> along with other aggressive 276optimizations that may violate strict compliance with language standards. On 277supported platforms, B<-O4> enables link-time optimization; object files are 278stored in the LLVM bitcode file format and whole program optimization is done at 279link time. B<-O1> is somewhere between B<-O0> and B<-O2>. 280 281=item B<-g> 282 283Generate debug information. Note that Clang debug information works best at 284B<-O0>. At higher optimization levels, only line number information is 285currently available. 286 287=item B<-fexceptions> 288 289Enable generation of unwind information, this allows exceptions to be thrown 290through Clang compiled stack frames. This is on by default in x86-64. 291 292=item B<-ftrapv> 293 294Generate code to catch integer overflow errors. Signed integer overflow is 295undefined in C, with this flag, extra code is generated to detect this and abort 296when it happens. 297 298 299=item B<-fvisibility> 300 301This flag sets the default visibility level. 302 303=item B<-fcommon> 304 305This flag specifies that variables without initializers get common linkage. It 306can be disabled with B<-fno-common>. 307 308=item B<-ftls-model> 309 310Set the default thread-local storage (TLS) model to use for thread-local 311variables. Valid values are: "global-dynamic", "local-dynamic", "initial-exec" 312and "local-exec". The default is "global-dynamic". The default model can be 313overridden with the tls_model attribute. The compiler will try to choose a more 314efficient model if possible. 315 316=item B<-flto> B<-emit-llvm> 317 318Generate output files in LLVM formats, suitable for link time optimization. When 319used with B<-S> this generates LLVM intermediate language assembly files, 320otherwise this generates LLVM bitcode format object files (which may be passed 321to the linker depending on the stage selection options). 322 323=cut 324 325##=item B<-fnext-runtime> B<-fobjc-nonfragile-abi> B<-fgnu-runtime> 326##These options specify which Objective-C runtime the code generator should 327##target. FIXME: we don't want people poking these generally. 328 329=pod 330 331=back 332 333 334=head2 Driver Options 335 336=over 337 338=item B<-###> 339 340Print the commands to run for this compilation. 341 342=item B<--help> 343 344Display available options. 345 346=item B<-Qunused-arguments> 347 348Don't emit warning for unused driver arguments. 349 350=item B<-Wa,>I<args> 351 352Pass the comma separated arguments in I<args> to the assembler. 353 354=item B<-Wl,>I<args> 355 356Pass the comma separated arguments in I<args> to the linker. 357 358=item B<-Wp,>I<args> 359 360Pass the comma separated arguments in I<args> to the preprocessor. 361 362=item B<-Xanalyzer> I<arg> 363 364Pass I<arg> to the static analyzer. 365 366=item B<-Xassembler> I<arg> 367 368Pass I<arg> to the assembler. 369 370=item B<-Xlinker> I<arg> 371 372Pass I<arg> to the linker. 373 374=item B<-Xpreprocessor> I<arg> 375 376Pass I<arg> to the preprocessor. 377 378=item B<-o> I<file> 379 380Write output to I<file>. 381 382=item B<-print-file-name>=I<file> 383 384Print the full library path of I<file>. 385 386=item B<-print-libgcc-file-name> 387 388Print the library path for "libgcc.a". 389 390=item B<-print-prog-name>=I<name> 391 392Print the full program path of I<name>. 393 394=item B<-print-search-dirs> 395 396Print the paths used for finding libraries and programs. 397 398=item B<-save-temps> 399 400Save intermediate compilation results. 401 402=item B<-integrated-as> B<-no-integrated-as> 403 404Used to enable and disable, respectively, the use of the integrated 405assembler. Whether the integrated assembler is on by default is target 406dependent. 407 408=item B<-time> 409 410Time individual commands. 411 412=item B<-ftime-report> 413 414Print timing summary of each stage of compilation. 415 416=item B<-v> 417 418Show commands to run and use verbose output. 419 420=back 421 422 423=head2 Diagnostics Options 424 425=over 426 427=item B<-fshow-column> 428B<-fshow-source-location> 429B<-fcaret-diagnostics> 430B<-fdiagnostics-fixit-info> 431B<-fdiagnostics-parseable-fixits> 432B<-fdiagnostics-print-source-range-info> 433B<-fprint-source-range-info> 434B<-fdiagnostics-show-option> 435B<-fmessage-length> 436 437These options control how Clang prints out information about diagnostics (errors 438and warnings). Please see the Clang User's Manual for more information. 439 440=back 441 442 443=head2 Preprocessor Options 444 445=over 446 447=item B<-D>I<macroname=value> 448 449Adds an implicit #define into the predefines buffer which is read before the 450source file is preprocessed. 451 452=item B<-U>I<macroname> 453 454Adds an implicit #undef into the predefines buffer which is read before the 455source file is preprocessed. 456 457=item B<-include> I<filename> 458 459Adds an implicit #include into the predefines buffer which is read before the 460source file is preprocessed. 461 462=item B<-I>I<directory> 463 464Add the specified directory to the search path for include files. 465 466=item B<-F>I<directory> 467 468Add the specified directory to the search path for framework include files. 469 470=item B<-nostdinc> 471 472Do not search the standard system directories or compiler builtin directories 473for include files. 474 475=item B<-nostdlibinc> 476 477Do not search the standard system directories for include files, but do search 478compiler builtin include directories. 479 480=item B<-nobuiltininc> 481 482Do not search clang's builtin directory for include files. 483 484=cut 485 486## TODO, but do we really want people using this stuff? 487#=item B<-idirafter>I<directory> 488#=item B<-iquote>I<directory> 489#=item B<-isystem>I<directory> 490#=item B<-iprefix>I<directory> 491#=item B<-iwithprefix>I<directory> 492#=item B<-iwithprefixbefore>I<directory> 493#=item B<-isysroot> 494 495=pod 496 497 498=back 499 500 501 502=cut 503 504### TODO someday. 505#=head2 Warning Control Options 506#=over 507#=back 508#=head2 Code Generation and Optimization Options 509#=over 510#=back 511#=head2 Assembler Options 512#=over 513#=back 514#=head2 Linker Options 515#=over 516#=back 517#=head2 Static Analyzer Options 518#=over 519#=back 520 521=pod 522 523 524=head1 ENVIRONMENT 525 526=over 527 528=item B<TMPDIR>, B<TEMP>, B<TMP> 529 530These environment variables are checked, in order, for the location to 531write temporary files used during the compilation process. 532 533=item B<CPATH> 534 535If this environment variable is present, it is treated as a delimited 536list of paths to be added to the default system include path list. The 537delimiter is the platform dependent delimitor, as used in the I<PATH> 538environment variable. 539 540Empty components in the environment variable are ignored. 541 542=item B<C_INCLUDE_PATH>, B<OBJC_INCLUDE_PATH>, B<CPLUS_INCLUDE_PATH>, 543B<OBJCPLUS_INCLUDE_PATH> 544 545These environment variables specify additional paths, as for CPATH, 546which are only used when processing the appropriate language. 547 548=item B<MACOSX_DEPLOYMENT_TARGET> 549 550If -mmacosx-version-min is unspecified, the default deployment target 551is read from this environment variable. This option only affects darwin 552targets. 553 554=back 555 556=head1 BUGS 557 558To report bugs, please visit L<http://llvm.org/bugs/>. Most bug reports should 559include preprocessed source files (use the B<-E> option) and the full output of 560the compiler, along with information to reproduce. 561 562=head1 SEE ALSO 563 564 as(1), ld(1) 565 566=head1 AUTHOR 567 568Maintained by the Clang / LLVM Team (L<http://clang.llvm.org>). 569 570=cut 571