| Daniel Dunbar | c1b1658 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 1 | =pod | 
|  | 2 |  | 
|  | 3 | =head1 NAME | 
|  | 4 |  | 
| Chris Lattner | 2080787 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 5 | clang - the Clang C and Objective-C compiler | 
| Daniel Dunbar | c1b1658 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 6 |  | 
|  | 7 | =head1 SYNOPSIS | 
|  | 8 |  | 
| Chris Lattner | 2080787 | 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 | c1b1658 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 18 |  | 
|  | 19 | =head1 DESCRIPTION | 
|  | 20 |  | 
| Chris Lattner | 2080787 | 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 | c1b1658 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 26 |  | 
|  | 27 | =over | 
|  | 28 |  | 
| Chris Lattner | 2080787 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 29 | =item B<Driver> | 
| Daniel Dunbar | c1b1658 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 30 |  | 
| Chris Lattner | 2080787 | 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 | c1b1658 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 35 |  | 
| Chris Lattner | 2080787 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 36 | =item B<Preprocessing> | 
| Daniel Dunbar | c1b1658 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 37 |  | 
| Chris Lattner | 2080787 | 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 |  | 
|  | 52 | This stage translates an AST into low-level intermediate code or machine code | 
|  | 53 | (depending on the optimization level).  This phase is responsible for optimizing | 
|  | 54 | the generated code and handling target-specfic code generation.  The output of | 
|  | 55 | this stage is typically called a ".s" file. | 
|  | 56 |  | 
| Chris Lattner | 164ac10 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 57 | =item B<Assembler> | 
| Chris Lattner | 2080787 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 58 |  | 
|  | 59 | This stage runs the target assembler to translate the output of the compiler | 
|  | 60 | into a target object file.  The output of this stage is typically called a ".o" | 
|  | 61 | file. | 
|  | 62 |  | 
| Chris Lattner | 164ac10 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 63 | =item B<Linker> | 
| Chris Lattner | 2080787 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 64 |  | 
|  | 65 | This stage runs the target linker to merge multiple object files into an | 
|  | 66 | executable or dynamic library.  The output of this stage is typically called an | 
|  | 67 | "a.out", ".dylib" or ".so" file. | 
|  | 68 |  | 
|  | 69 | =back | 
|  | 70 |  | 
|  | 71 | The Clang compiler supports a large number of options to control each of these | 
| Chris Lattner | 164ac10 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 72 | stages.  In addition to compilation of code, Clang also supports other tools. | 
|  | 73 |  | 
|  | 74 | B<Clang Static Analyzer> | 
|  | 75 |  | 
|  | 76 | The Clang Static Analyzer is a tool that scans source code to try to find bugs | 
|  | 77 | though code analysis.  This tool uses many parts of Clang and is built into the | 
|  | 78 | same driver. | 
|  | 79 |  | 
| Chris Lattner | 2080787 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 80 |  | 
|  | 81 | =head1 OPTIONS | 
|  | 82 |  | 
| Chris Lattner | 2080787 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 83 | =head2 Stage Selection Options | 
|  | 84 |  | 
|  | 85 | =over | 
| Daniel Dunbar | c1b1658 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 86 |  | 
| Daniel Dunbar | c1b1658 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 87 | =item B<-E> | 
|  | 88 |  | 
| Chris Lattner | 164ac10 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 89 | Run the preprocessor stage. | 
| Daniel Dunbar | c1b1658 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 90 |  | 
| Chris Lattner | 164ac10 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 91 | =item B<-fsyntax-only> | 
| Chris Lattner | 2080787 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 92 |  | 
| Chris Lattner | 164ac10 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 93 | Run the preprocessor, parser and type checking stages. | 
| Chris Lattner | 2080787 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 94 |  | 
|  | 95 | =item B<-emit-llvm> | 
|  | 96 |  | 
| Chris Lattner | 164ac10 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 97 | Run the preprocessor, parser, type checking stages, LLVM generation and | 
|  | 98 | optimization stages. | 
| Chris Lattner | 2080787 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 99 |  | 
| Chris Lattner | 164ac10 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 100 | =item B<-S> | 
| Chris Lattner | 2080787 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 101 |  | 
| Chris Lattner | 164ac10 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 102 | Run all of the above, plus target-specific code generation, producing an | 
|  | 103 | assembly file. | 
| Chris Lattner | 2080787 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 104 |  | 
| Chris Lattner | 164ac10 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 105 | =item B<-c> | 
|  | 106 |  | 
|  | 107 | Run all of the above, plus the assembler, generating a target ".o" object file. | 
|  | 108 |  | 
|  | 109 | =item B<no stage selection option> | 
|  | 110 |  | 
|  | 111 | If no stage selection option is specified, all stages above are run, and the | 
|  | 112 | linker is run to combine the results into an executable or shared library. | 
|  | 113 |  | 
|  | 114 | =item B<--analyze> | 
|  | 115 |  | 
|  | 116 | Run the Clang Static Analyzer. | 
| Chris Lattner | 2080787 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 117 |  | 
|  | 118 | =back | 
|  | 119 |  | 
|  | 120 |  | 
|  | 121 |  | 
| Chris Lattner | 164ac10 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 122 | =head2 Driver Options | 
| Chris Lattner | 2080787 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 123 |  | 
|  | 124 | =over | 
|  | 125 |  | 
| Chris Lattner | 164ac10 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 126 | =item B<-###> | 
| Chris Lattner | 2080787 | 2009-05-06 02:47:51 +0000 | [diff] [blame] | 127 |  | 
| Chris Lattner | 164ac10 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 128 | Print the commands to run for this compilation. | 
|  | 129 |  | 
|  | 130 | =item B<--help> | 
|  | 131 |  | 
|  | 132 | Display available options. | 
|  | 133 |  | 
| Daniel Dunbar | c1b1658 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 134 | =item B<-ObjC++> | 
|  | 135 |  | 
|  | 136 | Treat source input files as Objective-C++ inputs. | 
|  | 137 |  | 
|  | 138 | =item B<-ObjC> | 
|  | 139 |  | 
|  | 140 | Treat source input files as Objective-C inputs. | 
|  | 141 |  | 
|  | 142 | =item B<-Qunused-arguments> | 
|  | 143 |  | 
|  | 144 | Don't emit warning for unused driver arguments. | 
|  | 145 |  | 
| Daniel Dunbar | c1b1658 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 146 | =item B<-Wa,>I<args> | 
|  | 147 |  | 
|  | 148 | Pass the comma separated arguments in I<args> to the assembler. | 
|  | 149 |  | 
|  | 150 | =item B<-Wl,>I<args> | 
|  | 151 |  | 
|  | 152 | Pass the comma separated arguments in I<args> to the linker. | 
|  | 153 |  | 
|  | 154 | =item B<-Wp,>I<args> | 
|  | 155 |  | 
|  | 156 | Pass the comma separated arguments in I<args> to the preprocessor. | 
|  | 157 |  | 
|  | 158 | =item B<-Xanalyzer> I<arg> | 
|  | 159 |  | 
|  | 160 | Pass I<arg> to the static analyzer. | 
|  | 161 |  | 
|  | 162 | =item B<-Xassembler> I<arg> | 
|  | 163 |  | 
|  | 164 | Pass I<arg> to the assembler. | 
|  | 165 |  | 
|  | 166 | =item B<-Xclang> I<arg> | 
|  | 167 |  | 
|  | 168 | Pass I<arg> to the clang compiler. | 
|  | 169 |  | 
|  | 170 | =item B<-Xlinker> I<arg> | 
|  | 171 |  | 
|  | 172 | Pass I<arg> to the linker. | 
|  | 173 |  | 
|  | 174 | =item B<-Xpreprocessor> I<arg> | 
|  | 175 |  | 
|  | 176 | Pass I<arg> to the preprocessor. | 
|  | 177 |  | 
| Daniel Dunbar | c1b1658 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 178 | =item B<-o> I<file> | 
|  | 179 |  | 
|  | 180 | Write output to I<file>. | 
|  | 181 |  | 
|  | 182 | =item B<-pipe> | 
|  | 183 |  | 
| Chris Lattner | 164ac10 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 184 | FIXME: WHY DOCUMENT THIS. | 
| Daniel Dunbar | c1b1658 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 185 | Use pipes between commands, when possible. | 
|  | 186 |  | 
|  | 187 | =item B<-print-file-name>=I<file> | 
|  | 188 |  | 
|  | 189 | Print the full library path of I<file>. | 
|  | 190 |  | 
|  | 191 | =item B<-print-libgcc-file-name> | 
|  | 192 |  | 
|  | 193 | Print the library path for "libgcc.a". | 
|  | 194 |  | 
|  | 195 | =item B<-print-prog-name>=I<name> | 
|  | 196 |  | 
|  | 197 | Print the full program path of I<name>. | 
|  | 198 |  | 
|  | 199 | =item B<-print-search-dirs> | 
|  | 200 |  | 
|  | 201 | Print the paths used for finding libraries and programs. | 
|  | 202 |  | 
|  | 203 | =item B<-save-temps> | 
|  | 204 |  | 
|  | 205 | Save intermediate compilation results. | 
|  | 206 |  | 
|  | 207 | =item B<-time> | 
|  | 208 |  | 
|  | 209 | Time individual commands. | 
|  | 210 |  | 
|  | 211 | =item B<-v> | 
|  | 212 |  | 
|  | 213 | Show commands to run and use verbose output. | 
|  | 214 |  | 
|  | 215 | =item B<-x> I<language> | 
|  | 216 |  | 
|  | 217 | Treat subsequent input files as having type I<language>. | 
|  | 218 |  | 
| Chris Lattner | 164ac10 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 219 |  | 
| Daniel Dunbar | c1b1658 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 220 | =back | 
|  | 221 |  | 
| Chris Lattner | 164ac10 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 222 |  | 
|  | 223 |  | 
|  | 224 |  | 
|  | 225 |  | 
|  | 226 | =head2 Preprocessor Options | 
|  | 227 |  | 
|  | 228 | =over | 
|  | 229 |  | 
|  | 230 | =back | 
|  | 231 |  | 
|  | 232 |  | 
|  | 233 |  | 
|  | 234 |  | 
|  | 235 | =head2 Parser and Semantic Analysis Options | 
|  | 236 |  | 
|  | 237 | =over | 
|  | 238 |  | 
|  | 239 | =back | 
|  | 240 |  | 
|  | 241 |  | 
|  | 242 |  | 
|  | 243 | =head2 Code Generation and Optimization Options | 
|  | 244 |  | 
|  | 245 | =over | 
|  | 246 |  | 
|  | 247 | =back | 
|  | 248 |  | 
|  | 249 |  | 
|  | 250 | =head2 Assembler Options | 
|  | 251 |  | 
|  | 252 | =over | 
|  | 253 |  | 
|  | 254 | =back | 
|  | 255 |  | 
|  | 256 |  | 
|  | 257 | =head2 Linker Options | 
|  | 258 |  | 
|  | 259 | =over | 
|  | 260 |  | 
|  | 261 | =back | 
|  | 262 |  | 
|  | 263 |  | 
| Daniel Dunbar | c1b1658 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 264 | =head1 ENVIRONMENT | 
|  | 265 |  | 
| Chris Lattner | 164ac10 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 266 | No environment variables read. | 
| Daniel Dunbar | c1b1658 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 267 |  | 
|  | 268 | =head1 BUGS | 
|  | 269 |  | 
| Chris Lattner | 164ac10 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 270 | Clang currently does not have C++ support, and this manual page is incomplete. | 
|  | 271 | To report bugs, please visit L<http://llvm.org/bugs/>.  Most bug reports should | 
|  | 272 | include preprocessed source files (use the B<-E> option) along with information | 
|  | 273 | to reproduce. | 
| Daniel Dunbar | c1b1658 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 274 |  | 
|  | 275 | =head1 SEE ALSO | 
|  | 276 |  | 
| Chris Lattner | 164ac10 | 2009-05-06 17:22:08 +0000 | [diff] [blame] | 277 | as(1), ld(1) | 
| Daniel Dunbar | c1b1658 | 2009-04-29 01:00:32 +0000 | [diff] [blame] | 278 |  | 
|  | 279 | =head1 AUTHOR | 
|  | 280 |  | 
|  | 281 | Maintained by the Clang / LLVM Team (L<http://clang.llvm.org>). | 
|  | 282 |  | 
|  | 283 | =cut |