1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 2 "http://www.w3.org/TR/html4/strict.dtd"> 3<html> 4<head> 5<title>Clang Compiler User's Manual</title> 6<link type="text/css" rel="stylesheet" href="../menu.css"> 7<link type="text/css" rel="stylesheet" href="../content.css"> 8<style type="text/css"> 9td { 10 vertical-align: top; 11} 12</style> 13</head> 14<body> 15 16<!--#include virtual="../menu.html.incl"--> 17 18<div id="content"> 19 20<h1>Clang Compiler User's Manual</h1> 21 22<ul> 23<li><a href="#intro">Introduction</a> 24 <ul> 25 <li><a href="#terminology">Terminology</a></li> 26 <li><a href="#basicusage">Basic Usage</a></li> 27 </ul> 28</li> 29<li><a href="#commandline">Command Line Options</a> 30 <ul> 31 <li><a href="#cl_diagnostics">Options to Control Error and Warning 32 Messages</a></li> 33 <li><a href="#cl_crash_diagnostics">Options to Control Clang Crash 34 Diagnostics</a></li> 35 </ul> 36</li> 37<li><a href="#general_features">Language and Target-Independent Features</a> 38 <ul> 39 <li><a href="#diagnostics">Controlling Errors and Warnings</a> 40 <ul> 41 <li><a href="#diagnostics_display">Controlling How Clang Displays Diagnostics</a></li> 42 <li><a href="#diagnostics_mappings">Diagnostic Mappings</a></li> 43 <li><a href="#diagnostics_categories">Diagnostic Categories</a></li> 44 <li><a href="#diagnostics_commandline">Controlling Diagnostics via Command Line Flags</a></li> 45 <li><a href="#diagnostics_pragmas">Controlling Diagnostics via Pragmas</a></li> 46 <li><a href="#diagnostics_systemheader">Controlling Diagnostics in System Headers</a></li> 47 <li><a href="#diagnostics_enable_everything">Enabling All Warnings</a></li> 48 <li><a href="#analyzer_diagnositics">Controlling Static Analyzer Diagnostics</a></li> 49 </ul> 50 </li> 51 <li><a href="#precompiledheaders">Precompiled Headers</a></li> 52 <li><a href="#codegen">Controlling Code Generation</a></li> 53 <li><a href="#debuginfosize">Controlling Size of Debug Information</a></li> 54 </ul> 55</li> 56<li><a href="#c">C Language Features</a> 57 <ul> 58 <li><a href="#c_ext">Extensions supported by clang</a></li> 59 <li><a href="#c_modes">Differences between various standard modes</a></li> 60 <li><a href="#c_unimpl_gcc">GCC extensions not implemented yet</a></li> 61 <li><a href="#c_unsupp_gcc">Intentionally unsupported GCC extensions</a></li> 62 <li><a href="#c_ms">Microsoft extensions</a></li> 63 </ul> 64</li> 65<li><a href="#cxx">C++ Language Features</a> 66 <ul> 67 <li><a href="#cxx_implimits">Controlling implementation limits</a></li> 68 </ul> 69</li> 70<li><a href="#target_features">Target-Specific Features and Limitations</a> 71 <ul> 72 <li><a href="#target_arch">CPU Architectures Features and Limitations</a> 73 <ul> 74 <li><a href="#target_arch_x86">X86</a></li> 75 <li><a href="#target_arch_arm">ARM</a></li> 76 <li><a href="#target_arch_other">Other platforms</a></li> 77 </ul> 78 </li> 79 <li><a href="#target_os">Operating System Features and Limitations</a> 80 <ul> 81 <li><a href="#target_os_darwin">Darwin (Mac OS/X)</a></li> 82 <li>Linux, etc.</li> 83 <li><a href="#target_os_win32">Windows</a></li> 84 </ul> 85 </li> 86 </ul> 87</li> 88</ul> 89 90 91<!-- ======================================================================= --> 92<h2 id="intro">Introduction</h2> 93<!-- ======================================================================= --> 94 95<p>The Clang Compiler is an open-source compiler for the C family of programming 96languages, aiming to be the best in class implementation of these languages. 97Clang builds on the LLVM optimizer and code generator, allowing it to provide 98high-quality optimization and code generation support for many targets. For 99more general information, please see the <a href="http://clang.llvm.org">Clang 100Web Site</a> or the <a href="http://llvm.org">LLVM Web Site</a>.</p> 101 102<p>This document describes important notes about using Clang as a compiler for 103an end-user, documenting the supported features, command line options, etc. If 104you are interested in using Clang to build a tool that processes code, please 105see <a href="InternalsManual.html">the Clang Internals Manual</a>. If you are 106interested in the <a href="http://clang-analyzer.llvm.org">Clang 107Static Analyzer</a>, please see its web page.</p> 108 109<p>Clang is designed to support the C family of programming languages, which 110includes <a href="#c">C</a>, <a href="#objc">Objective-C</a>, <a 111href="#cxx">C++</a>, and <a href="#objcxx">Objective-C++</a> as well as many 112dialects of those. For language-specific information, please see the 113corresponding language specific section:</p> 114 115<ul> 116<li><a href="#c">C Language</a>: K&R C, ANSI C89, ISO C90, ISO C94 117 (C89+AMD1), ISO C99 (+TC1, TC2, TC3). </li> 118<li><a href="#objc">Objective-C Language</a>: ObjC 1, ObjC 2, ObjC 2.1, plus 119 variants depending on base language.</li> 120<li><a href="#cxx">C++ Language</a></li> 121<li><a href="#objcxx">Objective C++ Language</a></li> 122</ul> 123 124<p>In addition to these base languages and their dialects, Clang supports a 125broad variety of language extensions, which are documented in the corresponding 126language section. These extensions are provided to be compatible with the GCC, 127Microsoft, and other popular compilers as well as to improve functionality 128through Clang-specific features. The Clang driver and language features are 129intentionally designed to be as compatible with the GNU GCC compiler as 130reasonably possible, easing migration from GCC to Clang. In most cases, code 131"just works".</p> 132 133<p>In addition to language specific features, Clang has a variety of features 134that depend on what CPU architecture or operating system is being compiled for. 135Please see the <a href="#target_features">Target-Specific Features and 136Limitations</a> section for more details.</p> 137 138<p>The rest of the introduction introduces some basic <a 139href="#terminology">compiler terminology</a> that is used throughout this manual 140and contains a basic <a href="#basicusage">introduction to using Clang</a> 141as a command line compiler.</p> 142 143<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = --> 144<h3 id="terminology">Terminology</h3> 145<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = --> 146 147<p>Front end, parser, backend, preprocessor, undefined behavior, diagnostic, 148 optimizer</p> 149 150<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = --> 151<h3 id="basicusage">Basic Usage</h3> 152<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = --> 153 154<p>Intro to how to use a C compiler for newbies.</p> 155<p> 156compile + link 157 158compile then link 159 160debug info 161 162enabling optimizations 163 164picking a language to use, defaults to C99 by default. Autosenses based on 165extension. 166 167using a makefile 168</p> 169 170 171<!-- ======================================================================= --> 172<h2 id="commandline">Command Line Options</h2> 173<!-- ======================================================================= --> 174 175<p> 176This section is generally an index into other sections. It does not go into 177depth on the ones that are covered by other sections. However, the first part 178introduces the language selection and other high level options like -c, -g, etc. 179</p> 180 181 182<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = --> 183<h3 id="cl_diagnostics">Options to Control Error and Warning Messages</h3> 184<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = --> 185 186<p><b>-Werror</b>: Turn warnings into errors.</p> 187<p><b>-Werror=foo</b>: Turn warning "foo" into an error.</p> 188<p><b>-Wno-error=foo</b>: Turn warning "foo" into an warning even if -Werror is 189 specified.</p> 190<p><b>-Wfoo</b>: Enable warning "foo".</p> 191<p><b>-Wno-foo</b>: Disable warning "foo".</p> 192<p><b>-w</b>: Disable all warnings.</p> 193<p><b>-Weverything</b>: <a href="#diagnostics_enable_everything">Enable <b>all</b> warnings.</a></p> 194<p><b>-pedantic</b>: Warn on language extensions.</p> 195<p><b>-pedantic-errors</b>: Error on language extensions.</p> 196<p><b>-Wsystem-headers</b>: Enable warnings from system headers.</p> 197 198<p><b>-ferror-limit=123</b>: Stop emitting diagnostics after 123 errors have 199 been produced. The default is 20, and the error limit can be disabled with 200 -ferror-limit=0.</p> 201 202<p><b>-ftemplate-backtrace-limit=123</b>: Only emit up to 123 template instantiation notes within the template instantiation backtrace for a single warning or error. The default is 10, and the limit can be disabled with -ftemplate-backtrace-limit=0.</p> 203 204<!-- ================================================= --> 205<h4 id="cl_diag_formatting">Formatting of Diagnostics</h4> 206<!-- ================================================= --> 207 208<p>Clang aims to produce beautiful diagnostics by default, particularly for new 209users that first come to Clang. However, different people have different 210preferences, and sometimes Clang is driven by another program that wants to 211parse simple and consistent output, not a person. For these cases, Clang 212provides a wide range of options to control the exact output format of the 213diagnostics that it generates.</p> 214 215<dl> 216 217<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --> 218<dt id="opt_fshow-column"><b>-f[no-]show-column</b>: Print column number in 219diagnostic.</dt> 220<dd>This option, which defaults to on, controls whether or not Clang prints the 221column number of a diagnostic. For example, when this is enabled, Clang will 222print something like: 223 224<pre> 225 test.c:28:8: warning: extra tokens at end of #endif directive [-Wextra-tokens] 226 #endif bad 227 ^ 228 // 229</pre> 230 231<p>When this is disabled, Clang will print "test.c:28: warning..." with no 232column number.</p> 233 234<p>The printed column numbers count bytes from the beginning of the line; take 235care if your source contains multibyte characters.</p> 236</dd> 237 238<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --> 239<dt id="opt_fshow-source-location"><b>-f[no-]show-source-location</b>: Print 240source file/line/column information in diagnostic.</dt> 241<dd>This option, which defaults to on, controls whether or not Clang prints the 242filename, line number and column number of a diagnostic. For example, 243when this is enabled, Clang will print something like: 244 245<pre> 246 test.c:28:8: warning: extra tokens at end of #endif directive [-Wextra-tokens] 247 #endif bad 248 ^ 249 // 250</pre> 251 252<p>When this is disabled, Clang will not print the "test.c:28:8: " part.</p> 253</dd> 254 255<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --> 256<dt id="opt_fcaret-diagnostics"><b>-f[no-]caret-diagnostics</b>: Print source 257line and ranges from source code in diagnostic.</dt> 258<dd>This option, which defaults to on, controls whether or not Clang prints the 259source line, source ranges, and caret when emitting a diagnostic. For example, 260when this is enabled, Clang will print something like: 261 262<pre> 263 test.c:28:8: warning: extra tokens at end of #endif directive [-Wextra-tokens] 264 #endif bad 265 ^ 266 // 267</pre> 268</dd> 269<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --> 270<dt id="opt_fcolor_diagnostics"><b>-f[no-]color-diagnostics</b>: </dt> 271<dd>This option, which defaults to on when a color-capable terminal is 272 detected, controls whether or not Clang prints diagnostics in color. 273 When this option is enabled, Clang will use colors to highlight 274 specific parts of the diagnostic, e.g., 275 <pre> 276 <b><span style="color:black">test.c:28:8: <span style="color:magenta">warning</span>: extra tokens at end of #endif directive [-Wextra-tokens]</span></b> 277 #endif bad 278 <span style="color:green">^</span> 279 <span style="color:green">//</span> 280</pre> 281 282<p>When this is disabled, Clang will just print:</p> 283 284<pre> 285 test.c:2:8: warning: extra tokens at end of #endif directive [-Wextra-tokens] 286 #endif bad 287 ^ 288 // 289</pre> 290</dd> 291<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --> 292<dt id="opt_fdiagnostics-format"><b>-fdiagnostics-format=clang/msvc/vi</b>: 293Changes diagnostic output format to better match IDEs and command line tools.</dt> 294<dd>This option controls the output format of the filename, line number, and column printed in diagnostic messages. The options, and their affect on formatting a simple conversion diagnostic, follow: 295 296 <dl> 297 <dt><b>clang</b> (default)</dt> 298 <dd> 299 <pre>t.c:3:11: warning: conversion specifies type 'char *' but the argument has type 'int'</pre> 300 </dd> 301 302 <dt><b>msvc</b></dt> 303 <dd> 304 <pre>t.c(3,11) : warning: conversion specifies type 'char *' but the argument has type 'int'</pre> 305 </dd> 306 307 <dt><b>vi</b></dt> 308 <dd> 309 <pre>t.c +3:11: warning: conversion specifies type 'char *' but the argument has type 'int'</pre> 310 </dd> 311 </dl> 312</dd> 313 314<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --> 315<dt id="opt_fdiagnostics-show-name"><b>-f[no-]diagnostics-show-name</b>: 316Enable the display of the diagnostic name.</dt> 317<dd>This option, which defaults to off, controls whether or not 318Clang prints the associated name.<p></p></dd> 319<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --> 320<dt id="opt_fdiagnostics-show-option"><b>-f[no-]diagnostics-show-option</b>: 321Enable <tt>[-Woption]</tt> information in diagnostic line.</dt> 322<dd>This option, which defaults to on, 323controls whether or not Clang prints the associated <A 324href="#cl_diag_warning_groups">warning group</a> option name when outputting 325a warning diagnostic. For example, in this output: 326 327<pre> 328 test.c:28:8: warning: extra tokens at end of #endif directive [-Wextra-tokens] 329 #endif bad 330 ^ 331 // 332</pre> 333 334<p>Passing <b>-fno-diagnostics-show-option</b> will prevent Clang from printing 335the [<a href="#opt_Wextra-tokens">-Wextra-tokens</a>] information in the 336diagnostic. This information tells you the flag needed to enable or disable the 337diagnostic, either from the command line or through <a 338href="#pragma_GCC_diagnostic">#pragma GCC diagnostic</a>.</dd> 339 340<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --> 341<dt id="opt_fdiagnostics-show-category"><b>-fdiagnostics-show-category=none/id/name</b>: 342Enable printing category information in diagnostic line.</dt> 343<dd>This option, which defaults to "none", 344controls whether or not Clang prints the category associated with a diagnostic 345when emitting it. Each diagnostic may or many not have an associated category, 346if it has one, it is listed in the diagnostic categorization field of the 347diagnostic line (in the []'s). 348 349<p>For example, a format string warning will produce these three renditions 350based on the setting of this option:</p> 351 352<pre> 353 t.c:3:11: warning: conversion specifies type 'char *' but the argument has type 'int' [-Wformat] 354 t.c:3:11: warning: conversion specifies type 'char *' but the argument has type 'int' [-Wformat<b>,1</b>] 355 t.c:3:11: warning: conversion specifies type 'char *' but the argument has type 'int' [-Wformat<b>,Format String</b>] 356</pre> 357 358<p>This category can be used by clients that want to group diagnostics by 359category, so it should be a high level category. We want dozens of these, not 360hundreds or thousands of them.</p> 361</dd> 362 363 364 365<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --> 366<dt id="opt_fdiagnostics-fixit-info"><b>-f[no-]diagnostics-fixit-info</b>: 367Enable "FixIt" information in the diagnostics output.</dt> 368<dd>This option, which defaults to on, controls whether or not Clang prints the 369information on how to fix a specific diagnostic underneath it when it knows. 370For example, in this output: 371 372<pre> 373 test.c:28:8: warning: extra tokens at end of #endif directive [-Wextra-tokens] 374 #endif bad 375 ^ 376 // 377</pre> 378 379<p>Passing <b>-fno-diagnostics-fixit-info</b> will prevent Clang from printing 380the "//" line at the end of the message. This information is useful for users 381who may not understand what is wrong, but can be confusing for machine 382parsing.</p> 383</dd> 384 385<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --> 386<dt id="opt_fdiagnostics-print-source-range-info"> 387<b>-f[no-]diagnostics-print-source-range-info</b>: 388Print machine parsable information about source ranges.</dt> 389<dd>This option, which defaults to off, controls whether or not Clang prints 390information about source ranges in a machine parsable format after the 391file/line/column number information. The information is a simple sequence of 392brace enclosed ranges, where each range lists the start and end line/column 393locations. For example, in this output: 394 395<pre> 396exprs.c:47:15:{47:8-47:14}{47:17-47:24}: error: invalid operands to binary expression ('int *' and '_Complex float') 397 P = (P-42) + Gamma*4; 398 ~~~~~~ ^ ~~~~~~~ 399</pre> 400 401<p>The {}'s are generated by -fdiagnostics-print-source-range-info.</p> 402 403<p>The printed column numbers count bytes from the beginning of the line; take 404care if your source contains multibyte characters.</p> 405</dd> 406 407<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --> 408<dt id="opt_fdiagnostics-parseable-fixits"> 409<b>-fdiagnostics-parseable-fixits</b>: 410Print Fix-Its in a machine parseable form.</dt> 411<dd><p>This option makes Clang print available Fix-Its in a machine parseable format at the end of diagnostics. The following example illustrates the format:</p> 412 413<pre> 414 fix-it:"t.cpp":{7:25-7:29}:"Gamma" 415</pre> 416 417<p>The range printed is a half-open range, so in this example the characters at 418column 25 up to but not including column 29 on line 7 in t.cpp should be 419replaced with the string "Gamma". Either the range or the replacement 420string may be empty (representing strict insertions and strict erasures, 421respectively). Both the file name and the insertion string escape backslash (as 422"\\"), tabs (as "\t"), newlines (as "\n"), double 423quotes(as "\"") and non-printable characters (as octal 424"\xxx").</p> 425 426<p>The printed column numbers count bytes from the beginning of the line; take 427care if your source contains multibyte characters.</p> 428</dd> 429 430<dt id="opt_fno-elide-type"> 431<b>-fno-elide-type</b>: 432Turns off elision in template type printing.</dt> 433<dd><p>The default for template type printing is to elide as many template 434arguments as possible, removing those which are the same in both template types, 435leaving only the differences. Adding this flag will print all the template 436arguments. If supported by the terminal, highlighting will still appear on 437differing arguments.</p> 438 439Default: 440<pre> 441t.cc:4:5: <span class="note">note</span>: candidate function not viable: no known conversion from 'vector<map<[...], map<<span class="template-highlight">float</span>, [...]>>>' to 'vector<map<[...], map<<span class="template-highlight">double</span>, [...]>>>' for 1st argument; 442</pre> 443-fno-elide-type: 444<pre> 445t.cc:4:5: <span class="note">note</span>: candidate function not viable: no known conversion from 'vector<map<int, map<<span class="template-highlight">float</span>, int>>>' to 'vector<map<int, map<<span class="template-highlight">double</span>, int>>>' for 1st argument; 446</pre> 447</dd> 448 449<dt id="opt_fdiagnostics-show-template-tree"> 450<b>-fdiagnostics-show-template-tree</b>: 451Template type diffing prints a text tree.</dt> 452<dd><p>For diffing large templated types, this option will cause Clang to 453display the templates as an indented text tree, one argument per line, with 454differences marked inline. This is compatible with -fno-elide-type.</p> 455 456Default: 457<pre> 458t.cc:4:5: <span class="note">note</span>: candidate function not viable: no known conversion from 'vector<map<[...], map<<span class="template-highlight">float</span>, [...]>>>' to 'vector<map<[...], map<<span class="template-highlight">double</span>, [...]>>>' for 1st argument; 459</pre> 460-fdiagnostics-show-template-tree 461<pre> 462t.cc:4:5: <span class="note">note</span>: candidate function not viable: no known conversion for 1st argument; 463 vector< 464 map< 465 [...], 466 map< 467 [<span class="template-highlight">float</span> != <span class="template-highlight">float</span>], 468 [...]>>> 469</pre> 470</dd> 471 472</dl> 473 474 475 476<!-- ===================================================== --> 477<h4 id="cl_diag_warning_groups">Individual Warning Groups</h4> 478<!-- ===================================================== --> 479 480<p>TODO: Generate this from tblgen. Define one anchor per warning group.</p> 481 482 483<dl> 484 485 486<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --> 487<dt id="opt_Wextra-tokens"><b>-Wextra-tokens</b>: Warn about excess tokens at 488 the end of a preprocessor directive.</dt> 489<dd>This option, which defaults to on, enables warnings about extra tokens at 490the end of preprocessor directives. For example: 491 492<pre> 493 test.c:28:8: warning: extra tokens at end of #endif directive [-Wextra-tokens] 494 #endif bad 495 ^ 496</pre> 497 498<p>These extra tokens are not strictly conforming, and are usually best handled 499by commenting them out.</p> 500</dd> 501 502<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --> 503<dt id="opt_Wambiguous-member-template"><b>-Wambiguous-member-template</b>: 504Warn about unqualified uses of a member template whose name resolves 505to another template at the location of the use.</dt> 506<dd>This option, which defaults to on, enables a warning in the 507following code: 508 509<pre> 510template<typename T> struct set{}; 511template<typename T> struct trait { typedef const T& type; }; 512struct Value { 513 template<typename T> void set(typename trait<T>::type value) {} 514}; 515void foo() { 516 Value v; 517 v.set<double>(3.2); 518} 519</pre> 520 521<p>C++ [basic.lookup.classref] requires this to be an error, but, 522because it's hard to work around, Clang downgrades it to a warning as 523an extension.</p> 524</dd> 525 526<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --> 527<dt id="opt_Wbind-to-temporary-copy"><b>-Wbind-to-temporary-copy</b>: Warn about 528an unusable copy constructor when binding a reference to a temporary.</dt> 529<dd>This option, which defaults to on, enables warnings about binding a 530reference to a temporary when the temporary doesn't have a usable copy 531constructor. For example: 532 533<pre> 534 struct NonCopyable { 535 NonCopyable(); 536 private: 537 NonCopyable(const NonCopyable&); 538 }; 539 void foo(const NonCopyable&); 540 void bar() { 541 foo(NonCopyable()); // Disallowed in C++98; allowed in C++11. 542 } 543</pre> 544<pre> 545 struct NonCopyable2 { 546 NonCopyable2(); 547 NonCopyable2(NonCopyable2&); 548 }; 549 void foo(const NonCopyable2&); 550 void bar() { 551 foo(NonCopyable2()); // Disallowed in C++98; allowed in C++11. 552 } 553</pre> 554 555<p>Note that if <tt>NonCopyable2::NonCopyable2()</tt> has a default 556argument whose instantiation produces a compile error, that error will 557still be a hard error in C++98 mode even if this warning is turned 558off.</p> 559 560</dd> 561 562</dl> 563 564<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = --> 565<h3 id="cl_crash_diagnostics">Options to Control Clang Crash Diagnostics</h3> 566<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = --> 567 568<p>As unbelievable as it may sound, Clang does crash from time to time. 569Generally, this only occurs to those living on the 570<a href="http://llvm.org/releases/download.html#svn">bleeding edge</a>. Clang 571goes to great lengths to assist you in filing a bug report. Specifically, Clang 572generates preprocessed source file(s) and associated run script(s) upon a 573crash. These files should be attached to a bug report to ease reproducibility 574of the failure. Below are the command line options to control the crash 575diagnostics. 576</p> 577 578<p><b>-fno-crash-diagnostics</b>: Disable auto-generation of preprocessed 579source files during a clang crash.</p> 580 581<p>The -fno-crash-diagnostics flag can be helpful for speeding the process of 582generating a delta reduced test case.</p> 583 584 585<!-- ======================================================================= --> 586<h2 id="general_features">Language and Target-Independent Features</h2> 587<!-- ======================================================================= --> 588 589 590<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = --> 591<h3 id="diagnostics">Controlling Errors and Warnings</h3> 592<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = --> 593 594<p>Clang provides a number of ways to control which code constructs cause it to 595emit errors and warning messages, and how they are displayed to the console.</p> 596 597<h4 id="diagnostics_display">Controlling How Clang Displays Diagnostics</h4> 598 599<p>When Clang emits a diagnostic, it includes rich information in the output, 600and gives you fine-grain control over which information is printed. Clang has 601the ability to print this information, and these are the options that control 602it:</p> 603 604<ol> 605<li>A file/line/column indicator that shows exactly where the diagnostic occurs 606 in your code [<a href="#opt_fshow-column">-fshow-column</a>, <a 607 href="#opt_fshow-source-location">-fshow-source-location</a>].</li> 608<li>A categorization of the diagnostic as a note, warning, error, or fatal 609 error.</li> 610<li>A text string that describes what the problem is.</li> 611<li>An option that indicates how to control the diagnostic (for diagnostics that 612 support it) [<a 613 href="#opt_fdiagnostics-show-option">-fdiagnostics-show-option</a>].</li> 614<li>A <a href="#diagnostics_categories">high-level category</a> for the 615 diagnostic for clients that want to group diagnostics by class (for 616 diagnostics that support it) [<a 617 href="#opt_fdiagnostics-show-category">-fdiagnostics-show-category</a>].</li> 618<li>The line of source code that the issue occurs on, along with a caret and 619 ranges that indicate the important locations [<a 620 href="opt_fcaret-diagnostics">-fcaret-diagnostics</a>].</li> 621<li>"FixIt" information, which is a concise explanation of how to fix the 622 problem (when Clang is certain it knows) [<a 623 href="opt_fdiagnostics-fixit-info">-fdiagnostics-fixit-info</a>].</li> 624<li>A machine-parsable representation of the ranges involved (off by 625 default) [<a 626 href="opt_fdiagnostics-print-source-range-info">-fdiagnostics-print-source-range-info</a>].</li> 627</ol> 628 629<p>For more information please see <a href="#cl_diag_formatting">Formatting of 630Diagnostics</a>.</p> 631 632 633<h4 id="diagnostics_mappings">Diagnostic Mappings</h4> 634 635<p>All diagnostics are mapped into one of these 5 classes:</p> 636 637<ul> 638<li>Ignored</li> 639<li>Note</li> 640<li>Warning</li> 641<li>Error</li> 642<li>Fatal</li> 643</ul> 644 645<h4 id="diagnostics_categories">Diagnostic Categories</h4> 646 647<p>Though not shown by default, diagnostics may each be associated with a 648 high-level category. This category is intended to make it possible to triage 649 builds that produce a large number of errors or warnings in a grouped way. 650</p> 651 652<p>Categories are not shown by default, but they can be turned on with the 653<a href="#opt_fdiagnostics-show-category">-fdiagnostics-show-category</a> option. 654When set to "<tt>name</tt>", the category is printed textually in the diagnostic 655output. When it is set to "<tt>id</tt>", a category number is printed. The 656mapping of category names to category id's can be obtained by running '<tt>clang 657 --print-diagnostic-categories</tt>'. 658</p> 659 660<h4 id="diagnostics_commandline">Controlling Diagnostics via Command Line 661 Flags</h4> 662 663<p>TODO: -W flags, -pedantic, etc</p> 664 665<h4 id="diagnostics_pragmas">Controlling Diagnostics via Pragmas</h4> 666 667<p>Clang can also control what diagnostics are enabled through the use of 668pragmas in the source code. This is useful for turning off specific warnings 669in a section of source code. Clang supports GCC's pragma for compatibility 670with existing source code, as well as several extensions. </p> 671 672<p>The pragma may control any warning that can be used from the command line. 673Warnings may be set to ignored, warning, error, or fatal. The following 674example code will tell Clang or GCC to ignore the -Wall warnings:</p> 675 676<pre> 677#pragma GCC diagnostic ignored "-Wall" 678</pre> 679 680<p>In addition to all of the functionality provided by GCC's pragma, Clang 681also allows you to push and pop the current warning state. This is particularly 682useful when writing a header file that will be compiled by other people, because 683you don't know what warning flags they build with.</p> 684 685<p>In the below example 686-Wmultichar is ignored for only a single line of code, after which the 687diagnostics return to whatever state had previously existed.</p> 688 689<pre> 690#pragma clang diagnostic push 691#pragma clang diagnostic ignored "-Wmultichar" 692 693char b = 'df'; // no warning. 694 695#pragma clang diagnostic pop 696</pre> 697 698<p>The push and pop pragmas will save and restore the full diagnostic state of 699the compiler, regardless of how it was set. That means that it is possible to 700use push and pop around GCC compatible diagnostics and Clang will push and pop 701them appropriately, while GCC will ignore the pushes and pops as unknown 702pragmas. It should be noted that while Clang supports the GCC pragma, Clang and 703GCC do not support the exact same set of warnings, so even when using GCC 704compatible #pragmas there is no guarantee that they will have identical behaviour 705on both compilers. </p> 706 707<h4 id="diagnostics_systemheader">Controlling Diagnostics in System Headers</h4> 708 709<p>Warnings are suppressed when they occur in system headers. By default, an 710included file is treated as a system header if it is found in an include path 711specified by <tt>-isystem</tt>, but this can be overridden in several ways.</p> 712 713<p>The <tt>system_header</tt> pragma can be used to mark the current file as 714being a system header. No warnings will be produced from the location of the 715pragma onwards within the same file.</p> 716 717<pre> 718char a = 'xy'; // warning 719 720#pragma clang system_header 721 722char b = 'ab'; // no warning 723</pre> 724 725<p>The <tt>-isystem-prefix</tt> and <tt>-ino-system-prefix</tt> command-line 726arguments can be used to override whether subsets of an include path are treated 727as system headers. When the name in a <tt>#include</tt> directive is found 728within a header search path and starts with a system prefix, the header is 729treated as a system header. The last prefix on the command-line which matches 730the specified header name takes precedence. For instance:</p> 731 732<pre> 733clang -Ifoo -isystem bar -isystem-prefix x/ -ino-system-prefix x/y/ 734</pre> 735 736<p>Here, <tt>#include "x/a.h"</tt> is treated as including a system header, even 737if the header is found in <tt>foo</tt>, and <tt>#include "x/y/b.h"</tt> is 738treated as not including a system header, even if the header is found in 739<tt>bar</tt>. 740</p> 741 742<p>A <tt>#include</tt> directive which finds a file relative to the current 743directory is treated as including a system header if the including file is 744treated as a system header.</p> 745 746<h4 id="diagnostics_enable_everything">Enabling All Warnings</h4> 747 748<p>In addition to the traditional <tt>-W</tt> flags, one can enable <b>all</b> 749 warnings by passing <tt>-Weverything</tt>. 750 This works as expected with <tt>-Werror</tt>, 751 and also includes the warnings from <tt>-pedantic</tt>.</p> 752 753<p>Note that when combined with <tt>-w</tt> (which disables all warnings), that 754 flag wins.</p> 755 756<h4 id="analyzer_diagnositics">Controlling Static Analyzer Diagnostics</h4> 757 758<p>While not strictly part of the compiler, the diagnostics from Clang's <a 759href="http://clang-analyzer.llvm.org">static analyzer</a> can also be influenced 760by the user via changes to the source code. See the available 761<a href = "http://clang-analyzer.llvm.org/annotations.html" >annotations</a> and 762the analyzer's 763<a href= "http://clang-analyzer.llvm.org/faq.html#exclude_code" >FAQ page</a> for 764more information. 765 766<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = --> 767<h3 id="precompiledheaders">Precompiled Headers</h3> 768<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = --> 769 770<p><a href="http://en.wikipedia.org/wiki/Precompiled_header">Precompiled 771headers</a> are a general approach employed by many compilers to reduce 772compilation time. The underlying motivation of the approach is that it is 773common for the same (and often large) header files to be included by 774multiple source files. Consequently, compile times can often be greatly improved 775by caching some of the (redundant) work done by a compiler to process headers. 776Precompiled header files, which represent one of many ways to implement 777this optimization, are literally files that represent an on-disk cache that 778contains the vital information necessary to reduce some of the work 779needed to process a corresponding header file. While details of precompiled 780headers vary between compilers, precompiled headers have been shown to be 781highly effective at speeding up program compilation on systems with very large 782system headers (e.g., Mac OS/X).</p> 783 784<h4>Generating a PCH File</h4> 785 786<p>To generate a PCH file using Clang, one invokes Clang with 787the <b><tt>-x <i><language></i>-header</tt></b> option. This mirrors the 788interface in GCC for generating PCH files:</p> 789 790<pre> 791 $ gcc -x c-header test.h -o test.h.gch 792 $ clang -x c-header test.h -o test.h.pch 793</pre> 794 795<h4>Using a PCH File</h4> 796 797<p>A PCH file can then be used as a prefix header when a 798<b><tt>-include</tt></b> option is passed to <tt>clang</tt>:</p> 799 800<pre> 801 $ clang -include test.h test.c -o test 802</pre> 803 804<p>The <tt>clang</tt> driver will first check if a PCH file for <tt>test.h</tt> 805is available; if so, the contents of <tt>test.h</tt> (and the files it includes) 806will be processed from the PCH file. Otherwise, Clang falls back to 807directly processing the content of <tt>test.h</tt>. This mirrors the behavior of 808GCC.</p> 809 810<p><b>NOTE:</b> Clang does <em>not</em> automatically use PCH files 811for headers that are directly included within a source file. For example:</p> 812 813<pre> 814 $ clang -x c-header test.h -o test.h.pch 815 $ cat test.c 816 #include "test.h" 817 $ clang test.c -o test 818</pre> 819 820<p>In this example, <tt>clang</tt> will not automatically use the PCH file for 821<tt>test.h</tt> since <tt>test.h</tt> was included directly in the source file 822and not specified on the command line using <tt>-include</tt>.</p> 823 824<h4>Relocatable PCH Files</h4> 825<p>It is sometimes necessary to build a precompiled header from headers that 826are not yet in their final, installed locations. For example, one might build a 827precompiled header within the build tree that is then meant to be installed 828alongside the headers. Clang permits the creation of "relocatable" precompiled 829headers, which are built with a given path (into the build directory) and can 830later be used from an installed location.</p> 831 832<p>To build a relocatable precompiled header, place your headers into a 833subdirectory whose structure mimics the installed location. For example, if you 834want to build a precompiled header for the header <code>mylib.h</code> that 835will be installed into <code>/usr/include</code>, create a subdirectory 836<code>build/usr/include</code> and place the header <code>mylib.h</code> into 837that subdirectory. If <code>mylib.h</code> depends on other headers, then 838they can be stored within <code>build/usr/include</code> in a way that mimics 839the installed location.</p> 840 841<p>Building a relocatable precompiled header requires two additional arguments. 842First, pass the <code>--relocatable-pch</code> flag to indicate that the 843resulting PCH file should be relocatable. Second, pass 844<code>-isysroot /path/to/build</code>, which makes all includes for your 845library relative to the build directory. For example:</p> 846 847<pre> 848 # clang -x c-header --relocatable-pch -isysroot /path/to/build /path/to/build/mylib.h mylib.h.pch 849</pre> 850 851<p>When loading the relocatable PCH file, the various headers used in the PCH 852file are found from the system header root. For example, <code>mylib.h</code> 853can be found in <code>/usr/include/mylib.h</code>. If the headers are installed 854in some other system root, the <code>-isysroot</code> option can be used provide 855a different system root from which the headers will be based. For example, 856<code>-isysroot /Developer/SDKs/MacOSX10.4u.sdk</code> will look for 857<code>mylib.h</code> in 858<code>/Developer/SDKs/MacOSX10.4u.sdk/usr/include/mylib.h</code>.</p> 859 860<p>Relocatable precompiled headers are intended to be used in a limited number 861of cases where the compilation environment is tightly controlled and the 862precompiled header cannot be generated after headers have been installed. 863Relocatable precompiled headers also have some performance impact, because 864the difference in location between the header locations at PCH build time vs. 865at the time of PCH use requires one of the PCH optimizations, 866<code>stat()</code> caching, to be disabled. However, this change is only 867likely to affect PCH files that reference a large number of headers.</p> 868 869<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = --> 870<h3 id="codegen">Controlling Code Generation</h3> 871<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = --> 872 873<p>Clang provides a number of ways to control code generation. The options are listed below.</p> 874 875<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --> 876<dl> 877<dt id="opt_fcatch-undefined-behavior"><b>-fcatch-undefined-behavior</b>: Turn 878on runtime code generation to check for undefined behavior.</dt> 879 880<dd>This option, which defaults to off, controls whether or not Clang 881adds runtime checks for undefined runtime behavior. If a check fails, 882<tt>__builtin_trap()</tt> is used to indicate failure. 883The currently implemented checks include: 884<ul> 885<li>Subscripting where the static type of one operand is a variable 886 which is decayed from an array type and the other operand is 887 greater than the size of the array or less than zero.</li> 888<li>Shift operators where the amount shifted is greater or equal to the 889 promoted bit-width of the left-hand-side or less than zero.</li> 890<li>If control flow reaches __builtin_unreachable.</li> 891<li>Reads and writes for objects which are inappropriately aligned or are not 892 large enough (in cases where the size can be determined). 893<li>Signed integer overflow, including all the checks added by <tt>-ftrapv</tt> 894 and also checking for signed left shift overflow.</li> 895<li>Binding a reference to a storage location which is not of an appropriate 896 alignment or size (in cases where the size can be determined), or binding 897 a reference to an empty glvalue (a dereferenced null pointer). 898<li>Class member access or member function call where the <tt>this</tt> 899 pointer is not of an appropriate alignment or size (in cases where the size 900 can be determined), or where it is null.</li> 901</ul> 902 903<p>The sizes of objects are determined using <tt>__builtin_object_size</tt>, and 904consequently may be able to detect more problems at higher optimization levels. 905Bit-fields and vectors are not yet checked.</p> 906 907</dd> 908 909<dt id="opt_faddress-sanitizer"><b>-f[no-]address-sanitizer</b>: 910Turn on <a href="AddressSanitizer.html">AddressSanitizer</a>, 911a memory error detector. 912 913<dt id="opt_fthread-sanitizer"><b>-f[no-]thread-sanitizer</b>: 914Turn on ThreadSanitizer, an <em>experimental</em> data race detector. 915Not ready for widespread use. 916 917<dt id="opt_fno-assume-sane-operator-new"><b>-fno-assume-sane-operator-new</b>: 918Don't assume that the C++'s new operator is sane.</dt> 919<dd>This option tells the compiler to do not assume that C++'s global new 920operator will always return a pointer that does not 921alias any other pointer when the function returns.</dd> 922 923<dt id="opt_ftrap-function"><b>-ftrap-function=[name]</b>: Instruct code 924generator to emit a function call to the specified function name for 925<tt>__builtin_trap()</tt>.</dt> 926 927<dd>LLVM code generator translates <tt>__builtin_trap()</tt> to a trap 928instruction if it is supported by the target ISA. Otherwise, the builtin is 929translated into a call to <tt>abort</tt>. If this option is set, then the code 930generator will always lower the builtin to a call to the specified function 931regardless of whether the target ISA has a trap instruction. This option is 932useful for environments (e.g. deeply embedded) where a trap cannot be properly 933handled, or when some custom behavior is desired.</dd> 934 935<dt id="opt_ftls-model"><b>-ftls-model=[model]</b>: Select which TLS model to 936use.</dt> 937<dd>Valid values are: <tt>global-dynamic</tt>, <tt>local-dynamic</tt>, 938<tt>initial-exec</tt> and <tt>local-exec</tt>. The default value is 939<tt>global-dynamic</tt>. The compiler may use a different model if the selected 940model is not supported by the target, or if a more efficient model can be used. 941The TLS model can be overridden per variable using the <tt>tls_model</tt> 942attribute. 943</dd> 944</dl> 945 946<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = --> 947<h3 id="debuginfosize">Controlling Size of Debug Information</h3> 948<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = --> 949 950<p>Debug info kind generated by Clang can be set by one of the flags listed 951below. If multiple flags are present, the last one is used.</p> 952 953<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - --> 954<dl> 955<dt id="opt_g0"><b>-g0</b>: Don't generate any debug info (default). 956 957<dt id="opt_gline-tables-only"><b>-gline-tables-only</b>: 958Generate line number tables only. 959<dd> 960This kind of debug info allows to obtain stack traces with function 961names, file names and line numbers (by such tools as 962gdb or addr2line). It doesn't contain any other data (e.g. 963description of local variables or function parameters). 964</dd> 965 966<dt id="opt_g"><b>-g</b>: Generate complete debug info. 967</dl> 968 969<!-- ======================================================================= --> 970<h2 id="c">C Language Features</h2> 971<!-- ======================================================================= --> 972 973<p>The support for standard C in clang is feature-complete except for the C99 974floating-point pragmas.</p> 975 976<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = --> 977<h3 id="c_ext">Extensions supported by clang</h3> 978<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = --> 979 980<p>See <a href="LanguageExtensions.html">clang language extensions</a>.</p> 981 982<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = --> 983<h3 id="c_modes">Differences between various standard modes</h3> 984<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = --> 985 986<p>clang supports the -std option, which changes what language mode clang uses. 987The supported modes for C are c89, gnu89, c94, c99, gnu99 and various aliases 988for those modes. If no -std option is specified, clang defaults to gnu99 mode. 989</p> 990 991<p>Differences between all c* and gnu* modes:</p> 992<ul> 993<li>c* modes define "__STRICT_ANSI__".</li> 994<li>Target-specific defines not prefixed by underscores, like "linux", are 995defined in gnu* modes.</li> 996<li>Trigraphs default to being off in gnu* modes; they can be enabled by the 997-trigraphs option.</li> 998<li>The parser recognizes "asm" and "typeof" as keywords in gnu* modes; the 999variants "__asm__" and "__typeof__" are recognized in all modes.</li> 1000<li>The Apple "blocks" extension is recognized by default in gnu* modes 1001on some platforms; it can be enabled in any mode with the "-fblocks" 1002option.</li> 1003<li>Arrays that are VLA's according to the standard, but which can be constant 1004 folded by the frontend are treated as fixed size arrays. This occurs for 1005 things like "int X[(1, 2)];", which is technically a VLA. c* modes are 1006 strictly compliant and treat these as VLAs.</li> 1007</ul> 1008 1009<p>Differences between *89 and *99 modes:</p> 1010<ul> 1011<li>The *99 modes default to implementing "inline" as specified in C99, while 1012the *89 modes implement the GNU version. This can be overridden for individual 1013functions with the __gnu_inline__ attribute.</li> 1014<li>Digraphs are not recognized in c89 mode.</li> 1015<li>The scope of names defined inside a "for", "if", "switch", "while", or "do" 1016statement is different. (example: "if ((struct x {int x;}*)0) {}".)</li> 1017<li>__STDC_VERSION__ is not defined in *89 modes.</li> 1018<li>"inline" is not recognized as a keyword in c89 mode.</li> 1019<li>"restrict" is not recognized as a keyword in *89 modes.</li> 1020<li>Commas are allowed in integer constant expressions in *99 modes.</li> 1021<li>Arrays which are not lvalues are not implicitly promoted to pointers in 1022*89 modes.</li> 1023<li>Some warnings are different.</li> 1024</ul> 1025 1026<p>c94 mode is identical to c89 mode except that digraphs are enabled in 1027c94 mode (FIXME: And __STDC_VERSION__ should be defined!).</p> 1028 1029<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = --> 1030<h3 id="c_unimpl_gcc">GCC extensions not implemented yet</h3> 1031<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = --> 1032 1033<p>clang tries to be compatible with gcc as much as possible, but some gcc 1034extensions are not implemented yet:</p> 1035 1036<ul> 1037 1038<li>clang does not support #pragma weak 1039(<a href="http://llvm.org/bugs/show_bug.cgi?id=3679">bug 3679</a>). Due to 1040the uses described in the bug, this is likely to be implemented at some 1041point, at least partially.</li> 1042 1043<li>clang does not support decimal floating point types (_Decimal32 and 1044friends) or fixed-point types (_Fract and friends); nobody has expressed 1045interest in these features yet, so it's hard to say when they will be 1046implemented.</li> 1047 1048<li>clang does not support nested functions; this is a complex feature which 1049is infrequently used, so it is unlikely to be implemented anytime soon. In C++11 1050it can be emulated by assigning lambda functions to local variables, e.g: 1051<pre> 1052 auto const local_function = [&](int parameter) { 1053 // Do something 1054 }; 1055 ... 1056 local_function(1); 1057</pre> 1058</li> 1059 1060<li>clang does not support global register variables; this is unlikely 1061to be implemented soon because it requires additional LLVM backend support. 1062</li> 1063 1064<li>clang does not support static initialization of flexible array 1065members. This appears to be a rarely used extension, but could be 1066implemented pending user demand.</li> 1067 1068<li>clang does not support __builtin_va_arg_pack/__builtin_va_arg_pack_len. 1069This is used rarely, but in some potentially interesting places, like the 1070glibc headers, so it may be implemented pending user demand. Note that 1071because clang pretends to be like GCC 4.2, and this extension was introduced 1072in 4.3, the glibc headers will not try to use this extension with clang at 1073the moment.</li> 1074 1075<li>clang does not support the gcc extension for forward-declaring function 1076parameters; this has not shown up in any real-world code yet, though, so it 1077might never be implemented.</li> 1078 1079</ul> 1080 1081<p>This is not a complete list; if you find an unsupported extension 1082missing from this list, please send an e-mail to cfe-dev. This list 1083currently excludes C++; see <a href="#cxx">C++ Language Features</a>. 1084Also, this list does not include bugs in mostly-implemented features; please 1085see the <a href="http://llvm.org/bugs/buglist.cgi?quicksearch=product%3Aclang+component%3A-New%2BBugs%2CAST%2CBasic%2CDriver%2CHeaders%2CLLVM%2BCodeGen%2Cparser%2Cpreprocessor%2CSemantic%2BAnalyzer"> 1086bug tracker</a> for known existing bugs (FIXME: Is there a section for 1087bug-reporting guidelines somewhere?).</p> 1088 1089<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = --> 1090<h3 id="c_unsupp_gcc">Intentionally unsupported GCC extensions</h3> 1091<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = --> 1092 1093<ul> 1094 1095<li>clang does not support the gcc extension that allows variable-length arrays 1096in structures. This is for a few reasons: one, it is tricky 1097to implement, two, the extension is completely undocumented, and three, the 1098extension appears to be rarely used. Note that clang <em>does</em> support 1099flexible array members (arrays with a zero or unspecified size at the end of 1100a structure).</li> 1101 1102<li>clang does not have an equivalent to gcc's "fold"; this means that 1103clang doesn't accept some constructs gcc might accept in contexts where a 1104constant expression is required, like "x-x" where x is a variable.</li> 1105 1106<li>clang does not support __builtin_apply and friends; this extension is 1107extremely obscure and difficult to implement reliably.</li> 1108 1109</ul> 1110 1111<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = --> 1112<h3 id="c_ms">Microsoft extensions</h3> 1113<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = --> 1114 1115<p>clang has some experimental support for extensions from 1116Microsoft Visual C++; to enable it, use the -fms-extensions command-line 1117option. This is the default for Windows targets. Note that the 1118support is incomplete; enabling Microsoft extensions will silently drop 1119certain constructs (including __declspec and Microsoft-style asm statements). 1120</p> 1121 1122<p>clang has a -fms-compatibility flag that makes clang accept enough 1123invalid C++ to be able to parse most Microsoft headers. This flag is enabled by 1124default for Windows targets.</p> 1125 1126<p>-fdelayed-template-parsing lets clang delay all template instantiation until 1127the end of a translation unit. This flag is enabled by default for Windows 1128targets.</p> 1129 1130<ul> 1131<li>clang allows setting _MSC_VER with -fmsc-version=. It defaults to 1300 which 1132is the same as Visual C/C++ 2003. Any number is supported and can greatly affect 1133what Windows SDK and c++stdlib headers clang can compile. This option will be 1134removed when clang supports the full set of MS extensions required for these 1135headers.</li> 1136 1137<li>clang does not support the Microsoft extension where anonymous 1138record members can be declared using user defined typedefs.</li> 1139 1140<li>clang supports the Microsoft "#pragma pack" feature for 1141controlling record layout. GCC also contains support for this feature, 1142however where MSVC and GCC are incompatible clang follows the MSVC 1143definition.</li> 1144 1145<li>clang defaults to C++11 for Windows targets.</li> 1146</ul> 1147 1148<!-- ======================================================================= --> 1149<h2 id="cxx">C++ Language Features</h2> 1150<!-- ======================================================================= --> 1151 1152<p>clang fully implements all of standard C++98 except for exported templates 1153(which were removed in C++11), and 1154<a href="http://clang.llvm.org/cxx_status.html">many C++11 features</a> are also 1155implemented.</p> 1156 1157<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = --> 1158<h3 id="cxx_implimits">Controlling implementation limits</h3> 1159<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = --> 1160 1161<p><b>-fconstexpr-depth=N</b>: Sets the limit for recursive constexpr function 1162invocations to N. The default is 512.</p> 1163 1164<p><b>-ftemplate-depth=N</b>: Sets the limit for recursively nested template 1165instantiations to N. The default is 1024.</p> 1166 1167<!-- ======================================================================= --> 1168<h2 id="target_features">Target-Specific Features and Limitations</h2> 1169<!-- ======================================================================= --> 1170 1171 1172<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = --> 1173<h3 id="target_arch">CPU Architectures Features and Limitations</h3> 1174<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = --> 1175 1176<!-- ======================== --> 1177<h4 id="target_arch_x86">X86</h4> 1178<!-- ======================== --> 1179 1180<p>The support for X86 (both 32-bit and 64-bit) is considered stable on Darwin 1181(Mac OS/X), Linux, FreeBSD, and Dragonfly BSD: it has been tested to correctly 1182compile many large C, C++, Objective-C, and Objective-C++ codebases.</p> 1183 1184<p>On x86_64-mingw32, passing i128(by value) is incompatible to Microsoft x64 1185calling conversion. You might need to tweak WinX86_64ABIInfo::classify() 1186in lib/CodeGen/TargetInfo.cpp.</p> 1187 1188<!-- ======================== --> 1189<h4 id="target_arch_arm">ARM</h4> 1190<!-- ======================== --> 1191 1192<p>The support for ARM (specifically ARMv6 and ARMv7) is considered stable on 1193Darwin (iOS): it has been tested to correctly compile many large C, C++, 1194Objective-C, and Objective-C++ codebases. Clang only supports a limited number 1195of ARM architectures. It does not yet fully support ARMv5, for example.</p> 1196 1197<!-- ======================== --> 1198<h4 id="target_arch_other">Other platforms</h4> 1199<!-- ======================== --> 1200clang currently contains some support for PPC and Sparc; however, significant 1201pieces of code generation are still missing, and they haven't undergone 1202significant testing. 1203 1204<p>clang contains limited support for the MSP430 embedded processor, but both 1205the clang support and the LLVM backend support are highly experimental. 1206 1207<p>Other platforms are completely unsupported at the moment. Adding the 1208minimal support needed for parsing and semantic analysis on a new platform 1209is quite easy; see lib/Basic/Targets.cpp in the clang source tree. This level 1210of support is also sufficient for conversion to LLVM IR for simple programs. 1211Proper support for conversion to LLVM IR requires adding code to 1212lib/CodeGen/CGCall.cpp at the moment; this is likely to change soon, though. 1213Generating assembly requires a suitable LLVM backend. 1214 1215<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = --> 1216<h3 id="target_os">Operating System Features and Limitations</h3> 1217<!-- = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = --> 1218 1219<!-- ======================================= --> 1220<h4 id="target_os_darwin">Darwin (Mac OS/X)</h4> 1221<!-- ======================================= --> 1222 1223<p>None</p> 1224 1225<!-- ======================================= --> 1226<h4 id="target_os_win32">Windows</h4> 1227<!-- ======================================= --> 1228 1229<p>Experimental supports are on Cygming.</p> 1230 1231<p>See also <a href="#c_ms">Microsoft Extensions</a>.</p> 1232 1233<h5>Cygwin</h5> 1234 1235<p>Clang works on Cygwin-1.7.</p> 1236 1237<h5>MinGW32</h5> 1238 1239<p>Clang works on some mingw32 distributions. 1240Clang assumes directories as below;</p> 1241 1242<ul> 1243<li><tt>C:/mingw/include</tt></li> 1244<li><tt>C:/mingw/lib</tt></li> 1245<li><tt>C:/mingw/lib/gcc/mingw32/4.[3-5].0/include/c++</tt></li> 1246</ul> 1247 1248<p>On MSYS, a few tests might fail.</p> 1249 1250<h5>MinGW-w64</h5> 1251 1252<p>For 32-bit (i686-w64-mingw32), and 64-bit (x86_64-w64-mingw32), Clang assumes as below;<p> 1253 1254<ul> 1255<li><tt>GCC versions 4.5.0 to 4.5.3, 4.6.0 to 4.6.2, or 4.7.0 (for the C++ header search path)</tt></li> 1256<li><tt>some_directory/bin/gcc.exe</tt></li> 1257<li><tt>some_directory/bin/clang.exe</tt></li> 1258<li><tt>some_directory/bin/clang++.exe</tt></li> 1259<li><tt>some_directory/bin/../include/c++/GCC_version</tt></li> 1260<li><tt>some_directory/bin/../include/c++/GCC_version/x86_64-w64-mingw32</tt></li> 1261<li><tt>some_directory/bin/../include/c++/GCC_version/i686-w64-mingw32</tt></li> 1262<li><tt>some_directory/bin/../include/c++/GCC_version/backward</tt></li> 1263<li><tt>some_directory/bin/../x86_64-w64-mingw32/include</tt></li> 1264<li><tt>some_directory/bin/../i686-w64-mingw32/include</tt></li> 1265<li><tt>some_directory/bin/../include</tt></li> 1266</ul> 1267 1268<p>This directory layout is standard for any toolchain you will find on the official <a href="http://mingw-w64.sourceforge.net">MinGW-w64 website</a>. 1269 1270<p>Clang expects the GCC executable "gcc.exe" compiled for i686-w64-mingw32 (or x86_64-w64-mingw32) to be present on PATH.</p> 1271 1272<p><a href="http://llvm.org/bugs/show_bug.cgi?id=9072">Some tests might fail</a> 1273on x86_64-w64-mingw32.</p> 1274 1275</div> 1276</body> 1277</html> 1278