clang.pod 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614
  1. =pod
  2. =head1 NAME
  3. clang - the Clang C, C++, and Objective-C compiler
  4. =head1 SYNOPSIS
  5. B<clang> [B<-c>|B<-S>|B<-E>] B<-std=>I<standard> B<-g>
  6. [B<-O0>|B<-O1>|B<-O2>|B<-O3>|B<-Ofast>|B<-Os>|B<-Oz>|B<-O>|B<-O4>]
  7. B<-W>I<warnings...> B<-pedantic>
  8. B<-I>I<dir...> B<-L>I<dir...>
  9. B<-D>I<macro[=defn]>
  10. B<-f>I<feature-option...>
  11. B<-m>I<machine-option...>
  12. B<-o> I<output-file>
  13. B<-stdlib=>I<library>
  14. I<input-filenames>
  15. =head1 DESCRIPTION
  16. B<clang> is a C, C++, and Objective-C compiler which encompasses preprocessing,
  17. parsing, optimization, code generation, assembly, and linking. Depending on
  18. which high-level mode setting is passed, Clang will stop before doing a full
  19. link. While Clang is highly integrated, it is important to understand the
  20. stages of compilation, to understand how to invoke it. These stages are:
  21. =over
  22. =item B<Driver>
  23. The B<clang> executable is actually a small driver which controls the overall
  24. execution of other tools such as the compiler, assembler and linker. Typically
  25. you do not need to interact with the driver, but you transparently use it to run
  26. the other tools.
  27. =item B<Preprocessing>
  28. This stage handles tokenization of the input source file, macro expansion,
  29. #include expansion and handling of other preprocessor directives. The output of
  30. this stage is typically called a ".i" (for C), ".ii" (for C++), ".mi" (for
  31. Objective-C) , or ".mii" (for Objective-C++) file.
  32. =item B<Parsing and Semantic Analysis>
  33. This stage parses the input file, translating preprocessor tokens into a parse
  34. tree. Once in the form of a parser tree, it applies semantic analysis to compute
  35. types for expressions as well and determine whether the code is well formed. This
  36. stage is responsible for generating most of the compiler warnings as well as
  37. parse errors. The output of this stage is an "Abstract Syntax Tree" (AST).
  38. =item B<Code Generation and Optimization>
  39. This stage translates an AST into low-level intermediate code (known as "LLVM
  40. IR") and ultimately to machine code. This phase is responsible for optimizing
  41. the generated code and handling target-specific code generation. The output of
  42. this stage is typically called a ".s" file or "assembly" file.
  43. Clang also supports the use of an integrated assembler, in which the code
  44. generator produces object files directly. This avoids the overhead of generating
  45. the ".s" file and of calling the target assembler.
  46. =item B<Assembler>
  47. This stage runs the target assembler to translate the output of the compiler
  48. into a target object file. The output of this stage is typically called a ".o"
  49. file or "object" file.
  50. =item B<Linker>
  51. This stage runs the target linker to merge multiple object files into an
  52. executable or dynamic library. The output of this stage is typically called an
  53. "a.out", ".dylib" or ".so" file.
  54. =back
  55. The Clang compiler supports a large number of options to control each of these
  56. stages. In addition to compilation of code, Clang also supports other tools:
  57. B<Clang Static Analyzer>
  58. The Clang Static Analyzer is a tool that scans source code to try to find bugs
  59. through code analysis. This tool uses many parts of Clang and is built into the
  60. same driver. Please see L<http://clang-analyzer.llvm.org> for more details
  61. on how to use the static analyzer.
  62. =head1 OPTIONS
  63. =head2 Stage Selection Options
  64. =over
  65. =item B<-E>
  66. Run the preprocessor stage.
  67. =item B<-fsyntax-only>
  68. Run the preprocessor, parser and type checking stages.
  69. =item B<-S>
  70. Run the previous stages as well as LLVM generation and optimization stages and
  71. target-specific code generation, producing an assembly file.
  72. =item B<-c>
  73. Run all of the above, plus the assembler, generating a target ".o" object file.
  74. =item B<no stage selection option>
  75. If no stage selection option is specified, all stages above are run, and the
  76. linker is run to combine the results into an executable or shared library.
  77. =back
  78. =head2 Language Selection and Mode Options
  79. =over
  80. =item B<-x> I<language>
  81. Treat subsequent input files as having type I<language>.
  82. =item B<-std>=I<language>
  83. Specify the language standard to compile for.
  84. =item B<-stdlib>=I<library>
  85. Specify the C++ standard library to use; supported options are libstdc++ and
  86. libc++.
  87. =item B<-ansi>
  88. Same as B<-std=c89>.
  89. =item B<-ObjC++>
  90. Treat source input files as Objective-C++ inputs.
  91. =item B<-ObjC>
  92. Treat source input files as Objective-C inputs.
  93. =item B<-trigraphs>
  94. Enable trigraphs.
  95. =item B<-ffreestanding>
  96. Indicate that the file should be compiled for a freestanding, not a hosted,
  97. environment.
  98. =item B<-fno-builtin>
  99. Disable special handling and optimizations of builtin functions like strlen and
  100. malloc.
  101. =item B<-fmath-errno>
  102. Indicate that math functions should be treated as updating errno.
  103. =item B<-fpascal-strings>
  104. Enable support for Pascal-style strings with "\pfoo".
  105. =item B<-fms-extensions>
  106. Enable support for Microsoft extensions.
  107. =item B<-fmsc-version=>
  108. Set _MSC_VER. Defaults to 1300 on Windows. Not set otherwise.
  109. =item B<-fborland-extensions>
  110. Enable support for Borland extensions.
  111. =item B<-fwritable-strings>
  112. Make all string literals default to writable. This disables uniquing of
  113. strings and other optimizations.
  114. =item B<-flax-vector-conversions>
  115. Allow loose type checking rules for implicit vector conversions.
  116. =item B<-fblocks>
  117. Enable the "Blocks" language feature.
  118. =item B<-fobjc-gc-only>
  119. Indicate that Objective-C code should be compiled in GC-only mode, which only
  120. works when Objective-C Garbage Collection is enabled.
  121. =item B<-fobjc-gc>
  122. Indicate that Objective-C code should be compiled in hybrid-GC mode, which works
  123. with both GC and non-GC mode.
  124. =item B<-fobjc-abi-version>=I<version>
  125. Select the Objective-C ABI version to use. Available versions are 1 (legacy
  126. "fragile" ABI), 2 (non-fragile ABI 1), and 3 (non-fragile ABI 2).
  127. =item B<-fobjc-nonfragile-abi-version>=I<version>
  128. Select the Objective-C non-fragile ABI version to use by default. This will only
  129. be used as the Objective-C ABI when the non-fragile ABI is enabled (either via
  130. -fobjc-nonfragile-abi, or because it is the platform default).
  131. =item B<-fobjc-nonfragile-abi>
  132. Enable use of the Objective-C non-fragile ABI. On platforms for which this is
  133. the default ABI, it can be disabled with B<-fno-objc-nonfragile-abi>.
  134. =back
  135. =head2 Target Selection Options
  136. Clang fully supports cross compilation as an inherent part of its design.
  137. Depending on how your version of Clang is configured, it may have support for
  138. a number of cross compilers, or may only support a native target.
  139. =over
  140. =item B<-arch> I<architecture>
  141. Specify the architecture to build for.
  142. =item B<-mmacosx-version-min>=I<version>
  143. When building for Mac OS X, specify the minimum version supported by your
  144. application.
  145. =item B<-miphoneos-version-min>
  146. When building for iPhone OS, specify the minimum version supported by your
  147. application.
  148. =item B<-march>=I<cpu>
  149. Specify that Clang should generate code for a specific processor family member
  150. and later. For example, if you specify -march=i486, the compiler is allowed to
  151. generate instructions that are valid on i486 and later processors, but which
  152. may not exist on earlier ones.
  153. =back
  154. =head2 Code Generation Options
  155. =over
  156. =item B<-O0> B<-O1> B<-O2> B<-O3> B<-Ofast> B<-Os> B<-Oz> B<-O> B<-O4>
  157. Specify which optimization level to use:
  158. =over
  159. =item B<-O0>
  160. Means "no optimization": this level compiles the fastest and
  161. generates the most debuggable code.
  162. =item B<-O1>
  163. Somewhere between B<-O0> and B<-O2>.
  164. =item B<-O2>
  165. Moderate level of optimization which enables most optimizations.
  166. =item B<-O3>
  167. Like B<-O2>, except that it enables optimizations that take longer to perform
  168. or that may generate larger code (in an attempt to make the program run faster).
  169. =item B<-Ofast>
  170. Enables all the optimizations from B<-O3> along with other aggressive
  171. optimizations that may violate strict compliance with language standards.
  172. =item B<-Os>
  173. Like B<-O2> with extra optimizations to reduce code size.
  174. =item B<-Oz>
  175. Like B<-Os> (and thus B<-O2>), but reduces code size further.
  176. =item B<-O>
  177. Equivalent to B<-O2>.
  178. =item B<-O4> and higher
  179. Currently equivalent to B<-O3>
  180. =back
  181. =item B<-g>
  182. Generate debug information. Note that Clang debug information works best at
  183. B<-O0>.
  184. =item B<-fstandalone-debug> B<-fno-standalone-debug>
  185. Clang supports a number of optimizations to reduce the size of debug
  186. information in the binary. They work based on the assumption that the
  187. debug type information can be spread out over multiple compilation
  188. units. For instance, Clang will not emit type definitions for types
  189. that are not needed by a module and could be replaced with a forward
  190. declaration. Further, Clang will only emit type info for a dynamic
  191. C++ class in the module that contains the vtable for the class.
  192. The B<-fstandalone-debug> option turns off these optimizations. This
  193. is useful when working with 3rd-party libraries that don't come with
  194. debug information. This is the default on Darwin. Note that Clang
  195. will never emit type information for types that are not referenced at
  196. all by the program.
  197. =item B<-fexceptions>
  198. Enable generation of unwind information, this allows exceptions to be thrown
  199. through Clang compiled stack frames. This is on by default in x86-64.
  200. =item B<-ftrapv>
  201. Generate code to catch integer overflow errors. Signed integer overflow is
  202. undefined in C, with this flag, extra code is generated to detect this and abort
  203. when it happens.
  204. =item B<-fvisibility>
  205. This flag sets the default visibility level.
  206. =item B<-fcommon>
  207. This flag specifies that variables without initializers get common linkage. It
  208. can be disabled with B<-fno-common>.
  209. =item B<-ftls-model>
  210. Set the default thread-local storage (TLS) model to use for thread-local
  211. variables. Valid values are: "global-dynamic", "local-dynamic", "initial-exec"
  212. and "local-exec". The default is "global-dynamic". The default model can be
  213. overridden with the tls_model attribute. The compiler will try to choose a more
  214. efficient model if possible.
  215. =item B<-flto> B<-emit-llvm>
  216. Generate output files in LLVM formats, suitable for link time optimization. When
  217. used with B<-S> this generates LLVM intermediate language assembly files,
  218. otherwise this generates LLVM bitcode format object files (which may be passed
  219. to the linker depending on the stage selection options).
  220. =cut
  221. ##=item B<-fnext-runtime> B<-fobjc-nonfragile-abi> B<-fgnu-runtime>
  222. ##These options specify which Objective-C runtime the code generator should
  223. ##target. FIXME: we don't want people poking these generally.
  224. =pod
  225. =back
  226. =head2 Driver Options
  227. =over
  228. =item B<-###>
  229. Print (but do not run) the commands to run for this compilation.
  230. =item B<--help>
  231. Display available options.
  232. =item B<-Qunused-arguments>
  233. Don't emit warning for unused driver arguments.
  234. =item B<-Wa,>I<args>
  235. Pass the comma separated arguments in I<args> to the assembler.
  236. =item B<-Wl,>I<args>
  237. Pass the comma separated arguments in I<args> to the linker.
  238. =item B<-Wp,>I<args>
  239. Pass the comma separated arguments in I<args> to the preprocessor.
  240. =item B<-Xanalyzer> I<arg>
  241. Pass I<arg> to the static analyzer.
  242. =item B<-Xassembler> I<arg>
  243. Pass I<arg> to the assembler.
  244. =item B<-Xlinker> I<arg>
  245. Pass I<arg> to the linker.
  246. =item B<-Xpreprocessor> I<arg>
  247. Pass I<arg> to the preprocessor.
  248. =item B<-o> I<file>
  249. Write output to I<file>.
  250. =item B<-print-file-name>=I<file>
  251. Print the full library path of I<file>.
  252. =item B<-print-libgcc-file-name>
  253. Print the library path for "libgcc.a".
  254. =item B<-print-prog-name>=I<name>
  255. Print the full program path of I<name>.
  256. =item B<-print-search-dirs>
  257. Print the paths used for finding libraries and programs.
  258. =item B<-save-temps>
  259. Save intermediate compilation results.
  260. =item B<-integrated-as> B<-no-integrated-as>
  261. Used to enable and disable, respectively, the use of the integrated
  262. assembler. Whether the integrated assembler is on by default is target
  263. dependent.
  264. =item B<-time>
  265. Time individual commands.
  266. =item B<-ftime-report>
  267. Print timing summary of each stage of compilation.
  268. =item B<-v>
  269. Show commands to run and use verbose output.
  270. =back
  271. =head2 Diagnostics Options
  272. =over
  273. =item B<-fshow-column>
  274. B<-fshow-source-location>
  275. B<-fcaret-diagnostics>
  276. B<-fdiagnostics-fixit-info>
  277. B<-fdiagnostics-parseable-fixits>
  278. B<-fdiagnostics-print-source-range-info>
  279. B<-fprint-source-range-info>
  280. B<-fdiagnostics-show-option>
  281. B<-fmessage-length>
  282. These options control how Clang prints out information about diagnostics (errors
  283. and warnings). Please see the Clang User's Manual for more information.
  284. =back
  285. =head2 Preprocessor Options
  286. =over
  287. =item B<-D>I<macroname=value>
  288. Adds an implicit #define into the predefines buffer which is read before the
  289. source file is preprocessed.
  290. =item B<-U>I<macroname>
  291. Adds an implicit #undef into the predefines buffer which is read before the
  292. source file is preprocessed.
  293. =item B<-include> I<filename>
  294. Adds an implicit #include into the predefines buffer which is read before the
  295. source file is preprocessed.
  296. =item B<-I>I<directory>
  297. Add the specified directory to the search path for include files.
  298. =item B<-F>I<directory>
  299. Add the specified directory to the search path for framework include files.
  300. =item B<-nostdinc>
  301. Do not search the standard system directories or compiler builtin directories
  302. for include files.
  303. =item B<-nostdlibinc>
  304. Do not search the standard system directories for include files, but do search
  305. compiler builtin include directories.
  306. =item B<-nobuiltininc>
  307. Do not search clang's builtin directory for include files.
  308. =cut
  309. ## TODO, but do we really want people using this stuff?
  310. #=item B<-idirafter>I<directory>
  311. #=item B<-iquote>I<directory>
  312. #=item B<-isystem>I<directory>
  313. #=item B<-iprefix>I<directory>
  314. #=item B<-iwithprefix>I<directory>
  315. #=item B<-iwithprefixbefore>I<directory>
  316. #=item B<-isysroot>
  317. =pod
  318. =back
  319. =cut
  320. ### TODO someday.
  321. #=head2 Warning Control Options
  322. #=over
  323. #=back
  324. #=head2 Code Generation and Optimization Options
  325. #=over
  326. #=back
  327. #=head2 Assembler Options
  328. #=over
  329. #=back
  330. #=head2 Linker Options
  331. #=over
  332. #=back
  333. #=head2 Static Analyzer Options
  334. #=over
  335. #=back
  336. =pod
  337. =head1 ENVIRONMENT
  338. =over
  339. =item B<TMPDIR>, B<TEMP>, B<TMP>
  340. These environment variables are checked, in order, for the location to
  341. write temporary files used during the compilation process.
  342. =item B<CPATH>
  343. If this environment variable is present, it is treated as a delimited
  344. list of paths to be added to the default system include path list. The
  345. delimiter is the platform dependent delimitor, as used in the I<PATH>
  346. environment variable.
  347. Empty components in the environment variable are ignored.
  348. =item B<C_INCLUDE_PATH>, B<OBJC_INCLUDE_PATH>, B<CPLUS_INCLUDE_PATH>,
  349. B<OBJCPLUS_INCLUDE_PATH>
  350. These environment variables specify additional paths, as for CPATH,
  351. which are only used when processing the appropriate language.
  352. =item B<MACOSX_DEPLOYMENT_TARGET>
  353. If -mmacosx-version-min is unspecified, the default deployment target
  354. is read from this environment variable. This option only affects darwin
  355. targets.
  356. =back
  357. =head1 BUGS
  358. To report bugs, please visit L<http://llvm.org/bugs/>. Most bug reports should
  359. include preprocessed source files (use the B<-E> option) and the full output of
  360. the compiler, along with information to reproduce.
  361. =head1 SEE ALSO
  362. as(1), ld(1)
  363. =head1 AUTHOR
  364. Maintained by the Clang / LLVM Team (L<http://clang.llvm.org>).
  365. =cut