Mercurial > hg > CbC > CbC_gcc
comparison gcc/doc/extend.texi @ 145:1830386684a0
gcc-9.2.0
author | anatofuz |
---|---|
date | Thu, 13 Feb 2020 11:34:05 +0900 |
parents | 84e7813d76e9 |
children |
comparison
equal
deleted
inserted
replaced
131:84e7813d76e9 | 145:1830386684a0 |
---|---|
1 c Copyright (C) 1988-2018 Free Software Foundation, Inc. | 1 c Copyright (C) 1988-2020 Free Software Foundation, Inc. |
2 | 2 |
3 @c This is part of the GCC manual. | 3 @c This is part of the GCC manual. |
4 @c For copying conditions, see the file gcc.texi. | 4 @c For copying conditions, see the file gcc.texi. |
5 | 5 |
6 @node C Extensions | 6 @node C Extensions |
25 @menu | 25 @menu |
26 * Statement Exprs:: Putting statements and declarations inside expressions. | 26 * Statement Exprs:: Putting statements and declarations inside expressions. |
27 * Local Labels:: Labels local to a block. | 27 * Local Labels:: Labels local to a block. |
28 * Labels as Values:: Getting pointers to labels, and computed gotos. | 28 * Labels as Values:: Getting pointers to labels, and computed gotos. |
29 * Nested Functions:: Nested function in GNU C. | 29 * Nested Functions:: Nested function in GNU C. |
30 * Nonlocal Gotos:: Nonlocal gotos. | |
30 * Constructing Calls:: Dispatching a call to another function. | 31 * Constructing Calls:: Dispatching a call to another function. |
31 * Typeof:: @code{typeof}: referring to the type of an expression. | 32 * Typeof:: @code{typeof}: referring to the type of an expression. |
32 * Conditionals:: Omitting the middle operand of a @samp{?:} expression. | 33 * Conditionals:: Omitting the middle operand of a @samp{?:} expression. |
33 * __int128:: 128-bit integers---@code{__int128}. | 34 * __int128:: 128-bit integers---@code{__int128}. |
34 * Long Long:: Double-word integers---@code{long long int}. | 35 * Long Long:: Double-word integers---@code{long long int}. |
44 * Variable Length:: Arrays whose length is computed at run time. | 45 * Variable Length:: Arrays whose length is computed at run time. |
45 * Variadic Macros:: Macros with a variable number of arguments. | 46 * Variadic Macros:: Macros with a variable number of arguments. |
46 * Escaped Newlines:: Slightly looser rules for escaped newlines. | 47 * Escaped Newlines:: Slightly looser rules for escaped newlines. |
47 * Subscripting:: Any array can be subscripted, even if not an lvalue. | 48 * Subscripting:: Any array can be subscripted, even if not an lvalue. |
48 * Pointer Arith:: Arithmetic on @code{void}-pointers and function pointers. | 49 * Pointer Arith:: Arithmetic on @code{void}-pointers and function pointers. |
50 * Variadic Pointer Args:: Pointer arguments to variadic functions. | |
49 * Pointers to Arrays:: Pointers to arrays with qualifiers work as expected. | 51 * Pointers to Arrays:: Pointers to arrays with qualifiers work as expected. |
50 * Initializers:: Non-constant initializers. | 52 * Initializers:: Non-constant initializers. |
51 * Compound Literals:: Compound literals give structures, unions | 53 * Compound Literals:: Compound literals give structures, unions |
52 or arrays as values. | 54 or arrays as values. |
53 * Designated Inits:: Labeling elements of initializers. | 55 * Designated Inits:: Labeling elements of initializers. |
64 * Attribute Syntax:: Formal syntax for attributes. | 66 * Attribute Syntax:: Formal syntax for attributes. |
65 * Function Prototypes:: Prototype declarations and old-style definitions. | 67 * Function Prototypes:: Prototype declarations and old-style definitions. |
66 * C++ Comments:: C++ comments are recognized. | 68 * C++ Comments:: C++ comments are recognized. |
67 * Dollar Signs:: Dollar sign is allowed in identifiers. | 69 * Dollar Signs:: Dollar sign is allowed in identifiers. |
68 * Character Escapes:: @samp{\e} stands for the character @key{ESC}. | 70 * Character Escapes:: @samp{\e} stands for the character @key{ESC}. |
69 * Alignment:: Inquiring about the alignment of a type or variable. | 71 * Alignment:: Determining the alignment of a function, type or variable. |
70 * Inline:: Defining inline functions (as fast as macros). | 72 * Inline:: Defining inline functions (as fast as macros). |
71 * Volatiles:: What constitutes an access to a volatile object. | 73 * Volatiles:: What constitutes an access to a volatile object. |
72 * Using Assembly Language with C:: Instructions and extensions for interfacing C with assembler. | 74 * Using Assembly Language with C:: Instructions and extensions for interfacing C with assembler. |
73 * Alternate Keywords:: @code{__const__}, @code{__asm__}, etc., for header files. | 75 * Alternate Keywords:: @code{__const__}, @code{__asm__}, etc., for header files. |
74 * Incomplete Enums:: @code{enum foo;}, with details to follow. | 76 * Incomplete Enums:: @code{enum foo;}, with details to follow. |
138 | 140 |
139 @noindent | 141 @noindent |
140 @cindex side effects, macro argument | 142 @cindex side effects, macro argument |
141 But this definition computes either @var{a} or @var{b} twice, with bad | 143 But this definition computes either @var{a} or @var{b} twice, with bad |
142 results if the operand has side effects. In GNU C, if you know the | 144 results if the operand has side effects. In GNU C, if you know the |
143 type of the operands (here taken as @code{int}), you can define | 145 type of the operands (here taken as @code{int}), you can avoid this |
144 the macro safely as follows: | 146 problem by defining the macro as follows: |
145 | 147 |
146 @smallexample | 148 @smallexample |
147 #define maxint(a,b) \ | 149 #define maxint(a,b) \ |
148 (@{int _a = (a), _b = (b); _a > _b ? _a : _b; @}) | 150 (@{int _a = (a), _b = (b); _a > _b ? _a : _b; @}) |
151 @end smallexample | |
152 | |
153 Note that introducing variable declarations (as we do in @code{maxint}) can | |
154 cause variable shadowing, so while this example using the @code{max} macro | |
155 produces correct results: | |
156 @smallexample | |
157 int _a = 1, _b = 2, c; | |
158 c = max (_a, _b); | |
159 @end smallexample | |
160 @noindent | |
161 this example using maxint will not: | |
162 @smallexample | |
163 int _a = 1, _b = 2, c; | |
164 c = maxint (_a, _b); | |
165 @end smallexample | |
166 | |
167 This problem may for instance occur when we use this pattern recursively, like | |
168 so: | |
169 | |
170 @smallexample | |
171 #define maxint3(a, b, c) \ | |
172 (@{int _a = (a), _b = (b), _c = (c); maxint (maxint (_a, _b), _c); @}) | |
149 @end smallexample | 173 @end smallexample |
150 | 174 |
151 Embedded statements are not allowed in constant expressions, such as | 175 Embedded statements are not allowed in constant expressions, such as |
152 the value of an enumeration constant, the width of a bit-field, or | 176 the value of an enumeration constant, the width of a bit-field, or |
153 the initial value of a static variable. | 177 the initial value of a static variable. |
210 Jumping out of a statement expression is permitted, but if the | 234 Jumping out of a statement expression is permitted, but if the |
211 statement expression is part of a larger expression then it is | 235 statement expression is part of a larger expression then it is |
212 unspecified which other subexpressions of that expression have been | 236 unspecified which other subexpressions of that expression have been |
213 evaluated except where the language definition requires certain | 237 evaluated except where the language definition requires certain |
214 subexpressions to be evaluated before or after the statement | 238 subexpressions to be evaluated before or after the statement |
215 expression. In any case, as with a function call, the evaluation of a | 239 expression. A @code{break} or @code{continue} statement inside of |
240 a statement expression used in @code{while}, @code{do} or @code{for} | |
241 loop or @code{switch} statement condition | |
242 or @code{for} statement init or increment expressions jumps to an | |
243 outer loop or @code{switch} statement if any (otherwise it is an error), | |
244 rather than to the loop or @code{switch} statement in whose condition | |
245 or init or increment expression it appears. | |
246 In any case, as with a function call, the evaluation of a | |
216 statement expression is not interleaved with the evaluation of other | 247 statement expression is not interleaved with the evaluation of other |
217 parts of the containing expression. For example, | 248 parts of the containing expression. For example, |
218 | 249 |
219 @smallexample | 250 @smallexample |
220 foo (), ((@{ bar1 (); goto a; 0; @}) + bar2 ()), baz(); | 251 foo (), ((@{ bar1 (); goto a; 0; @}) + bar2 ()), baz(); |
517 return array[index + offset]; | 548 return array[index + offset]; |
518 @} | 549 @} |
519 /* @r{@dots{}} */ | 550 /* @r{@dots{}} */ |
520 @} | 551 @} |
521 @end smallexample | 552 @end smallexample |
553 | |
554 @node Nonlocal Gotos | |
555 @section Nonlocal Gotos | |
556 @cindex nonlocal gotos | |
557 | |
558 GCC provides the built-in functions @code{__builtin_setjmp} and | |
559 @code{__builtin_longjmp} which are similar to, but not interchangeable | |
560 with, the C library functions @code{setjmp} and @code{longjmp}. | |
561 The built-in versions are used internally by GCC's libraries | |
562 to implement exception handling on some targets. You should use the | |
563 standard C library functions declared in @code{<setjmp.h>} in user code | |
564 instead of the builtins. | |
565 | |
566 The built-in versions of these functions use GCC's normal | |
567 mechanisms to save and restore registers using the stack on function | |
568 entry and exit. The jump buffer argument @var{buf} holds only the | |
569 information needed to restore the stack frame, rather than the entire | |
570 set of saved register values. | |
571 | |
572 An important caveat is that GCC arranges to save and restore only | |
573 those registers known to the specific architecture variant being | |
574 compiled for. This can make @code{__builtin_setjmp} and | |
575 @code{__builtin_longjmp} more efficient than their library | |
576 counterparts in some cases, but it can also cause incorrect and | |
577 mysterious behavior when mixing with code that uses the full register | |
578 set. | |
579 | |
580 You should declare the jump buffer argument @var{buf} to the | |
581 built-in functions as: | |
582 | |
583 @smallexample | |
584 #include <stdint.h> | |
585 intptr_t @var{buf}[5]; | |
586 @end smallexample | |
587 | |
588 @deftypefn {Built-in Function} {int} __builtin_setjmp (intptr_t *@var{buf}) | |
589 This function saves the current stack context in @var{buf}. | |
590 @code{__builtin_setjmp} returns 0 when returning directly, | |
591 and 1 when returning from @code{__builtin_longjmp} using the same | |
592 @var{buf}. | |
593 @end deftypefn | |
594 | |
595 @deftypefn {Built-in Function} {void} __builtin_longjmp (intptr_t *@var{buf}, int @var{val}) | |
596 This function restores the stack context in @var{buf}, | |
597 saved by a previous call to @code{__builtin_setjmp}. After | |
598 @code{__builtin_longjmp} is finished, the program resumes execution as | |
599 if the matching @code{__builtin_setjmp} returns the value @var{val}, | |
600 which must be 1. | |
601 | |
602 Because @code{__builtin_longjmp} depends on the function return | |
603 mechanism to restore the stack context, it cannot be called | |
604 from the same function calling @code{__builtin_setjmp} to | |
605 initialize @var{buf}. It can only be called from a function called | |
606 (directly or indirectly) from the function calling @code{__builtin_setjmp}. | |
607 @end deftypefn | |
522 | 608 |
523 @node Constructing Calls | 609 @node Constructing Calls |
524 @section Constructing Function Calls | 610 @section Constructing Function Calls |
525 @cindex constructing calls | 611 @cindex constructing calls |
526 @cindex forwarding calls | 612 @cindex forwarding calls |
1297 | 1383 |
1298 As an extension, GNU C supports named address spaces as | 1384 As an extension, GNU C supports named address spaces as |
1299 defined in the N1275 draft of ISO/IEC DTR 18037. Support for named | 1385 defined in the N1275 draft of ISO/IEC DTR 18037. Support for named |
1300 address spaces in GCC will evolve as the draft technical report | 1386 address spaces in GCC will evolve as the draft technical report |
1301 changes. Calling conventions for any target might also change. At | 1387 changes. Calling conventions for any target might also change. At |
1302 present, only the AVR, SPU, M32C, RL78, and x86 targets support | 1388 present, only the AVR, M32C, RL78, and x86 targets support |
1303 address spaces other than the generic address space. | 1389 address spaces other than the generic address space. |
1304 | 1390 |
1305 Address space identifiers may be used exactly like any other C type | 1391 Address space identifiers may be used exactly like any other C type |
1306 qualifier (e.g., @code{const} or @code{volatile}). See the N1275 | 1392 qualifier (e.g., @code{const} or @code{volatile}). See the N1275 |
1307 document for more details. | 1393 document for more details. |
1485 On the RL78 target, variables qualified with @code{__far} are accessed | 1571 On the RL78 target, variables qualified with @code{__far} are accessed |
1486 with 32-bit pointers (20-bit addresses) rather than the default 16-bit | 1572 with 32-bit pointers (20-bit addresses) rather than the default 16-bit |
1487 addresses. Non-far variables are assumed to appear in the topmost | 1573 addresses. Non-far variables are assumed to appear in the topmost |
1488 64@tie{}KiB of the address space. | 1574 64@tie{}KiB of the address space. |
1489 | 1575 |
1490 @subsection SPU Named Address Spaces | |
1491 @cindex @code{__ea} SPU Named Address Spaces | |
1492 | |
1493 On the SPU target variables may be declared as | |
1494 belonging to another address space by qualifying the type with the | |
1495 @code{__ea} address space identifier: | |
1496 | |
1497 @smallexample | |
1498 extern int __ea i; | |
1499 @end smallexample | |
1500 | |
1501 @noindent | |
1502 The compiler generates special code to access the variable @code{i}. | |
1503 It may use runtime library | |
1504 support, or generate special machine instructions to access that address | |
1505 space. | |
1506 | |
1507 @subsection x86 Named Address Spaces | 1576 @subsection x86 Named Address Spaces |
1508 @cindex x86 named address spaces | 1577 @cindex x86 named address spaces |
1509 | 1578 |
1510 On the x86 target, variables may be declared as being relative | 1579 On the x86 target, variables may be declared as being relative |
1511 to the @code{%fs} or @code{%gs} segments. | 1580 to the @code{%fs} or @code{%gs} segments. |
1879 | 1948 |
1880 @opindex Wpointer-arith | 1949 @opindex Wpointer-arith |
1881 The option @option{-Wpointer-arith} requests a warning if these extensions | 1950 The option @option{-Wpointer-arith} requests a warning if these extensions |
1882 are used. | 1951 are used. |
1883 | 1952 |
1953 @node Variadic Pointer Args | |
1954 @section Pointer Arguments in Variadic Functions | |
1955 @cindex pointer arguments in variadic functions | |
1956 @cindex variadic functions, pointer arguments | |
1957 | |
1958 Standard C requires that pointer types used with @code{va_arg} in | |
1959 functions with variable argument lists either must be compatible with | |
1960 that of the actual argument, or that one type must be a pointer to | |
1961 @code{void} and the other a pointer to a character type. GNU C | |
1962 implements the POSIX XSI extension that additionally permits the use | |
1963 of @code{va_arg} with a pointer type to receive arguments of any other | |
1964 pointer type. | |
1965 | |
1966 In particular, in GNU C @samp{va_arg (ap, void *)} can safely be used | |
1967 to consume an argument of any pointer type. | |
1968 | |
1884 @node Pointers to Arrays | 1969 @node Pointers to Arrays |
1885 @section Pointers to Arrays with Qualifiers Work as Expected | 1970 @section Pointers to Arrays with Qualifiers Work as Expected |
1886 @cindex pointers to arrays | 1971 @cindex pointers to arrays |
1887 @cindex const qualifier | 1972 @cindex const qualifier |
1888 | 1973 |
2102 | 2187 |
2103 @smallexample | 2188 @smallexample |
2104 struct point p = @{ y: yvalue, x: xvalue @}; | 2189 struct point p = @{ y: yvalue, x: xvalue @}; |
2105 @end smallexample | 2190 @end smallexample |
2106 | 2191 |
2107 Omitted field members are implicitly initialized the same as objects | 2192 Omitted fields are implicitly initialized the same as for objects |
2108 that have static storage duration. | 2193 that have static storage duration. |
2109 | 2194 |
2110 @cindex designators | 2195 @cindex designators |
2111 The @samp{[@var{index}]} or @samp{.@var{fieldname}} is known as a | 2196 The @samp{[@var{index}]} or @samp{.@var{fieldname}} is known as a |
2112 @dfn{designator}. You can also use a designator (or the obsolete colon | 2197 @dfn{designator}. You can also use a designator (or the obsolete colon |
2160 | 2245 |
2161 @smallexample | 2246 @smallexample |
2162 struct point ptarray[10] = @{ [2].y = yv2, [2].x = xv2, [0].x = xv0 @}; | 2247 struct point ptarray[10] = @{ [2].y = yv2, [2].x = xv2, [0].x = xv0 @}; |
2163 @end smallexample | 2248 @end smallexample |
2164 | 2249 |
2165 @noindent | 2250 If the same field is initialized multiple times, or overlapping |
2166 If the same field is initialized multiple times, it has the value from | 2251 fields of a union are initialized, the value from the last |
2167 the last initialization. If any such overridden initialization has | 2252 initialization is used. When a field of a union is itself a structure, |
2168 side effect, it is unspecified whether the side effect happens or not. | 2253 the entire structure from the last field initialized is used. If any previous |
2169 Currently, GCC discards them and issues a warning. | 2254 initializer has side effect, it is unspecified whether the side effect |
2255 happens or not. Currently, GCC discards the side-effecting | |
2256 initializer expressions and issues a warning. | |
2170 | 2257 |
2171 @node Case Ranges | 2258 @node Case Ranges |
2172 @section Case Ranges | 2259 @section Case Ranges |
2173 @cindex case ranges | 2260 @cindex case ranges |
2174 @cindex ranges in case statements | 2261 @cindex ranges in case statements |
2208 @node Cast to Union | 2295 @node Cast to Union |
2209 @section Cast to a Union Type | 2296 @section Cast to a Union Type |
2210 @cindex cast to a union | 2297 @cindex cast to a union |
2211 @cindex union, casting to a | 2298 @cindex union, casting to a |
2212 | 2299 |
2213 A cast to union type looks similar to other casts, except that the type | 2300 A cast to a union type is a C extension not available in C++. It looks |
2214 specified is a union type. You can specify the type either with the | 2301 just like ordinary casts with the constraint that the type specified is |
2215 @code{union} keyword or with a @code{typedef} name that refers to | 2302 a union type. You can specify the type either with the @code{union} |
2216 a union. A cast to a union actually creates a compound literal and | 2303 keyword or with a @code{typedef} name that refers to a union. The result |
2217 yields an lvalue, not an rvalue like true casts do. | 2304 of a cast to a union is a temporary rvalue of the union type with a member |
2305 whose type matches that of the operand initialized to the value of | |
2306 the operand. The effect of a cast to a union is similar to a compound | |
2307 literal except that it yields an rvalue like standard casts do. | |
2218 @xref{Compound Literals}. | 2308 @xref{Compound Literals}. |
2219 | 2309 |
2220 The types that may be cast to the union type are those of the members | 2310 Expressions that may be cast to the union type are those whose type matches |
2221 of the union. Thus, given the following union and variables: | 2311 at least one of the members of the union. Thus, given the following union |
2312 and variables: | |
2222 | 2313 |
2223 @smallexample | 2314 @smallexample |
2224 union foo @{ int i; double d; @}; | 2315 union foo @{ int i; double d; @}; |
2225 int x; | 2316 int x; |
2226 double y; | 2317 double y; |
2318 union foo z; | |
2227 @end smallexample | 2319 @end smallexample |
2228 | 2320 |
2229 @noindent | 2321 @noindent |
2230 both @code{x} and @code{y} can be cast to type @code{union foo}. | 2322 both @code{x} and @code{y} can be cast to type @code{union foo} and |
2323 the following assignments | |
2324 @smallexample | |
2325 z = (union foo) x; | |
2326 z = (union foo) y; | |
2327 @end smallexample | |
2328 are shorthand equivalents of these | |
2329 @smallexample | |
2330 z = (union foo) @{ .i = x @}; | |
2331 z = (union foo) @{ .d = y @}; | |
2332 @end smallexample | |
2333 | |
2334 However, @code{(union foo) FLT_MAX;} is not a valid cast because the union | |
2335 has no member of type @code{float}. | |
2231 | 2336 |
2232 Using the cast as the right-hand side of an assignment to a variable of | 2337 Using the cast as the right-hand side of an assignment to a variable of |
2233 union type is equivalent to storing in a member of the union: | 2338 union type is equivalent to storing in a member of the union with |
2339 the same type | |
2234 | 2340 |
2235 @smallexample | 2341 @smallexample |
2236 union foo u; | 2342 union foo u; |
2237 /* @r{@dots{}} */ | 2343 /* @r{@dots{}} */ |
2238 u = (union foo) x @equiv{} u.i = x | 2344 u = (union foo) x @equiv{} u.i = x |
2272 @cindex function attributes | 2378 @cindex function attributes |
2273 @cindex declaring attributes of functions | 2379 @cindex declaring attributes of functions |
2274 @cindex @code{volatile} applied to function | 2380 @cindex @code{volatile} applied to function |
2275 @cindex @code{const} applied to function | 2381 @cindex @code{const} applied to function |
2276 | 2382 |
2277 In GNU C, you can use function attributes to declare certain things | 2383 In GNU C and C++, you can use function attributes to specify certain |
2278 about functions called in your program which help the compiler | 2384 function properties that may help the compiler optimize calls or |
2279 optimize calls and check your code more carefully. For example, you | 2385 check code more carefully for correctness. For example, you |
2280 can use attributes to declare that a function never returns | 2386 can use attributes to specify that a function never returns |
2281 (@code{noreturn}), returns a value depending only on its arguments | 2387 (@code{noreturn}), returns a value depending only on the values of |
2282 (@code{pure}), or has @code{printf}-style arguments (@code{format}). | 2388 its arguments (@code{const}), or has @code{printf}-style arguments |
2389 (@code{format}). | |
2283 | 2390 |
2284 You can also use attributes to control memory placement, code | 2391 You can also use attributes to control memory placement, code |
2285 generation options or call/return conventions within the function | 2392 generation options or call/return conventions within the function |
2286 being annotated. Many of these attributes are target-specific. For | 2393 being annotated. Many of these attributes are target-specific. For |
2287 example, many targets support attributes for defining interrupt | 2394 example, many targets support attributes for defining interrupt |
2288 handler functions, which typically must follow special register usage | 2395 handler functions, which typically must follow special register usage |
2289 and return conventions. | 2396 and return conventions. Such attributes are described in the subsection |
2397 for each target. However, a considerable number of attributes are | |
2398 supported by most, if not all targets. Those are described in | |
2399 the @ref{Common Function Attributes} section. | |
2290 | 2400 |
2291 Function attributes are introduced by the @code{__attribute__} keyword | 2401 Function attributes are introduced by the @code{__attribute__} keyword |
2292 on a declaration, followed by an attribute specification inside double | 2402 in the declaration of a function, followed by an attribute specification |
2293 parentheses. You can specify multiple attributes in a declaration by | 2403 enclosed in double parentheses. You can specify multiple attributes in |
2294 separating them by commas within the double parentheses or by | 2404 a declaration by separating them by commas within the double parentheses |
2295 immediately following an attribute declaration with another attribute | 2405 or by immediately following one attribute specification with another. |
2296 declaration. @xref{Attribute Syntax}, for the exact rules on attribute | 2406 @xref{Attribute Syntax}, for the exact rules on attribute syntax and |
2297 syntax and placement. Compatible attribute specifications on distinct | 2407 placement. Compatible attribute specifications on distinct declarations |
2298 declarations of the same function are merged. An attribute specification | 2408 of the same function are merged. An attribute specification that is not |
2299 that is not compatible with attributes already applied to a declaration | 2409 compatible with attributes already applied to a declaration of the same |
2300 of the same function is ignored with a warning. | 2410 function is ignored with a warning. |
2411 | |
2412 Some function attributes take one or more arguments that refer to | |
2413 the function's parameters by their positions within the function parameter | |
2414 list. Such attribute arguments are referred to as @dfn{positional arguments}. | |
2415 Unless specified otherwise, positional arguments that specify properties | |
2416 of parameters with pointer types can also specify the same properties of | |
2417 the implicit C++ @code{this} argument in non-static member functions, and | |
2418 of parameters of reference to a pointer type. For ordinary functions, | |
2419 position one refers to the first parameter on the list. In C++ non-static | |
2420 member functions, position one refers to the implicit @code{this} pointer. | |
2421 The same restrictions and effects apply to function attributes used with | |
2422 ordinary functions or C++ member functions. | |
2301 | 2423 |
2302 GCC also supports attributes on | 2424 GCC also supports attributes on |
2303 variable declarations (@pxref{Variable Attributes}), | 2425 variable declarations (@pxref{Variable Attributes}), |
2304 labels (@pxref{Label Attributes}), | 2426 labels (@pxref{Label Attributes}), |
2305 enumerators (@pxref{Enumerator Attributes}), | 2427 enumerators (@pxref{Enumerator Attributes}), |
2317 GCC plugins may provide their own attributes. | 2439 GCC plugins may provide their own attributes. |
2318 | 2440 |
2319 @menu | 2441 @menu |
2320 * Common Function Attributes:: | 2442 * Common Function Attributes:: |
2321 * AArch64 Function Attributes:: | 2443 * AArch64 Function Attributes:: |
2444 * AMD GCN Function Attributes:: | |
2322 * ARC Function Attributes:: | 2445 * ARC Function Attributes:: |
2323 * ARM Function Attributes:: | 2446 * ARM Function Attributes:: |
2324 * AVR Function Attributes:: | 2447 * AVR Function Attributes:: |
2325 * Blackfin Function Attributes:: | 2448 * Blackfin Function Attributes:: |
2326 * CR16 Function Attributes:: | 2449 * CR16 Function Attributes:: |
2344 * RISC-V Function Attributes:: | 2467 * RISC-V Function Attributes:: |
2345 * RL78 Function Attributes:: | 2468 * RL78 Function Attributes:: |
2346 * RX Function Attributes:: | 2469 * RX Function Attributes:: |
2347 * S/390 Function Attributes:: | 2470 * S/390 Function Attributes:: |
2348 * SH Function Attributes:: | 2471 * SH Function Attributes:: |
2349 * SPU Function Attributes:: | |
2350 * Symbian OS Function Attributes:: | 2472 * Symbian OS Function Attributes:: |
2351 * V850 Function Attributes:: | 2473 * V850 Function Attributes:: |
2352 * Visium Function Attributes:: | 2474 * Visium Function Attributes:: |
2353 * x86 Function Attributes:: | 2475 * x86 Function Attributes:: |
2354 * Xstormy16 Function Attributes:: | 2476 * Xstormy16 Function Attributes:: |
2360 The following attributes are supported on most targets. | 2482 The following attributes are supported on most targets. |
2361 | 2483 |
2362 @table @code | 2484 @table @code |
2363 @c Keep this table alphabetized by attribute name. Treat _ as space. | 2485 @c Keep this table alphabetized by attribute name. Treat _ as space. |
2364 | 2486 |
2487 @item access | |
2488 @itemx access (@var{access-mode}, @var{ref-index}) | |
2489 @itemx access (@var{access-mode}, @var{ref-index}, @var{size-index}) | |
2490 | |
2491 The @code{access} attribute enables the detection of invalid or unsafe | |
2492 accesses by functions to which they apply or their callers, as well as | |
2493 write-only accesses to objects that are never read from. Such accesses | |
2494 may be diagnosed by warnings such as @option{-Wstringop-overflow}, | |
2495 @option{-Wuninitialized}, @option{-Wunused}, and others. | |
2496 | |
2497 The @code{access} attribute specifies that a function to whose by-reference | |
2498 arguments the attribute applies accesses the referenced object according to | |
2499 @var{access-mode}. The @var{access-mode} argument is required and must be | |
2500 one of three names: @code{read_only}, @code{read_write}, or @code{write_only}. | |
2501 The remaining two are positional arguments. | |
2502 | |
2503 The required @var{ref-index} positional argument denotes a function | |
2504 argument of pointer (or in C++, reference) type that is subject to | |
2505 the access. The same pointer argument can be referenced by at most one | |
2506 distinct @code{access} attribute. | |
2507 | |
2508 The optional @var{size-index} positional argument denotes a function | |
2509 argument of integer type that specifies the maximum size of the access. | |
2510 The size is the number of elements of the type referenced by @var{ref-index}, | |
2511 or the number of bytes when the pointer type is @code{void*}. When no | |
2512 @var{size-index} argument is specified, the pointer argument must be either | |
2513 null or point to a space that is suitably aligned and large for at least one | |
2514 object of the referenced type (this implies that a past-the-end pointer is | |
2515 not a valid argument). The actual size of the access may be less but it | |
2516 must not be more. | |
2517 | |
2518 The @code{read_only} access mode specifies that the pointer to which it | |
2519 applies is used to read the referenced object but not write to it. Unless | |
2520 the argument specifying the size of the access denoted by @var{size-index} | |
2521 is zero, the referenced object must be initialized. The mode implies | |
2522 a stronger guarantee than the @code{const} qualifier which, when cast away | |
2523 from a pointer, does not prevent the pointed-to object from being modified. | |
2524 Examples of the use of the @code{read_only} access mode is the argument to | |
2525 the @code{puts} function, or the second and third arguments to | |
2526 the @code{memcpy} function. | |
2527 | |
2528 @smallexample | |
2529 __attribute__ ((access (read_only))) int puts (const char*); | |
2530 __attribute__ ((access (read_only, 1, 2))) void* memcpy (void*, const void*, size_t); | |
2531 @end smallexample | |
2532 | |
2533 The @code{read_write} access mode applies to arguments of pointer types | |
2534 without the @code{const} qualifier. It specifies that the pointer to which | |
2535 it applies is used to both read and write the referenced object. Unless | |
2536 the argument specifying the size of the access denoted by @var{size-index} | |
2537 is zero, the object referenced by the pointer must be initialized. An example | |
2538 of the use of the @code{read_write} access mode is the first argument to | |
2539 the @code{strcat} function. | |
2540 | |
2541 @smallexample | |
2542 __attribute__ ((access (read_write, 1), access (read_only, 2))) char* strcat (char*, const char*); | |
2543 @end smallexample | |
2544 | |
2545 The @code{write_only} access mode applies to arguments of pointer types | |
2546 without the @code{const} qualifier. It specifies that the pointer to which | |
2547 it applies is used to write to the referenced object but not read from it. | |
2548 The object refrenced by the pointer need not be initialized. An example | |
2549 of the use of the @code{write_only} access mode is the first argument to | |
2550 the @code{strcpy} function, or the first two arguments to the @code{fgets} | |
2551 function. | |
2552 | |
2553 @smallexample | |
2554 __attribute__ ((access (write_only, 1), access (read_only, 2))) char* strcpy (char*, const char*); | |
2555 __attribute__ ((access (write_only, 1, 2), access (read_write, 3))) int fgets (char*, int, FILE*); | |
2556 @end smallexample | |
2557 | |
2365 @item alias ("@var{target}") | 2558 @item alias ("@var{target}") |
2366 @cindex @code{alias} function attribute | 2559 @cindex @code{alias} function attribute |
2367 The @code{alias} attribute causes the declaration to be emitted as an | 2560 The @code{alias} attribute causes the declaration to be emitted as an |
2368 alias for another symbol, which must be specified. For instance, | 2561 alias for another symbol, which must be specified. For instance, |
2369 | 2562 |
2378 is not defined in the same translation unit. | 2571 is not defined in the same translation unit. |
2379 | 2572 |
2380 This attribute requires assembler and object file support, | 2573 This attribute requires assembler and object file support, |
2381 and may not be available on all targets. | 2574 and may not be available on all targets. |
2382 | 2575 |
2383 @item aligned (@var{alignment}) | 2576 @item aligned |
2577 @itemx aligned (@var{alignment}) | |
2384 @cindex @code{aligned} function attribute | 2578 @cindex @code{aligned} function attribute |
2385 This attribute specifies a minimum alignment for the function, | 2579 The @code{aligned} attribute specifies a minimum alignment for |
2386 measured in bytes. | 2580 the first instruction of the function, measured in bytes. When specified, |
2387 | 2581 @var{alignment} must be an integer constant power of 2. Specifying no |
2388 You cannot use this attribute to decrease the alignment of a function, | 2582 @var{alignment} argument implies the ideal alignment for the target. |
2389 only to increase it. However, when you explicitly specify a function | 2583 The @code{__alignof__} operator can be used to determine what that is |
2390 alignment this overrides the effect of the | 2584 (@pxref{Alignment}). The attribute has no effect when a definition for |
2391 @option{-falign-functions} (@pxref{Optimize Options}) option for this | 2585 the function is not provided in the same translation unit. |
2392 function. | 2586 |
2587 The attribute cannot be used to decrease the alignment of a function | |
2588 previously declared with a more restrictive alignment; only to increase | |
2589 it. Attempts to do otherwise are diagnosed. Some targets specify | |
2590 a minimum default alignment for functions that is greater than 1. On | |
2591 such targets, specifying a less restrictive alignment is silently ignored. | |
2592 Using the attribute overrides the effect of the @option{-falign-functions} | |
2593 (@pxref{Optimize Options}) option for this function. | |
2393 | 2594 |
2394 Note that the effectiveness of @code{aligned} attributes may be | 2595 Note that the effectiveness of @code{aligned} attributes may be |
2395 limited by inherent limitations in your linker. On many systems, the | 2596 limited by inherent limitations in the system linker |
2597 and/or object file format. On some systems, the | |
2396 linker is only able to arrange for functions to be aligned up to a | 2598 linker is only able to arrange for functions to be aligned up to a |
2397 certain maximum alignment. (For some linkers, the maximum supported | 2599 certain maximum alignment. (For some linkers, the maximum supported |
2398 alignment may be very very small.) See your linker documentation for | 2600 alignment may be very very small.) See your linker documentation for |
2399 further information. | 2601 further information. |
2400 | 2602 |
2401 The @code{aligned} attribute can also be used for variables and fields | 2603 The @code{aligned} attribute can also be used for variables and fields |
2402 (@pxref{Variable Attributes}.) | 2604 (@pxref{Variable Attributes}.) |
2403 | 2605 |
2404 @item alloc_align | 2606 @item alloc_align (@var{position}) |
2405 @cindex @code{alloc_align} function attribute | 2607 @cindex @code{alloc_align} function attribute |
2406 The @code{alloc_align} attribute is used to tell the compiler that the | 2608 The @code{alloc_align} attribute may be applied to a function that |
2407 function return value points to memory, where the returned pointer minimum | 2609 returns a pointer and takes at least one argument of an integer or |
2408 alignment is given by one of the functions parameters. GCC uses this | 2610 enumerated type. |
2409 information to improve pointer alignment analysis. | 2611 It indicates that the returned pointer is aligned on a boundary given |
2612 by the function argument at @var{position}. Meaningful alignments are | |
2613 powers of 2 greater than one. GCC uses this information to improve | |
2614 pointer alignment analysis. | |
2410 | 2615 |
2411 The function parameter denoting the allocated alignment is specified by | 2616 The function parameter denoting the allocated alignment is specified by |
2412 one integer argument, whose number is the argument of the attribute. | 2617 one constant integer argument whose number is the argument of the attribute. |
2413 Argument numbering starts at one. | 2618 Argument numbering starts at one. |
2414 | 2619 |
2415 For instance, | 2620 For instance, |
2416 | 2621 |
2417 @smallexample | 2622 @smallexample |
2418 void* my_memalign(size_t, size_t) __attribute__((alloc_align(1))) | 2623 void* my_memalign (size_t, size_t) __attribute__ ((alloc_align (1))); |
2419 @end smallexample | 2624 @end smallexample |
2420 | 2625 |
2421 @noindent | 2626 @noindent |
2422 declares that @code{my_memalign} returns memory with minimum alignment | 2627 declares that @code{my_memalign} returns memory with minimum alignment |
2423 given by parameter 1. | 2628 given by parameter 1. |
2424 | 2629 |
2425 @item alloc_size | 2630 @item alloc_size (@var{position}) |
2631 @itemx alloc_size (@var{position-1}, @var{position-2}) | |
2426 @cindex @code{alloc_size} function attribute | 2632 @cindex @code{alloc_size} function attribute |
2427 The @code{alloc_size} attribute is used to tell the compiler that the | 2633 The @code{alloc_size} attribute may be applied to a function that |
2428 function return value points to memory, where the size is given by | 2634 returns a pointer and takes at least one argument of an integer or |
2429 one or two of the functions parameters. GCC uses this | 2635 enumerated type. |
2430 information to improve the correctness of @code{__builtin_object_size}. | 2636 It indicates that the returned pointer points to memory whose size is |
2637 given by the function argument at @var{position-1}, or by the product | |
2638 of the arguments at @var{position-1} and @var{position-2}. Meaningful | |
2639 sizes are positive values less than @code{PTRDIFF_MAX}. GCC uses this | |
2640 information to improve the results of @code{__builtin_object_size}. | |
2431 | 2641 |
2432 The function parameter(s) denoting the allocated size are specified by | 2642 The function parameter(s) denoting the allocated size are specified by |
2433 one or two integer arguments supplied to the attribute. The allocated size | 2643 one or two integer arguments supplied to the attribute. The allocated size |
2434 is either the value of the single function argument specified or the product | 2644 is either the value of the single function argument specified or the product |
2435 of the two function arguments specified. Argument numbering starts at | 2645 of the two function arguments specified. Argument numbering starts at |
2436 one. | 2646 one for ordinary functions, and at two for C++ non-static member functions. |
2437 | 2647 |
2438 For instance, | 2648 For instance, |
2439 | 2649 |
2440 @smallexample | 2650 @smallexample |
2441 void* my_calloc(size_t, size_t) __attribute__((alloc_size(1,2))) | 2651 void* my_calloc (size_t, size_t) __attribute__ ((alloc_size (1, 2))); |
2442 void* my_realloc(void*, size_t) __attribute__((alloc_size(2))) | 2652 void* my_realloc (void*, size_t) __attribute__ ((alloc_size (2))); |
2443 @end smallexample | 2653 @end smallexample |
2444 | 2654 |
2445 @noindent | 2655 @noindent |
2446 declares that @code{my_calloc} returns memory of the size given by | 2656 declares that @code{my_calloc} returns memory of the size given by |
2447 the product of parameter 1 and 2 and that @code{my_realloc} returns memory | 2657 the product of parameter 1 and 2 and that @code{my_realloc} returns memory |
2463 should appear during debugging as a unit. Depending on the debug | 2673 should appear during debugging as a unit. Depending on the debug |
2464 info format it either means marking the function as artificial | 2674 info format it either means marking the function as artificial |
2465 or using the caller location for all instructions within the inlined | 2675 or using the caller location for all instructions within the inlined |
2466 body. | 2676 body. |
2467 | 2677 |
2468 @item assume_aligned | 2678 @item assume_aligned (@var{alignment}) |
2679 @itemx assume_aligned (@var{alignment}, @var{offset}) | |
2469 @cindex @code{assume_aligned} function attribute | 2680 @cindex @code{assume_aligned} function attribute |
2470 The @code{assume_aligned} attribute is used to tell the compiler that the | 2681 The @code{assume_aligned} attribute may be applied to a function that |
2471 function return value points to memory, where the returned pointer minimum | 2682 returns a pointer. It indicates that the returned pointer is aligned |
2472 alignment is given by the first argument. | 2683 on a boundary given by @var{alignment}. If the attribute has two |
2473 If the attribute has two arguments, the second argument is misalignment offset. | 2684 arguments, the second argument is misalignment @var{offset}. Meaningful |
2685 values of @var{alignment} are powers of 2 greater than one. Meaningful | |
2686 values of @var{offset} are greater than zero and less than @var{alignment}. | |
2474 | 2687 |
2475 For instance | 2688 For instance |
2476 | 2689 |
2477 @smallexample | 2690 @smallexample |
2478 void* my_alloc1(size_t) __attribute__((assume_aligned(16))) | 2691 void* my_alloc1 (size_t) __attribute__((assume_aligned (16))); |
2479 void* my_alloc2(size_t) __attribute__((assume_aligned(32, 8))) | 2692 void* my_alloc2 (size_t) __attribute__((assume_aligned (32, 8))); |
2480 @end smallexample | 2693 @end smallexample |
2481 | 2694 |
2482 @noindent | 2695 @noindent |
2483 declares that @code{my_alloc1} returns 16-byte aligned pointer and | 2696 declares that @code{my_alloc1} returns 16-byte aligned pointers and |
2484 that @code{my_alloc2} returns a pointer whose value modulo 32 is equal | 2697 that @code{my_alloc2} returns a pointer whose value modulo 32 is equal |
2485 to 8. | 2698 to 8. |
2486 | 2699 |
2487 @item cold | 2700 @item cold |
2488 @cindex @code{cold} function attribute | 2701 @cindex @code{cold} function attribute |
2500 are automatically detected and this attribute is ignored. | 2713 are automatically detected and this attribute is ignored. |
2501 | 2714 |
2502 @item const | 2715 @item const |
2503 @cindex @code{const} function attribute | 2716 @cindex @code{const} function attribute |
2504 @cindex functions that have no side effects | 2717 @cindex functions that have no side effects |
2505 Many functions do not examine any values except their arguments, and | 2718 Calls to functions whose return value is not affected by changes to |
2506 have no effects except to return a value. Calls to such functions lend | 2719 the observable state of the program and that have no observable effects |
2507 themselves to optimization such as common subexpression elimination. | 2720 on such state other than to return a value may lend themselves to |
2721 optimizations such as common subexpression elimination. Declaring such | |
2722 functions with the @code{const} attribute allows GCC to avoid emitting | |
2723 some calls in repeated invocations of the function with the same argument | |
2724 values. | |
2725 | |
2726 For example, | |
2727 | |
2728 @smallexample | |
2729 int square (int) __attribute__ ((const)); | |
2730 @end smallexample | |
2731 | |
2732 @noindent | |
2733 tells GCC that subsequent calls to function @code{square} with the same | |
2734 argument value can be replaced by the result of the first call regardless | |
2735 of the statements in between. | |
2736 | |
2737 The @code{const} attribute prohibits a function from reading objects | |
2738 that affect its return value between successive invocations. However, | |
2739 functions declared with the attribute can safely read objects that do | |
2740 not change their return value, such as non-volatile constants. | |
2741 | |
2508 The @code{const} attribute imposes greater restrictions on a function's | 2742 The @code{const} attribute imposes greater restrictions on a function's |
2509 definition than the similar @code{pure} attribute below because it prohibits | 2743 definition than the similar @code{pure} attribute. Declaring the same |
2510 the function from reading global variables. Consequently, the presence of | 2744 function with both the @code{const} and the @code{pure} attribute is |
2511 the attribute on a function declaration allows GCC to emit more efficient | 2745 diagnosed. Because a const function cannot have any observable side |
2512 code for some calls to the function. Decorating the same function with | 2746 effects it does not make sense for it to return @code{void}. Declaring |
2513 both the @code{const} and the @code{pure} attribute is diagnosed. | 2747 such a function is diagnosed. |
2514 | 2748 |
2515 @cindex pointer arguments | 2749 @cindex pointer arguments |
2516 Note that a function that has pointer arguments and examines the data | 2750 Note that a function that has pointer arguments and examines the data |
2517 pointed to must @emph{not} be declared @code{const}. Likewise, a | 2751 pointed to must @emph{not} be declared @code{const} if the pointed-to |
2518 function that calls a non-@code{const} function usually must not be | 2752 data might change between successive invocations of the function. In |
2519 @code{const}. Because a @code{const} function cannot have any side | 2753 general, since a function cannot distinguish data that might change |
2520 effects it does not make sense for such a function to return @code{void}. | 2754 from data that cannot, const functions should never take pointer or, |
2521 Declaring such a function is diagnosed. | 2755 in C++, reference arguments. Likewise, a function that calls a non-const |
2756 function usually must not be const itself. | |
2522 | 2757 |
2523 @item constructor | 2758 @item constructor |
2524 @itemx destructor | 2759 @itemx destructor |
2525 @itemx constructor (@var{priority}) | 2760 @itemx constructor (@var{priority}) |
2526 @itemx destructor (@var{priority}) | 2761 @itemx destructor (@var{priority}) |
2532 automatically after @code{main ()} completes or @code{exit ()} is | 2767 automatically after @code{main ()} completes or @code{exit ()} is |
2533 called. Functions with these attributes are useful for | 2768 called. Functions with these attributes are useful for |
2534 initializing data that is used implicitly during the execution of | 2769 initializing data that is used implicitly during the execution of |
2535 the program. | 2770 the program. |
2536 | 2771 |
2537 You may provide an optional integer priority to control the order in | 2772 On some targets the attributes also accept an integer argument to |
2538 which constructor and destructor functions are run. A constructor | 2773 specify a priority to control the order in which constructor and |
2774 destructor functions are run. A constructor | |
2539 with a smaller priority number runs before a constructor with a larger | 2775 with a smaller priority number runs before a constructor with a larger |
2540 priority number; the opposite relationship holds for destructors. So, | 2776 priority number; the opposite relationship holds for destructors. So, |
2541 if you have a constructor that allocates a resource and a destructor | 2777 if you have a constructor that allocates a resource and a destructor |
2542 that deallocates the same resource, both functions typically have the | 2778 that deallocates the same resource, both functions typically have the |
2543 same priority. The priorities for constructor and destructor | 2779 same priority. The priorities for constructor and destructor |
2545 objects (@pxref{C++ Attributes}). However, at present, the order in which | 2781 objects (@pxref{C++ Attributes}). However, at present, the order in which |
2546 constructors for C++ objects with static storage duration and functions | 2782 constructors for C++ objects with static storage duration and functions |
2547 decorated with attribute @code{constructor} are invoked is unspecified. | 2783 decorated with attribute @code{constructor} are invoked is unspecified. |
2548 In mixed declarations, attribute @code{init_priority} can be used to | 2784 In mixed declarations, attribute @code{init_priority} can be used to |
2549 impose a specific ordering. | 2785 impose a specific ordering. |
2786 | |
2787 Using the argument forms of the @code{constructor} and @code{destructor} | |
2788 attributes on targets where the feature is not supported is rejected with | |
2789 an error. | |
2790 | |
2791 @item copy | |
2792 @itemx copy (@var{function}) | |
2793 @cindex @code{copy} function attribute | |
2794 The @code{copy} attribute applies the set of attributes with which | |
2795 @var{function} has been declared to the declaration of the function | |
2796 to which the attribute is applied. The attribute is designed for | |
2797 libraries that define aliases or function resolvers that are expected | |
2798 to specify the same set of attributes as their targets. The @code{copy} | |
2799 attribute can be used with functions, variables, or types. However, | |
2800 the kind of symbol to which the attribute is applied (either function | |
2801 or variable) must match the kind of symbol to which the argument refers. | |
2802 The @code{copy} attribute copies only syntactic and semantic attributes | |
2803 but not attributes that affect a symbol's linkage or visibility such as | |
2804 @code{alias}, @code{visibility}, or @code{weak}. The @code{deprecated} | |
2805 and @code{target_clones} attribute are also not copied. | |
2806 @xref{Common Type Attributes}. | |
2807 @xref{Common Variable Attributes}. | |
2808 | |
2809 For example, the @var{StrongAlias} macro below makes use of the @code{alias} | |
2810 and @code{copy} attributes to define an alias named @var{alloc} for function | |
2811 @var{allocate} declared with attributes @var{alloc_size}, @var{malloc}, and | |
2812 @var{nothrow}. Thanks to the @code{__typeof__} operator the alias has | |
2813 the same type as the target function. As a result of the @code{copy} | |
2814 attribute the alias also shares the same attributes as the target. | |
2815 | |
2816 @smallexample | |
2817 #define StrongAlias(TagetFunc, AliasDecl) \ | |
2818 extern __typeof__ (TargetFunc) AliasDecl \ | |
2819 __attribute__ ((alias (#TargetFunc), copy (TargetFunc))); | |
2820 | |
2821 extern __attribute__ ((alloc_size (1), malloc, nothrow)) | |
2822 void* allocate (size_t); | |
2823 StrongAlias (allocate, alloc); | |
2824 @end smallexample | |
2550 | 2825 |
2551 @item deprecated | 2826 @item deprecated |
2552 @itemx deprecated (@var{msg}) | 2827 @itemx deprecated (@var{msg}) |
2553 @cindex @code{deprecated} function attribute | 2828 @cindex @code{deprecated} function attribute |
2554 The @code{deprecated} attribute results in a warning if the function | 2829 The @code{deprecated} attribute results in a warning if the function |
2965 semantically equivalent function. | 3240 semantically equivalent function. |
2966 | 3241 |
2967 @item no_instrument_function | 3242 @item no_instrument_function |
2968 @cindex @code{no_instrument_function} function attribute | 3243 @cindex @code{no_instrument_function} function attribute |
2969 @opindex finstrument-functions | 3244 @opindex finstrument-functions |
2970 If @option{-finstrument-functions} is given, profiling function calls are | 3245 @opindex p |
3246 @opindex pg | |
3247 If any of @option{-finstrument-functions}, @option{-p}, or @option{-pg} are | |
3248 given, profiling function calls are | |
2971 generated at entry and exit of most user-compiled functions. | 3249 generated at entry and exit of most user-compiled functions. |
2972 Functions with this attribute are not so instrumented. | 3250 Functions with this attribute are not so instrumented. |
2973 | 3251 |
2974 @item no_profile_instrument_function | 3252 @item no_profile_instrument_function |
2975 @cindex @code{no_profile_instrument_function} function attribute | 3253 @cindex @code{no_profile_instrument_function} function attribute |
2988 marked symbols. | 3266 marked symbols. |
2989 | 3267 |
2990 @item no_sanitize ("@var{sanitize_option}") | 3268 @item no_sanitize ("@var{sanitize_option}") |
2991 @cindex @code{no_sanitize} function attribute | 3269 @cindex @code{no_sanitize} function attribute |
2992 The @code{no_sanitize} attribute on functions is used | 3270 The @code{no_sanitize} attribute on functions is used |
2993 to inform the compiler that it should not do sanitization of all options | 3271 to inform the compiler that it should not do sanitization of any option |
2994 mentioned in @var{sanitize_option}. A list of values acceptable by | 3272 mentioned in @var{sanitize_option}. A list of values acceptable by |
2995 @option{-fsanitize} option can be provided. | 3273 the @option{-fsanitize} option can be provided. |
2996 | 3274 |
2997 @smallexample | 3275 @smallexample |
2998 void __attribute__ ((no_sanitize ("alignment", "object-size"))) | 3276 void __attribute__ ((no_sanitize ("alignment", "object-size"))) |
2999 f () @{ /* @r{Do something.} */; @} | 3277 f () @{ /* @r{Do something.} */; @} |
3000 void __attribute__ ((no_sanitize ("alignment,object-size"))) | 3278 void __attribute__ ((no_sanitize ("alignment,object-size"))) |
3077 | 3355 |
3078 @item nonnull | 3356 @item nonnull |
3079 @itemx nonnull (@var{arg-index}, @dots{}) | 3357 @itemx nonnull (@var{arg-index}, @dots{}) |
3080 @cindex @code{nonnull} function attribute | 3358 @cindex @code{nonnull} function attribute |
3081 @cindex functions with non-null pointer arguments | 3359 @cindex functions with non-null pointer arguments |
3082 The @code{nonnull} attribute specifies that some function parameters should | 3360 The @code{nonnull} attribute may be applied to a function that takes at |
3083 be non-null pointers. For instance, the declaration: | 3361 least one argument of a pointer type. It indicates that the referenced |
3362 arguments must be non-null pointers. For instance, the declaration: | |
3084 | 3363 |
3085 @smallexample | 3364 @smallexample |
3086 extern void * | 3365 extern void * |
3087 my_memcpy (void *dest, const void *src, size_t len) | 3366 my_memcpy (void *dest, const void *src, size_t len) |
3088 __attribute__((nonnull (1, 2))); | 3367 __attribute__((nonnull (1, 2))); |
3187 function cannot throw an exception. For example, most functions in | 3466 function cannot throw an exception. For example, most functions in |
3188 the standard C library can be guaranteed not to throw an exception | 3467 the standard C library can be guaranteed not to throw an exception |
3189 with the notable exceptions of @code{qsort} and @code{bsearch} that | 3468 with the notable exceptions of @code{qsort} and @code{bsearch} that |
3190 take function pointer arguments. | 3469 take function pointer arguments. |
3191 | 3470 |
3192 @item optimize | 3471 @item optimize (@var{level}, @dots{}) |
3472 @item optimize (@var{string}, @dots{}) | |
3193 @cindex @code{optimize} function attribute | 3473 @cindex @code{optimize} function attribute |
3194 The @code{optimize} attribute is used to specify that a function is to | 3474 The @code{optimize} attribute is used to specify that a function is to |
3195 be compiled with different optimization options than specified on the | 3475 be compiled with different optimization options than specified on the |
3196 command line. Arguments can either be numbers or strings. Numbers | 3476 command line. Valid arguments are constant non-negative integers and |
3197 are assumed to be an optimization level. Strings that begin with | 3477 strings. Each numeric argument specifies an optimization @var{level}. |
3198 @code{O} are assumed to be an optimization option, while other options | 3478 Each @var{string} argument consists of one or more comma-separated |
3199 are assumed to be used with a @code{-f} prefix. You can also use the | 3479 substrings. Each substring that begins with the letter @code{O} refers |
3200 @samp{#pragma GCC optimize} pragma to set the optimization options | 3480 to an optimization option such as @option{-O0} or @option{-Os}. Other |
3201 that affect more than one function. | 3481 substrings are taken as suffixes to the @code{-f} prefix jointly |
3202 @xref{Function Specific Option Pragmas}, for details about the | 3482 forming the name of an optimization option. @xref{Optimize Options}. |
3203 @samp{#pragma GCC optimize} pragma. | 3483 |
3204 | 3484 @samp{#pragma GCC optimize} can be used to set optimization options |
3205 This attribute should be used for debugging purposes only. It is not | 3485 for more than one function. @xref{Function Specific Option Pragmas}, |
3206 suitable in production code. | 3486 for details about the pragma. |
3487 | |
3488 Providing multiple strings as arguments separated by commas to specify | |
3489 multiple options is equivalent to separating the option suffixes with | |
3490 a comma (@samp{,}) within a single string. Spaces are not permitted | |
3491 within the strings. | |
3492 | |
3493 Not every optimization option that starts with the @var{-f} prefix | |
3494 specified by the attribute necessarily has an effect on the function. | |
3495 The @code{optimize} attribute should be used for debugging purposes only. | |
3496 It is not suitable in production code. | |
3207 | 3497 |
3208 @item patchable_function_entry | 3498 @item patchable_function_entry |
3209 @cindex @code{patchable_function_entry} function attribute | 3499 @cindex @code{patchable_function_entry} function attribute |
3210 @cindex extra NOP instructions at the function entry point | 3500 @cindex extra NOP instructions at the function entry point |
3211 In case the target's text segment can be made writable at run time by | 3501 In case the target's text segment can be made writable at run time by |
3215 The @code{patchable_function_entry} function attribute can be used to | 3505 The @code{patchable_function_entry} function attribute can be used to |
3216 change the number of NOPs to any desired value. The two-value syntax | 3506 change the number of NOPs to any desired value. The two-value syntax |
3217 is the same as for the command-line switch | 3507 is the same as for the command-line switch |
3218 @option{-fpatchable-function-entry=N,M}, generating @var{N} NOPs, with | 3508 @option{-fpatchable-function-entry=N,M}, generating @var{N} NOPs, with |
3219 the function entry point before the @var{M}th NOP instruction. | 3509 the function entry point before the @var{M}th NOP instruction. |
3220 @var{M} defaults to 0 if omitted e.g. function entry point is before | 3510 @var{M} defaults to 0 if omitted e.g.@: function entry point is before |
3221 the first NOP. | 3511 the first NOP. |
3222 | 3512 |
3223 If patchable function entries are enabled globally using the command-line | 3513 If patchable function entries are enabled globally using the command-line |
3224 option @option{-fpatchable-function-entry=N,M}, then you must disable | 3514 option @option{-fpatchable-function-entry=N,M}, then you must disable |
3225 instrumentation on all functions that are part of the instrumentation | 3515 instrumentation on all functions that are part of the instrumentation |
3227 to prevent recursion. | 3517 to prevent recursion. |
3228 | 3518 |
3229 @item pure | 3519 @item pure |
3230 @cindex @code{pure} function attribute | 3520 @cindex @code{pure} function attribute |
3231 @cindex functions that have no side effects | 3521 @cindex functions that have no side effects |
3232 Many functions have no effects except the return value and their | 3522 |
3233 return value depends only on the parameters and/or global variables. | 3523 Calls to functions that have no observable effects on the state of |
3234 Calls to such functions can be subject | 3524 the program other than to return a value may lend themselves to optimizations |
3235 to common subexpression elimination and loop optimization just as an | 3525 such as common subexpression elimination. Declaring such functions with |
3236 arithmetic operator would be. These functions should be declared | 3526 the @code{pure} attribute allows GCC to avoid emitting some calls in repeated |
3237 with the attribute @code{pure}. For example, | 3527 invocations of the function with the same argument values. |
3238 | 3528 |
3239 @smallexample | 3529 The @code{pure} attribute prohibits a function from modifying the state |
3240 int square (int) __attribute__ ((pure)); | 3530 of the program that is observable by means other than inspecting |
3531 the function's return value. However, functions declared with the @code{pure} | |
3532 attribute can safely read any non-volatile objects, and modify the value of | |
3533 objects in a way that does not affect their return value or the observable | |
3534 state of the program. | |
3535 | |
3536 For example, | |
3537 | |
3538 @smallexample | |
3539 int hash (char *) __attribute__ ((pure)); | |
3241 @end smallexample | 3540 @end smallexample |
3242 | 3541 |
3243 @noindent | 3542 @noindent |
3244 says that the hypothetical function @code{square} is safe to call | 3543 tells GCC that subsequent calls to the function @code{hash} with the same |
3245 fewer times than the program says. | 3544 string can be replaced by the result of the first call provided the state |
3545 of the program observable by @code{hash}, including the contents of the array | |
3546 itself, does not change in between. Even though @code{hash} takes a non-const | |
3547 pointer argument it must not modify the array it points to, or any other object | |
3548 whose value the rest of the program may depend on. However, the caller may | |
3549 safely change the contents of the array between successive calls to | |
3550 the function (doing so disables the optimization). The restriction also | |
3551 applies to member objects referenced by the @code{this} pointer in C++ | |
3552 non-static member functions. | |
3246 | 3553 |
3247 Some common examples of pure functions are @code{strlen} or @code{memcmp}. | 3554 Some common examples of pure functions are @code{strlen} or @code{memcmp}. |
3248 Interesting non-pure functions are functions with infinite loops or those | 3555 Interesting non-pure functions are functions with infinite loops or those |
3249 depending on volatile memory or other system resource, that may change between | 3556 depending on volatile memory or other system resource, that may change between |
3250 two consecutive calls (such as @code{feof} in a multithreading environment). | 3557 consecutive calls (such as the standard C @code{feof} function in |
3558 a multithreading environment). | |
3251 | 3559 |
3252 The @code{pure} attribute imposes similar but looser restrictions on | 3560 The @code{pure} attribute imposes similar but looser restrictions on |
3253 a function's defintion than the @code{const} attribute: it allows the | 3561 a function's definition than the @code{const} attribute: @code{pure} |
3254 function to read global variables. Decorating the same function with | 3562 allows the function to read any non-volatile memory, even if it changes |
3255 both the @code{pure} and the @code{const} attribute is diagnosed. | 3563 in between successive invocations of the function. Declaring the same |
3256 Because a @code{pure} function cannot have any side effects it does not | 3564 function with both the @code{pure} and the @code{const} attribute is |
3257 make sense for such a function to return @code{void}. Declaring such | 3565 diagnosed. Because a pure function cannot have any observable side |
3258 a function is diagnosed. | 3566 effects it does not make sense for such a function to return @code{void}. |
3567 Declaring such a function is diagnosed. | |
3259 | 3568 |
3260 @item returns_nonnull | 3569 @item returns_nonnull |
3261 @cindex @code{returns_nonnull} function attribute | 3570 @cindex @code{returns_nonnull} function attribute |
3262 The @code{returns_nonnull} attribute specifies that the function | 3571 The @code{returns_nonnull} attribute specifies that the function |
3263 return value should be a non-null pointer. For instance, the declaration: | 3572 return value should be a non-null pointer. For instance, the declaration: |
3302 attribute is not available on all platforms. | 3611 attribute is not available on all platforms. |
3303 If you need to map the entire contents of a module to a particular | 3612 If you need to map the entire contents of a module to a particular |
3304 section, consider using the facilities of the linker instead. | 3613 section, consider using the facilities of the linker instead. |
3305 | 3614 |
3306 @item sentinel | 3615 @item sentinel |
3616 @itemx sentinel (@var{position}) | |
3307 @cindex @code{sentinel} function attribute | 3617 @cindex @code{sentinel} function attribute |
3308 This function attribute ensures that a parameter in a function call is | 3618 This function attribute indicates that an argument in a call to the function |
3309 an explicit @code{NULL}. The attribute is only valid on variadic | 3619 is expected to be an explicit @code{NULL}. The attribute is only valid on |
3310 functions. By default, the sentinel is located at position zero, the | 3620 variadic functions. By default, the sentinel is expected to be the last |
3311 last parameter of the function call. If an optional integer position | 3621 argument of the function call. If the optional @var{position} argument |
3312 argument P is supplied to the attribute, the sentinel must be located at | 3622 is specified to the attribute, the sentinel must be located at |
3313 position P counting backwards from the end of the argument list. | 3623 @var{position} counting backwards from the end of the argument list. |
3314 | 3624 |
3315 @smallexample | 3625 @smallexample |
3316 __attribute__ ((sentinel)) | 3626 __attribute__ ((sentinel)) |
3317 is equivalent to | 3627 is equivalent to |
3318 __attribute__ ((sentinel(0))) | 3628 __attribute__ ((sentinel(0))) |
3320 | 3630 |
3321 The attribute is automatically set with a position of 0 for the built-in | 3631 The attribute is automatically set with a position of 0 for the built-in |
3322 functions @code{execl} and @code{execlp}. The built-in function | 3632 functions @code{execl} and @code{execlp}. The built-in function |
3323 @code{execle} has the attribute set with a position of 1. | 3633 @code{execle} has the attribute set with a position of 1. |
3324 | 3634 |
3325 A valid @code{NULL} in this context is defined as zero with any pointer | 3635 A valid @code{NULL} in this context is defined as zero with any object |
3326 type. If your system defines the @code{NULL} macro with an integer type | 3636 pointer type. If your system defines the @code{NULL} macro with |
3327 then you need to add an explicit cast. GCC replaces @code{stddef.h} | 3637 an integer type then you need to add an explicit cast. During |
3328 with a copy that redefines NULL appropriately. | 3638 installation GCC replaces the system @code{<stddef.h>} header with |
3639 a copy that redefines NULL appropriately. | |
3329 | 3640 |
3330 The warnings for missing or incorrect sentinels are enabled with | 3641 The warnings for missing or incorrect sentinels are enabled with |
3331 @option{-Wformat}. | 3642 @option{-Wformat}. |
3332 | 3643 |
3333 @item simd | 3644 @item simd |
3355 @cindex @code{stack_protect} function attribute | 3666 @cindex @code{stack_protect} function attribute |
3356 This attribute adds stack protection code to the function if | 3667 This attribute adds stack protection code to the function if |
3357 flags @option{-fstack-protector}, @option{-fstack-protector-strong} | 3668 flags @option{-fstack-protector}, @option{-fstack-protector-strong} |
3358 or @option{-fstack-protector-explicit} are set. | 3669 or @option{-fstack-protector-explicit} are set. |
3359 | 3670 |
3360 @item target (@var{options}) | 3671 @item target (@var{string}, @dots{}) |
3361 @cindex @code{target} function attribute | 3672 @cindex @code{target} function attribute |
3362 Multiple target back ends implement the @code{target} attribute | 3673 Multiple target back ends implement the @code{target} attribute |
3363 to specify that a function is to | 3674 to specify that a function is to |
3364 be compiled with different target options than specified on the | 3675 be compiled with different target options than specified on the |
3365 command line. This can be used for instance to have functions | 3676 command line. One or more strings can be provided as arguments. |
3677 Each string consists of one or more comma-separated suffixes to | |
3678 the @code{-m} prefix jointly forming the name of a machine-dependent | |
3679 option. @xref{Submodel Options,,Machine-Dependent Options}. | |
3680 | |
3681 The @code{target} attribute can be used for instance to have a function | |
3366 compiled with a different ISA (instruction set architecture) than the | 3682 compiled with a different ISA (instruction set architecture) than the |
3367 default. You can also use the @samp{#pragma GCC target} pragma to set | 3683 default. @samp{#pragma GCC target} can be used to specify target-specific |
3368 more than one function to be compiled with specific target options. | 3684 options for more than one function. @xref{Function Specific Option Pragmas}, |
3369 @xref{Function Specific Option Pragmas}, for details about the | 3685 for details about the pragma. |
3370 @samp{#pragma GCC target} pragma. | |
3371 | 3686 |
3372 For instance, on an x86, you could declare one function with the | 3687 For instance, on an x86, you could declare one function with the |
3373 @code{target("sse4.1,arch=core2")} attribute and another with | 3688 @code{target("sse4.1,arch=core2")} attribute and another with |
3374 @code{target("sse4a,arch=amdfam10")}. This is equivalent to | 3689 @code{target("sse4a,arch=amdfam10")}. This is equivalent to |
3375 compiling the first function with @option{-msse4.1} and | 3690 compiling the first function with @option{-msse4.1} and |
3383 @smallexample | 3698 @smallexample |
3384 int core2_func (void) __attribute__ ((__target__ ("arch=core2"))); | 3699 int core2_func (void) __attribute__ ((__target__ ("arch=core2"))); |
3385 int sse3_func (void) __attribute__ ((__target__ ("sse3"))); | 3700 int sse3_func (void) __attribute__ ((__target__ ("sse3"))); |
3386 @end smallexample | 3701 @end smallexample |
3387 | 3702 |
3388 You can either use multiple | 3703 Providing multiple strings as arguments separated by commas to specify |
3389 strings separated by commas to specify multiple options, | 3704 multiple options is equivalent to separating the option suffixes with |
3390 or separate the options with a comma (@samp{,}) within a single string. | 3705 a comma (@samp{,}) within a single string. Spaces are not permitted |
3706 within the strings. | |
3391 | 3707 |
3392 The options supported are specific to each target; refer to @ref{x86 | 3708 The options supported are specific to each target; refer to @ref{x86 |
3393 Function Attributes}, @ref{PowerPC Function Attributes}, | 3709 Function Attributes}, @ref{PowerPC Function Attributes}, |
3394 @ref{ARM Function Attributes}, @ref{AArch64 Function Attributes}, | 3710 @ref{ARM Function Attributes}, @ref{AArch64 Function Attributes}, |
3395 @ref{Nios II Function Attributes}, and @ref{S/390 Function Attributes} | 3711 @ref{Nios II Function Attributes}, and @ref{S/390 Function Attributes} |
3396 for details. | 3712 for details. |
3713 | |
3714 @item symver ("@var{name2}@@@var{nodename}") | |
3715 On ELF targets this attribute creates a symbol version. The @var{name2} part | |
3716 of the parameter is the actual name of the symbol by which it will be | |
3717 externally referenced. The @code{nodename} portion should be the name of a | |
3718 node specified in the version script supplied to the linker when building a | |
3719 shared library. Versioned symbol must be defined and must be exported with | |
3720 default visibility. | |
3721 | |
3722 @smallexample | |
3723 __attribute__ ((__symver__ ("foo@@VERS_1"))) int | |
3724 foo_v1 (void) | |
3725 @{ | |
3726 @} | |
3727 @end smallexample | |
3728 | |
3729 Will produce a @code{.symver foo_v1, foo@@VERS_1} directive in the assembler | |
3730 output. | |
3731 | |
3732 It's an error to define multiple version of a given symbol. In such case | |
3733 an alias can be used. | |
3734 | |
3735 @smallexample | |
3736 __attribute__ ((__symver__ ("foo@@VERS_2"))) | |
3737 __attribute__ ((alias ("foo_v1"))) | |
3738 int symver_foo_v1 (void); | |
3739 @end smallexample | |
3740 | |
3741 This example creates an alias of @code{foo_v1} with symbol name | |
3742 @code{symver_foo_v1} which will be version @code{VERS_2} of @code{foo}. | |
3743 | |
3744 Finally if the parameter is @code{"@var{name2}@@@@@var{nodename}"} then in | |
3745 addition to creating a symbol version (as if | |
3746 @code{"@var{name2}@@@var{nodename}"} was used) the version will be also used | |
3747 to resolve @var{name2} by the linker. | |
3397 | 3748 |
3398 @item target_clones (@var{options}) | 3749 @item target_clones (@var{options}) |
3399 @cindex @code{target_clones} function attribute | 3750 @cindex @code{target_clones} function attribute |
3400 The @code{target_clones} attribute is used to specify that a function | 3751 The @code{target_clones} attribute is used to specify that a function |
3401 be cloned into multiple versions compiled with different target options | 3752 be cloned into multiple versions compiled with different target options |
3414 | 3765 |
3415 It also creates a resolver function (see | 3766 It also creates a resolver function (see |
3416 the @code{ifunc} attribute above) that dynamically selects a clone | 3767 the @code{ifunc} attribute above) that dynamically selects a clone |
3417 suitable for current architecture. The resolver is created only if there | 3768 suitable for current architecture. The resolver is created only if there |
3418 is a usage of a function with @code{target_clones} attribute. | 3769 is a usage of a function with @code{target_clones} attribute. |
3770 | |
3771 Note that any subsequent call of a function without @code{target_clone} | |
3772 from a @code{target_clone} caller will not lead to copying | |
3773 (target clone) of the called function. | |
3774 If you want to enforce such behaviour, | |
3775 we recommend declaring the calling function with the @code{flatten} attribute? | |
3419 | 3776 |
3420 @item unused | 3777 @item unused |
3421 @cindex @code{unused} function attribute | 3778 @cindex @code{unused} function attribute |
3422 This attribute, attached to a function, means that the function is meant | 3779 This attribute, attached to a function, means that the function is meant |
3423 to be possibly unused. GCC does not produce a warning for this | 3780 to be possibly unused. GCC does not produce a warning for this |
3597 symbol, not necessarily in the same translation unit. | 3954 symbol, not necessarily in the same translation unit. |
3598 | 3955 |
3599 The effect is equivalent to moving all references to the alias to a | 3956 The effect is equivalent to moving all references to the alias to a |
3600 separate translation unit, renaming the alias to the aliased symbol, | 3957 separate translation unit, renaming the alias to the aliased symbol, |
3601 declaring it as weak, compiling the two separate translation units and | 3958 declaring it as weak, compiling the two separate translation units and |
3602 performing a reloadable link on them. | 3959 performing a link with relocatable output (ie: @code{ld -r}) on them. |
3603 | 3960 |
3604 At present, a declaration to which @code{weakref} is attached can | 3961 At present, a declaration to which @code{weakref} is attached can |
3605 only be @code{static}. | 3962 only be @code{static}. |
3606 | |
3607 | 3963 |
3608 @end table | 3964 @end table |
3609 | 3965 |
3610 @c This is the end of the target-independent attribute table | 3966 @c This is the end of the target-independent attribute table |
3611 | 3967 |
3683 | 4039 |
3684 @item sign-return-address | 4040 @item sign-return-address |
3685 @cindex @code{sign-return-address} function attribute, AArch64 | 4041 @cindex @code{sign-return-address} function attribute, AArch64 |
3686 Select the function scope on which return address signing will be applied. The | 4042 Select the function scope on which return address signing will be applied. The |
3687 behavior and permissible arguments are the same as for the command-line option | 4043 behavior and permissible arguments are the same as for the command-line option |
3688 @option{-msign-return-address=}. The default value is @code{none}. | 4044 @option{-msign-return-address=}. The default value is @code{none}. This |
4045 attribute is deprecated. The @code{branch-protection} attribute should | |
4046 be used instead. | |
4047 | |
4048 @item branch-protection | |
4049 @cindex @code{branch-protection} function attribute, AArch64 | |
4050 Select the function scope on which branch protection will be applied. The | |
4051 behavior and permissible arguments are the same as for the command-line option | |
4052 @option{-mbranch-protection=}. The default value is @code{none}. | |
3689 | 4053 |
3690 @end table | 4054 @end table |
3691 | 4055 |
3692 The above target attributes can be specified as follows: | 4056 The above target attributes can be specified as follows: |
3693 | 4057 |
3756 Note that CPU tuning options and attributes such as the @option{-mcpu=}, | 4120 Note that CPU tuning options and attributes such as the @option{-mcpu=}, |
3757 @option{-mtune=} do not inhibit inlining unless the CPU specified by the | 4121 @option{-mtune=} do not inhibit inlining unless the CPU specified by the |
3758 @option{-mcpu=} option or the @code{cpu=} attribute conflicts with the | 4122 @option{-mcpu=} option or the @code{cpu=} attribute conflicts with the |
3759 architectural feature rules specified above. | 4123 architectural feature rules specified above. |
3760 | 4124 |
4125 @node AMD GCN Function Attributes | |
4126 @subsection AMD GCN Function Attributes | |
4127 | |
4128 These function attributes are supported by the AMD GCN back end: | |
4129 | |
4130 @table @code | |
4131 @item amdgpu_hsa_kernel | |
4132 @cindex @code{amdgpu_hsa_kernel} function attribute, AMD GCN | |
4133 This attribute indicates that the corresponding function should be compiled as | |
4134 a kernel function, that is an entry point that can be invoked from the host | |
4135 via the HSA runtime library. By default functions are only callable only from | |
4136 other GCN functions. | |
4137 | |
4138 This attribute is implicitly applied to any function named @code{main}, using | |
4139 default parameters. | |
4140 | |
4141 Kernel functions may return an integer value, which will be written to a | |
4142 conventional place within the HSA "kernargs" region. | |
4143 | |
4144 The attribute parameters configure what values are passed into the kernel | |
4145 function by the GPU drivers, via the initial register state. Some values are | |
4146 used by the compiler, and therefore forced on. Enabling other options may | |
4147 break assumptions in the compiler and/or run-time libraries. | |
4148 | |
4149 @table @code | |
4150 @item private_segment_buffer | |
4151 Set @code{enable_sgpr_private_segment_buffer} flag. Always on (required to | |
4152 locate the stack). | |
4153 | |
4154 @item dispatch_ptr | |
4155 Set @code{enable_sgpr_dispatch_ptr} flag. Always on (required to locate the | |
4156 launch dimensions). | |
4157 | |
4158 @item queue_ptr | |
4159 Set @code{enable_sgpr_queue_ptr} flag. Always on (required to convert address | |
4160 spaces). | |
4161 | |
4162 @item kernarg_segment_ptr | |
4163 Set @code{enable_sgpr_kernarg_segment_ptr} flag. Always on (required to | |
4164 locate the kernel arguments, "kernargs"). | |
4165 | |
4166 @item dispatch_id | |
4167 Set @code{enable_sgpr_dispatch_id} flag. | |
4168 | |
4169 @item flat_scratch_init | |
4170 Set @code{enable_sgpr_flat_scratch_init} flag. | |
4171 | |
4172 @item private_segment_size | |
4173 Set @code{enable_sgpr_private_segment_size} flag. | |
4174 | |
4175 @item grid_workgroup_count_X | |
4176 Set @code{enable_sgpr_grid_workgroup_count_x} flag. Always on (required to | |
4177 use OpenACC/OpenMP). | |
4178 | |
4179 @item grid_workgroup_count_Y | |
4180 Set @code{enable_sgpr_grid_workgroup_count_y} flag. | |
4181 | |
4182 @item grid_workgroup_count_Z | |
4183 Set @code{enable_sgpr_grid_workgroup_count_z} flag. | |
4184 | |
4185 @item workgroup_id_X | |
4186 Set @code{enable_sgpr_workgroup_id_x} flag. | |
4187 | |
4188 @item workgroup_id_Y | |
4189 Set @code{enable_sgpr_workgroup_id_y} flag. | |
4190 | |
4191 @item workgroup_id_Z | |
4192 Set @code{enable_sgpr_workgroup_id_z} flag. | |
4193 | |
4194 @item workgroup_info | |
4195 Set @code{enable_sgpr_workgroup_info} flag. | |
4196 | |
4197 @item private_segment_wave_offset | |
4198 Set @code{enable_sgpr_private_segment_wave_byte_offset} flag. Always on | |
4199 (required to locate the stack). | |
4200 | |
4201 @item work_item_id_X | |
4202 Set @code{enable_vgpr_workitem_id} parameter. Always on (can't be disabled). | |
4203 | |
4204 @item work_item_id_Y | |
4205 Set @code{enable_vgpr_workitem_id} parameter. Always on (required to enable | |
4206 vectorization.) | |
4207 | |
4208 @item work_item_id_Z | |
4209 Set @code{enable_vgpr_workitem_id} parameter. Always on (required to use | |
4210 OpenACC/OpenMP). | |
4211 | |
4212 @end table | |
4213 @end table | |
4214 | |
3761 @node ARC Function Attributes | 4215 @node ARC Function Attributes |
3762 @subsection ARC Function Attributes | 4216 @subsection ARC Function Attributes |
3763 | 4217 |
3764 These function attributes are supported by the ARC back end: | 4218 These function attributes are supported by the ARC back end: |
3765 | 4219 |
3777 @smallexample | 4231 @smallexample |
3778 void f () __attribute__ ((interrupt ("ilink1"))); | 4232 void f () __attribute__ ((interrupt ("ilink1"))); |
3779 @end smallexample | 4233 @end smallexample |
3780 | 4234 |
3781 Permissible values for this parameter are: @w{@code{ilink1}} and | 4235 Permissible values for this parameter are: @w{@code{ilink1}} and |
3782 @w{@code{ilink2}}. | 4236 @w{@code{ilink2}} for ARCv1 architecture, and @w{@code{ilink}} and |
4237 @w{@code{firq}} for ARCv2 architecture. | |
3783 | 4238 |
3784 @item long_call | 4239 @item long_call |
3785 @itemx medium_call | 4240 @itemx medium_call |
3786 @itemx short_call | 4241 @itemx short_call |
3787 @cindex @code{long_call} function attribute, ARC | 4242 @cindex @code{long_call} function attribute, ARC |
3820 @cindex @code{secure_call} function attribute, ARC | 4275 @cindex @code{secure_call} function attribute, ARC |
3821 This attribute allows one to mark secure-code functions that are | 4276 This attribute allows one to mark secure-code functions that are |
3822 callable from normal mode. The location of the secure call function | 4277 callable from normal mode. The location of the secure call function |
3823 into the @code{sjli} table needs to be passed as argument. | 4278 into the @code{sjli} table needs to be passed as argument. |
3824 | 4279 |
4280 @item naked | |
4281 @cindex @code{naked} function attribute, ARC | |
4282 This attribute allows the compiler to construct the requisite function | |
4283 declaration, while allowing the body of the function to be assembly | |
4284 code. The specified function will not have prologue/epilogue | |
4285 sequences generated by the compiler. Only basic @code{asm} statements | |
4286 can safely be included in naked functions (@pxref{Basic Asm}). While | |
4287 using extended @code{asm} or a mixture of basic @code{asm} and C code | |
4288 may appear to work, they cannot be depended upon to work reliably and | |
4289 are not supported. | |
4290 | |
3825 @end table | 4291 @end table |
3826 | 4292 |
3827 @node ARM Function Attributes | 4293 @node ARM Function Attributes |
3828 @subsection ARM Function Attributes | 4294 @subsection ARM Function Attributes |
3829 | 4295 |
3830 These function attributes are supported for ARM targets: | 4296 These function attributes are supported for ARM targets: |
3831 | 4297 |
3832 @table @code | 4298 @table @code |
4299 | |
4300 @item general-regs-only | |
4301 @cindex @code{general-regs-only} function attribute, ARM | |
4302 Indicates that no floating-point or Advanced SIMD registers should be | |
4303 used when generating code for this function. If the function explicitly | |
4304 uses floating-point code, then the compiler gives an error. This is | |
4305 the same behavior as that of the command-line option | |
4306 @option{-mgeneral-regs-only}. | |
4307 | |
3833 @item interrupt | 4308 @item interrupt |
3834 @cindex @code{interrupt} function attribute, ARM | 4309 @cindex @code{interrupt} function attribute, ARM |
3835 Use this attribute to indicate | 4310 Use this attribute to indicate |
3836 that the specified function is an interrupt handler. The compiler generates | 4311 that the specified function is an interrupt handler. The compiler generates |
3837 function entry and exit sequences suitable for use in an interrupt handler | 4312 function entry and exit sequences suitable for use in an interrupt handler |
4782 @table @code | 5257 @table @code |
4783 @item critical | 5258 @item critical |
4784 @cindex @code{critical} function attribute, MSP430 | 5259 @cindex @code{critical} function attribute, MSP430 |
4785 Critical functions disable interrupts upon entry and restore the | 5260 Critical functions disable interrupts upon entry and restore the |
4786 previous interrupt state upon exit. Critical functions cannot also | 5261 previous interrupt state upon exit. Critical functions cannot also |
4787 have the @code{naked} or @code{reentrant} attributes. They can have | 5262 have the @code{naked}, @code{reentrant} or @code{interrupt} attributes. |
4788 the @code{interrupt} attribute. | 5263 |
5264 The MSP430 hardware ensures that interrupts are disabled on entry to | |
5265 @code{interrupt} functions, and restores the previous interrupt state | |
5266 on exit. The @code{critical} attribute is therefore redundant on | |
5267 @code{interrupt} functions. | |
4789 | 5268 |
4790 @item interrupt | 5269 @item interrupt |
4791 @cindex @code{interrupt} function attribute, MSP430 | 5270 @cindex @code{interrupt} function attribute, MSP430 |
4792 Use this attribute to indicate | 5271 Use this attribute to indicate |
4793 that the specified function is an interrupt handler. The compiler generates | 5272 that the specified function is an interrupt handler. The compiler generates |
4836 @cindex @code{either} function attribute, MSP430 | 5315 @cindex @code{either} function attribute, MSP430 |
4837 On the MSP430 target these attributes can be used to specify whether | 5316 On the MSP430 target these attributes can be used to specify whether |
4838 the function or variable should be placed into low memory, high | 5317 the function or variable should be placed into low memory, high |
4839 memory, or the placement should be left to the linker to decide. The | 5318 memory, or the placement should be left to the linker to decide. The |
4840 attributes are only significant if compiling for the MSP430X | 5319 attributes are only significant if compiling for the MSP430X |
4841 architecture. | 5320 architecture in the large memory model. |
4842 | 5321 |
4843 The attributes work in conjunction with a linker script that has been | 5322 The attributes work in conjunction with a linker script that has been |
4844 augmented to specify where to place sections with a @code{.lower} and | 5323 augmented to specify where to place sections with a @code{.lower} and |
4845 a @code{.upper} prefix. So, for example, as well as placing the | 5324 a @code{.upper} prefix. So, for example, as well as placing the |
4846 @code{.data} section, the script also specifies the placement of a | 5325 @code{.data} section, the script also specifies the placement of a |
5056 @cindex @code{target("mfcrf")} function attribute, PowerPC | 5535 @cindex @code{target("mfcrf")} function attribute, PowerPC |
5057 Generate code that uses (does not use) the move from condition | 5536 Generate code that uses (does not use) the move from condition |
5058 register field instruction implemented on the POWER4 processor and | 5537 register field instruction implemented on the POWER4 processor and |
5059 other processors that support the PowerPC V2.01 architecture. | 5538 other processors that support the PowerPC V2.01 architecture. |
5060 | 5539 |
5061 @item mfpgpr | |
5062 @itemx no-mfpgpr | |
5063 @cindex @code{target("mfpgpr")} function attribute, PowerPC | |
5064 Generate code that uses (does not use) the FP move to/from general | |
5065 purpose register instructions implemented on the POWER6X processor and | |
5066 other processors that support the extended PowerPC V2.05 architecture. | |
5067 | |
5068 @item mulhw | 5540 @item mulhw |
5069 @itemx no-mulhw | 5541 @itemx no-mulhw |
5070 @cindex @code{target("mulhw")} function attribute, PowerPC | 5542 @cindex @code{target("mulhw")} function attribute, PowerPC |
5071 Generate code that uses (does not use) the half-word multiply and | 5543 Generate code that uses (does not use) the half-word multiply and |
5072 multiply-accumulate instructions on the IBM 405, 440, 464 and 476 processors. | 5544 multiply-accumulate instructions on the IBM 405, 440, 464 and 476 processors. |
5307 | 5779 |
5308 @item vector | 5780 @item vector |
5309 @cindex @code{vector} function attribute, RX | 5781 @cindex @code{vector} function attribute, RX |
5310 This RX attribute is similar to the @code{interrupt} attribute, including its | 5782 This RX attribute is similar to the @code{interrupt} attribute, including its |
5311 parameters, but does not make the function an interrupt-handler type | 5783 parameters, but does not make the function an interrupt-handler type |
5312 function (i.e. it retains the normal C function calling ABI). See the | 5784 function (i.e.@: it retains the normal C function calling ABI). See the |
5313 @code{interrupt} attribute for a description of its arguments. | 5785 @code{interrupt} attribute for a description of its arguments. |
5314 @end table | 5786 @end table |
5315 | 5787 |
5316 @node S/390 Function Attributes | 5788 @node S/390 Function Attributes |
5317 @subsection S/390 Function Attributes | 5789 @subsection S/390 Function Attributes |
5458 @cindex @code{trapa_handler} function attribute, SH | 5930 @cindex @code{trapa_handler} function attribute, SH |
5459 On SH targets this function attribute is similar to @code{interrupt_handler} | 5931 On SH targets this function attribute is similar to @code{interrupt_handler} |
5460 but it does not save and restore all registers. | 5932 but it does not save and restore all registers. |
5461 @end table | 5933 @end table |
5462 | 5934 |
5463 @node SPU Function Attributes | |
5464 @subsection SPU Function Attributes | |
5465 | |
5466 These function attributes are supported by the SPU back end: | |
5467 | |
5468 @table @code | |
5469 @item naked | |
5470 @cindex @code{naked} function attribute, SPU | |
5471 This attribute allows the compiler to construct the | |
5472 requisite function declaration, while allowing the body of the | |
5473 function to be assembly code. The specified function will not have | |
5474 prologue/epilogue sequences generated by the compiler. Only basic | |
5475 @code{asm} statements can safely be included in naked functions | |
5476 (@pxref{Basic Asm}). While using extended @code{asm} or a mixture of | |
5477 basic @code{asm} and C code may appear to work, they cannot be | |
5478 depended upon to work reliably and are not supported. | |
5479 @end table | |
5480 | |
5481 @node Symbian OS Function Attributes | 5935 @node Symbian OS Function Attributes |
5482 @subsection Symbian OS Function Attributes | 5936 @subsection Symbian OS Function Attributes |
5483 | 5937 |
5484 @xref{Microsoft Windows Function Attributes}, for discussion of the | 5938 @xref{Microsoft Windows Function Attributes}, for discussion of the |
5485 @code{dllexport} and @code{dllimport} attributes. | 5939 @code{dllexport} and @code{dllimport} attributes. |
5721 As discussed in @ref{Common Function Attributes}, this attribute | 6175 As discussed in @ref{Common Function Attributes}, this attribute |
5722 allows specification of target-specific compilation options. | 6176 allows specification of target-specific compilation options. |
5723 | 6177 |
5724 On the x86, the following options are allowed: | 6178 On the x86, the following options are allowed: |
5725 @table @samp | 6179 @table @samp |
6180 @item 3dnow | |
6181 @itemx no-3dnow | |
6182 @cindex @code{target("3dnow")} function attribute, x86 | |
6183 Enable/disable the generation of the 3DNow!@: instructions. | |
6184 | |
6185 @item 3dnowa | |
6186 @itemx no-3dnowa | |
6187 @cindex @code{target("3dnowa")} function attribute, x86 | |
6188 Enable/disable the generation of the enhanced 3DNow!@: instructions. | |
6189 | |
5726 @item abm | 6190 @item abm |
5727 @itemx no-abm | 6191 @itemx no-abm |
5728 @cindex @code{target("abm")} function attribute, x86 | 6192 @cindex @code{target("abm")} function attribute, x86 |
5729 Enable/disable the generation of the advanced bit instructions. | 6193 Enable/disable the generation of the advanced bit instructions. |
5730 | 6194 |
6195 @item adx | |
6196 @itemx no-adx | |
6197 @cindex @code{target("adx")} function attribute, x86 | |
6198 Enable/disable the generation of the ADX instructions. | |
6199 | |
5731 @item aes | 6200 @item aes |
5732 @itemx no-aes | 6201 @itemx no-aes |
5733 @cindex @code{target("aes")} function attribute, x86 | 6202 @cindex @code{target("aes")} function attribute, x86 |
5734 Enable/disable the generation of the AES instructions. | 6203 Enable/disable the generation of the AES instructions. |
5735 | 6204 |
6205 @item avx | |
6206 @itemx no-avx | |
6207 @cindex @code{target("avx")} function attribute, x86 | |
6208 Enable/disable the generation of the AVX instructions. | |
6209 | |
6210 @item avx2 | |
6211 @itemx no-avx2 | |
6212 @cindex @code{target("avx2")} function attribute, x86 | |
6213 Enable/disable the generation of the AVX2 instructions. | |
6214 | |
6215 @item avx5124fmaps | |
6216 @itemx no-avx5124fmaps | |
6217 @cindex @code{target("avx5124fmaps")} function attribute, x86 | |
6218 Enable/disable the generation of the AVX5124FMAPS instructions. | |
6219 | |
6220 @item avx5124vnniw | |
6221 @itemx no-avx5124vnniw | |
6222 @cindex @code{target("avx5124vnniw")} function attribute, x86 | |
6223 Enable/disable the generation of the AVX5124VNNIW instructions. | |
6224 | |
6225 @item avx512bitalg | |
6226 @itemx no-avx512bitalg | |
6227 @cindex @code{target("avx512bitalg")} function attribute, x86 | |
6228 Enable/disable the generation of the AVX512BITALG instructions. | |
6229 | |
6230 @item avx512bw | |
6231 @itemx no-avx512bw | |
6232 @cindex @code{target("avx512bw")} function attribute, x86 | |
6233 Enable/disable the generation of the AVX512BW instructions. | |
6234 | |
6235 @item avx512cd | |
6236 @itemx no-avx512cd | |
6237 @cindex @code{target("avx512cd")} function attribute, x86 | |
6238 Enable/disable the generation of the AVX512CD instructions. | |
6239 | |
6240 @item avx512dq | |
6241 @itemx no-avx512dq | |
6242 @cindex @code{target("avx512dq")} function attribute, x86 | |
6243 Enable/disable the generation of the AVX512DQ instructions. | |
6244 | |
6245 @item avx512er | |
6246 @itemx no-avx512er | |
6247 @cindex @code{target("avx512er")} function attribute, x86 | |
6248 Enable/disable the generation of the AVX512ER instructions. | |
6249 | |
6250 @item avx512f | |
6251 @itemx no-avx512f | |
6252 @cindex @code{target("avx512f")} function attribute, x86 | |
6253 Enable/disable the generation of the AVX512F instructions. | |
6254 | |
6255 @item avx512ifma | |
6256 @itemx no-avx512ifma | |
6257 @cindex @code{target("avx512ifma")} function attribute, x86 | |
6258 Enable/disable the generation of the AVX512IFMA instructions. | |
6259 | |
6260 @item avx512pf | |
6261 @itemx no-avx512pf | |
6262 @cindex @code{target("avx512pf")} function attribute, x86 | |
6263 Enable/disable the generation of the AVX512PF instructions. | |
6264 | |
6265 @item avx512vbmi | |
6266 @itemx no-avx512vbmi | |
6267 @cindex @code{target("avx512vbmi")} function attribute, x86 | |
6268 Enable/disable the generation of the AVX512VBMI instructions. | |
6269 | |
6270 @item avx512vbmi2 | |
6271 @itemx no-avx512vbmi2 | |
6272 @cindex @code{target("avx512vbmi2")} function attribute, x86 | |
6273 Enable/disable the generation of the AVX512VBMI2 instructions. | |
6274 | |
6275 @item avx512vl | |
6276 @itemx no-avx512vl | |
6277 @cindex @code{target("avx512vl")} function attribute, x86 | |
6278 Enable/disable the generation of the AVX512VL instructions. | |
6279 | |
6280 @item avx512vnni | |
6281 @itemx no-avx512vnni | |
6282 @cindex @code{target("avx512vnni")} function attribute, x86 | |
6283 Enable/disable the generation of the AVX512VNNI instructions. | |
6284 | |
6285 @item avx512vpopcntdq | |
6286 @itemx no-avx512vpopcntdq | |
6287 @cindex @code{target("avx512vpopcntdq")} function attribute, x86 | |
6288 Enable/disable the generation of the AVX512VPOPCNTDQ instructions. | |
6289 | |
6290 @item bmi | |
6291 @itemx no-bmi | |
6292 @cindex @code{target("bmi")} function attribute, x86 | |
6293 Enable/disable the generation of the BMI instructions. | |
6294 | |
6295 @item bmi2 | |
6296 @itemx no-bmi2 | |
6297 @cindex @code{target("bmi2")} function attribute, x86 | |
6298 Enable/disable the generation of the BMI2 instructions. | |
6299 | |
6300 @item cldemote | |
6301 @itemx no-cldemote | |
6302 @cindex @code{target("cldemote")} function attribute, x86 | |
6303 Enable/disable the generation of the CLDEMOTE instructions. | |
6304 | |
6305 @item clflushopt | |
6306 @itemx no-clflushopt | |
6307 @cindex @code{target("clflushopt")} function attribute, x86 | |
6308 Enable/disable the generation of the CLFLUSHOPT instructions. | |
6309 | |
6310 @item clwb | |
6311 @itemx no-clwb | |
6312 @cindex @code{target("clwb")} function attribute, x86 | |
6313 Enable/disable the generation of the CLWB instructions. | |
6314 | |
6315 @item clzero | |
6316 @itemx no-clzero | |
6317 @cindex @code{target("clzero")} function attribute, x86 | |
6318 Enable/disable the generation of the CLZERO instructions. | |
6319 | |
6320 @item crc32 | |
6321 @itemx no-crc32 | |
6322 @cindex @code{target("crc32")} function attribute, x86 | |
6323 Enable/disable the generation of the CRC32 instructions. | |
6324 | |
6325 @item cx16 | |
6326 @itemx no-cx16 | |
6327 @cindex @code{target("cx16")} function attribute, x86 | |
6328 Enable/disable the generation of the CMPXCHG16B instructions. | |
6329 | |
5736 @item default | 6330 @item default |
5737 @cindex @code{target("default")} function attribute, x86 | 6331 @cindex @code{target("default")} function attribute, x86 |
5738 @xref{Function Multiversioning}, where it is used to specify the | 6332 @xref{Function Multiversioning}, where it is used to specify the |
5739 default function version. | 6333 default function version. |
5740 | 6334 |
6335 @item f16c | |
6336 @itemx no-f16c | |
6337 @cindex @code{target("f16c")} function attribute, x86 | |
6338 Enable/disable the generation of the F16C instructions. | |
6339 | |
6340 @item fma | |
6341 @itemx no-fma | |
6342 @cindex @code{target("fma")} function attribute, x86 | |
6343 Enable/disable the generation of the FMA instructions. | |
6344 | |
6345 @item fma4 | |
6346 @itemx no-fma4 | |
6347 @cindex @code{target("fma4")} function attribute, x86 | |
6348 Enable/disable the generation of the FMA4 instructions. | |
6349 | |
6350 @item fsgsbase | |
6351 @itemx no-fsgsbase | |
6352 @cindex @code{target("fsgsbase")} function attribute, x86 | |
6353 Enable/disable the generation of the FSGSBASE instructions. | |
6354 | |
6355 @item fxsr | |
6356 @itemx no-fxsr | |
6357 @cindex @code{target("fxsr")} function attribute, x86 | |
6358 Enable/disable the generation of the FXSR instructions. | |
6359 | |
6360 @item gfni | |
6361 @itemx no-gfni | |
6362 @cindex @code{target("gfni")} function attribute, x86 | |
6363 Enable/disable the generation of the GFNI instructions. | |
6364 | |
6365 @item hle | |
6366 @itemx no-hle | |
6367 @cindex @code{target("hle")} function attribute, x86 | |
6368 Enable/disable the generation of the HLE instruction prefixes. | |
6369 | |
6370 @item lwp | |
6371 @itemx no-lwp | |
6372 @cindex @code{target("lwp")} function attribute, x86 | |
6373 Enable/disable the generation of the LWP instructions. | |
6374 | |
6375 @item lzcnt | |
6376 @itemx no-lzcnt | |
6377 @cindex @code{target("lzcnt")} function attribute, x86 | |
6378 Enable/disable the generation of the LZCNT instructions. | |
6379 | |
5741 @item mmx | 6380 @item mmx |
5742 @itemx no-mmx | 6381 @itemx no-mmx |
5743 @cindex @code{target("mmx")} function attribute, x86 | 6382 @cindex @code{target("mmx")} function attribute, x86 |
5744 Enable/disable the generation of the MMX instructions. | 6383 Enable/disable the generation of the MMX instructions. |
5745 | 6384 |
6385 @item movbe | |
6386 @itemx no-movbe | |
6387 @cindex @code{target("movbe")} function attribute, x86 | |
6388 Enable/disable the generation of the MOVBE instructions. | |
6389 | |
6390 @item movdir64b | |
6391 @itemx no-movdir64b | |
6392 @cindex @code{target("movdir64b")} function attribute, x86 | |
6393 Enable/disable the generation of the MOVDIR64B instructions. | |
6394 | |
6395 @item movdiri | |
6396 @itemx no-movdiri | |
6397 @cindex @code{target("movdiri")} function attribute, x86 | |
6398 Enable/disable the generation of the MOVDIRI instructions. | |
6399 | |
6400 @item mwaitx | |
6401 @itemx no-mwaitx | |
6402 @cindex @code{target("mwaitx")} function attribute, x86 | |
6403 Enable/disable the generation of the MWAITX instructions. | |
6404 | |
5746 @item pclmul | 6405 @item pclmul |
5747 @itemx no-pclmul | 6406 @itemx no-pclmul |
5748 @cindex @code{target("pclmul")} function attribute, x86 | 6407 @cindex @code{target("pclmul")} function attribute, x86 |
5749 Enable/disable the generation of the PCLMUL instructions. | 6408 Enable/disable the generation of the PCLMUL instructions. |
5750 | 6409 |
6410 @item pconfig | |
6411 @itemx no-pconfig | |
6412 @cindex @code{target("pconfig")} function attribute, x86 | |
6413 Enable/disable the generation of the PCONFIG instructions. | |
6414 | |
6415 @item pku | |
6416 @itemx no-pku | |
6417 @cindex @code{target("pku")} function attribute, x86 | |
6418 Enable/disable the generation of the PKU instructions. | |
6419 | |
5751 @item popcnt | 6420 @item popcnt |
5752 @itemx no-popcnt | 6421 @itemx no-popcnt |
5753 @cindex @code{target("popcnt")} function attribute, x86 | 6422 @cindex @code{target("popcnt")} function attribute, x86 |
5754 Enable/disable the generation of the POPCNT instruction. | 6423 Enable/disable the generation of the POPCNT instruction. |
6424 | |
6425 @item prefetchwt1 | |
6426 @itemx no-prefetchwt1 | |
6427 @cindex @code{target("prefetchwt1")} function attribute, x86 | |
6428 Enable/disable the generation of the PREFETCHWT1 instructions. | |
6429 | |
6430 @item prfchw | |
6431 @itemx no-prfchw | |
6432 @cindex @code{target("prfchw")} function attribute, x86 | |
6433 Enable/disable the generation of the PREFETCHW instruction. | |
6434 | |
6435 @item ptwrite | |
6436 @itemx no-ptwrite | |
6437 @cindex @code{target("ptwrite")} function attribute, x86 | |
6438 Enable/disable the generation of the PTWRITE instructions. | |
6439 | |
6440 @item rdpid | |
6441 @itemx no-rdpid | |
6442 @cindex @code{target("rdpid")} function attribute, x86 | |
6443 Enable/disable the generation of the RDPID instructions. | |
6444 | |
6445 @item rdrnd | |
6446 @itemx no-rdrnd | |
6447 @cindex @code{target("rdrnd")} function attribute, x86 | |
6448 Enable/disable the generation of the RDRND instructions. | |
6449 | |
6450 @item rdseed | |
6451 @itemx no-rdseed | |
6452 @cindex @code{target("rdseed")} function attribute, x86 | |
6453 Enable/disable the generation of the RDSEED instructions. | |
6454 | |
6455 @item rtm | |
6456 @itemx no-rtm | |
6457 @cindex @code{target("rtm")} function attribute, x86 | |
6458 Enable/disable the generation of the RTM instructions. | |
6459 | |
6460 @item sahf | |
6461 @itemx no-sahf | |
6462 @cindex @code{target("sahf")} function attribute, x86 | |
6463 Enable/disable the generation of the SAHF instructions. | |
6464 | |
6465 @item sgx | |
6466 @itemx no-sgx | |
6467 @cindex @code{target("sgx")} function attribute, x86 | |
6468 Enable/disable the generation of the SGX instructions. | |
6469 | |
6470 @item sha | |
6471 @itemx no-sha | |
6472 @cindex @code{target("sha")} function attribute, x86 | |
6473 Enable/disable the generation of the SHA instructions. | |
6474 | |
6475 @item shstk | |
6476 @itemx no-shstk | |
6477 @cindex @code{target("shstk")} function attribute, x86 | |
6478 Enable/disable the shadow stack built-in functions from CET. | |
5755 | 6479 |
5756 @item sse | 6480 @item sse |
5757 @itemx no-sse | 6481 @itemx no-sse |
5758 @cindex @code{target("sse")} function attribute, x86 | 6482 @cindex @code{target("sse")} function attribute, x86 |
5759 Enable/disable the generation of the SSE instructions. | 6483 Enable/disable the generation of the SSE instructions. |
5787 @item sse4a | 6511 @item sse4a |
5788 @itemx no-sse4a | 6512 @itemx no-sse4a |
5789 @cindex @code{target("sse4a")} function attribute, x86 | 6513 @cindex @code{target("sse4a")} function attribute, x86 |
5790 Enable/disable the generation of the SSE4A instructions. | 6514 Enable/disable the generation of the SSE4A instructions. |
5791 | 6515 |
5792 @item fma4 | 6516 @item ssse3 |
5793 @itemx no-fma4 | 6517 @itemx no-ssse3 |
5794 @cindex @code{target("fma4")} function attribute, x86 | 6518 @cindex @code{target("ssse3")} function attribute, x86 |
5795 Enable/disable the generation of the FMA4 instructions. | 6519 Enable/disable the generation of the SSSE3 instructions. |
6520 | |
6521 @item tbm | |
6522 @itemx no-tbm | |
6523 @cindex @code{target("tbm")} function attribute, x86 | |
6524 Enable/disable the generation of the TBM instructions. | |
6525 | |
6526 @item vaes | |
6527 @itemx no-vaes | |
6528 @cindex @code{target("vaes")} function attribute, x86 | |
6529 Enable/disable the generation of the VAES instructions. | |
6530 | |
6531 @item vpclmulqdq | |
6532 @itemx no-vpclmulqdq | |
6533 @cindex @code{target("vpclmulqdq")} function attribute, x86 | |
6534 Enable/disable the generation of the VPCLMULQDQ instructions. | |
6535 | |
6536 @item waitpkg | |
6537 @itemx no-waitpkg | |
6538 @cindex @code{target("waitpkg")} function attribute, x86 | |
6539 Enable/disable the generation of the WAITPKG instructions. | |
6540 | |
6541 @item wbnoinvd | |
6542 @itemx no-wbnoinvd | |
6543 @cindex @code{target("wbnoinvd")} function attribute, x86 | |
6544 Enable/disable the generation of the WBNOINVD instructions. | |
5796 | 6545 |
5797 @item xop | 6546 @item xop |
5798 @itemx no-xop | 6547 @itemx no-xop |
5799 @cindex @code{target("xop")} function attribute, x86 | 6548 @cindex @code{target("xop")} function attribute, x86 |
5800 Enable/disable the generation of the XOP instructions. | 6549 Enable/disable the generation of the XOP instructions. |
5801 | 6550 |
5802 @item lwp | 6551 @item xsave |
5803 @itemx no-lwp | 6552 @itemx no-xsave |
5804 @cindex @code{target("lwp")} function attribute, x86 | 6553 @cindex @code{target("xsave")} function attribute, x86 |
5805 Enable/disable the generation of the LWP instructions. | 6554 Enable/disable the generation of the XSAVE instructions. |
5806 | 6555 |
5807 @item ssse3 | 6556 @item xsavec |
5808 @itemx no-ssse3 | 6557 @itemx no-xsavec |
5809 @cindex @code{target("ssse3")} function attribute, x86 | 6558 @cindex @code{target("xsavec")} function attribute, x86 |
5810 Enable/disable the generation of the SSSE3 instructions. | 6559 Enable/disable the generation of the XSAVEC instructions. |
6560 | |
6561 @item xsaveopt | |
6562 @itemx no-xsaveopt | |
6563 @cindex @code{target("xsaveopt")} function attribute, x86 | |
6564 Enable/disable the generation of the XSAVEOPT instructions. | |
6565 | |
6566 @item xsaves | |
6567 @itemx no-xsaves | |
6568 @cindex @code{target("xsaves")} function attribute, x86 | |
6569 Enable/disable the generation of the XSAVES instructions. | |
5811 | 6570 |
5812 @item cld | 6571 @item cld |
5813 @itemx no-cld | 6572 @itemx no-cld |
5814 @cindex @code{target("cld")} function attribute, x86 | 6573 @cindex @code{target("cld")} function attribute, x86 |
5815 Enable/disable the generation of the CLD before string moves. | 6574 Enable/disable the generation of the CLD before string moves. |
5937 | 6696 |
5938 return 0; | 6697 return 0; |
5939 @} | 6698 @} |
5940 @end smallexample | 6699 @end smallexample |
5941 | 6700 |
6701 @item cf_check | |
6702 @cindex @code{cf_check} function attribute, x86 | |
6703 | |
6704 The @code{cf_check} attribute on a function is used to inform the | |
6705 compiler that ENDBR instruction should be placed at the function | |
6706 entry when @option{-fcf-protection=branch} is enabled. | |
6707 | |
5942 @item indirect_return | 6708 @item indirect_return |
5943 @cindex @code{indirect_return} function attribute, x86 | 6709 @cindex @code{indirect_return} function attribute, x86 |
5944 | 6710 |
5945 The @code{indirect_return} attribute can be applied to a function, | 6711 The @code{indirect_return} attribute can be applied to a function, |
5946 as well as variable or type of function pointer to inform the | 6712 as well as variable or type of function pointer to inform the |
5947 compiler that the function may return via indirect branch. | 6713 compiler that the function may return via indirect branch. |
6714 | |
6715 @item fentry_name("@var{name}") | |
6716 @cindex @code{fentry_name} function attribute, x86 | |
6717 On x86 targets, the @code{fentry_name} attribute sets the function to | |
6718 call on function entry when function instrumentation is enabled | |
6719 with @option{-pg -mfentry}. When @var{name} is nop then a 5 byte | |
6720 nop sequence is generated. | |
6721 | |
6722 @item fentry_section("@var{name}") | |
6723 @cindex @code{fentry_section} function attribute, x86 | |
6724 On x86 targets, the @code{fentry_section} attribute sets the name | |
6725 of the section to record function entry instrumentation calls in when | |
6726 enabled with @option{-pg -mrecord-mcount} | |
5948 | 6727 |
5949 @end table | 6728 @end table |
5950 | 6729 |
5951 On the x86, the inliner does not inline a | 6730 On the x86, the inliner does not inline a |
5952 function that has different target options than the caller, unless the | 6731 function that has different target options than the caller, unless the |
5972 @node Variable Attributes | 6751 @node Variable Attributes |
5973 @section Specifying Attributes of Variables | 6752 @section Specifying Attributes of Variables |
5974 @cindex attribute of variables | 6753 @cindex attribute of variables |
5975 @cindex variable attributes | 6754 @cindex variable attributes |
5976 | 6755 |
5977 The keyword @code{__attribute__} allows you to specify special | 6756 The keyword @code{__attribute__} allows you to specify special properties |
5978 attributes of variables or structure fields. This keyword is followed | 6757 of variables, function parameters, or structure, union, and, in C++, class |
5979 by an attribute specification inside double parentheses. Some | 6758 members. This @code{__attribute__} keyword is followed by an attribute |
5980 attributes are currently defined generically for variables. | 6759 specification enclosed in double parentheses. Some attributes are currently |
5981 Other attributes are defined for variables on particular target | 6760 defined generically for variables. Other attributes are defined for |
5982 systems. Other attributes are available for functions | 6761 variables on particular target systems. Other attributes are available |
5983 (@pxref{Function Attributes}), labels (@pxref{Label Attributes}), | 6762 for functions (@pxref{Function Attributes}), labels (@pxref{Label Attributes}), |
5984 enumerators (@pxref{Enumerator Attributes}), statements | 6763 enumerators (@pxref{Enumerator Attributes}), statements |
5985 (@pxref{Statement Attributes}), and for types (@pxref{Type Attributes}). | 6764 (@pxref{Statement Attributes}), and for types (@pxref{Type Attributes}). |
5986 Other front ends might define more attributes | 6765 Other front ends might define more attributes |
5987 (@pxref{C++ Extensions,,Extensions to the C++ Language}). | 6766 (@pxref{C++ Extensions,,Extensions to the C++ Language}). |
5988 | 6767 |
6001 * Microsoft Windows Variable Attributes:: | 6780 * Microsoft Windows Variable Attributes:: |
6002 * MSP430 Variable Attributes:: | 6781 * MSP430 Variable Attributes:: |
6003 * Nvidia PTX Variable Attributes:: | 6782 * Nvidia PTX Variable Attributes:: |
6004 * PowerPC Variable Attributes:: | 6783 * PowerPC Variable Attributes:: |
6005 * RL78 Variable Attributes:: | 6784 * RL78 Variable Attributes:: |
6006 * SPU Variable Attributes:: | |
6007 * V850 Variable Attributes:: | 6785 * V850 Variable Attributes:: |
6008 * x86 Variable Attributes:: | 6786 * x86 Variable Attributes:: |
6009 * Xstormy16 Variable Attributes:: | 6787 * Xstormy16 Variable Attributes:: |
6010 @end menu | 6788 @end menu |
6011 | 6789 |
6013 @subsection Common Variable Attributes | 6791 @subsection Common Variable Attributes |
6014 | 6792 |
6015 The following attributes are supported on most targets. | 6793 The following attributes are supported on most targets. |
6016 | 6794 |
6017 @table @code | 6795 @table @code |
6796 | |
6797 @item alias ("@var{target}") | |
6798 @cindex @code{alias} variable attribute | |
6799 The @code{alias} variable attribute causes the declaration to be emitted | |
6800 as an alias for another symbol known as an @dfn{alias target}. Except | |
6801 for top-level qualifiers the alias target must have the same type as | |
6802 the alias. For instance, the following | |
6803 | |
6804 @smallexample | |
6805 int var_target; | |
6806 extern int __attribute__ ((alias ("var_target"))) var_alias; | |
6807 @end smallexample | |
6808 | |
6809 @noindent | |
6810 defines @code{var_alias} to be an alias for the @code{var_target} variable. | |
6811 | |
6812 It is an error if the alias target is not defined in the same translation | |
6813 unit as the alias. | |
6814 | |
6815 Note that in the absence of the attribute GCC assumes that distinct | |
6816 declarations with external linkage denote distinct objects. Using both | |
6817 the alias and the alias target to access the same object is undefined | |
6818 in a translation unit without a declaration of the alias with the attribute. | |
6819 | |
6820 This attribute requires assembler and object file support, and may not be | |
6821 available on all targets. | |
6822 | |
6018 @cindex @code{aligned} variable attribute | 6823 @cindex @code{aligned} variable attribute |
6019 @item aligned (@var{alignment}) | 6824 @item aligned |
6020 This attribute specifies a minimum alignment for the variable or | 6825 @itemx aligned (@var{alignment}) |
6021 structure field, measured in bytes. For example, the declaration: | 6826 The @code{aligned} attribute specifies a minimum alignment for the variable |
6827 or structure field, measured in bytes. When specified, @var{alignment} must | |
6828 be an integer constant power of 2. Specifying no @var{alignment} argument | |
6829 implies the maximum alignment for the target, which is often, but by no | |
6830 means always, 8 or 16 bytes. | |
6831 | |
6832 For example, the declaration: | |
6022 | 6833 |
6023 @smallexample | 6834 @smallexample |
6024 int x __attribute__ ((aligned (16))) = 0; | 6835 int x __attribute__ ((aligned (16))) = 0; |
6025 @end smallexample | 6836 @end smallexample |
6026 | 6837 |
6070 only increase the alignment; in order to decrease it, the @code{packed} | 6881 only increase the alignment; in order to decrease it, the @code{packed} |
6071 attribute must be specified as well. When used as part of a typedef, the | 6882 attribute must be specified as well. When used as part of a typedef, the |
6072 @code{aligned} attribute can both increase and decrease alignment, and | 6883 @code{aligned} attribute can both increase and decrease alignment, and |
6073 specifying the @code{packed} attribute generates a warning. | 6884 specifying the @code{packed} attribute generates a warning. |
6074 | 6885 |
6075 Note that the effectiveness of @code{aligned} attributes may be limited | 6886 Note that the effectiveness of @code{aligned} attributes for static |
6076 by inherent limitations in your linker. On many systems, the linker is | 6887 variables may be limited by inherent limitations in the system linker |
6888 and/or object file format. On some systems, the linker is | |
6077 only able to arrange for variables to be aligned up to a certain maximum | 6889 only able to arrange for variables to be aligned up to a certain maximum |
6078 alignment. (For some linkers, the maximum supported alignment may | 6890 alignment. (For some linkers, the maximum supported alignment may |
6079 be very very small.) If your linker is only able to align variables | 6891 be very very small.) If your linker is only able to align variables |
6080 up to a maximum of 8-byte alignment, then specifying @code{aligned(16)} | 6892 up to a maximum of 8-byte alignment, then specifying @code{aligned(16)} |
6081 in an @code{__attribute__} still only provides you with 8-byte | 6893 in an @code{__attribute__} still only provides you with 8-byte |
6082 alignment. See your linker documentation for further information. | 6894 alignment. See your linker documentation for further information. |
6083 | 6895 |
6896 Stack variables are not affected by linker restrictions; GCC can properly | |
6897 align them on any target. | |
6898 | |
6084 The @code{aligned} attribute can also be used for functions | 6899 The @code{aligned} attribute can also be used for functions |
6085 (@pxref{Common Function Attributes}.) | 6900 (@pxref{Common Function Attributes}.) |
6086 | 6901 |
6087 @cindex @code{warn_if_not_aligned} variable attribute | 6902 @cindex @code{warn_if_not_aligned} variable attribute |
6088 @item warn_if_not_aligned (@var{alignment}) | 6903 @item warn_if_not_aligned (@var{alignment}) |
6093 @smallexample | 6908 @smallexample |
6094 struct foo | 6909 struct foo |
6095 @{ | 6910 @{ |
6096 int i1; | 6911 int i1; |
6097 int i2; | 6912 int i2; |
6098 unsigned long long x __attribute__((warn_if_not_aligned(16))); | 6913 unsigned long long x __attribute__ ((warn_if_not_aligned (16))); |
6099 @}; | 6914 @}; |
6100 @end smallexample | 6915 @end smallexample |
6101 | 6916 |
6102 @noindent | 6917 @noindent |
6103 causes the compiler to issue an warning on @code{struct foo}, like | 6918 causes the compiler to issue an warning on @code{struct foo}, like |
6105 The compiler also issues a warning, like @samp{warning: 'x' offset | 6920 The compiler also issues a warning, like @samp{warning: 'x' offset |
6106 8 in 'struct foo' isn't aligned to 16}, when the structure field has | 6921 8 in 'struct foo' isn't aligned to 16}, when the structure field has |
6107 the misaligned offset: | 6922 the misaligned offset: |
6108 | 6923 |
6109 @smallexample | 6924 @smallexample |
6110 struct foo | 6925 struct __attribute__ ((aligned (16))) foo |
6111 @{ | 6926 @{ |
6112 int i1; | 6927 int i1; |
6113 int i2; | 6928 int i2; |
6114 unsigned long long x __attribute__((warn_if_not_aligned(16))); | 6929 unsigned long long x __attribute__ ((warn_if_not_aligned (16))); |
6115 @} __attribute__((aligned(16))); | 6930 @}; |
6116 @end smallexample | 6931 @end smallexample |
6117 | 6932 |
6118 This warning can be disabled by @option{-Wno-if-not-aligned}. | 6933 This warning can be disabled by @option{-Wno-if-not-aligned}. |
6119 The @code{warn_if_not_aligned} attribute can also be used for types | 6934 The @code{warn_if_not_aligned} attribute can also be used for types |
6120 (@pxref{Common Type Attributes}.) | 6935 (@pxref{Common Type Attributes}.) |
6936 | |
6937 @item alloc_size (@var{position}) | |
6938 @itemx alloc_size (@var{position-1}, @var{position-2}) | |
6939 @cindex @code{alloc_size} variable attribute | |
6940 The @code{alloc_size} variable attribute may be applied to the declaration | |
6941 of a pointer to a function that returns a pointer and takes at least one | |
6942 argument of an integer type. It indicates that the returned pointer points | |
6943 to an object whose size is given by the function argument at @var{position-1}, | |
6944 or by the product of the arguments at @var{position-1} and @var{position-2}. | |
6945 Meaningful sizes are positive values less than @code{PTRDIFF_MAX}. Other | |
6946 sizes are disagnosed when detected. GCC uses this information to improve | |
6947 the results of @code{__builtin_object_size}. | |
6948 | |
6949 For instance, the following declarations | |
6950 | |
6951 @smallexample | |
6952 typedef __attribute__ ((alloc_size (1, 2))) void* | |
6953 (*calloc_ptr) (size_t, size_t); | |
6954 typedef __attribute__ ((alloc_size (1))) void* | |
6955 (*malloc_ptr) (size_t); | |
6956 @end smallexample | |
6957 | |
6958 @noindent | |
6959 specify that @code{calloc_ptr} is a pointer of a function that, like | |
6960 the standard C function @code{calloc}, returns an object whose size | |
6961 is given by the product of arguments 1 and 2, and similarly, that | |
6962 @code{malloc_ptr}, like the standard C function @code{malloc}, | |
6963 returns an object whose size is given by argument 1 to the function. | |
6121 | 6964 |
6122 @item cleanup (@var{cleanup_function}) | 6965 @item cleanup (@var{cleanup_function}) |
6123 @cindex @code{cleanup} variable attribute | 6966 @cindex @code{cleanup} variable attribute |
6124 The @code{cleanup} attribute runs a function when the variable goes | 6967 The @code{cleanup} attribute runs a function when the variable goes |
6125 out of scope. This attribute can only be applied to auto function | 6968 out of scope. This attribute can only be applied to auto function |
6145 ``common'' storage. The @code{nocommon} attribute requests the | 6988 ``common'' storage. The @code{nocommon} attribute requests the |
6146 opposite---to allocate space for it directly. | 6989 opposite---to allocate space for it directly. |
6147 | 6990 |
6148 These attributes override the default chosen by the | 6991 These attributes override the default chosen by the |
6149 @option{-fno-common} and @option{-fcommon} flags respectively. | 6992 @option{-fno-common} and @option{-fcommon} flags respectively. |
6993 | |
6994 @item copy | |
6995 @itemx copy (@var{variable}) | |
6996 @cindex @code{copy} variable attribute | |
6997 The @code{copy} attribute applies the set of attributes with which | |
6998 @var{variable} has been declared to the declaration of the variable | |
6999 to which the attribute is applied. The attribute is designed for | |
7000 libraries that define aliases that are expected to specify the same | |
7001 set of attributes as the aliased symbols. The @code{copy} attribute | |
7002 can be used with variables, functions or types. However, the kind | |
7003 of symbol to which the attribute is applied (either varible or | |
7004 function) must match the kind of symbol to which the argument refers. | |
7005 The @code{copy} attribute copies only syntactic and semantic attributes | |
7006 but not attributes that affect a symbol's linkage or visibility such as | |
7007 @code{alias}, @code{visibility}, or @code{weak}. The @code{deprecated} | |
7008 attribute is also not copied. @xref{Common Function Attributes}. | |
7009 @xref{Common Type Attributes}. | |
6150 | 7010 |
6151 @item deprecated | 7011 @item deprecated |
6152 @itemx deprecated (@var{msg}) | 7012 @itemx deprecated (@var{msg}) |
6153 @cindex @code{deprecated} variable attribute | 7013 @cindex @code{deprecated} variable attribute |
6154 The @code{deprecated} attribute results in a warning if the variable | 7014 The @code{deprecated} attribute results in a warning if the variable |
6325 attribute also means that the member is instantiated if the | 7185 attribute also means that the member is instantiated if the |
6326 class itself is instantiated. | 7186 class itself is instantiated. |
6327 | 7187 |
6328 @item vector_size (@var{bytes}) | 7188 @item vector_size (@var{bytes}) |
6329 @cindex @code{vector_size} variable attribute | 7189 @cindex @code{vector_size} variable attribute |
6330 This attribute specifies the vector size for the variable, measured in | 7190 This attribute specifies the vector size for the type of the declared |
6331 bytes. For example, the declaration: | 7191 variable, measured in bytes. The type to which it applies is known as |
7192 the @dfn{base type}. The @var{bytes} argument must be a positive | |
7193 power-of-two multiple of the base type size. For example, the declaration: | |
6332 | 7194 |
6333 @smallexample | 7195 @smallexample |
6334 int foo __attribute__ ((vector_size (16))); | 7196 int foo __attribute__ ((vector_size (16))); |
6335 @end smallexample | 7197 @end smallexample |
6336 | 7198 |
6337 @noindent | 7199 @noindent |
6338 causes the compiler to set the mode for @code{foo}, to be 16 bytes, | 7200 causes the compiler to set the mode for @code{foo}, to be 16 bytes, |
6339 divided into @code{int} sized units. Assuming a 32-bit int (a vector of | 7201 divided into @code{int} sized units. Assuming a 32-bit @code{int}, |
6340 4 units of 4 bytes), the corresponding mode of @code{foo} is V4SI@. | 7202 @code{foo}'s type is a vector of four units of four bytes each, and |
6341 | 7203 the corresponding mode of @code{foo} is @code{V4SI}. |
6342 This attribute is only applicable to integral and float scalars, | 7204 @xref{Vector Extensions}, for details of manipulating vector variables. |
7205 | |
7206 This attribute is only applicable to integral and floating scalars, | |
6343 although arrays, pointers, and function return values are allowed in | 7207 although arrays, pointers, and function return values are allowed in |
6344 conjunction with this construct. | 7208 conjunction with this construct. |
6345 | 7209 |
6346 Aggregates with this attribute are invalid, even if they are of the same | 7210 Aggregates with this attribute are invalid, even if they are of the same |
6347 size as a corresponding scalar. For example, the declaration: | 7211 size as a corresponding scalar. For example, the declaration: |
6363 | 7227 |
6364 @item weak | 7228 @item weak |
6365 @cindex @code{weak} variable attribute | 7229 @cindex @code{weak} variable attribute |
6366 The @code{weak} attribute is described in | 7230 The @code{weak} attribute is described in |
6367 @ref{Common Function Attributes}. | 7231 @ref{Common Function Attributes}. |
7232 | |
7233 @item noinit | |
7234 @cindex @code{noinit} variable attribute | |
7235 Any data with the @code{noinit} attribute will not be initialized by | |
7236 the C runtime startup code, or the program loader. Not initializing | |
7237 data in this way can reduce program startup times. This attribute is | |
7238 specific to ELF targets and relies on the linker to place such data in | |
7239 the right location | |
6368 | 7240 |
6369 @end table | 7241 @end table |
6370 | 7242 |
6371 @node ARC Variable Attributes | 7243 @node ARC Variable Attributes |
6372 @subsection ARC Variable Attributes | 7244 @subsection ARC Variable Attributes |
6774 Persistent data is intended to be placed into FLASH RAM, where its | 7646 Persistent data is intended to be placed into FLASH RAM, where its |
6775 value will be retained across resets. The linker script being used to | 7647 value will be retained across resets. The linker script being used to |
6776 create the application should ensure that persistent data is correctly | 7648 create the application should ensure that persistent data is correctly |
6777 placed. | 7649 placed. |
6778 | 7650 |
6779 @item lower | 7651 @item upper |
6780 @itemx upper | |
6781 @itemx either | 7652 @itemx either |
6782 @cindex @code{lower} variable attribute, MSP430 | |
6783 @cindex @code{upper} variable attribute, MSP430 | 7653 @cindex @code{upper} variable attribute, MSP430 |
6784 @cindex @code{either} variable attribute, MSP430 | 7654 @cindex @code{either} variable attribute, MSP430 |
6785 These attributes are the same as the MSP430 function attributes of the | 7655 These attributes are the same as the MSP430 function attributes of the |
6786 same name (@pxref{MSP430 Function Attributes}). | 7656 same name (@pxref{MSP430 Function Attributes}). |
6787 These attributes can be applied to both functions and variables. | 7657 |
7658 @item lower | |
7659 @cindex @code{lower} variable attribute, MSP430 | |
7660 This option behaves mostly the same as the MSP430 function attribute of the | |
7661 same name (@pxref{MSP430 Function Attributes}), but it has some additional | |
7662 functionality. | |
7663 | |
7664 If @option{-mdata-region=}@{@code{upper,either,none}@} has been passed, or | |
7665 the @code{section} attribute is applied to a variable, the compiler will | |
7666 generate 430X instructions to handle it. This is because the compiler has | |
7667 to assume that the variable could get placed in the upper memory region | |
7668 (above address 0xFFFF). Marking the variable with the @code{lower} attribute | |
7669 informs the compiler that the variable will be placed in lower memory so it | |
7670 is safe to use 430 instructions to handle it. | |
7671 | |
7672 In the case of the @code{section} attribute, the section name given | |
7673 will be used, and the @code{.lower} prefix will not be added. | |
7674 | |
6788 @end table | 7675 @end table |
6789 | 7676 |
6790 @node Nvidia PTX Variable Attributes | 7677 @node Nvidia PTX Variable Attributes |
6791 @subsection Nvidia PTX Variable Attributes | 7678 @subsection Nvidia PTX Variable Attributes |
6792 | 7679 |
6822 @cindex @code{saddr} variable attribute, RL78 | 7709 @cindex @code{saddr} variable attribute, RL78 |
6823 The RL78 back end supports the @code{saddr} variable attribute. This | 7710 The RL78 back end supports the @code{saddr} variable attribute. This |
6824 specifies placement of the corresponding variable in the SADDR area, | 7711 specifies placement of the corresponding variable in the SADDR area, |
6825 which can be accessed more efficiently than the default memory region. | 7712 which can be accessed more efficiently than the default memory region. |
6826 | 7713 |
6827 @node SPU Variable Attributes | |
6828 @subsection SPU Variable Attributes | |
6829 | |
6830 @cindex @code{spu_vector} variable attribute, SPU | |
6831 The SPU supports the @code{spu_vector} attribute for variables. For | |
6832 documentation of this attribute please see the documentation in | |
6833 @ref{SPU Type Attributes}. | |
6834 | |
6835 @node V850 Variable Attributes | 7714 @node V850 Variable Attributes |
6836 @subsection V850 Variable Attributes | 7715 @subsection V850 Variable Attributes |
6837 | 7716 |
6838 These variable attributes are supported by the V850 back end: | 7717 These variable attributes are supported by the V850 back end: |
6839 | 7718 |
6904 @node Type Attributes | 7783 @node Type Attributes |
6905 @section Specifying Attributes of Types | 7784 @section Specifying Attributes of Types |
6906 @cindex attribute of types | 7785 @cindex attribute of types |
6907 @cindex type attributes | 7786 @cindex type attributes |
6908 | 7787 |
6909 The keyword @code{__attribute__} allows you to specify special | 7788 The keyword @code{__attribute__} allows you to specify various special |
6910 attributes of types. Some type attributes apply only to @code{struct} | 7789 properties of types. Some type attributes apply only to structure and |
6911 and @code{union} types, while others can apply to any type defined | 7790 union types, and in C++, also class types, while others can apply to |
6912 via a @code{typedef} declaration. Other attributes are defined for | 7791 any type defined via a @code{typedef} declaration. Unless otherwise |
6913 functions (@pxref{Function Attributes}), labels (@pxref{Label | 7792 specified, the same restrictions and effects apply to attributes regardless |
6914 Attributes}), enumerators (@pxref{Enumerator Attributes}), | 7793 of whether a type is a trivial structure or a C++ class with user-defined |
6915 statements (@pxref{Statement Attributes}), and for | 7794 constructors, destructors, or a copy assignment. |
6916 variables (@pxref{Variable Attributes}). | 7795 |
7796 Other attributes are defined for functions (@pxref{Function Attributes}), | |
7797 labels (@pxref{Label Attributes}), enumerators (@pxref{Enumerator | |
7798 Attributes}), statements (@pxref{Statement Attributes}), and for variables | |
7799 (@pxref{Variable Attributes}). | |
6917 | 7800 |
6918 The @code{__attribute__} keyword is followed by an attribute specification | 7801 The @code{__attribute__} keyword is followed by an attribute specification |
6919 inside double parentheses. | 7802 enclosed in double parentheses. |
6920 | 7803 |
6921 You may specify type attributes in an enum, struct or union type | 7804 You may specify type attributes in an enum, struct or union type |
6922 declaration or definition by placing them immediately after the | 7805 declaration or definition by placing them immediately after the |
6923 @code{struct}, @code{union} or @code{enum} keyword. A less preferred | 7806 @code{struct}, @code{union} or @code{enum} keyword. You can also place |
6924 syntax is to place them just past the closing curly brace of the | 7807 them just past the closing curly brace of the definition, but this is less |
6925 definition. | 7808 preferred because logically the type should be fully defined at |
7809 the closing brace. | |
6926 | 7810 |
6927 You can also include type attributes in a @code{typedef} declaration. | 7811 You can also include type attributes in a @code{typedef} declaration. |
6928 @xref{Attribute Syntax}, for details of the exact syntax for using | 7812 @xref{Attribute Syntax}, for details of the exact syntax for using |
6929 attributes. | 7813 attributes. |
6930 | 7814 |
6932 * Common Type Attributes:: | 7816 * Common Type Attributes:: |
6933 * ARC Type Attributes:: | 7817 * ARC Type Attributes:: |
6934 * ARM Type Attributes:: | 7818 * ARM Type Attributes:: |
6935 * MeP Type Attributes:: | 7819 * MeP Type Attributes:: |
6936 * PowerPC Type Attributes:: | 7820 * PowerPC Type Attributes:: |
6937 * SPU Type Attributes:: | |
6938 * x86 Type Attributes:: | 7821 * x86 Type Attributes:: |
6939 @end menu | 7822 @end menu |
6940 | 7823 |
6941 @node Common Type Attributes | 7824 @node Common Type Attributes |
6942 @subsection Common Type Attributes | 7825 @subsection Common Type Attributes |
6943 | 7826 |
6944 The following type attributes are supported on most targets. | 7827 The following type attributes are supported on most targets. |
6945 | 7828 |
6946 @table @code | 7829 @table @code |
6947 @cindex @code{aligned} type attribute | 7830 @cindex @code{aligned} type attribute |
6948 @item aligned (@var{alignment}) | 7831 @item aligned |
6949 This attribute specifies a minimum alignment (in bytes) for variables | 7832 @itemx aligned (@var{alignment}) |
6950 of the specified type. For example, the declarations: | 7833 The @code{aligned} attribute specifies a minimum alignment (in bytes) for |
6951 | 7834 variables of the specified type. When specified, @var{alignment} must be |
6952 @smallexample | 7835 a power of 2. Specifying no @var{alignment} argument implies the maximum |
6953 struct S @{ short f[3]; @} __attribute__ ((aligned (8))); | 7836 alignment for the target, which is often, but by no means always, 8 or 16 |
7837 bytes. For example, the declarations: | |
7838 | |
7839 @smallexample | |
7840 struct __attribute__ ((aligned (8))) S @{ short f[3]; @}; | |
6954 typedef int more_aligned_int __attribute__ ((aligned (8))); | 7841 typedef int more_aligned_int __attribute__ ((aligned (8))); |
6955 @end smallexample | 7842 @end smallexample |
6956 | 7843 |
6957 @noindent | 7844 @noindent |
6958 force the compiler to ensure (as far as it can) that each variable whose | 7845 force the compiler to ensure (as far as it can) that each variable whose |
6979 and just ask the compiler to align a type to the maximum | 7866 and just ask the compiler to align a type to the maximum |
6980 useful alignment for the target machine you are compiling for. For | 7867 useful alignment for the target machine you are compiling for. For |
6981 example, you could write: | 7868 example, you could write: |
6982 | 7869 |
6983 @smallexample | 7870 @smallexample |
6984 struct S @{ short f[3]; @} __attribute__ ((aligned)); | 7871 struct __attribute__ ((aligned)) S @{ short f[3]; @}; |
6985 @end smallexample | 7872 @end smallexample |
6986 | 7873 |
6987 Whenever you leave out the alignment factor in an @code{aligned} | 7874 Whenever you leave out the alignment factor in an @code{aligned} |
6988 attribute specification, the compiler automatically sets the alignment | 7875 attribute specification, the compiler automatically sets the alignment |
6989 for the type to the largest alignment that is ever used for any data | 7876 for the type to the largest alignment that is ever used for any data |
7014 Note that the effectiveness of @code{aligned} attributes may be limited | 7901 Note that the effectiveness of @code{aligned} attributes may be limited |
7015 by inherent limitations in your linker. On many systems, the linker is | 7902 by inherent limitations in your linker. On many systems, the linker is |
7016 only able to arrange for variables to be aligned up to a certain maximum | 7903 only able to arrange for variables to be aligned up to a certain maximum |
7017 alignment. (For some linkers, the maximum supported alignment may | 7904 alignment. (For some linkers, the maximum supported alignment may |
7018 be very very small.) If your linker is only able to align variables | 7905 be very very small.) If your linker is only able to align variables |
7019 up to a maximum of 8-byte alignment, then specifying @code{aligned(16)} | 7906 up to a maximum of 8-byte alignment, then specifying @code{aligned (16)} |
7020 in an @code{__attribute__} still only provides you with 8-byte | 7907 in an @code{__attribute__} still only provides you with 8-byte |
7021 alignment. See your linker documentation for further information. | 7908 alignment. See your linker documentation for further information. |
7022 | 7909 |
7023 The @code{aligned} attribute can only increase alignment. Alignment | 7910 When used on a struct, or struct member, the @code{aligned} attribute can |
7024 can be decreased by specifying the @code{packed} attribute. See below. | 7911 only increase the alignment; in order to decrease it, the @code{packed} |
7912 attribute must be specified as well. When used as part of a typedef, the | |
7913 @code{aligned} attribute can both increase and decrease alignment, and | |
7914 specifying the @code{packed} attribute generates a warning. | |
7025 | 7915 |
7026 @cindex @code{warn_if_not_aligned} type attribute | 7916 @cindex @code{warn_if_not_aligned} type attribute |
7027 @item warn_if_not_aligned (@var{alignment}) | 7917 @item warn_if_not_aligned (@var{alignment}) |
7028 This attribute specifies a threshold for the structure field, measured | 7918 This attribute specifies a threshold for the structure field, measured |
7029 in bytes. If the structure field is aligned below the threshold, a | 7919 in bytes. If the structure field is aligned below the threshold, a |
7030 warning will be issued. For example, the declaration: | 7920 warning will be issued. For example, the declaration: |
7031 | 7921 |
7032 @smallexample | 7922 @smallexample |
7033 typedef unsigned long long __u64 | 7923 typedef unsigned long long __u64 |
7034 __attribute__((aligned(4),warn_if_not_aligned(8))); | 7924 __attribute__((aligned (4), warn_if_not_aligned (8))); |
7035 | 7925 |
7036 struct foo | 7926 struct foo |
7037 @{ | 7927 @{ |
7038 int i1; | 7928 int i1; |
7039 int i2; | 7929 int i2; |
7048 @code{struct foo} has the same layout and the structure field @code{x} | 7938 @code{struct foo} has the same layout and the structure field @code{x} |
7049 has the same alignment when @code{__u64} is aligned at either 4 or | 7939 has the same alignment when @code{__u64} is aligned at either 4 or |
7050 8 bytes. Align @code{struct foo} to 8 bytes: | 7940 8 bytes. Align @code{struct foo} to 8 bytes: |
7051 | 7941 |
7052 @smallexample | 7942 @smallexample |
7053 struct foo | 7943 struct __attribute__ ((aligned (8))) foo |
7054 @{ | 7944 @{ |
7055 int i1; | 7945 int i1; |
7056 int i2; | 7946 int i2; |
7057 __u64 x; | 7947 __u64 x; |
7058 @} __attribute__((aligned(8))); | 7948 @}; |
7059 @end smallexample | 7949 @end smallexample |
7060 | 7950 |
7061 @noindent | 7951 @noindent |
7062 silences the warning. The compiler also issues a warning, like | 7952 silences the warning. The compiler also issues a warning, like |
7063 @samp{warning: 'x' offset 12 in 'struct foo' isn't aligned to 8}, | 7953 @samp{warning: 'x' offset 12 in 'struct foo' isn't aligned to 8}, |
7064 when the structure field has the misaligned offset: | 7954 when the structure field has the misaligned offset: |
7065 | 7955 |
7066 @smallexample | 7956 @smallexample |
7067 struct foo | 7957 struct __attribute__ ((aligned (8))) foo |
7068 @{ | 7958 @{ |
7069 int i1; | 7959 int i1; |
7070 int i2; | 7960 int i2; |
7071 int i3; | 7961 int i3; |
7072 __u64 x; | 7962 __u64 x; |
7073 @} __attribute__((aligned(8))); | 7963 @}; |
7074 @end smallexample | 7964 @end smallexample |
7075 | 7965 |
7076 This warning can be disabled by @option{-Wno-if-not-aligned}. | 7966 This warning can be disabled by @option{-Wno-if-not-aligned}. |
7967 | |
7968 @item alloc_size (@var{position}) | |
7969 @itemx alloc_size (@var{position-1}, @var{position-2}) | |
7970 @cindex @code{alloc_size} type attribute | |
7971 The @code{alloc_size} type attribute may be applied to the definition | |
7972 of a type of a function that returns a pointer and takes at least one | |
7973 argument of an integer type. It indicates that the returned pointer | |
7974 points to an object whose size is given by the function argument at | |
7975 @var{position-1}, or by the product of the arguments at @var{position-1} | |
7976 and @var{position-2}. Meaningful sizes are positive values less than | |
7977 @code{PTRDIFF_MAX}. Other sizes are disagnosed when detected. GCC uses | |
7978 this information to improve the results of @code{__builtin_object_size}. | |
7979 | |
7980 For instance, the following declarations | |
7981 | |
7982 @smallexample | |
7983 typedef __attribute__ ((alloc_size (1, 2))) void* | |
7984 calloc_type (size_t, size_t); | |
7985 typedef __attribute__ ((alloc_size (1))) void* | |
7986 malloc_type (size_t); | |
7987 @end smallexample | |
7988 | |
7989 @noindent | |
7990 specify that @code{calloc_type} is a type of a function that, like | |
7991 the standard C function @code{calloc}, returns an object whose size | |
7992 is given by the product of arguments 1 and 2, and that | |
7993 @code{malloc_type}, like the standard C function @code{malloc}, | |
7994 returns an object whose size is given by argument 1 to the function. | |
7995 | |
7996 @item copy | |
7997 @itemx copy (@var{expression}) | |
7998 @cindex @code{copy} type attribute | |
7999 The @code{copy} attribute applies the set of attributes with which | |
8000 the type of the @var{expression} has been declared to the declaration | |
8001 of the type to which the attribute is applied. The attribute is | |
8002 designed for libraries that define aliases that are expected to | |
8003 specify the same set of attributes as the aliased symbols. | |
8004 The @code{copy} attribute can be used with types, variables, or | |
8005 functions. However, the kind of symbol to which the attribute is | |
8006 applied (either varible or function) must match the kind of symbol | |
8007 to which the argument refers. | |
8008 The @code{copy} attribute copies only syntactic and semantic attributes | |
8009 but not attributes that affect a symbol's linkage or visibility such as | |
8010 @code{alias}, @code{visibility}, or @code{weak}. The @code{deprecated} | |
8011 attribute is also not copied. @xref{Common Function Attributes}. | |
8012 @xref{Common Variable Attributes}. | |
8013 | |
8014 For example, suppose @code{struct A} below is defined in some third | |
8015 party library header to have the alignment requirement @code{N} and | |
8016 to force a warning whenever a variable of the type is not so aligned | |
8017 due to attribute @code{packed}. Specifying the @code{copy} attribute | |
8018 on the definition on the unrelated @code{struct B} has the effect of | |
8019 copying all relevant attributes from the type referenced by the pointer | |
8020 expression to @code{struct B}. | |
8021 | |
8022 @smallexample | |
8023 struct __attribute__ ((aligned (N), warn_if_not_aligned (N))) | |
8024 A @{ /* @r{@dots{}} */ @}; | |
8025 struct __attribute__ ((copy ( (struct A *)0)) B @{ /* @r{@dots{}} */ @}; | |
8026 @end smallexample | |
7077 | 8027 |
7078 @item deprecated | 8028 @item deprecated |
7079 @itemx deprecated (@var{msg}) | 8029 @itemx deprecated (@var{msg}) |
7080 @cindex @code{deprecated} type attribute | 8030 @cindex @code{deprecated} type attribute |
7081 The @code{deprecated} attribute results in a warning if the type | 8031 The @code{deprecated} attribute results in a warning if the type |
7141 special semantics. | 8091 special semantics. |
7142 | 8092 |
7143 Example of use: | 8093 Example of use: |
7144 | 8094 |
7145 @smallexample | 8095 @smallexample |
7146 typedef short __attribute__((__may_alias__)) short_a; | 8096 typedef short __attribute__ ((__may_alias__)) short_a; |
7147 | 8097 |
7148 int | 8098 int |
7149 main (void) | 8099 main (void) |
7150 @{ | 8100 @{ |
7151 int a = 0x12345678; | 8101 int a = 0x12345678; |
7179 @code{__word__} for the mode of a one-word integer, and @code{pointer} | 8129 @code{__word__} for the mode of a one-word integer, and @code{pointer} |
7180 or @code{__pointer__} for the mode used to represent pointers. | 8130 or @code{__pointer__} for the mode used to represent pointers. |
7181 | 8131 |
7182 @item packed | 8132 @item packed |
7183 @cindex @code{packed} type attribute | 8133 @cindex @code{packed} type attribute |
7184 This attribute, attached to @code{struct} or @code{union} type | 8134 This attribute, attached to a @code{struct}, @code{union}, or C++ @code{class} |
7185 definition, specifies that each member (other than zero-width bit-fields) | 8135 type definition, specifies that each of its members (other than zero-width |
7186 of the structure or union is placed to minimize the memory required. When | 8136 bit-fields) is placed to minimize the memory required. This is equivalent |
7187 attached to an @code{enum} definition, it indicates that the smallest | 8137 to specifying the @code{packed} attribute on each of the members. |
7188 integral type should be used. | |
7189 | 8138 |
7190 @opindex fshort-enums | 8139 @opindex fshort-enums |
7191 Specifying the @code{packed} attribute for @code{struct} and @code{union} | 8140 When attached to an @code{enum} definition, the @code{packed} attribute |
7192 types is equivalent to specifying the @code{packed} attribute on each | 8141 indicates that the smallest integral type should be used. |
7193 of the structure or union members. Specifying the @option{-fshort-enums} | 8142 Specifying the @option{-fshort-enums} flag on the command line |
7194 flag on the command line is equivalent to specifying the @code{packed} | 8143 is equivalent to specifying the @code{packed} |
7195 attribute on all @code{enum} definitions. | 8144 attribute on all @code{enum} definitions. |
7196 | 8145 |
7197 In the following example @code{struct my_packed_struct}'s members are | 8146 In the following example @code{struct my_packed_struct}'s members are |
7198 packed closely together, but the internal layout of its @code{s} member | 8147 packed closely together, but the internal layout of its @code{s} member |
7199 is not packed---to do that, @code{struct my_unpacked_struct} needs to | 8148 is not packed---to do that, @code{struct my_unpacked_struct} needs to |
7212 int i; | 8161 int i; |
7213 struct my_unpacked_struct s; | 8162 struct my_unpacked_struct s; |
7214 @}; | 8163 @}; |
7215 @end smallexample | 8164 @end smallexample |
7216 | 8165 |
7217 You may only specify the @code{packed} attribute attribute on the definition | 8166 You may only specify the @code{packed} attribute on the definition |
7218 of an @code{enum}, @code{struct} or @code{union}, not on a @code{typedef} | 8167 of an @code{enum}, @code{struct}, @code{union}, or @code{class}, |
7219 that does not also define the enumerated type, structure or union. | 8168 not on a @code{typedef} that does not also define the enumerated type, |
8169 structure, union, or class. | |
7220 | 8170 |
7221 @item scalar_storage_order ("@var{endianness}") | 8171 @item scalar_storage_order ("@var{endianness}") |
7222 @cindex @code{scalar_storage_order} type attribute | 8172 @cindex @code{scalar_storage_order} type attribute |
7223 When attached to a @code{union} or a @code{struct}, this attribute sets | 8173 When attached to a @code{union} or a @code{struct}, this attribute sets |
7224 the storage order, aka endianness, of the scalar fields of the type, as | 8174 the storage order, aka endianness, of the scalar fields of the type, as |
7228 or an array whose component is a @code{union} or a @code{struct}, and it is | 8178 or an array whose component is a @code{union} or a @code{struct}, and it is |
7229 possible for these fields to have a different scalar storage order than the | 8179 possible for these fields to have a different scalar storage order than the |
7230 enclosing type. | 8180 enclosing type. |
7231 | 8181 |
7232 This attribute is supported only for targets that use a uniform default | 8182 This attribute is supported only for targets that use a uniform default |
7233 scalar storage order (fortunately, most of them), i.e. targets that store | 8183 scalar storage order (fortunately, most of them), i.e.@: targets that store |
7234 the scalars either all in big-endian or all in little-endian. | 8184 the scalars either all in big-endian or all in little-endian. |
7235 | 8185 |
7236 Additional restrictions are enforced for types with the reverse scalar | 8186 Additional restrictions are enforced for types with the reverse scalar |
7237 storage order with regard to the scalar storage order of the target: | 8187 storage order with regard to the scalar storage order of the target: |
7238 | 8188 |
7328 that type, even if the variable appears to do nothing. This is often | 8278 that type, even if the variable appears to do nothing. This is often |
7329 the case with lock or thread classes, which are usually defined and then | 8279 the case with lock or thread classes, which are usually defined and then |
7330 not referenced, but contain constructors and destructors that have | 8280 not referenced, but contain constructors and destructors that have |
7331 nontrivial bookkeeping functions. | 8281 nontrivial bookkeeping functions. |
7332 | 8282 |
8283 @item vector_size (@var{bytes}) | |
8284 @cindex @code{vector_size} type attribute | |
8285 This attribute specifies the vector size for the type, measured in bytes. | |
8286 The type to which it applies is known as the @dfn{base type}. The @var{bytes} | |
8287 argument must be a positive power-of-two multiple of the base type size. For | |
8288 example, the following declarations: | |
8289 | |
8290 @smallexample | |
8291 typedef __attribute__ ((vector_size (32))) int int_vec32_t ; | |
8292 typedef __attribute__ ((vector_size (32))) int* int_vec32_ptr_t; | |
8293 typedef __attribute__ ((vector_size (32))) int int_vec32_arr3_t[3]; | |
8294 @end smallexample | |
8295 | |
8296 @noindent | |
8297 define @code{int_vec32_t} to be a 32-byte vector type composed of @code{int} | |
8298 sized units. With @code{int} having a size of 4 bytes, the type defines | |
8299 a vector of eight units, four bytes each. The mode of variables of type | |
8300 @code{int_vec32_t} is @code{V8SI}. @code{int_vec32_ptr_t} is then defined | |
8301 to be a pointer to such a vector type, and @code{int_vec32_arr3_t} to be | |
8302 an array of three such vectors. @xref{Vector Extensions}, for details of | |
8303 manipulating objects of vector types. | |
8304 | |
8305 This attribute is only applicable to integral and floating scalar types. | |
8306 In function declarations the attribute applies to the function return | |
8307 type. | |
8308 | |
8309 For example, the following: | |
8310 @smallexample | |
8311 __attribute__ ((vector_size (16))) float get_flt_vec16 (void); | |
8312 @end smallexample | |
8313 declares @code{get_flt_vec16} to be a function returning a 16-byte vector | |
8314 with the base type @code{float}. | |
8315 | |
7333 @item visibility | 8316 @item visibility |
7334 @cindex @code{visibility} type attribute | 8317 @cindex @code{visibility} type attribute |
7335 In C++, attribute visibility (@pxref{Function Attributes}) can also be | 8318 In C++, attribute visibility (@pxref{Function Attributes}) can also be |
7336 applied to class, struct, union and enum types. Unlike other type | 8319 applied to class, struct, union and enum types. Unlike other type |
7337 attributes, the attribute must appear between the initial keyword and | 8320 attributes, the attribute must appear between the initial keyword and |
7422 __attribute__((altivec(bool__))) unsigned | 8405 __attribute__((altivec(bool__))) unsigned |
7423 @end smallexample | 8406 @end smallexample |
7424 | 8407 |
7425 These attributes mainly are intended to support the @code{__vector}, | 8408 These attributes mainly are intended to support the @code{__vector}, |
7426 @code{__pixel}, and @code{__bool} AltiVec keywords. | 8409 @code{__pixel}, and @code{__bool} AltiVec keywords. |
7427 | |
7428 @node SPU Type Attributes | |
7429 @subsection SPU Type Attributes | |
7430 | |
7431 @cindex @code{spu_vector} type attribute, SPU | |
7432 The SPU supports the @code{spu_vector} attribute for types. This attribute | |
7433 allows one to declare vector data types supported by the Sony/Toshiba/IBM SPU | |
7434 Language Extensions Specification. It is intended to support the | |
7435 @code{__vector} keyword. | |
7436 | 8410 |
7437 @node x86 Type Attributes | 8411 @node x86 Type Attributes |
7438 @subsection x86 Type Attributes | 8412 @subsection x86 Type Attributes |
7439 | 8413 |
7440 Two attributes are currently defined for x86 configurations: | 8414 Two attributes are currently defined for x86 configurations: |
7942 | 8916 |
7943 You can use the sequence @samp{\e} in a string or character constant to | 8917 You can use the sequence @samp{\e} in a string or character constant to |
7944 stand for the ASCII character @key{ESC}. | 8918 stand for the ASCII character @key{ESC}. |
7945 | 8919 |
7946 @node Alignment | 8920 @node Alignment |
7947 @section Inquiring on Alignment of Types or Variables | 8921 @section Determining the Alignment of Functions, Types or Variables |
7948 @cindex alignment | 8922 @cindex alignment |
7949 @cindex type alignment | 8923 @cindex type alignment |
7950 @cindex variable alignment | 8924 @cindex variable alignment |
7951 | 8925 |
7952 The keyword @code{__alignof__} allows you to inquire about how an object | 8926 The keyword @code{__alignof__} determines the alignment requirement of |
7953 is aligned, or the minimum alignment usually required by a type. Its | 8927 a function, object, or a type, or the minimum alignment usually required |
7954 syntax is just like @code{sizeof}. | 8928 by a type. Its syntax is just like @code{sizeof} and C11 @code{_Alignof}. |
7955 | 8929 |
7956 For example, if the target machine requires a @code{double} value to be | 8930 For example, if the target machine requires a @code{double} value to be |
7957 aligned on an 8-byte boundary, then @code{__alignof__ (double)} is 8. | 8931 aligned on an 8-byte boundary, then @code{__alignof__ (double)} is 8. |
7958 This is true on many RISC machines. On more traditional machine | 8932 This is true on many RISC machines. On more traditional machine |
7959 designs, @code{__alignof__ (double)} is 4 or even 2. | 8933 designs, @code{__alignof__ (double)} is 4 or even 2. |
7960 | 8934 |
7961 Some machines never actually require alignment; they allow reference to any | 8935 Some machines never actually require alignment; they allow references to any |
7962 data type even at an odd address. For these machines, @code{__alignof__} | 8936 data type even at an odd address. For these machines, @code{__alignof__} |
7963 reports the smallest alignment that GCC gives the data type, usually as | 8937 reports the smallest alignment that GCC gives the data type, usually as |
7964 mandated by the target ABI. | 8938 mandated by the target ABI. |
7965 | 8939 |
7966 If the operand of @code{__alignof__} is an lvalue rather than a type, | 8940 If the operand of @code{__alignof__} is an lvalue rather than a type, |
7967 its value is the required alignment for its type, taking into account | 8941 its value is the required alignment for its type, taking into account |
7968 any minimum alignment specified with GCC's @code{__attribute__} | 8942 any minimum alignment specified by attribute @code{aligned} |
7969 extension (@pxref{Variable Attributes}). For example, after this | 8943 (@pxref{Common Variable Attributes}). For example, after this |
7970 declaration: | 8944 declaration: |
7971 | 8945 |
7972 @smallexample | 8946 @smallexample |
7973 struct foo @{ int x; char y; @} foo1; | 8947 struct foo @{ int x; char y; @} foo1; |
7974 @end smallexample | 8948 @end smallexample |
7975 | 8949 |
7976 @noindent | 8950 @noindent |
7977 the value of @code{__alignof__ (foo1.y)} is 1, even though its actual | 8951 the value of @code{__alignof__ (foo1.y)} is 1, even though its actual |
7978 alignment is probably 2 or 4, the same as @code{__alignof__ (int)}. | 8952 alignment is probably 2 or 4, the same as @code{__alignof__ (int)}. |
7979 | 8953 It is an error to ask for the alignment of an incomplete type other |
7980 It is an error to ask for the alignment of an incomplete type. | 8954 than @code{void}. |
7981 | 8955 |
8956 If the operand of the @code{__alignof__} expression is a function, | |
8957 the expression evaluates to the alignment of the function which may | |
8958 be specified by attribute @code{aligned} (@pxref{Common Function Attributes}). | |
7982 | 8959 |
7983 @node Inline | 8960 @node Inline |
7984 @section An Inline Function is As Fast As a Macro | 8961 @section An Inline Function is As Fast As a Macro |
7985 @cindex inline functions | 8962 @cindex inline functions |
7986 @cindex integrating function code | 8963 @cindex integrating function code |
8222 @cindex assembly language in C, basic | 9199 @cindex assembly language in C, basic |
8223 | 9200 |
8224 A basic @code{asm} statement has the following syntax: | 9201 A basic @code{asm} statement has the following syntax: |
8225 | 9202 |
8226 @example | 9203 @example |
8227 asm @r{[} volatile @r{]} ( @var{AssemblerInstructions} ) | 9204 asm @var{asm-qualifiers} ( @var{AssemblerInstructions} ) |
8228 @end example | 9205 @end example |
8229 | 9206 |
8230 The @code{asm} keyword is a GNU extension. | 9207 The @code{asm} keyword is a GNU extension. |
8231 When writing code that can be compiled with @option{-ansi} and the | 9208 When writing code that can be compiled with @option{-ansi} and the |
8232 various @option{-std} options, use @code{__asm__} instead of | 9209 various @option{-std} options, use @code{__asm__} instead of |
8235 @subsubheading Qualifiers | 9212 @subsubheading Qualifiers |
8236 @table @code | 9213 @table @code |
8237 @item volatile | 9214 @item volatile |
8238 The optional @code{volatile} qualifier has no effect. | 9215 The optional @code{volatile} qualifier has no effect. |
8239 All basic @code{asm} blocks are implicitly volatile. | 9216 All basic @code{asm} blocks are implicitly volatile. |
9217 | |
9218 @item inline | |
9219 If you use the @code{inline} qualifier, then for inlining purposes the size | |
9220 of the @code{asm} statement is taken as the smallest size possible (@pxref{Size | |
9221 of an asm}). | |
8240 @end table | 9222 @end table |
8241 | 9223 |
8242 @subsubheading Parameters | 9224 @subsubheading Parameters |
8243 @table @var | 9225 @table @var |
8244 | 9226 |
8268 function, so to write inline assembly language at file scope (``top-level''), | 9250 function, so to write inline assembly language at file scope (``top-level''), |
8269 outside of C functions, you must use basic @code{asm}. | 9251 outside of C functions, you must use basic @code{asm}. |
8270 You can use this technique to emit assembler directives, | 9252 You can use this technique to emit assembler directives, |
8271 define assembly language macros that can be invoked elsewhere in the file, | 9253 define assembly language macros that can be invoked elsewhere in the file, |
8272 or write entire functions in assembly language. | 9254 or write entire functions in assembly language. |
9255 Basic @code{asm} statements outside of functions may not use any | |
9256 qualifiers. | |
8273 | 9257 |
8274 @item | 9258 @item |
8275 Functions declared | 9259 Functions declared |
8276 with the @code{naked} attribute also require basic @code{asm} | 9260 with the @code{naked} attribute also require basic @code{asm} |
8277 (@pxref{Function Attributes}). | 9261 (@pxref{Function Attributes}). |
8350 assembler and perform jumps from assembler code to C labels. | 9334 assembler and perform jumps from assembler code to C labels. |
8351 Extended @code{asm} syntax uses colons (@samp{:}) to delimit | 9335 Extended @code{asm} syntax uses colons (@samp{:}) to delimit |
8352 the operand parameters after the assembler template: | 9336 the operand parameters after the assembler template: |
8353 | 9337 |
8354 @example | 9338 @example |
8355 asm @r{[}volatile@r{]} ( @var{AssemblerTemplate} | 9339 asm @var{asm-qualifiers} ( @var{AssemblerTemplate} |
8356 : @var{OutputOperands} | 9340 : @var{OutputOperands} |
8357 @r{[} : @var{InputOperands} | 9341 @r{[} : @var{InputOperands} |
8358 @r{[} : @var{Clobbers} @r{]} @r{]}) | 9342 @r{[} : @var{Clobbers} @r{]} @r{]}) |
8359 | 9343 |
8360 asm @r{[}volatile@r{]} goto ( @var{AssemblerTemplate} | 9344 asm @var{asm-qualifiers} ( @var{AssemblerTemplate} |
8361 : | 9345 : |
8362 : @var{InputOperands} | 9346 : @var{InputOperands} |
8363 : @var{Clobbers} | 9347 : @var{Clobbers} |
8364 : @var{GotoLabels}) | 9348 : @var{GotoLabels}) |
8365 @end example | 9349 @end example |
9350 where in the last form, @var{asm-qualifiers} contains @code{goto} (and in the | |
9351 first form, not). | |
8366 | 9352 |
8367 The @code{asm} keyword is a GNU extension. | 9353 The @code{asm} keyword is a GNU extension. |
8368 When writing code that can be compiled with @option{-ansi} and the | 9354 When writing code that can be compiled with @option{-ansi} and the |
8369 various @option{-std} options, use @code{__asm__} instead of | 9355 various @option{-std} options, use @code{__asm__} instead of |
8370 @code{asm} (@pxref{Alternate Keywords}). | 9356 @code{asm} (@pxref{Alternate Keywords}). |
8375 @item volatile | 9361 @item volatile |
8376 The typical use of extended @code{asm} statements is to manipulate input | 9362 The typical use of extended @code{asm} statements is to manipulate input |
8377 values to produce output values. However, your @code{asm} statements may | 9363 values to produce output values. However, your @code{asm} statements may |
8378 also produce side effects. If so, you may need to use the @code{volatile} | 9364 also produce side effects. If so, you may need to use the @code{volatile} |
8379 qualifier to disable certain optimizations. @xref{Volatile}. | 9365 qualifier to disable certain optimizations. @xref{Volatile}. |
9366 | |
9367 @item inline | |
9368 If you use the @code{inline} qualifier, then for inlining purposes the size | |
9369 of the @code{asm} statement is taken as the smallest size possible | |
9370 (@pxref{Size of an asm}). | |
8380 | 9371 |
8381 @item goto | 9372 @item goto |
8382 This qualifier informs the compiler that the @code{asm} statement may | 9373 This qualifier informs the compiler that the @code{asm} statement may |
8383 perform a jump to one of the labels listed in the @var{GotoLabels}. | 9374 perform a jump to one of the labels listed in the @var{GotoLabels}. |
8384 @xref{GotoLabels}. | 9375 @xref{GotoLabels}. |
8454 @cindex @code{asm} volatile | 9445 @cindex @code{asm} volatile |
8455 | 9446 |
8456 GCC's optimizers sometimes discard @code{asm} statements if they determine | 9447 GCC's optimizers sometimes discard @code{asm} statements if they determine |
8457 there is no need for the output variables. Also, the optimizers may move | 9448 there is no need for the output variables. Also, the optimizers may move |
8458 code out of loops if they believe that the code will always return the same | 9449 code out of loops if they believe that the code will always return the same |
8459 result (i.e. none of its input values change between calls). Using the | 9450 result (i.e.@: none of its input values change between calls). Using the |
8460 @code{volatile} qualifier disables these optimizations. @code{asm} statements | 9451 @code{volatile} qualifier disables these optimizations. @code{asm} statements |
8461 that have no output operands, including @code{asm goto} statements, | 9452 that have no output operands, including @code{asm goto} statements, |
8462 are implicitly volatile. | 9453 are implicitly volatile. |
8463 | 9454 |
8464 This i386 code demonstrates a case that does not use (or require) the | 9455 This i386 code demonstrates a case that does not use (or require) the |
8486 @end example | 9477 @end example |
8487 | 9478 |
8488 The next example shows a case where the optimizers can recognize that the input | 9479 The next example shows a case where the optimizers can recognize that the input |
8489 (@code{dwSomeValue}) never changes during the execution of the function and can | 9480 (@code{dwSomeValue}) never changes during the execution of the function and can |
8490 therefore move the @code{asm} outside the loop to produce more efficient code. | 9481 therefore move the @code{asm} outside the loop to produce more efficient code. |
8491 Again, using @code{volatile} disables this type of optimization. | 9482 Again, using the @code{volatile} qualifier disables this type of optimization. |
8492 | 9483 |
8493 @example | 9484 @example |
8494 void do_print(uint32_t dwSomeValue) | 9485 void do_print(uint32_t dwSomeValue) |
8495 @{ | 9486 @{ |
8496 uint32_t dwRes; | 9487 uint32_t dwRes; |
8542 | 9533 |
8543 GCC's optimizers do not treat this code like the non-volatile code in the | 9534 GCC's optimizers do not treat this code like the non-volatile code in the |
8544 earlier examples. They do not move it out of loops or omit it on the | 9535 earlier examples. They do not move it out of loops or omit it on the |
8545 assumption that the result from a previous call is still valid. | 9536 assumption that the result from a previous call is still valid. |
8546 | 9537 |
8547 Note that the compiler can move even volatile @code{asm} instructions relative | 9538 Note that the compiler can move even @code{volatile asm} instructions relative |
8548 to other code, including across jump instructions. For example, on many | 9539 to other code, including across jump instructions. For example, on many |
8549 targets there is a system register that controls the rounding mode of | 9540 targets there is a system register that controls the rounding mode of |
8550 floating-point operations. Setting it with a volatile @code{asm}, as in the | 9541 floating-point operations. Setting it with a @code{volatile asm} statement, |
8551 following PowerPC example, does not work reliably. | 9542 as in the following PowerPC example, does not work reliably. |
8552 | 9543 |
8553 @example | 9544 @example |
8554 asm volatile("mtfsf 255, %0" : : "f" (fpenv)); | 9545 asm volatile("mtfsf 255, %0" : : "f" (fpenv)); |
8555 sum = x + y; | 9546 sum = x + y; |
8556 @end example | 9547 @end example |
8557 | 9548 |
8558 The compiler may move the addition back before the volatile @code{asm}. To | 9549 The compiler may move the addition back before the @code{volatile asm} |
8559 make it work as expected, add an artificial dependency to the @code{asm} by | 9550 statement. To make it work as expected, add an artificial dependency to |
8560 referencing a variable in the subsequent code, for example: | 9551 the @code{asm} by referencing a variable in the subsequent code, for |
9552 example: | |
8561 | 9553 |
8562 @example | 9554 @example |
8563 asm volatile ("mtfsf 255,%1" : "=X" (sum) : "f" (fpenv)); | 9555 asm volatile ("mtfsf 255,%1" : "=X" (sum) : "f" (fpenv)); |
8564 sum = x + y; | 9556 sum = x + y; |
8565 @end example | 9557 @end example |
8566 | 9558 |
8567 Under certain circumstances, GCC may duplicate (or remove duplicates of) your | 9559 Under certain circumstances, GCC may duplicate (or remove duplicates of) your |
8568 assembly code when optimizing. This can lead to unexpected duplicate symbol | 9560 assembly code when optimizing. This can lead to unexpected duplicate symbol |
8569 errors during compilation if your asm code defines symbols or labels. | 9561 errors during compilation if your @code{asm} code defines symbols or labels. |
8570 Using @samp{%=} | 9562 Using @samp{%=} |
8571 (@pxref{AssemblerTemplate}) may help resolve this problem. | 9563 (@pxref{AssemblerTemplate}) may help resolve this problem. |
8572 | 9564 |
8573 @anchor{AssemblerTemplate} | 9565 @anchor{AssemblerTemplate} |
8574 @subsubsection Assembler Template | 9566 @subsubsection Assembler Template |
8593 that some assembler dialects use semicolons to start a comment. | 9585 that some assembler dialects use semicolons to start a comment. |
8594 | 9586 |
8595 Do not expect a sequence of @code{asm} statements to remain perfectly | 9587 Do not expect a sequence of @code{asm} statements to remain perfectly |
8596 consecutive after compilation, even when you are using the @code{volatile} | 9588 consecutive after compilation, even when you are using the @code{volatile} |
8597 qualifier. If certain instructions need to remain consecutive in the output, | 9589 qualifier. If certain instructions need to remain consecutive in the output, |
8598 put them in a single multi-instruction asm statement. | 9590 put them in a single multi-instruction @code{asm} statement. |
8599 | 9591 |
8600 Accessing data from C programs without using input/output operands (such as | 9592 Accessing data from C programs without using input/output operands (such as |
8601 by using global symbols directly from the assembler template) may not work as | 9593 by using global symbols directly from the assembler template) may not work as |
8602 expected. Similarly, calling functions directly from an assembler template | 9594 expected. Similarly, calling functions directly from an assembler template |
8603 requires a detailed understanding of the target assembler and ABI. | 9595 requires a detailed understanding of the target assembler and ABI. |
8719 @table @var | 9711 @table @var |
8720 @item asmSymbolicName | 9712 @item asmSymbolicName |
8721 Specifies a symbolic name for the operand. | 9713 Specifies a symbolic name for the operand. |
8722 Reference the name in the assembler template | 9714 Reference the name in the assembler template |
8723 by enclosing it in square brackets | 9715 by enclosing it in square brackets |
8724 (i.e. @samp{%[Value]}). The scope of the name is the @code{asm} statement | 9716 (i.e.@: @samp{%[Value]}). The scope of the name is the @code{asm} statement |
8725 that contains the definition. Any valid C variable name is acceptable, | 9717 that contains the definition. Any valid C variable name is acceptable, |
8726 including names already defined in the surrounding code. No two operands | 9718 including names already defined in the surrounding code. No two operands |
8727 within the same @code{asm} statement can use the same symbolic name. | 9719 within the same @code{asm} statement can use the same symbolic name. |
8728 | 9720 |
8729 When not using an @var{asmSymbolicName}, use the (zero-based) position | 9721 When not using an @var{asmSymbolicName}, use the (zero-based) position |
8786 constraint and another output parameter (@var{b}) allows a memory constraint. | 9778 constraint and another output parameter (@var{b}) allows a memory constraint. |
8787 The code generated by GCC to access the memory address in @var{b} can contain | 9779 The code generated by GCC to access the memory address in @var{b} can contain |
8788 registers which @emph{might} be shared by @var{a}, and GCC considers those | 9780 registers which @emph{might} be shared by @var{a}, and GCC considers those |
8789 registers to be inputs to the asm. As above, GCC assumes that such input | 9781 registers to be inputs to the asm. As above, GCC assumes that such input |
8790 registers are consumed before any outputs are written. This assumption may | 9782 registers are consumed before any outputs are written. This assumption may |
8791 result in incorrect behavior if the asm writes to @var{a} before using | 9783 result in incorrect behavior if the @code{asm} statement writes to @var{a} |
9784 before using | |
8792 @var{b}. Combining the @samp{&} modifier with the register constraint on @var{a} | 9785 @var{b}. Combining the @samp{&} modifier with the register constraint on @var{a} |
8793 ensures that modifying @var{a} does not affect the address referenced by | 9786 ensures that modifying @var{a} does not affect the address referenced by |
8794 @var{b}. Otherwise, the location of @var{b} | 9787 @var{b}. Otherwise, the location of @var{b} |
8795 is undefined if @var{a} is modified before using @var{b}. | 9788 is undefined if @var{a} is modified before using @var{b}. |
8796 | 9789 |
8868 @subsubsection Flag Output Operands | 9861 @subsubsection Flag Output Operands |
8869 @cindex @code{asm} flag output operands | 9862 @cindex @code{asm} flag output operands |
8870 | 9863 |
8871 Some targets have a special register that holds the ``flags'' for the | 9864 Some targets have a special register that holds the ``flags'' for the |
8872 result of an operation or comparison. Normally, the contents of that | 9865 result of an operation or comparison. Normally, the contents of that |
8873 register are either unmodifed by the asm, or the asm is considered to | 9866 register are either unmodifed by the asm, or the @code{asm} statement is |
8874 clobber the contents. | 9867 considered to clobber the contents. |
8875 | 9868 |
8876 On some targets, a special form of output operand exists by which | 9869 On some targets, a special form of output operand exists by which |
8877 conditions in the flags register may be outputs of the asm. The set of | 9870 conditions in the flags register may be outputs of the asm. The set of |
8878 conditions supported are target specific, but the general rule is that | 9871 conditions supported are target specific, but the general rule is that |
8879 the output variable must be a scalar integer, and the value is boolean. | 9872 the output variable must be a scalar integer, and the value is boolean. |
8887 operand of many instructions. In this case, the operand should not be | 9880 operand of many instructions. In this case, the operand should not be |
8888 referenced within the assembler template via @code{%0} etc, as there's | 9881 referenced within the assembler template via @code{%0} etc, as there's |
8889 no corresponding text in the assembly language. | 9882 no corresponding text in the assembly language. |
8890 | 9883 |
8891 @table @asis | 9884 @table @asis |
9885 @item ARM | |
9886 @itemx AArch64 | |
9887 The flag output constraints for the ARM family are of the form | |
9888 @samp{=@@cc@var{cond}} where @var{cond} is one of the standard | |
9889 conditions defined in the ARM ARM for @code{ConditionHolds}. | |
9890 | |
9891 @table @code | |
9892 @item eq | |
9893 Z flag set, or equal | |
9894 @item ne | |
9895 Z flag clear or not equal | |
9896 @item cs | |
9897 @itemx hs | |
9898 C flag set or unsigned greater than equal | |
9899 @item cc | |
9900 @itemx lo | |
9901 C flag clear or unsigned less than | |
9902 @item mi | |
9903 N flag set or ``minus'' | |
9904 @item pl | |
9905 N flag clear or ``plus'' | |
9906 @item vs | |
9907 V flag set or signed overflow | |
9908 @item vc | |
9909 V flag clear | |
9910 @item hi | |
9911 unsigned greater than | |
9912 @item ls | |
9913 unsigned less than equal | |
9914 @item ge | |
9915 signed greater than equal | |
9916 @item lt | |
9917 signed less than | |
9918 @item gt | |
9919 signed greater than | |
9920 @item le | |
9921 signed less than equal | |
9922 @end table | |
9923 | |
9924 The flag output constraints are not supported in thumb1 mode. | |
9925 | |
8892 @item x86 family | 9926 @item x86 family |
8893 The flag output constraints for the x86 family are of the form | 9927 The flag output constraints for the x86 family are of the form |
8894 @samp{=@@cc@var{cond}} where @var{cond} is one of the standard | 9928 @samp{=@@cc@var{cond}} where @var{cond} is one of the standard |
8895 conditions defined in the ISA manual for @code{j@var{cc}} or | 9929 conditions defined in the ISA manual for @code{j@var{cc}} or |
8896 @code{set@var{cc}}. | 9930 @code{set@var{cc}}. |
8959 @table @var | 9993 @table @var |
8960 @item asmSymbolicName | 9994 @item asmSymbolicName |
8961 Specifies a symbolic name for the operand. | 9995 Specifies a symbolic name for the operand. |
8962 Reference the name in the assembler template | 9996 Reference the name in the assembler template |
8963 by enclosing it in square brackets | 9997 by enclosing it in square brackets |
8964 (i.e. @samp{%[Value]}). The scope of the name is the @code{asm} statement | 9998 (i.e.@: @samp{%[Value]}). The scope of the name is the @code{asm} statement |
8965 that contains the definition. Any valid C variable name is acceptable, | 9999 that contains the definition. Any valid C variable name is acceptable, |
8966 including names already defined in the surrounding code. No two operands | 10000 including names already defined in the surrounding code. No two operands |
8967 within the same @code{asm} statement can use the same symbolic name. | 10001 within the same @code{asm} statement can use the same symbolic name. |
8968 | 10002 |
8969 When not using an @var{asmSymbolicName}, use the (zero-based) position | 10003 When not using an @var{asmSymbolicName}, use the (zero-based) position |
9074 operands get modified without also specifying them as output operands. | 10108 operands get modified without also specifying them as output operands. |
9075 | 10109 |
9076 When the compiler selects which registers to use to represent input and output | 10110 When the compiler selects which registers to use to represent input and output |
9077 operands, it does not use any of the clobbered registers. As a result, | 10111 operands, it does not use any of the clobbered registers. As a result, |
9078 clobbered registers are available for any use in the assembler code. | 10112 clobbered registers are available for any use in the assembler code. |
10113 | |
10114 Another restriction is that the clobber list should not contain the | |
10115 stack pointer register. This is because the compiler requires the | |
10116 value of the stack pointer to be the same after an @code{asm} | |
10117 statement as it was on entry to the statement. However, previous | |
10118 versions of GCC did not enforce this rule and allowed the stack | |
10119 pointer to appear in the list, with unclear semantics. This behavior | |
10120 is deprecated and listing the stack pointer may become an error in | |
10121 future versions of GCC@. | |
9079 | 10122 |
9080 Here is a realistic example for the VAX showing the use of clobbered | 10123 Here is a realistic example for the VAX showing the use of clobbered |
9081 registers: | 10124 registers: |
9082 | 10125 |
9083 @example | 10126 @example |
9688 @option{-ffixed-@var{reg}} (@pxref{Code Gen Options}) to reserve the | 10731 @option{-ffixed-@var{reg}} (@pxref{Code Gen Options}) to reserve the |
9689 register. | 10732 register. |
9690 | 10733 |
9691 @subsubheading Declaring the variable | 10734 @subsubheading Declaring the variable |
9692 | 10735 |
9693 Global register variables can not have initial values, because an | 10736 Global register variables cannot have initial values, because an |
9694 executable file has no means to supply initial contents for a register. | 10737 executable file has no means to supply initial contents for a register. |
9695 | 10738 |
9696 When selecting a register, choose one that is normally saved and | 10739 When selecting a register, choose one that is normally saved and |
9697 restored by function calls on your machine. This ensures that code | 10740 restored by function calls on your machine. This ensures that code |
9698 which is unaware of this reservation (such as library routines) will | 10741 which is unaware of this reservation (such as library routines) will |
9834 assembler, GCC must make an estimate as to how big it will be. It | 10877 assembler, GCC must make an estimate as to how big it will be. It |
9835 does this by counting the number of instructions in the pattern of the | 10878 does this by counting the number of instructions in the pattern of the |
9836 @code{asm} and multiplying that by the length of the longest | 10879 @code{asm} and multiplying that by the length of the longest |
9837 instruction supported by that processor. (When working out the number | 10880 instruction supported by that processor. (When working out the number |
9838 of instructions, it assumes that any occurrence of a newline or of | 10881 of instructions, it assumes that any occurrence of a newline or of |
9839 whatever statement separator character is supported by the assembler -- | 10882 whatever statement separator character is supported by the assembler --- |
9840 typically @samp{;} --- indicates the end of an instruction.) | 10883 typically @samp{;} --- indicates the end of an instruction.) |
9841 | 10884 |
9842 Normally, GCC's estimate is adequate to ensure that correct | 10885 Normally, GCC's estimate is adequate to ensure that correct |
9843 code is generated, but it is possible to confuse the compiler if you use | 10886 code is generated, but it is possible to confuse the compiler if you use |
9844 pseudo instructions or assembler macros that expand into multiple real | 10887 pseudo instructions or assembler macros that expand into multiple real |
9845 instructions, or if you use assembler directives that expand to more | 10888 instructions, or if you use assembler directives that expand to more |
9846 space in the object file than is needed for a single instruction. | 10889 space in the object file than is needed for a single instruction. |
9847 If this happens then the assembler may produce a diagnostic saying that | 10890 If this happens then the assembler may produce a diagnostic saying that |
9848 a label is unreachable. | 10891 a label is unreachable. |
9849 | 10892 |
10893 @cindex @code{asm inline} | |
10894 This size is also used for inlining decisions. If you use @code{asm inline} | |
10895 instead of just @code{asm}, then for inlining purposes the size of the asm | |
10896 is taken as the minimum size, ignoring how many instructions GCC thinks it is. | |
10897 | |
9850 @node Alternate Keywords | 10898 @node Alternate Keywords |
9851 @section Alternate Keywords | 10899 @section Alternate Keywords |
9852 @cindex alternate keywords | 10900 @cindex alternate keywords |
9853 @cindex keywords, alternate | 10901 @cindex keywords, alternate |
9854 | 10902 |
9856 keywords. This causes trouble when you want to use GNU C extensions, or | 10904 keywords. This causes trouble when you want to use GNU C extensions, or |
9857 a general-purpose header file that should be usable by all programs, | 10905 a general-purpose header file that should be usable by all programs, |
9858 including ISO C programs. The keywords @code{asm}, @code{typeof} and | 10906 including ISO C programs. The keywords @code{asm}, @code{typeof} and |
9859 @code{inline} are not available in programs compiled with | 10907 @code{inline} are not available in programs compiled with |
9860 @option{-ansi} or @option{-std} (although @code{inline} can be used in a | 10908 @option{-ansi} or @option{-std} (although @code{inline} can be used in a |
9861 program compiled with @option{-std=c99} or @option{-std=c11}). The | 10909 program compiled with @option{-std=c99} or a later standard). The |
9862 ISO C99 keyword | 10910 ISO C99 keyword |
9863 @code{restrict} is only available when @option{-std=gnu99} (which will | 10911 @code{restrict} is only available when @option{-std=gnu99} (which will |
9864 eventually be the default) or @option{-std=c99} (or the equivalent | 10912 eventually be the default) or @option{-std=c99} (or the equivalent |
9865 @option{-std=iso9899:1999}), or an option for a later standard | 10913 @option{-std=iso9899:1999}), or an option for a later standard |
9866 version, is used. | 10914 version, is used. |
9932 | 10980 |
9933 @code{__FUNCTION__} is another name for @code{__func__}, provided for | 10981 @code{__FUNCTION__} is another name for @code{__func__}, provided for |
9934 backward compatibility with old versions of GCC. | 10982 backward compatibility with old versions of GCC. |
9935 | 10983 |
9936 In C, @code{__PRETTY_FUNCTION__} is yet another name for | 10984 In C, @code{__PRETTY_FUNCTION__} is yet another name for |
9937 @code{__func__}, except that at file (or, in C++, namespace scope), | 10985 @code{__func__}, except that at file scope (or, in C++, namespace scope), |
9938 it evaluates to the string @code{"top level"}. In addition, in C++, | 10986 it evaluates to the string @code{"top level"}. In addition, in C++, |
9939 @code{__PRETTY_FUNCTION__} contains the signature of the function as | 10987 @code{__PRETTY_FUNCTION__} contains the signature of the function as |
9940 well as its bare name. For example, this program: | 10988 well as its bare name. For example, this program: |
9941 | 10989 |
9942 @smallexample | 10990 @smallexample |
10014 executed. | 11062 executed. |
10015 | 11063 |
10016 If no fixup is needed, this function simply passes through @var{addr}. | 11064 If no fixup is needed, this function simply passes through @var{addr}. |
10017 @end deftypefn | 11065 @end deftypefn |
10018 | 11066 |
10019 @deftypefn {Built-in Function} {void *} __builtin_frob_return_address (void *@var{addr}) | 11067 @deftypefn {Built-in Function} {void *} __builtin_frob_return_addr (void *@var{addr}) |
10020 This function does the reverse of @code{__builtin_extract_return_addr}. | 11068 This function does the reverse of @code{__builtin_extract_return_addr}. |
10021 @end deftypefn | 11069 @end deftypefn |
10022 | 11070 |
10023 @deftypefn {Built-in Function} {void *} __builtin_frame_address (unsigned int @var{level}) | 11071 @deftypefn {Built-in Function} {void *} __builtin_frame_address (unsigned int @var{level}) |
10024 This function is similar to @code{__builtin_return_address}, but it | 11072 This function is similar to @code{__builtin_return_address}, but it |
10062 @smallexample | 11110 @smallexample |
10063 typedef int v4si __attribute__ ((vector_size (16))); | 11111 typedef int v4si __attribute__ ((vector_size (16))); |
10064 @end smallexample | 11112 @end smallexample |
10065 | 11113 |
10066 @noindent | 11114 @noindent |
10067 The @code{int} type specifies the base type, while the attribute specifies | 11115 The @code{int} type specifies the @dfn{base type}, while the attribute specifies |
10068 the vector size for the variable, measured in bytes. For example, the | 11116 the vector size for the variable, measured in bytes. For example, the |
10069 declaration above causes the compiler to set the mode for the @code{v4si} | 11117 declaration above causes the compiler to set the mode for the @code{v4si} |
10070 type to be 16 bytes wide and divided into @code{int} sized units. For | 11118 type to be 16 bytes wide and divided into @code{int} sized units. For |
10071 a 32-bit @code{int} this means a vector of 4 units of 4 bytes, and the | 11119 a 32-bit @code{int} this means a vector of 4 units of 4 bytes, and the |
10072 corresponding mode of @code{foo} is @acronym{V4SI}. | 11120 corresponding mode of @code{foo} is @acronym{V4SI}. |
10073 | 11121 |
10074 The @code{vector_size} attribute is only applicable to integral and | 11122 The @code{vector_size} attribute is only applicable to integral and |
10075 float scalars, although arrays, pointers, and function return values | 11123 floating scalars, although arrays, pointers, and function return values |
10076 are allowed in conjunction with this construct. Only sizes that are | 11124 are allowed in conjunction with this construct. Only sizes that are |
10077 a power of two are currently allowed. | 11125 positive power-of-two multiples of the base type size are currently allowed. |
10078 | 11126 |
10079 All the basic integer types can be used as base types, both as signed | 11127 All the basic integer types can be used as base types, both as signed |
10080 and as unsigned: @code{char}, @code{short}, @code{int}, @code{long}, | 11128 and as unsigned: @code{char}, @code{short}, @code{int}, @code{long}, |
10081 @code{long long}. In addition, @code{float} and @code{double} can be | 11129 @code{long long}. In addition, @code{float} and @code{double} can be |
10082 used to build floating-point vector types. | 11130 used to build floating-point vector types. |
10224 provided they are of the same size (in fact, you can also cast vectors | 11272 provided they are of the same size (in fact, you can also cast vectors |
10225 to and from other datatypes of the same size). | 11273 to and from other datatypes of the same size). |
10226 | 11274 |
10227 You cannot operate between vectors of different lengths or different | 11275 You cannot operate between vectors of different lengths or different |
10228 signedness without a cast. | 11276 signedness without a cast. |
11277 | |
11278 @findex __builtin_convertvector | |
11279 Vector conversion is available using the | |
11280 @code{__builtin_convertvector (vec, vectype)} | |
11281 function. @var{vec} must be an expression with integral or floating | |
11282 vector type and @var{vectype} an integral or floating vector type with the | |
11283 same number of elements. The result has @var{vectype} type and value of | |
11284 a C cast of every element of @var{vec} to the element type of @var{vectype}. | |
11285 | |
11286 Consider the following example, | |
11287 @smallexample | |
11288 typedef int v4si __attribute__ ((vector_size (16))); | |
11289 typedef float v4sf __attribute__ ((vector_size (16))); | |
11290 typedef double v4df __attribute__ ((vector_size (32))); | |
11291 typedef unsigned long long v4di __attribute__ ((vector_size (32))); | |
11292 | |
11293 v4si a = @{1,-2,3,-4@}; | |
11294 v4sf b = @{1.5f,-2.5f,3.f,7.f@}; | |
11295 v4di c = @{1ULL,5ULL,0ULL,10ULL@}; | |
11296 v4sf d = __builtin_convertvector (a, v4sf); /* d is @{1.f,-2.f,3.f,-4.f@} */ | |
11297 /* Equivalent of: | |
11298 v4sf d = @{ (float)a[0], (float)a[1], (float)a[2], (float)a[3] @}; */ | |
11299 v4df e = __builtin_convertvector (a, v4df); /* e is @{1.,-2.,3.,-4.@} */ | |
11300 v4df f = __builtin_convertvector (b, v4df); /* f is @{1.5,-2.5,3.,7.@} */ | |
11301 v4si g = __builtin_convertvector (f, v4si); /* g is @{1,-2,3,7@} */ | |
11302 v4si h = __builtin_convertvector (c, v4si); /* h is @{1,5,0,10@} */ | |
11303 @end smallexample | |
11304 | |
11305 @cindex vector types, using with x86 intrinsics | |
11306 Sometimes it is desirable to write code using a mix of generic vector | |
11307 operations (for clarity) and machine-specific vector intrinsics (to | |
11308 access vector instructions that are not exposed via generic built-ins). | |
11309 On x86, intrinsic functions for integer vectors typically use the same | |
11310 vector type @code{__m128i} irrespective of how they interpret the vector, | |
11311 making it necessary to cast their arguments and return values from/to | |
11312 other vector types. In C, you can make use of a @code{union} type: | |
11313 @c In C++ such type punning via a union is not allowed by the language | |
11314 @smallexample | |
11315 #include <immintrin.h> | |
11316 | |
11317 typedef unsigned char u8x16 __attribute__ ((vector_size (16))); | |
11318 typedef unsigned int u32x4 __attribute__ ((vector_size (16))); | |
11319 | |
11320 typedef union @{ | |
11321 __m128i mm; | |
11322 u8x16 u8; | |
11323 u32x4 u32; | |
11324 @} v128; | |
11325 @end smallexample | |
11326 | |
11327 @noindent | |
11328 for variables that can be used with both built-in operators and x86 | |
11329 intrinsics: | |
11330 | |
11331 @smallexample | |
11332 v128 x, y = @{ 0 @}; | |
11333 memcpy (&x, ptr, sizeof x); | |
11334 y.u8 += 0x80; | |
11335 x.mm = _mm_adds_epu8 (x.mm, y.mm); | |
11336 x.u32 &= 0xffffff; | |
11337 | |
11338 /* Instead of a variable, a compound literal may be used to pass the | |
11339 return value of an intrinsic call to a function expecting the union: */ | |
11340 v128 foo (v128); | |
11341 x = foo ((v128) @{_mm_adds_epu8 (x.mm, y.mm)@}); | |
11342 @c This could be done implicitly with __attribute__((transparent_union)), | |
11343 @c but GCC does not accept it for unions of vector types (PR 88955). | |
11344 @end smallexample | |
10229 | 11345 |
10230 @node Offsetof | 11346 @node Offsetof |
10231 @section Support for @code{offsetof} | 11347 @section Support for @code{offsetof} |
10232 @findex __builtin_offsetof | 11348 @findex __builtin_offsetof |
10233 | 11349 |
10370 These built-in functions perform an atomic compare and swap. | 11486 These built-in functions perform an atomic compare and swap. |
10371 That is, if the current | 11487 That is, if the current |
10372 value of @code{*@var{ptr}} is @var{oldval}, then write @var{newval} into | 11488 value of @code{*@var{ptr}} is @var{oldval}, then write @var{newval} into |
10373 @code{*@var{ptr}}. | 11489 @code{*@var{ptr}}. |
10374 | 11490 |
10375 The ``bool'' version returns true if the comparison is successful and | 11491 The ``bool'' version returns @code{true} if the comparison is successful and |
10376 @var{newval} is written. The ``val'' version returns the contents | 11492 @var{newval} is written. The ``val'' version returns the contents |
10377 of @code{*@var{ptr}} before the operation. | 11493 of @code{*@var{ptr}} before the operation. |
10378 | 11494 |
10379 @item __sync_synchronize (...) | 11495 @item __sync_synchronize (...) |
10380 @findex __sync_synchronize | 11496 @findex __sync_synchronize |
10571 This built-in function implements an atomic compare and exchange operation. | 11687 This built-in function implements an atomic compare and exchange operation. |
10572 This compares the contents of @code{*@var{ptr}} with the contents of | 11688 This compares the contents of @code{*@var{ptr}} with the contents of |
10573 @code{*@var{expected}}. If equal, the operation is a @emph{read-modify-write} | 11689 @code{*@var{expected}}. If equal, the operation is a @emph{read-modify-write} |
10574 operation that writes @var{desired} into @code{*@var{ptr}}. If they are not | 11690 operation that writes @var{desired} into @code{*@var{ptr}}. If they are not |
10575 equal, the operation is a @emph{read} and the current contents of | 11691 equal, the operation is a @emph{read} and the current contents of |
10576 @code{*@var{ptr}} are written into @code{*@var{expected}}. @var{weak} is true | 11692 @code{*@var{ptr}} are written into @code{*@var{expected}}. @var{weak} is @code{true} |
10577 for weak compare_exchange, which may fail spuriously, and false for | 11693 for weak compare_exchange, which may fail spuriously, and @code{false} for |
10578 the strong variation, which never fails spuriously. Many targets | 11694 the strong variation, which never fails spuriously. Many targets |
10579 only offer the strong variation and ignore the parameter. When in doubt, use | 11695 only offer the strong variation and ignore the parameter. When in doubt, use |
10580 the strong variation. | 11696 the strong variation. |
10581 | 11697 |
10582 If @var{desired} is written into @code{*@var{ptr}} then true is returned | 11698 If @var{desired} is written into @code{*@var{ptr}} then @code{true} is returned |
10583 and memory is affected according to the | 11699 and memory is affected according to the |
10584 memory order specified by @var{success_memorder}. There are no | 11700 memory order specified by @var{success_memorder}. There are no |
10585 restrictions on what memory order can be used here. | 11701 restrictions on what memory order can be used here. |
10586 | 11702 |
10587 Otherwise, false is returned and memory is affected according | 11703 Otherwise, @code{false} is returned and memory is affected according |
10588 to @var{failure_memorder}. This memory order cannot be | 11704 to @var{failure_memorder}. This memory order cannot be |
10589 @code{__ATOMIC_RELEASE} nor @code{__ATOMIC_ACQ_REL}. It also cannot be a | 11705 @code{__ATOMIC_RELEASE} nor @code{__ATOMIC_ACQ_REL}. It also cannot be a |
10590 stronger order than that specified by @var{success_memorder}. | 11706 stronger order than that specified by @var{success_memorder}. |
10591 | 11707 |
10592 @end deftypefn | 11708 @end deftypefn |
10610 performed as if the operands were of the @code{uintptr_t} type. That is, | 11726 performed as if the operands were of the @code{uintptr_t} type. That is, |
10611 they are not scaled by the size of the type to which the pointer points. | 11727 they are not scaled by the size of the type to which the pointer points. |
10612 | 11728 |
10613 @smallexample | 11729 @smallexample |
10614 @{ *ptr @var{op}= val; return *ptr; @} | 11730 @{ *ptr @var{op}= val; return *ptr; @} |
11731 @{ *ptr = ~(*ptr & val); return *ptr; @} // nand | |
10615 @end smallexample | 11732 @end smallexample |
10616 | 11733 |
10617 The object pointed to by the first argument must be of integer or pointer | 11734 The object pointed to by the first argument must be of integer or pointer |
10618 type. It must not be a boolean type. All memory orders are valid. | 11735 type. It must not be a boolean type. All memory orders are valid. |
10619 | 11736 |
10631 the @code{uintptr_t} type. That is, they are not scaled by the size of | 11748 the @code{uintptr_t} type. That is, they are not scaled by the size of |
10632 the type to which the pointer points. | 11749 the type to which the pointer points. |
10633 | 11750 |
10634 @smallexample | 11751 @smallexample |
10635 @{ tmp = *ptr; *ptr @var{op}= val; return tmp; @} | 11752 @{ tmp = *ptr; *ptr @var{op}= val; return tmp; @} |
11753 @{ tmp = *ptr; *ptr = ~(*ptr & val); return tmp; @} // nand | |
10636 @end smallexample | 11754 @end smallexample |
10637 | 11755 |
10638 The same constraints on arguments apply as for the corresponding | 11756 The same constraints on arguments apply as for the corresponding |
10639 @code{__atomic_op_fetch} built-in functions. All memory orders are valid. | 11757 @code{__atomic_op_fetch} built-in functions. All memory orders are valid. |
10640 | 11758 |
10686 | 11804 |
10687 @end deftypefn | 11805 @end deftypefn |
10688 | 11806 |
10689 @deftypefn {Built-in Function} bool __atomic_always_lock_free (size_t size, void *ptr) | 11807 @deftypefn {Built-in Function} bool __atomic_always_lock_free (size_t size, void *ptr) |
10690 | 11808 |
10691 This built-in function returns true if objects of @var{size} bytes always | 11809 This built-in function returns @code{true} if objects of @var{size} bytes always |
10692 generate lock-free atomic instructions for the target architecture. | 11810 generate lock-free atomic instructions for the target architecture. |
10693 @var{size} must resolve to a compile-time constant and the result also | 11811 @var{size} must resolve to a compile-time constant and the result also |
10694 resolves to a compile-time constant. | 11812 resolves to a compile-time constant. |
10695 | 11813 |
10696 @var{ptr} is an optional pointer to the object that may be used to determine | 11814 @var{ptr} is an optional pointer to the object that may be used to determine |
10703 | 11821 |
10704 @end deftypefn | 11822 @end deftypefn |
10705 | 11823 |
10706 @deftypefn {Built-in Function} bool __atomic_is_lock_free (size_t size, void *ptr) | 11824 @deftypefn {Built-in Function} bool __atomic_is_lock_free (size_t size, void *ptr) |
10707 | 11825 |
10708 This built-in function returns true if objects of @var{size} bytes always | 11826 This built-in function returns @code{true} if objects of @var{size} bytes always |
10709 generate lock-free atomic instructions for the target architecture. If | 11827 generate lock-free atomic instructions for the target architecture. If |
10710 the built-in function is not known to be lock-free, a call is made to a | 11828 the built-in function is not known to be lock-free, a call is made to a |
10711 runtime routine named @code{__atomic_is_lock_free}. | 11829 runtime routine named @code{__atomic_is_lock_free}. |
10712 | 11830 |
10713 @var{ptr} is an optional pointer to the object that may be used to determine | 11831 @var{ptr} is an optional pointer to the object that may be used to determine |
10731 | 11849 |
10732 These built-in functions promote the first two operands into infinite precision signed | 11850 These built-in functions promote the first two operands into infinite precision signed |
10733 type and perform addition on those promoted operands. The result is then | 11851 type and perform addition on those promoted operands. The result is then |
10734 cast to the type the third pointer argument points to and stored there. | 11852 cast to the type the third pointer argument points to and stored there. |
10735 If the stored result is equal to the infinite precision result, the built-in | 11853 If the stored result is equal to the infinite precision result, the built-in |
10736 functions return false, otherwise they return true. As the addition is | 11854 functions return @code{false}, otherwise they return @code{true}. As the addition is |
10737 performed in infinite signed precision, these built-in functions have fully defined | 11855 performed in infinite signed precision, these built-in functions have fully defined |
10738 behavior for all argument values. | 11856 behavior for all argument values. |
10739 | 11857 |
10740 The first built-in function allows arbitrary integral types for operands and | 11858 The first built-in function allows arbitrary integral types for operands and |
10741 the result type must be pointer to some integral type other than enumerated or | 11859 the result type must be pointer to some integral type other than enumerated or |
10788 than enumerated or boolean type. | 11906 than enumerated or boolean type. |
10789 | 11907 |
10790 The built-in functions promote the first two operands into infinite precision signed type | 11908 The built-in functions promote the first two operands into infinite precision signed type |
10791 and perform addition on those promoted operands. The result is then | 11909 and perform addition on those promoted operands. The result is then |
10792 cast to the type of the third argument. If the cast result is equal to the infinite | 11910 cast to the type of the third argument. If the cast result is equal to the infinite |
10793 precision result, the built-in functions return false, otherwise they return true. | 11911 precision result, the built-in functions return @code{false}, otherwise they return @code{true}. |
10794 The value of the third argument is ignored, just the side effects in the third argument | 11912 The value of the third argument is ignored, just the side effects in the third argument |
10795 are evaluated, and no integral argument promotions are performed on the last argument. | 11913 are evaluated, and no integral argument promotions are performed on the last argument. |
10796 If the third argument is a bit-field, the type used for the result cast has the | 11914 If the third argument is a bit-field, the type used for the result cast has the |
10797 precision and signedness of the given bit-field, rather than precision and signedness | 11915 precision and signedness of the given bit-field, rather than precision and signedness |
10798 of the underlying type. | 11916 of the underlying type. |
10884 a limited extent, they can be used without optimization as well. | 12002 a limited extent, they can be used without optimization as well. |
10885 | 12003 |
10886 @deftypefn {Built-in Function} {size_t} __builtin_object_size (const void * @var{ptr}, int @var{type}) | 12004 @deftypefn {Built-in Function} {size_t} __builtin_object_size (const void * @var{ptr}, int @var{type}) |
10887 is a built-in construct that returns a constant number of bytes from | 12005 is a built-in construct that returns a constant number of bytes from |
10888 @var{ptr} to the end of the object @var{ptr} pointer points to | 12006 @var{ptr} to the end of the object @var{ptr} pointer points to |
10889 (if known at compile time). @code{__builtin_object_size} never evaluates | 12007 (if known at compile time). To determine the sizes of dynamically allocated |
12008 objects the function relies on the allocation functions called to obtain | |
12009 the storage to be declared with the @code{alloc_size} attribute (@pxref{Common | |
12010 Function Attributes}). @code{__builtin_object_size} never evaluates | |
10890 its arguments for side effects. If there are any side effects in them, it | 12011 its arguments for side effects. If there are any side effects in them, it |
10891 returns @code{(size_t) -1} for @var{type} 0 or 1 and @code{(size_t) 0} | 12012 returns @code{(size_t) -1} for @var{type} 0 or 1 and @code{(size_t) 0} |
10892 for @var{type} 2 or 3. If there are multiple objects @var{ptr} can | 12013 for @var{type} 2 or 3. If there are multiple objects @var{ptr} can |
10893 point to and all of them are known at compile time, the returned number | 12014 point to and all of them are known at compile time, the returned number |
10894 is the maximum of remaining byte counts in those objects if @var{type} & 2 is | 12015 is the maximum of remaining byte counts in those objects if @var{type} & 2 is |
10999 @findex __builtin_alloca_with_align | 12120 @findex __builtin_alloca_with_align |
11000 @findex __builtin_alloca_with_align_and_max | 12121 @findex __builtin_alloca_with_align_and_max |
11001 @findex __builtin_call_with_static_chain | 12122 @findex __builtin_call_with_static_chain |
11002 @findex __builtin_extend_pointer | 12123 @findex __builtin_extend_pointer |
11003 @findex __builtin_fpclassify | 12124 @findex __builtin_fpclassify |
12125 @findex __builtin_has_attribute | |
11004 @findex __builtin_isfinite | 12126 @findex __builtin_isfinite |
11005 @findex __builtin_isnormal | 12127 @findex __builtin_isnormal |
11006 @findex __builtin_isgreater | 12128 @findex __builtin_isgreater |
11007 @findex __builtin_isgreaterequal | 12129 @findex __builtin_isgreaterequal |
11008 @findex __builtin_isinf_sign | 12130 @findex __builtin_isinf_sign |
11009 @findex __builtin_isless | 12131 @findex __builtin_isless |
11010 @findex __builtin_islessequal | 12132 @findex __builtin_islessequal |
11011 @findex __builtin_islessgreater | 12133 @findex __builtin_islessgreater |
11012 @findex __builtin_isunordered | 12134 @findex __builtin_isunordered |
12135 @findex __builtin_object_size | |
11013 @findex __builtin_powi | 12136 @findex __builtin_powi |
11014 @findex __builtin_powif | 12137 @findex __builtin_powif |
11015 @findex __builtin_powil | 12138 @findex __builtin_powil |
11016 @findex __builtin_speculation_safe_value | 12139 @findex __builtin_speculation_safe_value |
11017 @findex _Exit | 12140 @findex _Exit |
11435 @code{gammaf_r}, @code{gammal_r}, @code{gamma_r}, @code{gettext}, | 12558 @code{gammaf_r}, @code{gammal_r}, @code{gamma_r}, @code{gettext}, |
11436 @code{index}, @code{isascii}, @code{j0f}, @code{j0l}, @code{j0}, | 12559 @code{index}, @code{isascii}, @code{j0f}, @code{j0l}, @code{j0}, |
11437 @code{j1f}, @code{j1l}, @code{j1}, @code{jnf}, @code{jnl}, @code{jn}, | 12560 @code{j1f}, @code{j1l}, @code{j1}, @code{jnf}, @code{jnl}, @code{jn}, |
11438 @code{lgammaf_r}, @code{lgammal_r}, @code{lgamma_r}, @code{mempcpy}, | 12561 @code{lgammaf_r}, @code{lgammal_r}, @code{lgamma_r}, @code{mempcpy}, |
11439 @code{pow10f}, @code{pow10l}, @code{pow10}, @code{printf_unlocked}, | 12562 @code{pow10f}, @code{pow10l}, @code{pow10}, @code{printf_unlocked}, |
11440 @code{rindex}, @code{scalbf}, @code{scalbl}, @code{scalb}, | 12563 @code{rindex}, @code{roundeven}, @code{roundevenf}, @code{roudnevenl}, |
12564 @code{scalbf}, @code{scalbl}, @code{scalb}, | |
11441 @code{signbit}, @code{signbitf}, @code{signbitl}, @code{signbitd32}, | 12565 @code{signbit}, @code{signbitf}, @code{signbitl}, @code{signbitd32}, |
11442 @code{signbitd64}, @code{signbitd128}, @code{significandf}, | 12566 @code{signbitd64}, @code{signbitd128}, @code{significandf}, |
11443 @code{significandl}, @code{significand}, @code{sincosf}, | 12567 @code{significandl}, @code{significand}, @code{sincosf}, |
11444 @code{sincosl}, @code{sincos}, @code{stpcpy}, @code{stpncpy}, | 12568 @code{sincosl}, @code{sincos}, @code{stpcpy}, @code{stpncpy}, |
11445 @code{strcasecmp}, @code{strdup}, @code{strfmon}, @code{strncasecmp}, | 12569 @code{strcasecmp}, @code{strdup}, @code{strfmon}, @code{strncasecmp}, |
11656 expression, it has no effect on code generation and no attempt is made to | 12780 expression, it has no effect on code generation and no attempt is made to |
11657 check its compatibility with @var{size}. | 12781 check its compatibility with @var{size}. |
11658 | 12782 |
11659 @end deftypefn | 12783 @end deftypefn |
11660 | 12784 |
12785 @deftypefn {Built-in Function} bool __builtin_has_attribute (@var{type-or-expression}, @var{attribute}) | |
12786 The @code{__builtin_has_attribute} function evaluates to an integer constant | |
12787 expression equal to @code{true} if the symbol or type referenced by | |
12788 the @var{type-or-expression} argument has been declared with | |
12789 the @var{attribute} referenced by the second argument. For | |
12790 an @var{type-or-expression} argument that does not reference a symbol, | |
12791 since attributes do not apply to expressions the built-in consider | |
12792 the type of the argument. Neither argument is evaluated. | |
12793 The @var{type-or-expression} argument is subject to the same | |
12794 restrictions as the argument to @code{typeof} (@pxref{Typeof}). The | |
12795 @var{attribute} argument is an attribute name optionally followed by | |
12796 a comma-separated list of arguments enclosed in parentheses. Both forms | |
12797 of attribute names---with and without double leading and trailing | |
12798 underscores---are recognized. @xref{Attribute Syntax}, for details. | |
12799 When no attribute arguments are specified for an attribute that expects | |
12800 one or more arguments the function returns @code{true} if | |
12801 @var{type-or-expression} has been declared with the attribute regardless | |
12802 of the attribute argument values. Arguments provided for an attribute | |
12803 that expects some are validated and matched up to the provided number. | |
12804 The function returns @code{true} if all provided arguments match. For | |
12805 example, the first call to the function below evaluates to @code{true} | |
12806 because @code{x} is declared with the @code{aligned} attribute but | |
12807 the second call evaluates to @code{false} because @code{x} is declared | |
12808 @code{aligned (8)} and not @code{aligned (4)}. | |
12809 | |
12810 @smallexample | |
12811 __attribute__ ((aligned (8))) int x; | |
12812 _Static_assert (__builtin_has_attribute (x, aligned), "aligned"); | |
12813 _Static_assert (!__builtin_has_attribute (x, aligned (4)), "aligned (4)"); | |
12814 @end smallexample | |
12815 | |
12816 Due to a limitation the @code{__builtin_has_attribute} function returns | |
12817 @code{false} for the @code{mode} attribute even if the type or variable | |
12818 referenced by the @var{type-or-expression} argument was declared with one. | |
12819 The function is also not supported with labels, and in C with enumerators. | |
12820 | |
12821 Note that unlike the @code{__has_attribute} preprocessor operator which | |
12822 is suitable for use in @code{#if} preprocessing directives | |
12823 @code{__builtin_has_attribute} is an intrinsic function that is not | |
12824 recognized in such contexts. | |
12825 | |
12826 @end deftypefn | |
12827 | |
11661 @deftypefn {Built-in Function} @var{type} __builtin_speculation_safe_value (@var{type} val, @var{type} failval) | 12828 @deftypefn {Built-in Function} @var{type} __builtin_speculation_safe_value (@var{type} val, @var{type} failval) |
11662 | 12829 |
11663 This built-in function can be used to help mitigate against unsafe | 12830 This built-in function can be used to help mitigate against unsafe |
11664 speculative execution. @var{type} may be any integral type or any | 12831 speculative execution. @var{type} may be any integral type or any |
11665 pointer type. | 12832 pointer type. |
11819 integer constant expression, is nonzero. Otherwise it returns @var{exp2}. | 12986 integer constant expression, is nonzero. Otherwise it returns @var{exp2}. |
11820 | 12987 |
11821 This built-in function is analogous to the @samp{? :} operator in C, | 12988 This built-in function is analogous to the @samp{? :} operator in C, |
11822 except that the expression returned has its type unaltered by promotion | 12989 except that the expression returned has its type unaltered by promotion |
11823 rules. Also, the built-in function does not evaluate the expression | 12990 rules. Also, the built-in function does not evaluate the expression |
11824 that is not chosen. For example, if @var{const_exp} evaluates to true, | 12991 that is not chosen. For example, if @var{const_exp} evaluates to @code{true}, |
11825 @var{exp2} is not evaluated even if it has side effects. | 12992 @var{exp2} is not evaluated even if it has side effects. |
11826 | 12993 |
11827 This built-in function can return an lvalue if the chosen argument is an | 12994 This built-in function can return an lvalue if the chosen argument is an |
11828 lvalue. | 12995 lvalue. |
11829 | 12996 |
11973 @code{0 && foo ()}). GCC must be more conservative about evaluating the | 13140 @code{0 && foo ()}). GCC must be more conservative about evaluating the |
11974 built-in in this case, because it has no opportunity to perform | 13141 built-in in this case, because it has no opportunity to perform |
11975 optimization. | 13142 optimization. |
11976 @end deftypefn | 13143 @end deftypefn |
11977 | 13144 |
13145 @deftypefn {Built-in Function} bool __builtin_is_constant_evaluated (void) | |
13146 The @code{__builtin_is_constant_evaluated} function is available only | |
13147 in C++. The built-in is intended to be used by implementations of | |
13148 the @code{std::is_constant_evaluated} C++ function. Programs should make | |
13149 use of the latter function rather than invoking the built-in directly. | |
13150 | |
13151 The main use case of the built-in is to determine whether a @code{constexpr} | |
13152 function is being called in a @code{constexpr} context. A call to | |
13153 the function evaluates to a core constant expression with the value | |
13154 @code{true} if and only if it occurs within the evaluation of an expression | |
13155 or conversion that is manifestly constant-evaluated as defined in the C++ | |
13156 standard. Manifestly constant-evaluated contexts include constant-expressions, | |
13157 the conditions of @code{constexpr if} statements, constraint-expressions, and | |
13158 initializers of variables usable in constant expressions. For more details | |
13159 refer to the latest revision of the C++ standard. | |
13160 @end deftypefn | |
13161 | |
11978 @deftypefn {Built-in Function} long __builtin_expect (long @var{exp}, long @var{c}) | 13162 @deftypefn {Built-in Function} long __builtin_expect (long @var{exp}, long @var{c}) |
11979 @opindex fprofile-arcs | 13163 @opindex fprofile-arcs |
11980 You may use @code{__builtin_expect} to provide the compiler with | 13164 You may use @code{__builtin_expect} to provide the compiler with |
11981 branch prediction information. In general, you should prefer to | 13165 branch prediction information. In general, you should prefer to |
11982 use actual profile feedback for this (@option{-fprofile-arcs}), as | 13166 use actual profile feedback for this (@option{-fprofile-arcs}), as |
12003 foo (*ptr); | 13187 foo (*ptr); |
12004 @end smallexample | 13188 @end smallexample |
12005 | 13189 |
12006 @noindent | 13190 @noindent |
12007 when testing pointer or floating-point values. | 13191 when testing pointer or floating-point values. |
13192 | |
13193 For the purposes of branch prediction optimizations, the probability that | |
13194 a @code{__builtin_expect} expression is @code{true} is controlled by GCC's | |
13195 @code{builtin-expect-probability} parameter, which defaults to 90%. | |
13196 | |
13197 You can also use @code{__builtin_expect_with_probability} to explicitly | |
13198 assign a probability value to individual expressions. If the built-in | |
13199 is used in a loop construct, the provided probability will influence | |
13200 the expected number of iterations made by loop optimizations. | |
12008 @end deftypefn | 13201 @end deftypefn |
12009 | 13202 |
12010 @deftypefn {Built-in Function} long __builtin_expect_with_probability | 13203 @deftypefn {Built-in Function} long __builtin_expect_with_probability |
12011 (long @var{exp}, long @var{c}, long @var{probability}) | 13204 (long @var{exp}, long @var{c}, double @var{probability}) |
12012 | 13205 |
12013 The built-in has same semantics as @code{__builtin_expect_with_probability}, | 13206 This function has the same semantics as @code{__builtin_expect}, |
12014 but user can provide expected probability (in percent) for value of @var{exp}. | 13207 but the caller provides the expected probability that @var{exp} == @var{c}. |
12015 Last argument @var{probability} is of float type and valid values | 13208 The last argument, @var{probability}, is a floating-point value in the |
12016 are in inclusive range 0.0f and 1.0f. | 13209 range 0.0 to 1.0, inclusive. The @var{probability} argument must be |
13210 constant floating-point expression. | |
12017 @end deftypefn | 13211 @end deftypefn |
12018 | 13212 |
12019 @deftypefn {Built-in Function} void __builtin_trap (void) | 13213 @deftypefn {Built-in Function} void __builtin_trap (void) |
12020 This function causes the program to exit abnormally. GCC implements | 13214 This function causes the program to exit abnormally. GCC implements |
12021 this function by using a target-dependent mechanism (such as | 13215 this function by using a target-dependent mechanism (such as |
12149 @} | 13343 @} |
12150 @end smallexample | 13344 @end smallexample |
12151 | 13345 |
12152 @end deftypefn | 13346 @end deftypefn |
12153 | 13347 |
12154 @deftypefn {Built-in Function} void __builtin___clear_cache (char *@var{begin}, char *@var{end}) | 13348 @deftypefn {Built-in Function} void __builtin___clear_cache (void *@var{begin}, void *@var{end}) |
12155 This function is used to flush the processor's instruction cache for | 13349 This function is used to flush the processor's instruction cache for |
12156 the region of memory between @var{begin} inclusive and @var{end} | 13350 the region of memory between @var{begin} inclusive and @var{end} |
12157 exclusive. Some targets require that the instruction cache be | 13351 exclusive. Some targets require that the instruction cache be |
12158 flushed, after modifying memory containing code, in order to obtain | 13352 flushed, after modifying memory containing code, in order to obtain |
12159 deterministic behavior. | 13353 deterministic behavior. |
12204 If the target does not support data prefetch, the address expression | 13398 If the target does not support data prefetch, the address expression |
12205 is evaluated if it includes side effects but no other code is generated | 13399 is evaluated if it includes side effects but no other code is generated |
12206 and GCC does not issue a warning. | 13400 and GCC does not issue a warning. |
12207 @end deftypefn | 13401 @end deftypefn |
12208 | 13402 |
13403 @deftypefn {Built-in Function}{size_t} __builtin_object_size (const void * @var{ptr}, int @var{type}) | |
13404 Returns the size of an object pointed to by @var{ptr}. @xref{Object Size | |
13405 Checking}, for a detailed description of the function. | |
13406 @end deftypefn | |
13407 | |
12209 @deftypefn {Built-in Function} double __builtin_huge_val (void) | 13408 @deftypefn {Built-in Function} double __builtin_huge_val (void) |
12210 Returns a positive infinity, if supported by the floating-point format, | 13409 Returns a positive infinity, if supported by the floating-point format, |
12211 else @code{DBL_MAX}. This function is suitable for implementing the | 13410 else @code{DBL_MAX}. This function is suitable for implementing the |
12212 ISO C macro @code{HUGE_VAL}. | 13411 ISO C macro @code{HUGE_VAL}. |
12213 @end deftypefn | 13412 @end deftypefn |
12515 * ARM C Language Extensions (ACLE):: | 13714 * ARM C Language Extensions (ACLE):: |
12516 * ARM Floating Point Status and Control Intrinsics:: | 13715 * ARM Floating Point Status and Control Intrinsics:: |
12517 * ARM ARMv8-M Security Extensions:: | 13716 * ARM ARMv8-M Security Extensions:: |
12518 * AVR Built-in Functions:: | 13717 * AVR Built-in Functions:: |
12519 * Blackfin Built-in Functions:: | 13718 * Blackfin Built-in Functions:: |
13719 * BPF Built-in Functions:: | |
13720 * BPF Kernel Helpers:: | |
12520 * FR-V Built-in Functions:: | 13721 * FR-V Built-in Functions:: |
12521 * MIPS DSP Built-in Functions:: | 13722 * MIPS DSP Built-in Functions:: |
12522 * MIPS Paired-Single Support:: | 13723 * MIPS Paired-Single Support:: |
12523 * MIPS Loongson Built-in Functions:: | 13724 * MIPS Loongson Built-in Functions:: |
12524 * MIPS SIMD Architecture (MSA) Support:: | 13725 * MIPS SIMD Architecture (MSA) Support:: |
12532 * PowerPC Atomic Memory Operation Functions:: | 13733 * PowerPC Atomic Memory Operation Functions:: |
12533 * RX Built-in Functions:: | 13734 * RX Built-in Functions:: |
12534 * S/390 System z Built-in Functions:: | 13735 * S/390 System z Built-in Functions:: |
12535 * SH Built-in Functions:: | 13736 * SH Built-in Functions:: |
12536 * SPARC VIS Built-in Functions:: | 13737 * SPARC VIS Built-in Functions:: |
12537 * SPU Built-in Functions:: | |
12538 * TI C6X Built-in Functions:: | 13738 * TI C6X Built-in Functions:: |
12539 * TILE-Gx Built-in Functions:: | 13739 * TILE-Gx Built-in Functions:: |
12540 * TILEPro Built-in Functions:: | 13740 * TILEPro Built-in Functions:: |
12541 * x86 Built-in Functions:: | 13741 * x86 Built-in Functions:: |
12542 * x86 transactional memory intrinsics:: | 13742 * x86 transactional memory intrinsics:: |
13511 | 14711 |
13512 @smallexample | 14712 @smallexample |
13513 void __builtin_bfin_csync (void) | 14713 void __builtin_bfin_csync (void) |
13514 void __builtin_bfin_ssync (void) | 14714 void __builtin_bfin_ssync (void) |
13515 @end smallexample | 14715 @end smallexample |
14716 | |
14717 @node BPF Built-in Functions | |
14718 @subsection BPF Built-in Functions | |
14719 | |
14720 The following built-in functions are available for eBPF targets. | |
14721 | |
14722 @deftypefn {Built-in Function} unsigned long long __builtin_bpf_load_byte (unsigned long long @var{offset}) | |
14723 Load a byte from the @code{struct sk_buff} packet data pointed by the register @code{%r6} and return it. | |
14724 @end deftypefn | |
14725 | |
14726 @deftypefn {Built-in Function} unsigned long long __builtin_bpf_load_half (unsigned long long @var{offset}) | |
14727 Load 16-bits from the @code{struct sk_buff} packet data pointed by the register @code{%r6} and return it. | |
14728 @end deftypefn | |
14729 | |
14730 @deftypefn {Built-in Function} unsigned long long __builtin_bpf_load_word (unsigned long long @var{offset}) | |
14731 Load 32-bits from the @code{struct sk_buff} packet data pointed by the register @code{%r6} and return it. | |
14732 @end deftypefn | |
14733 | |
14734 @node BPF Kernel Helpers | |
14735 @subsection BPF Kernel Helpers | |
14736 | |
14737 These built-in functions are available for calling kernel helpers, and | |
14738 they are available depending on the kernel version selected as the | |
14739 CPU. | |
14740 | |
14741 Rather than using the built-ins directly, it is preferred for programs | |
14742 to include @file{bpf-helpers.h} and use the wrappers defined there. | |
14743 | |
14744 For a full description of what the helpers do, the arguments they | |
14745 take, and the returned value, see the | |
14746 @file{linux/include/uapi/linux/bpf.h} in a Linux source tree. | |
14747 | |
14748 @smallexample | |
14749 void *__builtin_bpf_helper_map_lookup_elem (void *map, void *key) | |
14750 int __builtin_bpf_helper_map_update_elem (void *map, void *key, | |
14751 void *value, | |
14752 unsigned long long flags) | |
14753 int __builtin_bpf_helper_map_delete_elem (void *map, const void *key) | |
14754 int __builtin_bpf_helper_map_push_elem (void *map, const void *value, | |
14755 unsigned long long flags) | |
14756 int __builtin_bpf_helper_map_pop_elem (void *map, void *value) | |
14757 int __builtin_bpf_helper_map_peek_elem (void *map, void *value) | |
14758 int __builtin_bpf_helper_clone_redirect (void *skb, | |
14759 unsigned int ifindex, | |
14760 unsigned long long flags) | |
14761 int __builtin_bpf_helper_skb_get_tunnel_key (void *ctx, void *key, int size, int flags) | |
14762 int __builtin_bpf_helper_skb_set_tunnel_key (void *ctx, void *key, int size, int flags) | |
14763 int __builtin_bpf_helper_skb_get_tunnel_opt (void *ctx, void *md, int size) | |
14764 int __builtin_bpf_helper_skb_set_tunnel_opt (void *ctx, void *md, int size) | |
14765 int __builtin_bpf_helper_skb_get_xfrm_state (void *ctx, int index, void *state, | |
14766 int size, int flags) | |
14767 static unsigned long long __builtin_bpf_helper_skb_cgroup_id (void *ctx) | |
14768 static unsigned long long __builtin_bpf_helper_skb_ancestor_cgroup_id | |
14769 (void *ctx, int level) | |
14770 int __builtin_bpf_helper_skb_vlan_push (void *ctx, __be16 vlan_proto, __u16 vlan_tci) | |
14771 int __builtin_bpf_helper_skb_vlan_pop (void *ctx) | |
14772 int __builtin_bpf_helper_skb_ecn_set_ce (void *ctx) | |
14773 | |
14774 int __builtin_bpf_helper_skb_load_bytes (void *ctx, int off, void *to, int len) | |
14775 int __builtin_bpf_helper_skb_load_bytes_relative (void *ctx, int off, void *to, int len, __u32 start_header) | |
14776 int __builtin_bpf_helper_skb_store_bytes (void *ctx, int off, void *from, int len, int flags) | |
14777 int __builtin_bpf_helper_skb_under_cgroup (void *ctx, void *map, int index) | |
14778 int __builtin_bpf_helper_skb_change_head (void *, int len, int flags) | |
14779 int __builtin_bpf_helper_skb_pull_data (void *, int len) | |
14780 int __builtin_bpf_helper_skb_change_proto (void *ctx, __be16 proto, __u64 flags) | |
14781 int __builtin_bpf_helper_skb_change_type (void *ctx, __u32 type) | |
14782 int __builtin_bpf_helper_skb_change_tail (void *ctx, __u32 len, __u64 flags) | |
14783 int __builtin_bpf_helper_skb_adjust_room (void *ctx, __s32 len_diff, __u32 mode, | |
14784 unsigned long long flags) | |
14785 @end smallexample | |
14786 | |
14787 Other helpers: | |
14788 | |
14789 @smallexample | |
14790 int __builtin_bpf_helper_probe_read (void *dst, unsigned int size, void *src) | |
14791 unsigned long long __builtin_bpf_helper_ktime_get_ns (void) | |
14792 int __builtin_bpf_helper_trace_printk (const char *fmt, unsigned int fmt_size, ...) | |
14793 void __builtin_bpf_helper_tail_call (void *ctx, void *prog_array_map, unsigned int index) | |
14794 unsigned int __builtin_bpf_helper_get_smp_processor_id (void) | |
14795 unsigned long long __builtin_bpf_helper_get_current_pid_tgid (void) | |
14796 unsigned long long __builtin_bpf_helper_get_current_uid_gid (void) | |
14797 int __builtin_bpf_helper_get_current_comm (void *buf, unsigned int size_of_buf) | |
14798 unsigned long long __builtin_bpf_helper_perf_event_read (void *map, unsigned long long flags) | |
14799 | |
14800 int __builtin_bpf_helper_redirect (unsigned int ifindex, unsigned long long flags) | |
14801 int __builtin_bpf_helper_redirect_map (void *map, unsigned int key, unsigned long long flags) | |
14802 int __builtin_bpf_helper_perf_event_output (void *ctx,void *map, unsigned long long flags, void *data, unsigned long long size) | |
14803 int __builtin_bpf_helper_get_stackid (void *ctx, void *map, unsigned long long flags) | |
14804 int __builtin_bpf_helper_probe_write_user (void *dst, const void *src, unsigned int len) | |
14805 int __builtin_bpf_helper_current_task_under_cgroup (void *map, unsigned int index) | |
14806 | |
14807 static unsigned long long __builtin_bpf_helper_get_prandom_u32 (void) | |
14808 int __builtin_bpf_helper_xdp_adjust_head (void *ctx, int offset) | |
14809 int __builtin_bpf_helper_xdp_adjust_meta (void *ctx, int offset) | |
14810 int __builtin_bpf_helper_get_socket_cookie (void *ctx) | |
14811 int __builtin_bpf_helper_setsockopt (void *ctx, int level, int optname, void *optval, | |
14812 int optlen) | |
14813 int __builtin_bpf_helper_getsockopt (void *ctx, int level, int optname, void *optval, | |
14814 int optlen) | |
14815 int __builtin_bpf_helper_sock_ops_cb_flags_set (void *ctx, int flags) | |
14816 int __builtin_bpf_helper_sk_redirect_map (void *ctx, void *map, int key, int flags) | |
14817 int __builtin_bpf_helper_sk_redirect_hash (void *ctx, void *map, void *key, int flags) | |
14818 int __builtin_bpf_helper_sock_map_update (void *map, void *key, void *value, | |
14819 unsigned long long flags) | |
14820 int __builtin_bpf_helper_sock_hash_update (void *map, void *key, void *value, | |
14821 unsigned long long flags) | |
14822 int __builtin_bpf_helper_perf_event_read_value (void *map, unsigned long long flags, | |
14823 void *buf, unsigned int buf_size) | |
14824 int __builtin_bpf_helper_perf_prog_read_value (void *ctx, void *buf, | |
14825 unsigned int buf_size) | |
14826 | |
14827 int __builtin_bpf_helper_override_return (void *ctx, unsigned long rc) | |
14828 int __builtin_bpf_helper_msg_redirect_map (void *ctx, void *map, int key, int flags) | |
14829 int __builtin_bpf_helper_msg_redirect_hash (void *ctx, | |
14830 void *map, void *key, int flags) | |
14831 int __builtin_bpf_helper_msg_apply_bytes (void *ctx, int len) | |
14832 int __builtin_bpf_helper_msg_cork_bytes (void *ctx, int len) | |
14833 int __builtin_bpf_helper_msg_pull_data (void *ctx, int start, int end, int flags) | |
14834 int __builtin_bpf_helper_msg_push_data (void *ctx, int start, int end, int flags) | |
14835 int __builtin_bpf_helper_msg_pop_data (void *ctx, int start, int cut, int flags) | |
14836 int __builtin_bpf_helper_bind (void *ctx, void *addr, int addr_len) | |
14837 int __builtin_bpf_helper_xdp_adjust_tail (void *ctx, int offset) | |
14838 int __builtin_bpf_helper_sk_select_reuseport (void *ctx, void *map, void *key, __u32 flags) | |
14839 int __builtin_bpf_helper_get_stack (void *ctx, void *buf, int size, int flags) | |
14840 int __builtin_bpf_helper_fib_lookup (void *ctx, struct bpf_fib_lookup *params, | |
14841 int plen, __u32 flags) | |
14842 | |
14843 int __builtin_bpf_helper_lwt_push_encap (void *ctx, unsigned int type, void *hdr, | |
14844 unsigned int len) | |
14845 int __builtin_bpf_helper_lwt_seg6_store_bytes (void *ctx, unsigned int offset, | |
14846 void *from, unsigned int len) | |
14847 int __builtin_bpf_helper_lwt_seg6_action (void *ctx, unsigned int action, void *param, | |
14848 unsigned int param_len) | |
14849 int __builtin_bpf_helper_lwt_seg6_adjust_srh (void *ctx, unsigned int offset, | |
14850 unsigned int len) | |
14851 int __builtin_bpf_helper_rc_repeat (void *ctx) | |
14852 int __builtin_bpf_helper_rc_keydown (void *ctx, unsigned int protocol, | |
14853 unsigned long long scancode, unsigned int toggle) | |
14854 static unsigned long long __builtin_bpf_helper_get_current_cgroup_id (void) | |
14855 static void *__builtin_bpf_helper_get_local_storage (void *map, unsigned long long flags) | |
14856 static struct bpf_sock *__builtin_bpf_helper_sk_lookup_tcp (void *ctx, void *tuple, int size, unsigned long long netns_id, unsigned long long flags) | |
14857 static struct bpf_sock *__builtin_bpf_helper_sk_lookup_udp (void *ctx, void *tuple, int size, unsigned long long netns_id, unsigned long long flags) | |
14858 int __builtin_bpf_helper_sk_release (struct bpf_sock *sk) | |
14859 int __builtin_bpf_helper_rc_pointer_rel (void *ctx, int rel_x, int rel_y) | |
14860 static void __builtin_bpf_helper_spin_lock (struct bpf_spin_lock *lock) | |
14861 static void __builtin_bpf_helper_spin_unlock (struct bpf_spin_lock *lock) | |
14862 | |
14863 static struct bpf_sock *__builtin_bpf_helper_sk_fullsock (struct bpf_sock *sk) | |
14864 static struct bpf_tcp_sock *__builtin_bpf_helper_tcp_sock (struct bpf_sock *sk) | |
14865 static struct bpf_sock *__builtin_bpf_helper_get_listener_sock (struct bpf_sock *sk) | |
14866 | |
14867 int __builtin_bpf_helper_l3_csum_replace (void *ctx, int off, int from, int to, int flags) | |
14868 int __builtin_bpf_helper_l4_csum_replace (void *ctx, int off, int from, int to, int flags) | |
14869 int __builtin_bpf_helper_csum_diff (void *from, int from_size, void *to, int to_size, int seed) | |
14870 | |
14871 static unsigned int __builtin_bpf_helper_get_cgroup_classid (void *ctx) | |
14872 static unsigned int __builtin_bpf_helper_get_route_realm (void *ctx) | |
14873 static unsigned int __builtin_bpf_helper_get_hash_recalc (void *ctx) | |
14874 static unsigned long long __builtin_bpf_helper_get_current_task (void *ctx) | |
14875 | |
14876 static long long __builtin_bpf_helper_csum_update (void *ctx, __u32 csum) | |
14877 static void __builtin_bpf_helper_set_hash_invalid (void *ctx) | |
14878 int __builtin_bpf_helper_get_numa_node_id (void) | |
14879 int __builtin_bpf_helper_probe_read_str (void *ctx, __u32 size, | |
14880 const void *unsafe_ptr) | |
14881 static unsigned int __builtin_bpf_helper_get_socket_uid (void *ctx) | |
14882 static unsigned int __builtin_bpf_helper_set_hash (void *ctx, __u32 hash) | |
14883 @end smallexample | |
14884 | |
13516 | 14885 |
13517 @node FR-V Built-in Functions | 14886 @node FR-V Built-in Functions |
13518 @subsection FR-V Built-in Functions | 14887 @subsection FR-V Built-in Functions |
13519 | 14888 |
13520 GCC provides many FR-V-specific built-in functions. In general, | 14889 GCC provides many FR-V-specific built-in functions. In general, |
14626 Comparison of two paired-single values | 15995 Comparison of two paired-single values |
14627 (@code{c.@var{cond}.ps}/@code{cabs.@var{cond}.ps}, | 15996 (@code{c.@var{cond}.ps}/@code{cabs.@var{cond}.ps}, |
14628 @code{bc1any2t}/@code{bc1any2f}). | 15997 @code{bc1any2t}/@code{bc1any2f}). |
14629 | 15998 |
14630 These functions compare @var{a} and @var{b} using @code{c.@var{cond}.ps} | 15999 These functions compare @var{a} and @var{b} using @code{c.@var{cond}.ps} |
14631 or @code{cabs.@var{cond}.ps}. The @code{any} forms return true if either | 16000 or @code{cabs.@var{cond}.ps}. The @code{any} forms return @code{true} if either |
14632 result is true and the @code{all} forms return true if both results are true. | 16001 result is @code{true} and the @code{all} forms return @code{true} if both results are @code{true}. |
14633 For example: | 16002 For example: |
14634 | 16003 |
14635 @smallexample | 16004 @smallexample |
14636 v2sf a, b; | 16005 v2sf a, b; |
14637 if (__builtin_mips_any_c_eq_ps (a, b)) | 16006 if (__builtin_mips_any_c_eq_ps (a, b)) |
14653 (@code{c.@var{cond}.ps}/@code{cabs.@var{cond}.ps}, | 16022 (@code{c.@var{cond}.ps}/@code{cabs.@var{cond}.ps}, |
14654 @code{bc1any4t}/@code{bc1any4f}). | 16023 @code{bc1any4t}/@code{bc1any4f}). |
14655 | 16024 |
14656 These functions use @code{c.@var{cond}.ps} or @code{cabs.@var{cond}.ps} | 16025 These functions use @code{c.@var{cond}.ps} or @code{cabs.@var{cond}.ps} |
14657 to compare @var{a} with @var{b} and to compare @var{c} with @var{d}. | 16026 to compare @var{a} with @var{b} and to compare @var{c} with @var{d}. |
14658 The @code{any} forms return true if any of the four results are true | 16027 The @code{any} forms return @code{true} if any of the four results are @code{true} |
14659 and the @code{all} forms return true if all four results are true. | 16028 and the @code{all} forms return @code{true} if all four results are @code{true}. |
14660 For example: | 16029 For example: |
14661 | 16030 |
14662 @smallexample | 16031 @smallexample |
14663 v2sf a, b, c, d; | 16032 v2sf a, b, c, d; |
14664 if (__builtin_mips_any_c_eq_4s (a, b, c, d)) | 16033 if (__builtin_mips_any_c_eq_4s (a, b, c, d)) |
15192 v16i8 __builtin_msa_insve_b (v16i8, imm0_15, v16i8); | 16561 v16i8 __builtin_msa_insve_b (v16i8, imm0_15, v16i8); |
15193 v8i16 __builtin_msa_insve_h (v8i16, imm0_7, v8i16); | 16562 v8i16 __builtin_msa_insve_h (v8i16, imm0_7, v8i16); |
15194 v4i32 __builtin_msa_insve_w (v4i32, imm0_3, v4i32); | 16563 v4i32 __builtin_msa_insve_w (v4i32, imm0_3, v4i32); |
15195 v2i64 __builtin_msa_insve_d (v2i64, imm0_1, v2i64); | 16564 v2i64 __builtin_msa_insve_d (v2i64, imm0_1, v2i64); |
15196 | 16565 |
15197 v16i8 __builtin_msa_ld_b (void *, imm_n512_511); | 16566 v16i8 __builtin_msa_ld_b (const void *, imm_n512_511); |
15198 v8i16 __builtin_msa_ld_h (void *, imm_n1024_1022); | 16567 v8i16 __builtin_msa_ld_h (const void *, imm_n1024_1022); |
15199 v4i32 __builtin_msa_ld_w (void *, imm_n2048_2044); | 16568 v4i32 __builtin_msa_ld_w (const void *, imm_n2048_2044); |
15200 v2i64 __builtin_msa_ld_d (void *, imm_n4096_4088); | 16569 v2i64 __builtin_msa_ld_d (const void *, imm_n4096_4088); |
15201 | 16570 |
15202 v16i8 __builtin_msa_ldi_b (imm_n512_511); | 16571 v16i8 __builtin_msa_ldi_b (imm_n512_511); |
15203 v8i16 __builtin_msa_ldi_h (imm_n512_511); | 16572 v8i16 __builtin_msa_ldi_h (imm_n512_511); |
15204 v4i32 __builtin_msa_ldi_w (imm_n512_511); | 16573 v4i32 __builtin_msa_ldi_w (imm_n512_511); |
15205 v2i64 __builtin_msa_ldi_d (imm_n512_511); | 16574 v2i64 __builtin_msa_ldi_d (imm_n512_511); |
15792 The following built-in functions are also available on all PowerPC | 17161 The following built-in functions are also available on all PowerPC |
15793 processors: | 17162 processors: |
15794 @smallexample | 17163 @smallexample |
15795 uint64_t __builtin_ppc_get_timebase (); | 17164 uint64_t __builtin_ppc_get_timebase (); |
15796 unsigned long __builtin_ppc_mftb (); | 17165 unsigned long __builtin_ppc_mftb (); |
15797 __ibm128 __builtin_unpack_ibm128 (__ibm128, int); | 17166 double __builtin_unpack_ibm128 (__ibm128, int); |
15798 __ibm128 __builtin_pack_ibm128 (double, double); | 17167 __ibm128 __builtin_pack_ibm128 (double, double); |
15799 double __builtin_mffs (void); | 17168 double __builtin_mffs (void); |
17169 void __builtin_mtfsf (const int, double); | |
15800 void __builtin_mtfsb0 (const int); | 17170 void __builtin_mtfsb0 (const int); |
15801 void __builtin_mtfsb1 (const int); | 17171 void __builtin_mtfsb1 (const int); |
15802 void __builtin_set_fpscr_rn (int); | 17172 void __builtin_set_fpscr_rn (int); |
15803 @end smallexample | 17173 @end smallexample |
15804 | 17174 |
15810 returns the Time Base Register value as an unsigned long, throwing away | 17180 returns the Time Base Register value as an unsigned long, throwing away |
15811 the most significant word on 32-bit environments. The @code{__builtin_mffs} | 17181 the most significant word on 32-bit environments. The @code{__builtin_mffs} |
15812 return the value of the FPSCR register. Note, ISA 3.0 supports the | 17182 return the value of the FPSCR register. Note, ISA 3.0 supports the |
15813 @code{__builtin_mffsl()} which permits software to read the control and | 17183 @code{__builtin_mffsl()} which permits software to read the control and |
15814 non-sticky status bits in the FSPCR without the higher latency associated with | 17184 non-sticky status bits in the FSPCR without the higher latency associated with |
15815 accessing the sticky status bits. The | 17185 accessing the sticky status bits. The @code{__builtin_mtfsf} takes a constant |
17186 8-bit integer field mask and a double precision floating point argument | |
17187 and generates the @code{mtfsf} (extended mnemonic) instruction to write new | |
17188 values to selected fields of the FPSCR. The | |
15816 @code{__builtin_mtfsb0} and @code{__builtin_mtfsb1} take the bit to change | 17189 @code{__builtin_mtfsb0} and @code{__builtin_mtfsb1} take the bit to change |
15817 as an argument. The valid bit range is between 0 and 31. The builtins map to | 17190 as an argument. The valid bit range is between 0 and 31. The builtins map to |
15818 the @code{mtfsb0} and @code{mtfsb1} instructions which take the argument and | 17191 the @code{mtfsb0} and @code{mtfsb1} instructions which take the argument and |
15819 add 32. Hence these instructions only modify the FPSCR[32:63] bits by | 17192 add 32. Hence these instructions only modify the FPSCR[32:63] bits by |
15820 changing the specified bit to a zero or one respectively. The | 17193 changing the specified bit to a zero or one respectively. The |
15821 @code{__builtin_set_fpscr_rn} builtin allows changing both of the floating | 17194 @code{__builtin_set_fpscr_rn} builtin allows changing both of the floating |
15822 point rounding mode bits. The argument is a 2-bit value. The argument can | 17195 point rounding mode bits. The argument is a 2-bit value. The argument can |
15823 either be a const int or stored in a variable. The builtin uses the ISA 3.0 | 17196 either be a @code{const int} or stored in a variable. The builtin uses |
17197 the ISA 3.0 | |
15824 instruction @code{mffscrn} if available, otherwise it reads the FPSCR, masks | 17198 instruction @code{mffscrn} if available, otherwise it reads the FPSCR, masks |
15825 the current rounding mode bits out and OR's in the new value. | 17199 the current rounding mode bits out and OR's in the new value. |
15826 | 17200 |
15827 @node Basic PowerPC Built-in Functions Available on ISA 2.05 | 17201 @node Basic PowerPC Built-in Functions Available on ISA 2.05 |
15828 @subsubsection Basic PowerPC Built-in Functions Available on ISA 2.05 | 17202 @subsubsection Basic PowerPC Built-in Functions Available on ISA 2.05 |
15833 command line, specifying option @option{-mcpu=power6} has the effect of | 17207 command line, specifying option @option{-mcpu=power6} has the effect of |
15834 enabling the @option{-mpowerpc64}, @option{-mpowerpc-gpopt}, | 17208 enabling the @option{-mpowerpc64}, @option{-mpowerpc-gpopt}, |
15835 @option{-mpowerpc-gfxopt}, @option{-mmfcrf}, @option{-mpopcntb}, | 17209 @option{-mpowerpc-gfxopt}, @option{-mmfcrf}, @option{-mpopcntb}, |
15836 @option{-mfprnd}, @option{-mcmpb}, @option{-mhard-dfp}, and | 17210 @option{-mfprnd}, @option{-mcmpb}, @option{-mhard-dfp}, and |
15837 @option{-mrecip-precision} options. Specify the | 17211 @option{-mrecip-precision} options. Specify the |
15838 @option{-maltivec} and @option{-mfpgpr} options explicitly in | 17212 @option{-maltivec} option explicitly in |
15839 combination with the above options if they are desired. | 17213 combination with the above options if desired. |
15840 | 17214 |
15841 The following functions require option @option{-mcmpb}. | 17215 The following functions require option @option{-mcmpb}. |
15842 @smallexample | 17216 @smallexample |
15843 unsigned long long __builtin_cmpb (unsigned long long int, unsigned long long int); | 17217 unsigned long long __builtin_cmpb (unsigned long long int, unsigned long long int); |
15844 unsigned int __builtin_cmpb (unsigned int, unsigned int); | 17218 unsigned int __builtin_cmpb (unsigned int, unsigned int); |
15874 _Decimal128 __builtin_pack_dec128 (unsigned long long, unsigned long long); | 17248 _Decimal128 __builtin_pack_dec128 (unsigned long long, unsigned long long); |
15875 unsigned long long __builtin_unpack_dec128 (_Decimal128, int); | 17249 unsigned long long __builtin_unpack_dec128 (_Decimal128, int); |
15876 | 17250 |
15877 The @code{__builtin_set_fpscr_drn} builtin allows changing the three decimal | 17251 The @code{__builtin_set_fpscr_drn} builtin allows changing the three decimal |
15878 floating point rounding mode bits. The argument is a 3-bit value. The | 17252 floating point rounding mode bits. The argument is a 3-bit value. The |
15879 argument can either be a const int or the value can be stored in a variable. | 17253 argument can either be a @code{const int} or the value can be stored in |
17254 a variable. | |
15880 The builtin uses the ISA 3.0 instruction @code{mffscdrn} if available. | 17255 The builtin uses the ISA 3.0 instruction @code{mffscdrn} if available. |
15881 Otherwise the builtin reads the FPSCR, masks the current decimal rounding | 17256 Otherwise the builtin reads the FPSCR, masks the current decimal rounding |
15882 mode bits out and OR's in the new value. | 17257 mode bits out and OR's in the new value. |
15883 | 17258 |
15884 @end smallexample | 17259 @end smallexample |
15908 The @code{__builtin_unpack_longdouble} function takes a | 17283 The @code{__builtin_unpack_longdouble} function takes a |
15909 @code{long double} argument and a compile time constant of 0 or 1. If | 17284 @code{long double} argument and a compile time constant of 0 or 1. If |
15910 the constant is 0, the first @code{double} within the | 17285 the constant is 0, the first @code{double} within the |
15911 @code{long double} is returned, otherwise the second @code{double} | 17286 @code{long double} is returned, otherwise the second @code{double} |
15912 is returned. The @code{__builtin_unpack_longdouble} function is only | 17287 is returned. The @code{__builtin_unpack_longdouble} function is only |
15913 availble if @code{long double} uses the IBM extended double | 17288 available if @code{long double} uses the IBM extended double |
15914 representation. | 17289 representation. |
15915 | 17290 |
15916 The @code{__builtin_pack_longdouble} function takes two @code{double} | 17291 The @code{__builtin_pack_longdouble} function takes two @code{double} |
15917 arguments and returns a @code{long double} value that combines the two | 17292 arguments and returns a @code{long double} value that combines the two |
15918 arguments. The @code{__builtin_pack_longdouble} function is only | 17293 arguments. The @code{__builtin_pack_longdouble} function is only |
15919 availble if @code{long double} uses the IBM extended double | 17294 available if @code{long double} uses the IBM extended double |
15920 representation. | 17295 representation. |
15921 | 17296 |
15922 The @code{__builtin_unpack_ibm128} function takes a @code{__ibm128} | 17297 The @code{__builtin_unpack_ibm128} function takes a @code{__ibm128} |
15923 argument and a compile time constant of 0 or 1. If the constant is 0, | 17298 argument and a compile time constant of 0 or 1. If the constant is 0, |
15924 the first @code{double} within the @code{__ibm128} is returned, | 17299 the first @code{double} within the @code{__ibm128} is returned, |
16193 of the keywords @code{vector}, @code{pixel} and @code{bool} is | 17568 of the keywords @code{vector}, @code{pixel} and @code{bool} is |
16194 disabled. To use them, you must include @code{<altivec.h>} instead. | 17569 disabled. To use them, you must include @code{<altivec.h>} instead. |
16195 | 17570 |
16196 @item | 17571 @item |
16197 GCC allows using a @code{typedef} name as the type specifier for a | 17572 GCC allows using a @code{typedef} name as the type specifier for a |
16198 vector type. | 17573 vector type, but only under the following circumstances: |
17574 | |
17575 @itemize @bullet | |
17576 | |
17577 @item | |
17578 When using @code{__vector} instead of @code{vector}; for example, | |
17579 | |
17580 @smallexample | |
17581 typedef signed short int16; | |
17582 __vector int16 data; | |
17583 @end smallexample | |
17584 | |
17585 @item | |
17586 When using @code{vector} in keyword-and-predefine mode; for example, | |
17587 | |
17588 @smallexample | |
17589 typedef signed short int16; | |
17590 vector int16 data; | |
17591 @end smallexample | |
17592 | |
17593 Note that keyword-and-predefine mode is enabled by disabling GNU | |
17594 extensions (e.g., by using @code{-std=c11}) and including | |
17595 @code{<altivec.h>}. | |
17596 @end itemize | |
16199 | 17597 |
16200 @item | 17598 @item |
16201 For C, overloaded functions are implemented with macros so the following | 17599 For C, overloaded functions are implemented with macros so the following |
16202 does not work: | 17600 does not work: |
16203 | 17601 |
17972 vector float vec_div (vector float, vector float); | 19370 vector float vec_div (vector float, vector float); |
17973 vector double vec_div (vector double, vector double); | 19371 vector double vec_div (vector double, vector double); |
17974 vector long vec_div (vector long, vector long); | 19372 vector long vec_div (vector long, vector long); |
17975 vector unsigned long vec_div (vector unsigned long, vector unsigned long); | 19373 vector unsigned long vec_div (vector unsigned long, vector unsigned long); |
17976 vector double vec_floor (vector double); | 19374 vector double vec_floor (vector double); |
19375 vector signed long long vec_ld (int, const vector signed long long *); | |
19376 vector signed long long vec_ld (int, const signed long long *); | |
19377 vector unsigned long long vec_ld (int, const vector unsigned long long *); | |
19378 vector unsigned long long vec_ld (int, const unsigned long long *); | |
17977 vector __int128 vec_ld (int, const vector __int128 *); | 19379 vector __int128 vec_ld (int, const vector __int128 *); |
17978 vector unsigned __int128 vec_ld (int, const vector unsigned __int128 *); | 19380 vector unsigned __int128 vec_ld (int, const vector unsigned __int128 *); |
17979 vector __int128 vec_ld (int, const __int128 *); | 19381 vector __int128 vec_ld (int, const __int128 *); |
17980 vector unsigned __int128 vec_ld (int, const unsigned __int128 *); | 19382 vector unsigned __int128 vec_ld (int, const unsigned __int128 *); |
17981 vector double vec_ld (int, const vector double *); | 19383 vector double vec_ld (int, const vector double *); |
18050 vector double vec_splats (double); | 19452 vector double vec_splats (double); |
18051 vector signed long vec_splats (signed long); | 19453 vector signed long vec_splats (signed long); |
18052 vector unsigned long vec_splats (unsigned long); | 19454 vector unsigned long vec_splats (unsigned long); |
18053 vector float vec_sqrt (vector float); | 19455 vector float vec_sqrt (vector float); |
18054 vector double vec_sqrt (vector double); | 19456 vector double vec_sqrt (vector double); |
19457 void vec_st (vector signed long long, int, vector signed long long *); | |
19458 void vec_st (vector signed long long, int, signed long long *); | |
19459 void vec_st (vector unsigned long long, int, vector unsigned long long *); | |
19460 void vec_st (vector unsigned long long, int, unsigned long long *); | |
19461 void vec_st (vector bool long long, int, vector bool long long *); | |
19462 void vec_st (vector bool long long, int, signed long long *); | |
19463 void vec_st (vector bool long long, int, unsigned long long *); | |
18055 void vec_st (vector double, int, vector double *); | 19464 void vec_st (vector double, int, vector double *); |
18056 void vec_st (vector double, int, double *); | 19465 void vec_st (vector double, int, double *); |
18057 vector double vec_sub (vector double, vector double); | 19466 vector double vec_sub (vector double, vector double); |
18058 vector double vec_trunc (vector double); | 19467 vector double vec_trunc (vector double); |
18059 vector double vec_xl (int, vector double *); | 19468 vector double vec_xl (int, vector double *); |
19172 @option{-mcpu=power8}), the following builtins are enabled. | 20581 @option{-mcpu=power8}), the following builtins are enabled. |
19173 | 20582 |
19174 @smallexample | 20583 @smallexample |
19175 vector unsigned long long __builtin_crypto_vsbox (vector unsigned long long); | 20584 vector unsigned long long __builtin_crypto_vsbox (vector unsigned long long); |
19176 | 20585 |
20586 vector unsigned char vec_sbox_be (vector unsigned char); | |
20587 | |
19177 vector unsigned long long __builtin_crypto_vcipher (vector unsigned long long, | 20588 vector unsigned long long __builtin_crypto_vcipher (vector unsigned long long, |
19178 vector unsigned long long); | 20589 vector unsigned long long); |
20590 | |
20591 vector unsigned char vec_cipher_be (vector unsigned char, vector unsigned char); | |
19179 | 20592 |
19180 vector unsigned long long __builtin_crypto_vcipherlast | 20593 vector unsigned long long __builtin_crypto_vcipherlast |
19181 (vector unsigned long long, | 20594 (vector unsigned long long, |
19182 vector unsigned long long); | 20595 vector unsigned long long); |
19183 | 20596 |
20597 vector unsigned char vec_cipherlast_be (vector unsigned char, | |
20598 vector unsigned char); | |
20599 | |
19184 vector unsigned long long __builtin_crypto_vncipher (vector unsigned long long, | 20600 vector unsigned long long __builtin_crypto_vncipher (vector unsigned long long, |
19185 vector unsigned long long); | 20601 vector unsigned long long); |
19186 | 20602 |
20603 vector unsigned char vec_ncipher_be (vector unsigned char, | |
20604 vector unsigned char); | |
20605 | |
19187 vector unsigned long long __builtin_crypto_vncipherlast (vector unsigned long long, | 20606 vector unsigned long long __builtin_crypto_vncipherlast (vector unsigned long long, |
19188 vector unsigned long long); | 20607 vector unsigned long long); |
20608 | |
20609 vector unsigned char vec_ncipherlast_be (vector unsigned char, | |
20610 vector unsigned char); | |
19189 | 20611 |
19190 vector unsigned char __builtin_crypto_vpermxor (vector unsigned char, | 20612 vector unsigned char __builtin_crypto_vpermxor (vector unsigned char, |
19191 vector unsigned char, | 20613 vector unsigned char, |
19192 vector unsigned char); | 20614 vector unsigned char); |
19193 | 20615 |
19265 | 20687 |
19266 The HTM builtins (with the exception of @code{__builtin_tbegin}) return | 20688 The HTM builtins (with the exception of @code{__builtin_tbegin}) return |
19267 the full 4-bit condition register value set by their associated hardware | 20689 the full 4-bit condition register value set by their associated hardware |
19268 instruction. The header file @code{htmintrin.h} defines some macros that can | 20690 instruction. The header file @code{htmintrin.h} defines some macros that can |
19269 be used to decipher the return value. The @code{__builtin_tbegin} builtin | 20691 be used to decipher the return value. The @code{__builtin_tbegin} builtin |
19270 returns a simple true or false value depending on whether a transaction was | 20692 returns a simple @code{true} or @code{false} value depending on whether a transaction was |
19271 successfully started or not. The arguments of the builtins match exactly the | 20693 successfully started or not. The arguments of the builtins match exactly the |
19272 type and order of the associated hardware instruction's operands, except for | 20694 type and order of the associated hardware instruction's operands, except for |
19273 the @code{__builtin_tcheck} builtin, which does not take any input arguments. | 20695 the @code{__builtin_tcheck} builtin, which does not take any input arguments. |
19274 Refer to the ISA manual for a description of each instruction's operands. | 20696 Refer to the ISA manual for a description of each instruction's operands. |
19275 | 20697 |
20018 long __builtin_vis_fpcmpur8shl (v8qi, v8qi, int); | 21440 long __builtin_vis_fpcmpur8shl (v8qi, v8qi, int); |
20019 long __builtin_vis_fpcmpur16shl (v4hi, v4hi, int); | 21441 long __builtin_vis_fpcmpur16shl (v4hi, v4hi, int); |
20020 long __builtin_vis_fpcmpur32shl (v2si, v2si, int); | 21442 long __builtin_vis_fpcmpur32shl (v2si, v2si, int); |
20021 @end smallexample | 21443 @end smallexample |
20022 | 21444 |
20023 @node SPU Built-in Functions | |
20024 @subsection SPU Built-in Functions | |
20025 | |
20026 GCC provides extensions for the SPU processor as described in the | |
20027 Sony/Toshiba/IBM SPU Language Extensions Specification. GCC's | |
20028 implementation differs in several ways. | |
20029 | |
20030 @itemize @bullet | |
20031 | |
20032 @item | |
20033 The optional extension of specifying vector constants in parentheses is | |
20034 not supported. | |
20035 | |
20036 @item | |
20037 A vector initializer requires no cast if the vector constant is of the | |
20038 same type as the variable it is initializing. | |
20039 | |
20040 @item | |
20041 If @code{signed} or @code{unsigned} is omitted, the signedness of the | |
20042 vector type is the default signedness of the base type. The default | |
20043 varies depending on the operating system, so a portable program should | |
20044 always specify the signedness. | |
20045 | |
20046 @item | |
20047 By default, the keyword @code{__vector} is added. The macro | |
20048 @code{vector} is defined in @code{<spu_intrinsics.h>} and can be | |
20049 undefined. | |
20050 | |
20051 @item | |
20052 GCC allows using a @code{typedef} name as the type specifier for a | |
20053 vector type. | |
20054 | |
20055 @item | |
20056 For C, overloaded functions are implemented with macros so the following | |
20057 does not work: | |
20058 | |
20059 @smallexample | |
20060 spu_add ((vector signed int)@{1, 2, 3, 4@}, foo); | |
20061 @end smallexample | |
20062 | |
20063 @noindent | |
20064 Since @code{spu_add} is a macro, the vector constant in the example | |
20065 is treated as four separate arguments. Wrap the entire argument in | |
20066 parentheses for this to work. | |
20067 | |
20068 @item | |
20069 The extended version of @code{__builtin_expect} is not supported. | |
20070 | |
20071 @end itemize | |
20072 | |
20073 @emph{Note:} Only the interface described in the aforementioned | |
20074 specification is supported. Internally, GCC uses built-in functions to | |
20075 implement the required functionality, but these are not supported and | |
20076 are subject to change without notice. | |
20077 | |
20078 @node TI C6X Built-in Functions | 21445 @node TI C6X Built-in Functions |
20079 @subsection TI C6X Built-in Functions | 21446 @subsection TI C6X Built-in Functions |
20080 | 21447 |
20081 GCC provides intrinsics to access certain instructions of the TI C6X | 21448 GCC provides intrinsics to access certain instructions of the TI C6X |
20082 processors. These intrinsics, listed below, are available after | 21449 processors. These intrinsics, listed below, are available after |
20294 This function returns a positive integer if the run-time CPU | 21661 This function returns a positive integer if the run-time CPU |
20295 is of type @var{cpuname} | 21662 is of type @var{cpuname} |
20296 and returns @code{0} otherwise. The following CPU names can be detected: | 21663 and returns @code{0} otherwise. The following CPU names can be detected: |
20297 | 21664 |
20298 @table @samp | 21665 @table @samp |
21666 @item amd | |
21667 AMD CPU. | |
21668 | |
20299 @item intel | 21669 @item intel |
20300 Intel CPU. | 21670 Intel CPU. |
20301 | 21671 |
20302 @item atom | 21672 @item atom |
20303 Intel Atom CPU. | 21673 Intel Atom CPU. |
20304 | 21674 |
21675 @item slm | |
21676 Intel Silvermont CPU. | |
21677 | |
20305 @item core2 | 21678 @item core2 |
20306 Intel Core 2 CPU. | 21679 Intel Core 2 CPU. |
20307 | 21680 |
20308 @item corei7 | 21681 @item corei7 |
20309 Intel Core i7 CPU. | 21682 Intel Core i7 CPU. |
20315 Intel Core i7 Westmere CPU. | 21688 Intel Core i7 Westmere CPU. |
20316 | 21689 |
20317 @item sandybridge | 21690 @item sandybridge |
20318 Intel Core i7 Sandy Bridge CPU. | 21691 Intel Core i7 Sandy Bridge CPU. |
20319 | 21692 |
20320 @item amd | 21693 @item ivybridge |
20321 AMD CPU. | 21694 Intel Core i7 Ivy Bridge CPU. |
21695 | |
21696 @item haswell | |
21697 Intel Core i7 Haswell CPU. | |
21698 | |
21699 @item broadwell | |
21700 Intel Core i7 Broadwell CPU. | |
21701 | |
21702 @item skylake | |
21703 Intel Core i7 Skylake CPU. | |
21704 | |
21705 @item skylake-avx512 | |
21706 Intel Core i7 Skylake AVX512 CPU. | |
21707 | |
21708 @item cannonlake | |
21709 Intel Core i7 Cannon Lake CPU. | |
21710 | |
21711 @item icelake-client | |
21712 Intel Core i7 Ice Lake Client CPU. | |
21713 | |
21714 @item icelake-server | |
21715 Intel Core i7 Ice Lake Server CPU. | |
21716 | |
21717 @item cascadelake | |
21718 Intel Core i7 Cascadelake CPU. | |
21719 | |
21720 @item tigerlake | |
21721 Intel Core i7 Tigerlake CPU. | |
21722 | |
21723 @item cooperlake | |
21724 Intel Core i7 Cooperlake CPU. | |
21725 | |
21726 @item bonnell | |
21727 Intel Atom Bonnell CPU. | |
21728 | |
21729 @item silvermont | |
21730 Intel Atom Silvermont CPU. | |
21731 | |
21732 @item goldmont | |
21733 Intel Atom Goldmont CPU. | |
21734 | |
21735 @item goldmont-plus | |
21736 Intel Atom Goldmont Plus CPU. | |
21737 | |
21738 @item tremont | |
21739 Intel Atom Tremont CPU. | |
21740 | |
21741 @item knl | |
21742 Intel Knights Landing CPU. | |
21743 | |
21744 @item knm | |
21745 Intel Knights Mill CPU. | |
20322 | 21746 |
20323 @item amdfam10h | 21747 @item amdfam10h |
20324 AMD Family 10h CPU. | 21748 AMD Family 10h CPU. |
20325 | 21749 |
20326 @item barcelona | 21750 @item barcelona |
20356 @item amdfam17h | 21780 @item amdfam17h |
20357 AMD Family 17h CPU. | 21781 AMD Family 17h CPU. |
20358 | 21782 |
20359 @item znver1 | 21783 @item znver1 |
20360 AMD Family 17h Zen version 1. | 21784 AMD Family 17h Zen version 1. |
21785 | |
21786 @item znver2 | |
21787 AMD Family 17h Zen version 2. | |
20361 @end table | 21788 @end table |
20362 | 21789 |
20363 Here is an example: | 21790 Here is an example: |
20364 @smallexample | 21791 @smallexample |
20365 if (__builtin_cpu_is ("corei7")) | 21792 if (__builtin_cpu_is ("corei7")) |
20399 SSE4.2 instructions. | 21826 SSE4.2 instructions. |
20400 @item avx | 21827 @item avx |
20401 AVX instructions. | 21828 AVX instructions. |
20402 @item avx2 | 21829 @item avx2 |
20403 AVX2 instructions. | 21830 AVX2 instructions. |
21831 @item sse4a | |
21832 SSE4A instructions. | |
21833 @item fma4 | |
21834 FMA4 instructions. | |
21835 @item xop | |
21836 XOP instructions. | |
21837 @item fma | |
21838 FMA instructions. | |
20404 @item avx512f | 21839 @item avx512f |
20405 AVX512F instructions. | 21840 AVX512F instructions. |
21841 @item bmi | |
21842 BMI instructions. | |
21843 @item bmi2 | |
21844 BMI2 instructions. | |
21845 @item aes | |
21846 AES instructions. | |
21847 @item pclmul | |
21848 PCLMUL instructions. | |
21849 @item avx512vl | |
21850 AVX512VL instructions. | |
21851 @item avx512bw | |
21852 AVX512BW instructions. | |
21853 @item avx512dq | |
21854 AVX512DQ instructions. | |
21855 @item avx512cd | |
21856 AVX512CD instructions. | |
21857 @item avx512er | |
21858 AVX512ER instructions. | |
21859 @item avx512pf | |
21860 AVX512PF instructions. | |
21861 @item avx512vbmi | |
21862 AVX512VBMI instructions. | |
21863 @item avx512ifma | |
21864 AVX512IFMA instructions. | |
21865 @item avx5124vnniw | |
21866 AVX5124VNNIW instructions. | |
21867 @item avx5124fmaps | |
21868 AVX5124FMAPS instructions. | |
21869 @item avx512vpopcntdq | |
21870 AVX512VPOPCNTDQ instructions. | |
21871 @item avx512vbmi2 | |
21872 AVX512VBMI2 instructions. | |
21873 @item gfni | |
21874 GFNI instructions. | |
21875 @item vpclmulqdq | |
21876 VPCLMULQDQ instructions. | |
21877 @item avx512vnni | |
21878 AVX512VNNI instructions. | |
21879 @item avx512bitalg | |
21880 AVX512BITALG instructions. | |
20406 @end table | 21881 @end table |
20407 | 21882 |
20408 Here is an example: | 21883 Here is an example: |
20409 @smallexample | 21884 @smallexample |
20410 if (__builtin_cpu_supports ("popcnt")) | 21885 if (__builtin_cpu_supports ("popcnt")) |
21296 unsigned int __builtin_ia32_rdrand16_step (unsigned short *) | 22771 unsigned int __builtin_ia32_rdrand16_step (unsigned short *) |
21297 unsigned int __builtin_ia32_rdrand32_step (unsigned int *) | 22772 unsigned int __builtin_ia32_rdrand32_step (unsigned int *) |
21298 unsigned int __builtin_ia32_rdrand64_step (unsigned long long *) | 22773 unsigned int __builtin_ia32_rdrand64_step (unsigned long long *) |
21299 @end smallexample | 22774 @end smallexample |
21300 | 22775 |
22776 The following built-in function is available when @option{-mptwrite} is | |
22777 used. All of them generate the machine instruction that is part of the | |
22778 name. | |
22779 | |
22780 @smallexample | |
22781 void __builtin_ia32_ptwrite32 (unsigned) | |
22782 void __builtin_ia32_ptwrite64 (unsigned long long) | |
22783 @end smallexample | |
22784 | |
21301 The following built-in functions are available when @option{-msse4a} is used. | 22785 The following built-in functions are available when @option{-msse4a} is used. |
21302 All of them generate the machine instruction that is part of the name. | 22786 All of them generate the machine instruction that is part of the name. |
21303 | 22787 |
21304 @smallexample | 22788 @smallexample |
21305 void __builtin_ia32_movntsd (double *, v2df) | 22789 void __builtin_ia32_movntsd (double *, v2df) |
21807 bit-fields. See the Solaris man page for @code{cmn_err} for more information. | 23291 bit-fields. See the Solaris man page for @code{cmn_err} for more information. |
21808 | 23292 |
21809 @node Darwin Format Checks | 23293 @node Darwin Format Checks |
21810 @subsection Darwin Format Checks | 23294 @subsection Darwin Format Checks |
21811 | 23295 |
21812 Darwin targets support the @code{CFString} (or @code{__CFString__}) in the format | 23296 In addition to the full set of format archetypes (attribute format style |
21813 attribute context. Declarations made with such attribution are parsed for correct syntax | 23297 arguments such as @code{printf}, @code{scanf}, @code{strftime}, and |
21814 and format argument types. However, parsing of the format string itself is currently undefined | 23298 @code{strfmon}), Darwin targets also support the @code{CFString} (or |
21815 and is not carried out by this version of the compiler. | 23299 @code{__CFString__}) archetype in the @code{format} attribute. |
23300 Declarations with this archetype are parsed for correct syntax | |
23301 and argument types. However, parsing of the format string itself and | |
23302 validating arguments against it in calls to such functions is currently | |
23303 not performed. | |
21816 | 23304 |
21817 Additionally, @code{CFStringRefs} (defined by the @code{CoreFoundation} headers) may | 23305 Additionally, @code{CFStringRefs} (defined by the @code{CoreFoundation} headers) may |
21818 also be used as format arguments. Note that the relevant headers are only likely to be | 23306 also be used as format arguments. Note that the relevant headers are only likely to be |
21819 available on Darwin (OSX) installations. On such installations, the XCode and system | 23307 available on Darwin (OSX) installations. On such installations, the XCode and system |
21820 documentation provide descriptions of @code{CFString}, @code{CFStringRefs} and | 23308 documentation provide descriptions of @code{CFString}, @code{CFStringRefs} and |
21828 GCC supports several types of pragmas, primarily in order to compile | 23316 GCC supports several types of pragmas, primarily in order to compile |
21829 code originally written for other compilers. Note that in general | 23317 code originally written for other compilers. Note that in general |
21830 we do not recommend the use of pragmas; @xref{Function Attributes}, | 23318 we do not recommend the use of pragmas; @xref{Function Attributes}, |
21831 for further explanation. | 23319 for further explanation. |
21832 | 23320 |
23321 The GNU C preprocessor recognizes several pragmas in addition to the | |
23322 compiler pragmas documented here. Refer to the CPP manual for more | |
23323 information. | |
23324 | |
21833 @menu | 23325 @menu |
21834 * AArch64 Pragmas:: | 23326 * AArch64 Pragmas:: |
21835 * ARM Pragmas:: | 23327 * ARM Pragmas:: |
21836 * M32C Pragmas:: | 23328 * M32C Pragmas:: |
21837 * MeP Pragmas:: | 23329 * MeP Pragmas:: |
23330 * PRU Pragmas:: | |
21838 * RS/6000 and PowerPC Pragmas:: | 23331 * RS/6000 and PowerPC Pragmas:: |
21839 * S/390 Pragmas:: | 23332 * S/390 Pragmas:: |
21840 * Darwin Pragmas:: | 23333 * Darwin Pragmas:: |
21841 * Solaris Pragmas:: | 23334 * Solaris Pragmas:: |
21842 * Symbol-Renaming Pragmas:: | 23335 * Symbol-Renaming Pragmas:: |
21984 #pragma call foo | 23477 #pragma call foo |
21985 @end smallexample | 23478 @end smallexample |
21986 | 23479 |
21987 @end table | 23480 @end table |
21988 | 23481 |
23482 @node PRU Pragmas | |
23483 @subsection PRU Pragmas | |
23484 | |
23485 @table @code | |
23486 | |
23487 @item ctable_entry @var{index} @var{constant_address} | |
23488 @cindex pragma, ctable_entry | |
23489 Specifies that the PRU CTABLE entry given by @var{index} has the value | |
23490 @var{constant_address}. This enables GCC to emit LBCO/SBCO instructions | |
23491 when the load/store address is known and can be addressed with some CTABLE | |
23492 entry. For example: | |
23493 | |
23494 @smallexample | |
23495 /* will compile to "sbco Rx, 2, 0x10, 4" */ | |
23496 #pragma ctable_entry 2 0x4802a000 | |
23497 *(unsigned int *)0x4802a010 = val; | |
23498 @end smallexample | |
23499 | |
23500 @end table | |
23501 | |
21989 @node RS/6000 and PowerPC Pragmas | 23502 @node RS/6000 and PowerPC Pragmas |
21990 @subsection RS/6000 and PowerPC Pragmas | 23503 @subsection RS/6000 and PowerPC Pragmas |
21991 | 23504 |
21992 The RS/6000 and PowerPC targets define one pragma for controlling | 23505 The RS/6000 and PowerPC targets define one pragma for controlling |
21993 whether or not the @code{longcall} attribute is added to function | 23506 whether or not the @code{longcall} attribute is added to function |
22113 This pragma gives the C function @var{oldname} the assembly symbol | 23626 This pragma gives the C function @var{oldname} the assembly symbol |
22114 @var{newname}. The preprocessor macro @code{__PRAGMA_REDEFINE_EXTNAME} | 23627 @var{newname}. The preprocessor macro @code{__PRAGMA_REDEFINE_EXTNAME} |
22115 is defined if this pragma is available (currently on all platforms). | 23628 is defined if this pragma is available (currently on all platforms). |
22116 @end table | 23629 @end table |
22117 | 23630 |
22118 This pragma and the asm labels extension interact in a complicated | 23631 This pragma and the @code{asm} labels extension interact in a complicated |
22119 manner. Here are some corner cases you may want to be aware of: | 23632 manner. Here are some corner cases you may want to be aware of: |
22120 | 23633 |
22121 @enumerate | 23634 @enumerate |
22122 @item This pragma silently applies only to declarations with external | 23635 @item This pragma silently applies only to declarations with external |
22123 linkage. Asm labels do not have this restriction. | 23636 linkage. The @code{asm} label feature does not have this restriction. |
22124 | 23637 |
22125 @item In C++, this pragma silently applies only to declarations with | 23638 @item In C++, this pragma silently applies only to declarations with |
22126 ``C'' linkage. Again, asm labels do not have this restriction. | 23639 ``C'' linkage. Again, @code{asm} labels do not have this restriction. |
22127 | 23640 |
22128 @item If either of the ways of changing the assembly name of a | 23641 @item If either of the ways of changing the assembly name of a |
22129 declaration are applied to a declaration whose assembly name has | 23642 declaration are applied to a declaration whose assembly name has |
22130 already been determined (either by a previous use of one of these | 23643 already been determined (either by a previous use of one of these |
22131 features, or because the compiler needed the assembly name in order to | 23644 features, or because the compiler needed the assembly name in order to |
22385 | 23898 |
22386 @node Function Specific Option Pragmas | 23899 @node Function Specific Option Pragmas |
22387 @subsection Function Specific Option Pragmas | 23900 @subsection Function Specific Option Pragmas |
22388 | 23901 |
22389 @table @code | 23902 @table @code |
22390 @item #pragma GCC target (@var{"string"}...) | 23903 @item #pragma GCC target (@var{string}, @dots{}) |
22391 @cindex pragma GCC target | 23904 @cindex pragma GCC target |
22392 | 23905 |
22393 This pragma allows you to set target specific options for functions | 23906 This pragma allows you to set target-specific options for functions |
22394 defined later in the source file. One or more strings can be | 23907 defined later in the source file. One or more strings can be |
22395 specified. Each function that is defined after this point is as | 23908 specified. Each function that is defined after this point is treated |
22396 if @code{attribute((target("STRING")))} was specified for that | 23909 as if it had been declared with one @code{target(}@var{string}@code{)} |
22397 function. The parenthesis around the options is optional. | 23910 attribute for each @var{string} argument. The parentheses around |
22398 @xref{Function Attributes}, for more information about the | 23911 the strings in the pragma are optional. @xref{Function Attributes}, |
22399 @code{target} attribute and the attribute syntax. | 23912 for more information about the @code{target} attribute and the attribute |
23913 syntax. | |
22400 | 23914 |
22401 The @code{#pragma GCC target} pragma is presently implemented for | 23915 The @code{#pragma GCC target} pragma is presently implemented for |
22402 x86, ARM, AArch64, PowerPC, S/390, and Nios II targets only. | 23916 x86, ARM, AArch64, PowerPC, S/390, and Nios II targets only. |
22403 | 23917 |
22404 @item #pragma GCC optimize (@var{"string"}...) | 23918 @item #pragma GCC optimize (@var{string}, @dots{}) |
22405 @cindex pragma GCC optimize | 23919 @cindex pragma GCC optimize |
22406 | 23920 |
22407 This pragma allows you to set global optimization options for functions | 23921 This pragma allows you to set global optimization options for functions |
22408 defined later in the source file. One or more strings can be | 23922 defined later in the source file. One or more strings can be |
22409 specified. Each function that is defined after this point is as | 23923 specified. Each function that is defined after this point is treated |
22410 if @code{attribute((optimize("STRING")))} was specified for that | 23924 as if it had been declared with one @code{optimize(}@var{string}@code{)} |
22411 function. The parenthesis around the options is optional. | 23925 attribute for each @var{string} argument. The parentheses around |
22412 @xref{Function Attributes}, for more information about the | 23926 the strings in the pragma are optional. @xref{Function Attributes}, |
22413 @code{optimize} attribute and the attribute syntax. | 23927 for more information about the @code{optimize} attribute and the attribute |
23928 syntax. | |
22414 | 23929 |
22415 @item #pragma GCC push_options | 23930 @item #pragma GCC push_options |
22416 @itemx #pragma GCC pop_options | 23931 @itemx #pragma GCC pop_options |
22417 @cindex pragma GCC push_options | 23932 @cindex pragma GCC push_options |
22418 @cindex pragma GCC pop_options | 23933 @cindex pragma GCC pop_options |
23245 fine-grained control when necessary. It is also the most portable | 24760 fine-grained control when necessary. It is also the most portable |
23246 alternative and programs using this approach will work with most modern | 24761 alternative and programs using this approach will work with most modern |
23247 compilers. | 24762 compilers. |
23248 | 24763 |
23249 @item | 24764 @item |
23250 @opindex frepo | |
23251 Compile your template-using code with @option{-frepo}. The compiler | |
23252 generates files with the extension @samp{.rpo} listing all of the | |
23253 template instantiations used in the corresponding object files that | |
23254 could be instantiated there; the link wrapper, @samp{collect2}, | |
23255 then updates the @samp{.rpo} files to tell the compiler where to place | |
23256 those instantiations and rebuild any affected object files. The | |
23257 link-time overhead is negligible after the first pass, as the compiler | |
23258 continues to place the instantiations in the same files. | |
23259 | |
23260 This can be a suitable option for application code written for the Borland | |
23261 model, as it usually just works. Code written for the Cfront model | |
23262 needs to be modified so that the template definitions are available at | |
23263 one or more points of instantiation; usually this is as simple as adding | |
23264 @code{#include <tmethods.cc>} to the end of each template header. | |
23265 | |
23266 For library code, if you want the library to provide all of the template | |
23267 instantiations it needs, just try to link all of its object files | |
23268 together; the link will fail, but cause the instantiations to be | |
23269 generated as a side effect. Be warned, however, that this may cause | |
23270 conflicts if multiple libraries try to provide the same instantiations. | |
23271 For greater control, use explicit instantiation as described in the next | |
23272 option. | |
23273 | |
23274 @item | |
23275 @opindex fno-implicit-templates | 24765 @opindex fno-implicit-templates |
23276 Compile your code with @option{-fno-implicit-templates} to disable the | 24766 Compile your code with @option{-fno-implicit-templates} to disable the |
23277 implicit generation of template instances, and explicitly instantiate | 24767 implicit generation of template instances, and explicitly instantiate |
23278 all the ones you use. This approach requires more knowledge of exactly | 24768 all the ones you use. This approach requires more knowledge of exactly |
23279 which instances you need than do the others, but it's less | 24769 which instances you need than do the others, but it's less |
23502 various characteristics of a type (or of a | 24992 various characteristics of a type (or of a |
23503 pair of types). | 24993 pair of types). |
23504 | 24994 |
23505 @table @code | 24995 @table @code |
23506 @item __has_nothrow_assign (type) | 24996 @item __has_nothrow_assign (type) |
23507 If @code{type} is const qualified or is a reference type then the trait is | 24997 If @code{type} is @code{const}-qualified or is a reference type then |
23508 false. Otherwise if @code{__has_trivial_assign (type)} is true then the trait | 24998 the trait is @code{false}. Otherwise if @code{__has_trivial_assign (type)} |
23509 is true, else if @code{type} is a cv class or union type with copy assignment | 24999 is @code{true} then the trait is @code{true}, else if @code{type} is |
23510 operators that are known not to throw an exception then the trait is true, | 25000 a cv-qualified class or union type with copy assignment operators that are |
23511 else it is false. Requires: @code{type} shall be a complete type, | 25001 known not to throw an exception then the trait is @code{true}, else it is |
23512 (possibly cv-qualified) @code{void}, or an array of unknown bound. | 25002 @code{false}. |
23513 | |
23514 @item __has_nothrow_copy (type) | |
23515 If @code{__has_trivial_copy (type)} is true then the trait is true, else if | |
23516 @code{type} is a cv class or union type with copy constructors that | |
23517 are known not to throw an exception then the trait is true, else it is false. | |
23518 Requires: @code{type} shall be a complete type, (possibly cv-qualified) | 25003 Requires: @code{type} shall be a complete type, (possibly cv-qualified) |
23519 @code{void}, or an array of unknown bound. | 25004 @code{void}, or an array of unknown bound. |
23520 | 25005 |
25006 @item __has_nothrow_copy (type) | |
25007 If @code{__has_trivial_copy (type)} is @code{true} then the trait is | |
25008 @code{true}, else if @code{type} is a cv-qualified class or union type | |
25009 with copy constructors that are known not to throw an exception then | |
25010 the trait is @code{true}, else it is @code{false}. | |
25011 Requires: @code{type} shall be a complete type, (possibly cv-qualified) | |
25012 @code{void}, or an array of unknown bound. | |
25013 | |
23521 @item __has_nothrow_constructor (type) | 25014 @item __has_nothrow_constructor (type) |
23522 If @code{__has_trivial_constructor (type)} is true then the trait is | 25015 If @code{__has_trivial_constructor (type)} is @code{true} then the trait |
23523 true, else if @code{type} is a cv class or union type (or array | 25016 is @code{true}, else if @code{type} is a cv class or union type (or array |
23524 thereof) with a default constructor that is known not to throw an | 25017 thereof) with a default constructor that is known not to throw an |
23525 exception then the trait is true, else it is false. Requires: | 25018 exception then the trait is @code{true}, else it is @code{false}. |
23526 @code{type} shall be a complete type, (possibly cv-qualified) | 25019 Requires: @code{type} shall be a complete type, (possibly cv-qualified) |
23527 @code{void}, or an array of unknown bound. | 25020 @code{void}, or an array of unknown bound. |
23528 | 25021 |
23529 @item __has_trivial_assign (type) | 25022 @item __has_trivial_assign (type) |
23530 If @code{type} is const qualified or is a reference type then the trait is | 25023 If @code{type} is @code{const}- qualified or is a reference type then |
23531 false. Otherwise if @code{__is_pod (type)} is true then the trait is | 25024 the trait is @code{false}. Otherwise if @code{__is_pod (type)} is |
23532 true, else if @code{type} is a cv class or union type with a trivial | 25025 @code{true} then the trait is @code{true}, else if @code{type} is |
23533 copy assignment ([class.copy]) then the trait is true, else it is | 25026 a cv-qualified class or union type with a trivial copy assignment |
23534 false. Requires: @code{type} shall be a complete type, (possibly | 25027 ([class.copy]) then the trait is @code{true}, else it is @code{false}. |
23535 cv-qualified) @code{void}, or an array of unknown bound. | 25028 Requires: @code{type} shall be a complete type, (possibly cv-qualified) |
25029 @code{void}, or an array of unknown bound. | |
23536 | 25030 |
23537 @item __has_trivial_copy (type) | 25031 @item __has_trivial_copy (type) |
23538 If @code{__is_pod (type)} is true or @code{type} is a reference type | 25032 If @code{__is_pod (type)} is @code{true} or @code{type} is a reference |
23539 then the trait is true, else if @code{type} is a cv class or union type | 25033 type then the trait is @code{true}, else if @code{type} is a cv class |
23540 with a trivial copy constructor ([class.copy]) then the trait | 25034 or union type with a trivial copy constructor ([class.copy]) then the trait |
23541 is true, else it is false. Requires: @code{type} shall be a complete | 25035 is @code{true}, else it is @code{false}. Requires: @code{type} shall be |
23542 type, (possibly cv-qualified) @code{void}, or an array of unknown bound. | 25036 a complete type, (possibly cv-qualified) @code{void}, or an array of unknown |
25037 bound. | |
23543 | 25038 |
23544 @item __has_trivial_constructor (type) | 25039 @item __has_trivial_constructor (type) |
23545 If @code{__is_pod (type)} is true then the trait is true, else if | 25040 If @code{__is_pod (type)} is @code{true} then the trait is @code{true}, |
23546 @code{type} is a cv class or union type (or array thereof) with a | 25041 else if @code{type} is a cv-qualified class or union type (or array thereof) |
23547 trivial default constructor ([class.ctor]) then the trait is true, | 25042 with a trivial default constructor ([class.ctor]) then the trait is @code{true}, |
23548 else it is false. Requires: @code{type} shall be a complete | 25043 else it is @code{false}. |
23549 type, (possibly cv-qualified) @code{void}, or an array of unknown bound. | 25044 Requires: @code{type} shall be a complete type, (possibly cv-qualified) |
25045 @code{void}, or an array of unknown bound. | |
23550 | 25046 |
23551 @item __has_trivial_destructor (type) | 25047 @item __has_trivial_destructor (type) |
23552 If @code{__is_pod (type)} is true or @code{type} is a reference type then | 25048 If @code{__is_pod (type)} is @code{true} or @code{type} is a reference type |
23553 the trait is true, else if @code{type} is a cv class or union type (or | 25049 then the trait is @code{true}, else if @code{type} is a cv class or union |
23554 array thereof) with a trivial destructor ([class.dtor]) then the trait | 25050 type (or array thereof) with a trivial destructor ([class.dtor]) then |
23555 is true, else it is false. Requires: @code{type} shall be a complete | 25051 the trait is @code{true}, else it is @code{false}. |
23556 type, (possibly cv-qualified) @code{void}, or an array of unknown bound. | 25052 Requires: @code{type} shall be a complete type, (possibly cv-qualified) |
25053 @code{void}, or an array of unknown bound. | |
23557 | 25054 |
23558 @item __has_virtual_destructor (type) | 25055 @item __has_virtual_destructor (type) |
23559 If @code{type} is a class type with a virtual destructor | 25056 If @code{type} is a class type with a virtual destructor |
23560 ([class.dtor]) then the trait is true, else it is false. Requires: | 25057 ([class.dtor]) then the trait is @code{true}, else it is @code{false}. |
23561 @code{type} shall be a complete type, (possibly cv-qualified) | 25058 Requires: @code{type} shall be a complete type, (possibly cv-qualified) |
23562 @code{void}, or an array of unknown bound. | 25059 @code{void}, or an array of unknown bound. |
23563 | 25060 |
23564 @item __is_abstract (type) | 25061 @item __is_abstract (type) |
23565 If @code{type} is an abstract class ([class.abstract]) then the trait | 25062 If @code{type} is an abstract class ([class.abstract]) then the trait |
23566 is true, else it is false. Requires: @code{type} shall be a complete | 25063 is @code{true}, else it is @code{false}. |
23567 type, (possibly cv-qualified) @code{void}, or an array of unknown bound. | 25064 Requires: @code{type} shall be a complete type, (possibly cv-qualified) |
25065 @code{void}, or an array of unknown bound. | |
23568 | 25066 |
23569 @item __is_base_of (base_type, derived_type) | 25067 @item __is_base_of (base_type, derived_type) |
23570 If @code{base_type} is a base class of @code{derived_type} | 25068 If @code{base_type} is a base class of @code{derived_type} |
23571 ([class.derived]) then the trait is true, otherwise it is false. | 25069 ([class.derived]) then the trait is @code{true}, otherwise it is @code{false}. |
23572 Top-level cv qualifications of @code{base_type} and | 25070 Top-level cv-qualifications of @code{base_type} and |
23573 @code{derived_type} are ignored. For the purposes of this trait, a | 25071 @code{derived_type} are ignored. For the purposes of this trait, a |
23574 class type is considered is own base. Requires: if @code{__is_class | 25072 class type is considered is own base. |
23575 (base_type)} and @code{__is_class (derived_type)} are true and | 25073 Requires: if @code{__is_class (base_type)} and @code{__is_class (derived_type)} |
23576 @code{base_type} and @code{derived_type} are not the same type | 25074 are @code{true} and @code{base_type} and @code{derived_type} are not the same |
23577 (disregarding cv-qualifiers), @code{derived_type} shall be a complete | 25075 type (disregarding cv-qualifiers), @code{derived_type} shall be a complete |
23578 type. A diagnostic is produced if this requirement is not met. | 25076 type. A diagnostic is produced if this requirement is not met. |
23579 | 25077 |
23580 @item __is_class (type) | 25078 @item __is_class (type) |
23581 If @code{type} is a cv class type, and not a union type | 25079 If @code{type} is a cv-qualified class type, and not a union type |
23582 ([basic.compound]) the trait is true, else it is false. | 25080 ([basic.compound]) the trait is @code{true}, else it is @code{false}. |
23583 | 25081 |
23584 @item __is_empty (type) | 25082 @item __is_empty (type) |
23585 If @code{__is_class (type)} is false then the trait is false. | 25083 If @code{__is_class (type)} is @code{false} then the trait is @code{false}. |
23586 Otherwise @code{type} is considered empty if and only if: @code{type} | 25084 Otherwise @code{type} is considered empty if and only if: @code{type} |
23587 has no non-static data members, or all non-static data members, if | 25085 has no non-static data members, or all non-static data members, if |
23588 any, are bit-fields of length 0, and @code{type} has no virtual | 25086 any, are bit-fields of length 0, and @code{type} has no virtual |
23589 members, and @code{type} has no virtual base classes, and @code{type} | 25087 members, and @code{type} has no virtual base classes, and @code{type} |
23590 has no base classes @code{base_type} for which | 25088 has no base classes @code{base_type} for which |
23591 @code{__is_empty (base_type)} is false. Requires: @code{type} shall | 25089 @code{__is_empty (base_type)} is @code{false}. |
23592 be a complete type, (possibly cv-qualified) @code{void}, or an array | 25090 Requires: @code{type} shall be a complete type, (possibly cv-qualified) |
23593 of unknown bound. | 25091 @code{void}, or an array of unknown bound. |
23594 | 25092 |
23595 @item __is_enum (type) | 25093 @item __is_enum (type) |
23596 If @code{type} is a cv enumeration type ([basic.compound]) the trait is | 25094 If @code{type} is a cv enumeration type ([basic.compound]) the trait is |
23597 true, else it is false. | 25095 @code{true}, else it is @code{false}. |
23598 | 25096 |
23599 @item __is_literal_type (type) | 25097 @item __is_literal_type (type) |
23600 If @code{type} is a literal type ([basic.types]) the trait is | 25098 If @code{type} is a literal type ([basic.types]) the trait is |
23601 true, else it is false. Requires: @code{type} shall be a complete type, | 25099 @code{true}, else it is @code{false}. |
23602 (possibly cv-qualified) @code{void}, or an array of unknown bound. | 25100 Requires: @code{type} shall be a complete type, (possibly cv-qualified) |
25101 @code{void}, or an array of unknown bound. | |
23603 | 25102 |
23604 @item __is_pod (type) | 25103 @item __is_pod (type) |
23605 If @code{type} is a cv POD type ([basic.types]) then the trait is true, | 25104 If @code{type} is a cv POD type ([basic.types]) then the trait is @code{true}, |
23606 else it is false. Requires: @code{type} shall be a complete type, | 25105 else it is @code{false}. |
23607 (possibly cv-qualified) @code{void}, or an array of unknown bound. | 25106 Requires: @code{type} shall be a complete type, (possibly cv-qualified) |
25107 @code{void}, or an array of unknown bound. | |
23608 | 25108 |
23609 @item __is_polymorphic (type) | 25109 @item __is_polymorphic (type) |
23610 If @code{type} is a polymorphic class ([class.virtual]) then the trait | 25110 If @code{type} is a polymorphic class ([class.virtual]) then the trait |
23611 is true, else it is false. Requires: @code{type} shall be a complete | 25111 is @code{true}, else it is @code{false}. |
23612 type, (possibly cv-qualified) @code{void}, or an array of unknown bound. | 25112 Requires: @code{type} shall be a complete type, (possibly cv-qualified) |
25113 @code{void}, or an array of unknown bound. | |
23613 | 25114 |
23614 @item __is_standard_layout (type) | 25115 @item __is_standard_layout (type) |
23615 If @code{type} is a standard-layout type ([basic.types]) the trait is | 25116 If @code{type} is a standard-layout type ([basic.types]) the trait is |
23616 true, else it is false. Requires: @code{type} shall be a complete | 25117 @code{true}, else it is @code{false}. |
23617 type, (possibly cv-qualified) @code{void}, or an array of unknown bound. | 25118 Requires: @code{type} shall be a complete type, (possibly cv-qualified) |
25119 @code{void}, or an array of unknown bound. | |
23618 | 25120 |
23619 @item __is_trivial (type) | 25121 @item __is_trivial (type) |
23620 If @code{type} is a trivial type ([basic.types]) the trait is | 25122 If @code{type} is a trivial type ([basic.types]) the trait is |
23621 true, else it is false. Requires: @code{type} shall be a complete | 25123 @code{true}, else it is @code{false}. |
23622 type, (possibly cv-qualified) @code{void}, or an array of unknown bound. | 25124 Requires: @code{type} shall be a complete type, (possibly cv-qualified) |
25125 @code{void}, or an array of unknown bound. | |
23623 | 25126 |
23624 @item __is_union (type) | 25127 @item __is_union (type) |
23625 If @code{type} is a cv union type ([basic.compound]) the trait is | 25128 If @code{type} is a cv union type ([basic.compound]) the trait is |
23626 true, else it is false. | 25129 @code{true}, else it is @code{false}. |
23627 | 25130 |
23628 @item __underlying_type (type) | 25131 @item __underlying_type (type) |
23629 The underlying type of @code{type}. Requires: @code{type} shall be | 25132 The underlying type of @code{type}. |
23630 an enumeration type ([dcl.enum]). | 25133 Requires: @code{type} shall be an enumeration type ([dcl.enum]). |
23631 | 25134 |
23632 @item __integer_pack (length) | 25135 @item __integer_pack (length) |
23633 When used as the pattern of a pack expansion within a template | 25136 When used as the pattern of a pack expansion within a template |
23634 definition, expands to a template argument pack containing integers | 25137 definition, expands to a template argument pack containing integers |
23635 from @code{0} to @code{length-1}. This is provided for efficient | 25138 from @code{0} to @code{length-1}. This is provided for efficient |
23676 to simplify the writing of type traits. Note that some of these traits are | 25179 to simplify the writing of type traits. Note that some of these traits are |
23677 likely to be removed in the future. | 25180 likely to be removed in the future. |
23678 | 25181 |
23679 @table @code | 25182 @table @code |
23680 @item __is_same (type1, type2) | 25183 @item __is_same (type1, type2) |
23681 A binary type trait: true whenever the type arguments are the same. | 25184 A binary type trait: @code{true} whenever the type arguments are the same. |
23682 | 25185 |
23683 @end table | 25186 @end table |
23684 | 25187 |
23685 | 25188 |
23686 @node Deprecated Features | 25189 @node Deprecated Features |