Daniel Dunbar | dbec033 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 1 | =pod |
| 2 | |
| 3 | =head1 NAME |
| 4 | |
Chris Lattner | b5f6e80 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 5 | clang - the Clang C and Objective-C compiler |
Daniel Dunbar | dbec033 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 6 | |
| 7 | =head1 SYNOPSIS |
| 8 | |
Chris Lattner | b5f6e80 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 9 | B<clang> [B<-c>|B<-S>|B<-E>] B<-std=>I<standard> B<-g> |
| 10 | [B<-O0>|B<-O1>|B<-O2>|B<-Os>|B<-O3>|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 | I<input-filenames> |
Daniel Dunbar | dbec033 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 18 | |
| 19 | =head1 DESCRIPTION |
| 20 | |
Chris Lattner | b5f6e80 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 21 | B<clang> is a C and Objective-C compiler which encompasses preprocessing, |
| 22 | parsing, optimization, code generation, assembly, and linking. Depending on |
| 23 | which high-level mode setting is passed, Clang will stop before doing a full |
| 24 | link. While Clang is highly integrated, it is important to understand the |
| 25 | stages of compilation, to understand how to invoke it. These stages are: |
Daniel Dunbar | dbec033 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 26 | |
| 27 | =over |
| 28 | |
Chris Lattner | b5f6e80 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 29 | =item B<Driver> |
Daniel Dunbar | dbec033 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 30 | |
Chris Lattner | b5f6e80 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 31 | The B<clang> executable is actually a small driver which controls the overall |
| 32 | execution of other tools such as the compiler, assembler and linker. Typically |
| 33 | you do not need to interact with the driver, but you transparently use it to run |
| 34 | the other tools. |
Daniel Dunbar | dbec033 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 35 | |
Chris Lattner | b5f6e80 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 36 | =item B<Preprocessing> |
Daniel Dunbar | dbec033 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 37 | |
Chris Lattner | b5f6e80 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 38 | This stage handles tokenization of the input source file, macro expansion, |
| 39 | #include expansion and handling of other preprocessor directives. The output of |
| 40 | this stage is typically called a ".i" (for C) or ".mi" (for Objective-C) file. |
| 41 | |
| 42 | =item B<Parsing and Semantic Analysis> |
| 43 | |
| 44 | This stage parses the input file, translating preprocessor tokens into a parse |
| 45 | tree. Once in the form of a parser tree, it applies semantic analysis to compute |
| 46 | types for expressions as well and determine whether the code is well formed. This |
| 47 | stage is responsible for generating most of the compiler warnings as well as |
| 48 | parse errors. The output of this stage is an "Abstract Syntax Tree" (AST). |
| 49 | |
| 50 | =item B<Code Generation and Optimization> |
| 51 | |
Chris Lattner | 482c682 | 2009-05-11 22:45:37 +0000 | [diff] [blame^] | 52 | This stage translates an AST into low-level intermediate code (known as "LLVM |
| 53 | IR") and ultimately to machine code (depending on the optimization level). This |
| 54 | phase is responsible for optimizing the generated code and handling |
| 55 | target-specfic code generation. The output of this stage is typically called a |
| 56 | ".s" file or "assembly" file. |
Chris Lattner | b5f6e80 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 57 | |
Chris Lattner | 9b081c6 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 58 | =item B<Assembler> |
Chris Lattner | b5f6e80 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 59 | |
| 60 | This stage runs the target assembler to translate the output of the compiler |
| 61 | into a target object file. The output of this stage is typically called a ".o" |
Chris Lattner | 482c682 | 2009-05-11 22:45:37 +0000 | [diff] [blame^] | 62 | file or "object" file. |
Chris Lattner | b5f6e80 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 63 | |
Chris Lattner | 9b081c6 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 64 | =item B<Linker> |
Chris Lattner | b5f6e80 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 65 | |
| 66 | This stage runs the target linker to merge multiple object files into an |
| 67 | executable or dynamic library. The output of this stage is typically called an |
| 68 | "a.out", ".dylib" or ".so" file. |
| 69 | |
| 70 | =back |
| 71 | |
| 72 | The Clang compiler supports a large number of options to control each of these |
Chris Lattner | 482c682 | 2009-05-11 22:45:37 +0000 | [diff] [blame^] | 73 | stages. In addition to compilation of code, Clang also supports other tools: |
Chris Lattner | 9b081c6 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 74 | |
| 75 | B<Clang Static Analyzer> |
| 76 | |
| 77 | The Clang Static Analyzer is a tool that scans source code to try to find bugs |
| 78 | though code analysis. This tool uses many parts of Clang and is built into the |
| 79 | same driver. |
| 80 | |
Chris Lattner | b5f6e80 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 81 | |
| 82 | =head1 OPTIONS |
| 83 | |
Chris Lattner | b5f6e80 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 84 | =head2 Stage Selection Options |
| 85 | |
| 86 | =over |
Daniel Dunbar | dbec033 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 87 | |
Daniel Dunbar | dbec033 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 88 | =item B<-E> |
| 89 | |
Chris Lattner | 9b081c6 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 90 | Run the preprocessor stage. |
Daniel Dunbar | dbec033 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 91 | |
Chris Lattner | 9b081c6 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 92 | =item B<-fsyntax-only> |
Chris Lattner | b5f6e80 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 93 | |
Chris Lattner | 9b081c6 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 94 | Run the preprocessor, parser and type checking stages. |
Chris Lattner | b5f6e80 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 95 | |
| 96 | =item B<-emit-llvm> |
| 97 | |
Chris Lattner | 9b081c6 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 98 | Run the preprocessor, parser, type checking stages, LLVM generation and |
| 99 | optimization stages. |
Chris Lattner | b5f6e80 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 100 | |
Chris Lattner | 9b081c6 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 101 | =item B<-S> |
Chris Lattner | b5f6e80 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 102 | |
Chris Lattner | 9b081c6 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 103 | Run all of the above, plus target-specific code generation, producing an |
| 104 | assembly file. |
Chris Lattner | b5f6e80 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 105 | |
Chris Lattner | 9b081c6 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 106 | =item B<-c> |
| 107 | |
| 108 | Run all of the above, plus the assembler, generating a target ".o" object file. |
| 109 | |
| 110 | =item B<no stage selection option> |
| 111 | |
| 112 | If no stage selection option is specified, all stages above are run, and the |
| 113 | linker is run to combine the results into an executable or shared library. |
| 114 | |
| 115 | =item B<--analyze> |
| 116 | |
| 117 | Run the Clang Static Analyzer. |
Chris Lattner | b5f6e80 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 118 | |
| 119 | =back |
| 120 | |
| 121 | |
| 122 | |
Chris Lattner | 9b081c6 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 123 | =head2 Driver Options |
Chris Lattner | b5f6e80 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 124 | |
| 125 | =over |
| 126 | |
Chris Lattner | 9b081c6 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 127 | =item B<-###> |
Chris Lattner | b5f6e80 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 128 | |
Chris Lattner | 9b081c6 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 129 | Print the commands to run for this compilation. |
| 130 | |
| 131 | =item B<--help> |
| 132 | |
| 133 | Display available options. |
| 134 | |
Daniel Dunbar | dbec033 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 135 | =item B<-Qunused-arguments> |
| 136 | |
| 137 | Don't emit warning for unused driver arguments. |
| 138 | |
Daniel Dunbar | dbec033 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 139 | =item B<-Wa,>I<args> |
| 140 | |
| 141 | Pass the comma separated arguments in I<args> to the assembler. |
| 142 | |
| 143 | =item B<-Wl,>I<args> |
| 144 | |
| 145 | Pass the comma separated arguments in I<args> to the linker. |
| 146 | |
| 147 | =item B<-Wp,>I<args> |
| 148 | |
| 149 | Pass the comma separated arguments in I<args> to the preprocessor. |
| 150 | |
| 151 | =item B<-Xanalyzer> I<arg> |
| 152 | |
| 153 | Pass I<arg> to the static analyzer. |
| 154 | |
| 155 | =item B<-Xassembler> I<arg> |
| 156 | |
| 157 | Pass I<arg> to the assembler. |
| 158 | |
| 159 | =item B<-Xclang> I<arg> |
| 160 | |
| 161 | Pass I<arg> to the clang compiler. |
| 162 | |
| 163 | =item B<-Xlinker> I<arg> |
| 164 | |
| 165 | Pass I<arg> to the linker. |
| 166 | |
| 167 | =item B<-Xpreprocessor> I<arg> |
| 168 | |
| 169 | Pass I<arg> to the preprocessor. |
| 170 | |
Daniel Dunbar | dbec033 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 171 | =item B<-o> I<file> |
| 172 | |
| 173 | Write output to I<file>. |
| 174 | |
Daniel Dunbar | dbec033 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 175 | =item B<-print-file-name>=I<file> |
| 176 | |
| 177 | Print the full library path of I<file>. |
| 178 | |
| 179 | =item B<-print-libgcc-file-name> |
| 180 | |
| 181 | Print the library path for "libgcc.a". |
| 182 | |
| 183 | =item B<-print-prog-name>=I<name> |
| 184 | |
| 185 | Print the full program path of I<name>. |
| 186 | |
| 187 | =item B<-print-search-dirs> |
| 188 | |
| 189 | Print the paths used for finding libraries and programs. |
| 190 | |
| 191 | =item B<-save-temps> |
| 192 | |
| 193 | Save intermediate compilation results. |
| 194 | |
| 195 | =item B<-time> |
| 196 | |
| 197 | Time individual commands. |
| 198 | |
Chris Lattner | 482c682 | 2009-05-11 22:45:37 +0000 | [diff] [blame^] | 199 | =item B<-ftime-report> |
| 200 | |
| 201 | Print timing summary of each stage of compilation. |
| 202 | |
Daniel Dunbar | dbec033 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 203 | =item B<-v> |
| 204 | |
| 205 | Show commands to run and use verbose output. |
| 206 | |
Chris Lattner | 482c682 | 2009-05-11 22:45:37 +0000 | [diff] [blame^] | 207 | =back |
Daniel Dunbar | dbec033 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 208 | |
Chris Lattner | 482c682 | 2009-05-11 22:45:37 +0000 | [diff] [blame^] | 209 | |
| 210 | |
| 211 | =head2 Target Selection Options |
| 212 | |
| 213 | =over |
| 214 | |
| 215 | -triple |
| 216 | -arch |
| 217 | -mmacosx-version-min=10.3.9 |
| 218 | -miphoneos-version-min |
Daniel Dunbar | dbec033 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 219 | |
Chris Lattner | 9b081c6 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 220 | |
Daniel Dunbar | dbec033 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 221 | =back |
| 222 | |
Chris Lattner | 9b081c6 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 223 | |
| 224 | |
Chris Lattner | 482c682 | 2009-05-11 22:45:37 +0000 | [diff] [blame^] | 225 | =head2 Language Selection and Mode Options |
| 226 | |
| 227 | =over |
| 228 | |
| 229 | =item B<-x> I<language> |
| 230 | |
| 231 | Treat subsequent input files as having type I<language>. |
| 232 | |
| 233 | =item B<-ObjC++> |
| 234 | |
| 235 | Treat source input files as Objective-C++ inputs. |
| 236 | |
| 237 | =item B<-ObjC> |
| 238 | |
| 239 | Treat source input files as Objective-C inputs. |
| 240 | |
| 241 | B<-std>=I<language> |
| 242 | |
| 243 | |
| 244 | -ffreestanding |
| 245 | -fno-builtin |
| 246 | -fmath-errno |
| 247 | -fobjc-gc-only |
| 248 | -fobjc-gc |
| 249 | -fpascal-strings |
| 250 | -fms-extensions |
| 251 | -fwritable-strings |
| 252 | -fno-lax-vector-conversions |
| 253 | -fblocks |
| 254 | -trigraphs |
| 255 | |
| 256 | |
| 257 | =back |
| 258 | |
| 259 | |
| 260 | |
| 261 | =head2 Code Generation Options |
| 262 | |
| 263 | =over |
| 264 | |
| 265 | -fexceptions |
| 266 | -fobjc-nonfragile-abi |
| 267 | -fgnu-runtime |
| 268 | -fnext-runtime |
| 269 | -ftrapv |
| 270 | -fvisibility |
| 271 | -Os, O0, O1, O2, O3, O4 |
| 272 | -fno-common |
| 273 | -g |
| 274 | -mcpu |
| 275 | |
| 276 | =back |
| 277 | |
| 278 | |
| 279 | |
| 280 | |
| 281 | =head2 Diagnostics Options |
| 282 | |
| 283 | =over |
| 284 | |
| 285 | -fshow-column |
| 286 | -fshow-source-location |
| 287 | -fcaret-diagnostics |
| 288 | -fdiagnostics-fixit-info |
| 289 | -fdiagnostics-print-source-range-info |
| 290 | -fprint-source-range-info |
| 291 | -fdiagnostics-show-option |
| 292 | -fmessage-length |
| 293 | |
| 294 | |
| 295 | =back |
Chris Lattner | 9b081c6 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 296 | |
| 297 | |
| 298 | =head2 Preprocessor Options |
| 299 | |
| 300 | =over |
| 301 | |
Chris Lattner | 482c682 | 2009-05-11 22:45:37 +0000 | [diff] [blame^] | 302 | =item B<-xyz> |
| 303 | |
| 304 | Frob |
| 305 | |
| 306 | -D |
| 307 | -U |
| 308 | -include |
| 309 | -imacros |
| 310 | |
| 311 | |
| 312 | |
| 313 | -nostdinc |
| 314 | -F |
| 315 | -I |
| 316 | -idirafter |
| 317 | -iquote |
| 318 | -isystem |
| 319 | -iprefix |
| 320 | -iwithprefix |
| 321 | -iwithprefixbefore |
| 322 | -isysroot |
| 323 | |
| 324 | |
| 325 | |
| 326 | |
Chris Lattner | 9b081c6 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 327 | =back |
| 328 | |
| 329 | |
| 330 | |
| 331 | |
| 332 | =head2 Parser and Semantic Analysis Options |
| 333 | |
| 334 | =over |
| 335 | |
| 336 | =back |
| 337 | |
| 338 | |
| 339 | |
Chris Lattner | 482c682 | 2009-05-11 22:45:37 +0000 | [diff] [blame^] | 340 | |
| 341 | |
Chris Lattner | 9b081c6 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 342 | =head2 Code Generation and Optimization Options |
| 343 | |
| 344 | =over |
| 345 | |
| 346 | =back |
| 347 | |
| 348 | |
Chris Lattner | 482c682 | 2009-05-11 22:45:37 +0000 | [diff] [blame^] | 349 | |
| 350 | |
| 351 | |
| 352 | |
Chris Lattner | 9b081c6 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 353 | =head2 Assembler Options |
| 354 | |
| 355 | =over |
| 356 | |
| 357 | =back |
| 358 | |
| 359 | |
Chris Lattner | 482c682 | 2009-05-11 22:45:37 +0000 | [diff] [blame^] | 360 | |
| 361 | |
| 362 | |
| 363 | |
Chris Lattner | 9b081c6 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 364 | =head2 Linker Options |
| 365 | |
| 366 | =over |
| 367 | |
| 368 | =back |
| 369 | |
| 370 | |
Chris Lattner | 482c682 | 2009-05-11 22:45:37 +0000 | [diff] [blame^] | 371 | |
| 372 | |
| 373 | |
| 374 | =head2 Static Analyzer Options |
| 375 | |
| 376 | =over |
| 377 | |
| 378 | =back |
| 379 | |
| 380 | |
| 381 | |
Daniel Dunbar | dbec033 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 382 | =head1 ENVIRONMENT |
| 383 | |
Daniel Dunbar | e58c943 | 2009-05-06 19:18:09 +0000 | [diff] [blame] | 384 | =over |
| 385 | |
| 386 | =item B<TMPDIR>, B<TEMP>, B<TMP> |
| 387 | |
| 388 | These environment variables are checked, in order, for the location to |
| 389 | write temporary files used during the compilation process. |
| 390 | |
| 391 | =item B<CPATH> |
| 392 | |
| 393 | If this environment variable is present, it is treated as a delimited |
| 394 | list of paths to be added to the default system include path list. The |
| 395 | delimiter is the platform dependent delimitor, as used in the I<PATH> |
| 396 | environment variable. |
| 397 | |
| 398 | Empty components in the environment variable are ignored. |
| 399 | |
| 400 | =item B<C_INCLUDE_PATH>, B<OBJC_INCLUDE_PATH>, B<CPLUS_INCLUDE_PATH>, |
| 401 | B<OBJCPLUS_INCLUDE_PATH> |
| 402 | |
| 403 | These environment variables specify additional paths, as for CPATH, |
| 404 | which are only used when processing the appropriate language. |
| 405 | |
Chris Lattner | 482c682 | 2009-05-11 22:45:37 +0000 | [diff] [blame^] | 406 | =item B<MACOSX_DEPLOYMENT_TARGET> |
Daniel Dunbar | e58c943 | 2009-05-06 19:18:09 +0000 | [diff] [blame] | 407 | |
| 408 | If -mmacosx-version-min is unspecified, the default deployment target |
Chris Lattner | 482c682 | 2009-05-11 22:45:37 +0000 | [diff] [blame^] | 409 | is read from this environment variable. This option only affects darwin |
| 410 | targets. |
Daniel Dunbar | e58c943 | 2009-05-06 19:18:09 +0000 | [diff] [blame] | 411 | |
| 412 | =back |
Daniel Dunbar | dbec033 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 413 | |
| 414 | =head1 BUGS |
| 415 | |
Chris Lattner | 9b081c6 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 416 | Clang currently does not have C++ support, and this manual page is incomplete. |
| 417 | To report bugs, please visit L<http://llvm.org/bugs/>. Most bug reports should |
Daniel Dunbar | e58c943 | 2009-05-06 19:18:09 +0000 | [diff] [blame] | 418 | include preprocessed source files (use the B<-E> option) and the full output of |
| 419 | the compiler, along with information to reproduce. |
Daniel Dunbar | dbec033 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 420 | |
| 421 | =head1 SEE ALSO |
| 422 | |
Chris Lattner | 482c682 | 2009-05-11 22:45:37 +0000 | [diff] [blame^] | 423 | as(1), ld(1) |
Daniel Dunbar | dbec033 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 424 | |
| 425 | =head1 AUTHOR |
| 426 | |
| 427 | Maintained by the Clang / LLVM Team (L<http://clang.llvm.org>). |
| 428 | |
| 429 | =cut |