blob: cfed51a202ddc9261f7ae27c7d96b47a3ec27cd4 [file] [log] [blame]
Chris Lattnercf17d9d2009-04-20 04:23:09 +00001<html>
2<head>
3<title>Clang Compiler User's Manual</title>
4<link type="text/css" rel="stylesheet" href="../menu.css" />
5<link type="text/css" rel="stylesheet" href="../content.css" />
6<style type="text/css">
7td {
8 vertical-align: top;
9}
10</style>
11</head>
12<body>
13
14<!--#include virtual="../menu.html.incl"-->
15
16<div id="content">
17
18<h1>Clang Compiler User's Manual</h1>
19
20<ul>
21<li><a href="#intro">Introduction</a>
22 <ul>
23 <li><a href="#terminology">Terminology</a></li>
24 <li><a href="#basicusage">Basic Usage</a></li>
25 </ul>
26</li>
27<li><a href="#commandline">Command Line Options</a></li>
28<li><a href="#general_features">Language and Target-Independent Features</a>
29 <ul>
30 <li><a href="#diagnostics">Controlling Errors and Warnings</a></li>
31 <li><a href="#precompiledheaders">Precompiled Headers</a></li>
32 </ul>
33</li>
34<li><a href="#c">C Language Features</a>
35 <ul>
36<!-- <li><a href="#pragmas">Pragmas Supported</a></li> -->
37 <li><a href="#c_extensions">C Extensions Supported</a></li>
38 <li><a href="#c_incompatibilities">Intentional Incompatibilities with
39 GCC</a></li>
40 </ul>
41</li>
42<li><a href="#objc">Objective-C Language Features</a>
43 <ul>
44 <li><a href="#objc_incompatibilities">Intentional Incompatibilities with
45 GCC</a></li>
46 </ul>
47</li>
48<li><a href="#cxx">C++ Language Features</a>
49 <ul>
50 <li>...</li>
51 </ul>
52</li>
53<li><a href="#objcxx">Objective C++ Language Features</a>
54 <ul>
55 <li>...</li>
56 </ul>
57</li>
58<li><a href="#target_features">Target-Specific Features and Limitations</a>
59 <ul>
60 <li><a href="#target_arch">CPU Architectures Features and Limitations</a>
61 <ul>
62 <li><a href="#target_arch_x86">X86</a></li>
63 <li>PPC</li>
64 <li>ARM</li>
65 </ul>
66 </li>
67 <li><a href="#target_os">Operating System Features and Limitations</a>
68 <ul>
69 <li><a href="#target_os_darwin">Darwin (Mac OS/X)</a></li>
70 <li>Linux, etc.</li>
71 </ul>
72
73 </li>
74 </ul>
75</li>
76</ul>
77
78
79<!-- ======================================================================= -->
80<h2 id="intro">Introduction</h2>
81<!-- ======================================================================= -->
82
83<p>The Clang Compiler is an open-source compiler for the C family of programming
84languages, aiming to be the best in class implementation of these languages.
85Clang builds on the LLVM optimizer and code generator, allowing it to provide
86high-quality optimization and code generation support for many targets. For
87more general information, please see the <a href="http://clang.llvm.org">Clang
88Web Site</a> or the <a href="http://llvm.org">LLVM Web Site</a>.</p>
89
90<p>This document describes important notes about using Clang as a compiler for
91an end-user, documenting the supported features, command line options, etc. If
92you are interested in using Clang to build a tool that processes code, please
93see <a href="InternalsManual.html">the Clang Internals Manual</a>. If you are
94interested in the <a href="http://clang.llvm.org/StaticAnalysis.html">Clang
95Static Analyzer</a>, please see its web page.</p>
96
97<p>Clang is designed to support the C family of programming languages, which
98includes <a href="#c">C</a>, <a href="#objc">Objective-C</a>, <a
99href="#cxx">C++</a>, and <a href="#objcxx">Objective-C++</a> as well as many
100dialects of those. For language-specific information, please see the
101corresponding language specific section:</p>
102
103<ul>
104<li><a href="#c">C Language</a>: K&amp;R C, ANSI C89, ISO C90, ISO C94
105 (C89+AMD1), ISO C99 (+TC1, TC2, TC3). </li>
106<li><a href="#objc">Objective-C Language</a>: ObjC 1, ObjC 2, ObjC 2.1, plus
107 variants depending on base language.</li>
108<li><a href="#cxx">C++ Language Features</a></li>
109<li><a href="#objcxx">Objective C++ Language</a></li>
110</ul>
111
112<p>In addition to these base languages and their dialects, Clang supports a
113broad variety of language extensions, which are documented in the corresponding
114language section. These extensions are provided to be compatible with the GCC,
115Microsoft, and other popular compilers as well as to improve functionality
116through Clang-specific features. The Clang driver and language features are
117intentionally designed to be as compatible with the GNU GCC compiler as
118reasonably possible, easing migration from GCC to Clang. In most cases, code
119"just works".</p>
120
121<p>In addition to language specific features, Clang has a variety of features
122that depend on what CPU architecture or operating system is being compiled for.
123Please see the <a href="target_features">Target-Specific Features and
124Limitations</a> section for more details.</p>
125
126<p>The rest of the introduction introduces some basic <a
127href="#terminology">compiler terminology</a> that is used throughout this manual
128and contains a basic <a href="#basicusage">introduction to using Clang</a>
129as a command line compiler.</p>
130
131<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = -->
132<h3 id="terminology">Terminology</h3>
133<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = -->
134
135<p>Front end, parser, backend, preprocessor, undefined behavior, diagnostic,
136 optimizer</p>
137
138<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = -->
139<h3 id="basicusage">Basic Usage</h3>
140<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = -->
141
142<p>Intro to how to use a C compiler for newbies.</p>
143<p>
144compile + link
145
146compile then link
147
148debug info
149
150enabling optimizations
151
152picking a language to use, defaults to C99 by default. Autosenses based on
153extension.
154
155using a makefile
156</p>
157
158
159<!-- ======================================================================= -->
160<h2 id="commandline">Command Line Options</h2>
161<!-- ======================================================================= -->
162
163<p>
164This section is generally an index into other sections. It does not go into
165depth on most. However, the first part introduces the language selection and
166other high level options like -c, -g, etc.
167</p>
168
169<!-- ======================================================================= -->
170<h2 id="general_features">Language and Target-Independent Features</h2>
171<!-- ======================================================================= -->
172
173
174<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = -->
175<h3 id="diagnostics">Controlling Errors and Warnings</h3>
176<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = -->
177
178
179<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = -->
180<h3 id="precompiledheaders">Precompiled Headers</h3>
181<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = -->
182
Chris Lattner5c3074f2009-04-20 04:37:38 +0000183<p><a href="http://en.wikipedia.org/wiki/Precompiled_header">Precompiled
184headers</a> are a general approach employed by many compilers to reduce
185compilation time. The underlying motivation of the approach is that it is
186common for the same (and often large) header files to be included by
187multiple source files. Consequently, compile times can often be greatly improved
188by caching some of the (redundant) work done by a compiler to process headers.
189Precompiled header files, which represent one of many ways to implement
190this optimization, are literally files that represent an on-disk cache that
191contains the vital information necessary to reduce some of the work
192needed to process a corresponding header file. While details of precompiled
193headers vary between compilers, precompiled headers have been shown to be a
194highly effective at speeding up program compilation on systems with very large
195system headers (e.g., Mac OS/X).</p>
196
197<p>Clang supports an implementation of precompiled headers known as
198<em>pre-tokenized headers</em> (PTH). Clang's pre-tokenized headers support most
199of same interfaces as GCC's pre-compiled headers (as well as others) but are
200completely different in their implementation. If you are interested in how
201PTH is implemented, please see the <a href="PTHInternals.html">PTH Internals
202 document</a>.</p>
203
204<h4>Generating a PTH File</h4>
205
206<p>To generate a PTH file using Clang, one invokes Clang with
207the <b><tt>-x <i>&lt;language&gt;</i>-header</tt></b> option. This mirrors the
208interface in GCC for generating PCH files:</p>
209
210<pre>
211 $ gcc -x c-header test.h -o test.h.gch
212 $ clang -x c-header test.h -o test.h.pth
213</pre>
214
215<h4>Using a PTH File</h4>
216
217<p>A PTH file can then be used as a prefix header when a
218<b><tt>-include</tt></b> option is passed to <tt>clang</tt>:</p>
219
220<pre>
221 $ clang -include test.h test.c -o test
222</pre>
223
224<p>The <tt>clang</tt> driver will first check if a PTH file for <tt>test.h</tt>
225is available; if so, the contents of <tt>test.h</tt> (and the files it includes)
226will be processed from the PTH file. Otherwise, Clang falls back to
227directly processing the content of <tt>test.h</tt>. This mirrors the behavior of
228GCC.</p>
229
230<p><b>NOTE:</b> Clang does <em>not</em> automatically used PTH files
231for headers that are directly included within a source file. For example:</p>
232
233<pre>
234 $ clang -x c-header test.h -o test.h.pth
235 $ cat test.c
236 #include "test.h"
237 $ clang test.c -o test
238</pre>
239
240<p>In this example, <tt>clang</tt> will not automatically use the PTH file for
241<tt>test.h</tt> since <tt>test.h</tt> was included directly in the source file
242and not specified on the command line using <tt>-include</tt>.</p>
Chris Lattnercf17d9d2009-04-20 04:23:09 +0000243
244
245<!-- ======================================================================= -->
246<h2 id="c">C Language Features</h2>
247<!-- ======================================================================= -->
248
249
250<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = -->
251<h3 id="c_incompatibilities">Intentional Incompatibilities with GCC</h3>
252<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = -->
253
254<p>No VLAs in structs.</p>
255
256
257
258
259<!-- ======================================================================= -->
260<h2 id="objc">Objective-C Language Features</h2>
261<!-- ======================================================================= -->
262
263
264<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = -->
265<h3 id="objc_incompatibilities">Intentional Incompatibilities with GCC</h3>
266<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = -->
267
268<p>No cast of super, no lvalue casts.</p>
269
270
271
272<!-- ======================================================================= -->
273<h2 id="cxx">C++ Language Features</h2>
274<!-- ======================================================================= -->
275
276<p>At this point, Clang C++ is not generally useful. However, Clang C++ support
277is under active development and is progressing rapidly. Please see the <a
278href="http://clang.llvm.org/cxx_status.html">C++ Status</a> page for details or
279ask on the mailing list about how you can help.</p>
280
281<p>Note that the clang driver will refuse to even try to use clang to compile
282C++ code unless you pass the <tt>-ccc-clang-cxx</tt> option to the driver. If
283you really want to play with Clang's C++ support, please pass that flag. </p>
284
285<!-- ======================================================================= -->
286<h2 id="objcxx">Objective C++ Language Features</h2>
287<!-- ======================================================================= -->
288
289<p>At this point, Clang C++ support is not generally useful (and therefore,
290neither is Objective-C++). Please see the <a href="#cxx">C++ section</a> for
291more information.</p>
292
293<!-- ======================================================================= -->
294<h2 id="target_features">Target-Specific Features and Limitations</h2>
295<!-- ======================================================================= -->
296
297
298<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = -->
299<h3 id="target_arch">CPU Architectures Features and Limitations</h3>
300<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = -->
301
302<!-- ======================== -->
303<h4 id="target_arch_x86">X86</h4>
304<!-- ======================== -->
305
306
307<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = -->
308<h3 id="target_os">Operating System Features and Limitations</h3>
309<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = -->
310
311<!-- ======================================= -->
312<h4 id="target_os_darwin">Darwin (Mac OS/X)</h4>
313<!-- ======================================= -->
314
315<p>No __thread support, 64-bit ObjC support requires SL tools.</p>
316
317</div>
318</body>
319</html>