diff options
author | Chris Lattner <sabre@nondot.org> | 2009-06-13 07:13:28 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-06-13 07:13:28 +0000 |
commit | 148772a841cae6f32db16d890e788b92a763bb3f (patch) | |
tree | 5481ed924f1f63b790e7ead89fa047446b976746 /docs | |
parent | 247baca66ca998de9c415c19019e199f4895e81c (diff) |
implement and document a new __has_feature and __has_builtin magic
builtin preprocessor macro. This appears to work with two caveats:
1) builtins are registered in -E mode, and 2) target-specific builtins
are unconditionally registered even if they aren't supported by the
target (e.g. SSE4 builtin when only SSE1 is enabled).
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73289 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'docs')
-rw-r--r-- | docs/LanguageExtensions.html | 77 |
1 files changed, 75 insertions, 2 deletions
diff --git a/docs/LanguageExtensions.html b/docs/LanguageExtensions.html index c486562b10..55fb615834 100644 --- a/docs/LanguageExtensions.html +++ b/docs/LanguageExtensions.html @@ -19,6 +19,7 @@ td { <ul> <li><a href="#intro">Introduction</a></li> +<li><a href="#feature_check">Feature Checking Macros</a></li> <li><a href="#builtinmacros">Builtin Macros</a></li> <li><a href="#vectors">Vectors and Extended Vectors</a></li> <li><a href="#blocks">Blocks</a></li> @@ -45,12 +46,73 @@ td { <!-- ======================================================================= --> <p>This document describes the language extensions provided by Clang. In -addition to the langauge extensions listed here, Clang aims to support a broad +addition to the language extensions listed here, Clang aims to support a broad range of GCC extensions. Please see the <a href="http://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html">GCC manual</a> for more information on these extensions.</p> <!-- ======================================================================= --> +<h2 id="feature_check">Feature Checking Macros</h2> +<!-- ======================================================================= --> + +<p>Language extensions can be very useful, but only if you know you can depend +on them. In order to allow fine-grain features checks, we support two builtin +function-like macros. This allows you to directly test for a feature in your +code without having to resort to something like autoconf or fragile "compiler +version checks".</p> + +<!-- ======================================================================= --> +<h3 id="__has_builtin">__has_builtin</h3> +<!-- ======================================================================= --> + +<p>This function-like macro takes a single identifier argument that is the name +of a builtin function. It evaluates to 1 if the builtin is supported or 0 if +not. It can be used like this:</p> + +<blockquote> +<pre> +#ifndef __has_builtin // Optional of course. + #define __has_builtin(x) 0 // Compatibility with non-clang compilers. +#endif + +... +#if __has_builtin(__builtin_trap) + __builtin_trap(); +#else + abort(); +#endif +... +</pre> +</blockquote> + + +<!-- ======================================================================= --> +<h3 id="__has_feature">__has_feature</h3> +<!-- ======================================================================= --> + +<p>This function-like macro takes a single identifier argument that is the name +of a feature. It evaluates to 1 if the feature is supported or 0 if not. It +can be used like this:</p> + +<blockquote> +<pre> +#ifndef __has_feature // Optional of course. + #define __has_feature(x) 0 // Compatibility with non-clang compilers. +#endif + +... +#if __has_feature(attribute_overloadable) || \ + __has_feature(blocks) +... +#endif +... +</pre> +</blockquote> + +<p>The feature tag is described along with the language feature below.</p> + + +<!-- ======================================================================= --> <h2 id="builtinmacros">Builtin Macros</h2> <!-- ======================================================================= --> @@ -64,6 +126,8 @@ more information on these extensions.</p> with V.xyzw syntax and other tidbits. See also <a href="#__builtin_shufflevector">__builtin_shufflevector</a>.</p> +<p>Query for this feature with __has_feature(attribute_ext_vector_type).</p> + <!-- ======================================================================= --> <h2 id="blocks">Blocks</h2> <!-- ======================================================================= --> @@ -73,6 +137,9 @@ href="BlockLanguageSpec.txt">BlockLanguageSpec.txt</a>. Implementation and ABI details for the clang implementation are in <a href="BlockImplementation.txt">BlockImplementation.txt</a>.</p> + +<p>Query for this feature with __has_feature(blocks).</p> + <!-- ======================================================================= --> <h2 id="overloading-in-c">Function Overloading in C</h2> <!-- ======================================================================= --> @@ -171,6 +238,9 @@ caveats to this use of name mangling:</p> C.</li> </ul> +<p>Query for this feature with __has_feature(attribute_overloadable).</p> + + <!-- ======================================================================= --> <h2 id="builtins">Builtin Functions</h2> <!-- ======================================================================= --> @@ -320,7 +390,10 @@ placed at the end of function prototypes:</p> <pre> void foo() <b>__attribute__((analyzer_noreturn))</b>; -</p> +</pre> + +<p>Query for this feature with __has_feature(attribute_analyzer_noreturn).</p> + </div> </body> |