diff options
Diffstat (limited to 'gcc/doc/extend.texi')
-rw-r--r-- | gcc/doc/extend.texi | 295 |
1 files changed, 178 insertions, 117 deletions
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 43b21c6231f..f34f0f955e9 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -339,6 +339,7 @@ serves as a jump table: static void *array[] = @{ &&foo, &&bar, &&hack @}; @end smallexample +@noindent Then you can select a label with indexing, like this: @smallexample @@ -601,7 +602,7 @@ an inline function. It can be used only in inline functions that are always inlined, never compiled as a separate function, such as those using @code{__attribute__ ((__always_inline__))} or @code{__attribute__ ((__gnu_inline__))} extern inline functions. -For example following does link or runtime checking of open +For example following does link- or run-time checking of open arguments for optimized code: @smallexample #ifdef __OPTIMIZE__ @@ -916,7 +917,7 @@ examine and set these two fictitious variables with your debugger. @cindex @code{W} floating point suffix @cindex @code{Q} floating point suffix -As an extension, the GNU C compiler supports additional floating +As an extension, GNU C supports additional floating types, @code{__float80} and @code{__float128} to support 80-bit (@code{XFmode}) and 128-bit (@code{TFmode}) floating types. Support for additional types includes the arithmetic operators: @@ -1000,7 +1001,7 @@ as library calls. @cindex @code{DD} integer suffix @cindex @code{DL} integer suffix -As an extension, the GNU C compiler supports decimal floating types as +As an extension, GNU C supports decimal floating types as defined in the N1312 draft of ISO/IEC WDTR24732. Support for decimal floating types in GCC will evolve as the draft technical report changes. Calling conventions for any target might also change. Not all targets @@ -1106,7 +1107,7 @@ extension for floating-point constants of type @code{float}. @cindex @code{ULK} fixed-suffix @cindex @code{ULLK} fixed-suffix -As an extension, the GNU C compiler supports fixed-point types as +As an extension, GNU C supports fixed-point types as defined in the N1169 draft of ISO/IEC DTR 18037. Support for fixed-point types in GCC will evolve as the draft technical report changes. Calling conventions for any target might also change. Not all targets @@ -1218,7 +1219,7 @@ Fixed-point types are supported by the DWARF2 debug information format. @section Named Address Spaces @cindex Named Address Spaces -As an extension, the GNU C compiler supports named address spaces as +As an extension, GNU C supports named address spaces as defined in the N1275 draft of ISO/IEC DTR 18037. Support for named address spaces in GCC will evolve as the draft technical report changes. Calling conventions for any target might also change. At @@ -1280,7 +1281,7 @@ Objects in this address space are located in @code{.progmem.data}. @b{Example} -@example +@smallexample char my_read (const __flash char ** p) @{ /* p is a pointer to RAM that points to a pointer to flash. @@ -1301,7 +1302,7 @@ int main (void) /* Return 17 by reading from flash memory */ return array[array[i]]; @} -@end example +@end smallexample @noindent For each named address space supported by avr-gcc there is an equally @@ -1309,7 +1310,7 @@ named but uppercase built-in macro defined. The purpose is to facilitate testing if respective address space support is available or not: -@example +@smallexample #ifdef __FLASH const __flash int var = 1; @@ -1327,7 +1328,7 @@ int read_var (void) return (int) pgm_read_word (&var); @} #endif /* __FLASH */ -@end example +@end smallexample @noindent Notice that attribute @ref{AVR Variable Attributes,,@code{progmem}} @@ -1345,7 +1346,7 @@ together with attribute @code{progmem}. @item Reading across the 64@tie{}KiB section boundary of the @code{__flash} or @code{__flash@var{N}} address spaces -shows undefined behaviour. The only address space that +shows undefined behavior. The only address space that supports reading across the 64@tie{}KiB flash segment boundaries is @code{__memx}. @@ -1367,10 +1368,12 @@ as immediates into operands of instructions. @item The following code initializes a variable @code{pfoo} located in static storage with a 24-bit address: -@example +@smallexample extern const __memx char foo; const __memx void *pfoo = &foo; -@end example +@end smallexample + +@noindent Such code requires at least binutils 2.23, see @w{@uref{http://sourceware.org/PR13503,PR13503}}. @@ -1404,6 +1407,7 @@ belonging to another address space by qualifying the type with the extern int __ea i; @end smallexample +@noindent The compiler generates special code to access the variable @code{i}. It may use runtime library support, or generate special machine instructions to access that address @@ -1463,14 +1467,14 @@ initialized, as if they were flexible arrays. In addition to those cases that were useful, it also allowed initializations in situations that would corrupt later data. Non-empty initialization of zero-length arrays is now treated like any case where there are more initializer -elements than the array holds, in that a suitable warning about "excess -elements in array" is given, and the excess elements (all of them, in +elements than the array holds, in that a suitable warning about ``excess +elements in array'' is given, and the excess elements (all of them, in this case) are ignored. Instead GCC allows static initialization of flexible array members. This is equivalent to defining a new structure containing the original structure followed by an array of sufficient size to contain the data. -I.e.@: in the following, @code{f1} is constructed as if it were declared +E.g.@: in the following, @code{f1} is constructed as if it were declared like @code{f2}. @smallexample @@ -1620,6 +1624,7 @@ example: #define debug(format, ...) fprintf (stderr, format, __VA_ARGS__) @end smallexample +@noindent Here @samp{@dots{}} is a @dfn{variable argument}. In the invocation of such a macro, it represents the zero or more tokens until the closing parenthesis that ends the invocation, including any commas. This set of @@ -1634,6 +1639,7 @@ argument. Here is an example: #define debug(format, args...) fprintf (stderr, format, args) @end smallexample +@noindent This is in all ways equivalent to the ISO C example above, but arguably more readable and descriptive. @@ -1661,6 +1667,7 @@ used with the token paste operator, @samp{##}. If instead you write #define debug(format, ...) fprintf (stderr, format, ## __VA_ARGS__) @end smallexample +@noindent and if the variable arguments are omitted or empty, the @samp{##} operator causes the preprocessor to remove the comma before it. If you do provide some variable arguments in your macro invocation, GNU CPP @@ -1693,7 +1700,7 @@ yet been replaced with spaces. In ISO C99, arrays that are not lvalues still decay to pointers, and may be subscripted, although they may not be modified or used after the next sequence point and the unary @samp{&} operator may not be -applied to them. As an extension, GCC allows such arrays to be +applied to them. As an extension, GNU C allows such arrays to be subscripted in C90 mode, though otherwise they do not decay to pointers outside C99 mode. For example, this is valid in GNU C though not valid in C90: @@ -2072,7 +2079,7 @@ hack ((union foo) x); @cindex code, mixed with declarations ISO C99 and ISO C++ allow declarations and code to be freely mixed -within compound statements. As an extension, GCC also allows this in +within compound statements. As an extension, GNU C also allows this in C90 mode. For example, you could do: @smallexample @@ -2123,10 +2130,11 @@ attributes are currently defined for functions on all targets: @code{weak}, @code{malloc}, @code{alias}, @code{ifunc}, @code{warn_unused_result}, @code{nonnull}, @code{gnu_inline}, @code{externally_visible}, @code{hot}, @code{cold}, @code{artificial}, -@code{error} and @code{warning}. Several other attributes are defined -for functions on particular target systems. Other attributes, -including @code{section} are supported for variables declarations -(@pxref{Variable Attributes}) and for types (@pxref{Type Attributes}). +@code{no_address_safety_analysis}, @code{error} and @code{warning}. +Several other attributes are defined for functions on particular +target systems. Other attributes, including @code{section} are +supported for variables declarations (@pxref{Variable Attributes}) +and for types (@pxref{Type Attributes}). GCC plugins may provide their own attributes. @@ -2151,6 +2159,7 @@ void __f () @{ /* @r{Do something.} */; @} void f () __attribute__ ((weak, alias ("__f"))); @end smallexample +@noindent defines @samp{f} to be a weak alias for @samp{__f}. In C++, the mangled name for the target must be used. It is an error if @samp{__f} is not defined in the same translation unit. @@ -2198,6 +2207,7 @@ void* my_calloc(size_t, size_t) __attribute__((alloc_size(1,2))) void my_realloc(void*, size_t) __attribute__((alloc_size(2))) @end smallexample +@noindent declares that @code{my_calloc} returns memory of the size given by the product of parameter 1 and 2 and that @code{my_realloc} returns memory of the size given by parameter 2. @@ -2272,7 +2282,7 @@ the current inlining parameters. If this attribute is used on a function declaration and a call to such a function is not eliminated through dead code elimination or other optimizations, an error that includes @var{message} is diagnosed. This is useful -for compile time checking, especially together with @code{__builtin_constant_p} +for compile-time checking, especially together with @code{__builtin_constant_p} and inline functions where checking the inline function arguments is not possible through @code{extern char [(condition) ? 1 : -1];} tricks. While it is possible to leave the function undefined and thus invoke @@ -2285,7 +2295,7 @@ functions or when not emitting debugging information. If this attribute is used on a function declaration and a call to such a function is not eliminated through dead code elimination or other optimizations, a warning that includes @var{message} is diagnosed. This is useful -for compile time checking, especially together with @code{__builtin_constant_p} +for compile-time checking, especially together with @code{__builtin_constant_p} and inline functions. While it is possible to define the function with a message in @code{.gnu.warning*} section, when using this attribute the problem is diagnosed earlier and with exact location of the call even in presence @@ -2324,6 +2334,7 @@ typedef int intfn (); extern const intfn square; @end smallexample +@noindent This approach does not work in GNU C++ from 2.6.0 on, since the language specifies that the @samp{const} must be attached to the return value. @@ -2403,9 +2414,9 @@ explicitly specify any other visibility. In previous versions of GCC, the @code{dllexport} attribute was ignored for inlined functions, unless the @option{-fkeep-inline-functions} flag -had been used. The default behaviour now is to emit all dllexported +had been used. The default behavior now is to emit all dllexported inline functions; however, this can cause object file-size bloat, in -which case the old behaviour can be restored by using +which case the old behavior can be restored by using @option{-fno-keep-inline-dllexport}. The attribute is also ignored for undefined symbols. @@ -2457,7 +2468,7 @@ and, for either of those two conditions, the class also has an inline constructor or destructor and has a key function that is defined in the current translation unit. -For Microsoft Windows based targets the use of the @code{dllimport} +For Microsoft Windows targets the use of the @code{dllimport} attribute on functions is not necessary, but provides a small performance benefit by eliminating a thunk in the DLL@. The use of the @code{dllimport} attribute on imported variables was required on older @@ -2544,7 +2555,7 @@ function pops the arguments off the stack. If the number of arguments is variable all arguments are pushed on the stack. The @code{thiscall} attribute is intended for C++ non-static member functions. -As gcc extension this calling convention can be used for C-functions +As a GCC extension, this calling convention can be used for C functions and for static member methods. @item format (@var{archetype}, @var{string-index}, @var{first-to-check}) @@ -2574,7 +2585,7 @@ interpreted, and should be @code{printf}, @code{scanf}, @code{strftime}, MinGW targets, @code{ms_printf}, @code{ms_scanf}, and @code{ms_strftime} are also present. @var{archtype} values such as @code{printf} refer to the formats accepted -by the system's C run-time library, while @code{gnu_} values always refer +by the system's C runtime library, while @code{gnu_} values always refer to the formats accepted by the GNU C Library. On Microsoft Windows targets, @code{ms_} values refer to the formats accepted by the @file{msvcrt.dll} library. @@ -2762,6 +2773,7 @@ static void (*resolve_memcpy (void)) (void) @} @end smallexample +@noindent The exported header file declaring the function the user calls would contain: @@ -2769,6 +2781,7 @@ contain: extern void *memcpy (void *, const void *, size_t); @end smallexample +@noindent allowing the user to call this as a regular function, unaware of the implementation. Finally, the indirect function needs to be defined in the same translation unit as the resolver function: @@ -2824,7 +2837,7 @@ Permissible values for these parameters are: @w{@code{reset}}, @w{@code{timer0}}, @w{@code{timer1}}, @w{@code{message}}, @w{@code{dma0}}, @w{@code{dma1}}, @w{@code{wand}} and @w{@code{swi}}. Multiple parameters indicate that multiple entries in the interrupt -vector table should be initialized for this function, i.e. for each +vector table should be initialized for this function, i.e.@: for each parameter @w{@var{name}}, a jump to the function is emitted in the section @w{ivt_entry_@var{name}}. The parameter(s) may be omitted entirely, in which case no interrupt vector table entry is provided. @@ -2892,7 +2905,7 @@ void __attribute__ ((interrupt, use_shadow_register_set, @end smallexample On RL78, use @code{brk_interrupt} instead of @code{interrupt} for -handlers intended to be used with the @code{BRK} opcode (i.e. those +handlers intended to be used with the @code{BRK} opcode (i.e.@: those that must end with @code{RETB} instead of @code{RETI}). @item interrupt_handler @@ -2957,7 +2970,7 @@ compliant way to write such a signal handler is to declare such variables The attribute has no effect on functions defined within the current compilation unit. This is to allow easy merging of multiple compilation units into one, -for example, by using the link time optimization. For this reason the +for example, by using the link-time optimization. For this reason the attribute is not allowed on types to annotate indirect calls. @item long_call/short_call @@ -3066,7 +3079,7 @@ while the @code{sysv_abi} attribute tells the compiler to use the ABI used on GNU/Linux and other systems. The default is to use the Microsoft ABI when targeting Windows. On all other systems, the default is the x86/AMD ABI. -Note, the @code{ms_abi} attribute for Windows 64-bit targets currently +Note, the @code{ms_abi} attribute for Microsoft Windows 64-bit targets currently requires the @option{-maccumulate-outgoing-args} option. @item callee_pop_aggregate_return (@var{number}) @@ -3079,14 +3092,15 @@ zero -, or if the callee is responsible to pop hidden pointer - @var{number} equal to one. The default i386 ABI assumes that the callee pops the stack for hidden pointer. -Note that on 32-bit i386 Windows targets, the compiler assumes that the +Note that on 32-bit i386 Microsoft Windows targets, +the compiler assumes that the caller pops the stack for hidden pointer. @item ms_hook_prologue @cindex @code{ms_hook_prologue} attribute On 32-bit i[34567]86-*-* targets and 64-bit x86_64-*-* targets, you can use -this function attribute to make gcc generate the "hot-patching" function +this function attribute to make GCC generate the ``hot-patching'' function prologue used in Win32 API functions in Microsoft Windows XP Service Pack 2 and newer. @@ -3111,7 +3125,7 @@ option. On MeP targets this attribute causes the compiler to assume the called function is close enough to use the normal calling convention, -overriding the @code{-mtf} command line option. +overriding the @code{-mtf} command-line option. @item nesting @cindex Allow nesting in an interrupt handler on the Blackfin processor. @@ -3154,6 +3168,8 @@ optimized away, put @smallexample asm (""); @end smallexample + +@noindent (@pxref{Extended Asm}) in the called function, to serve as a special side-effect. @@ -3240,6 +3256,7 @@ typedef void voidfn (); volatile voidfn fatal; @end smallexample +@noindent This approach does not work in GNU C++. @item nothrow @@ -3400,6 +3417,12 @@ with computed goto or @code{asm goto}. The @code{cold} attribute on labels is not implemented in GCC versions earlier than 4.8. +@item no_address_safety_analysis +@cindex @code{no_address_safety_analysis} function attribute +The @code{no_address_safety_analysis} attribute on functions is used +to inform the compiler that it should not instrument memory accesses +in the function when compiling with the @option{-fsanitize=address} option. + @item regparm (@var{number}) @cindex @code{regparm} attribute @cindex functions that are passed arguments in registers on the 386 @@ -3431,7 +3454,7 @@ floating-point arguments on the stack. @cindex @code{force_align_arg_pointer} attribute On the Intel x86, the @code{force_align_arg_pointer} attribute may be applied to individual function definitions, generating an alternate -prologue and epilogue that realigns the runtime stack if necessary. +prologue and epilogue that realigns the run-time stack if necessary. This supports mixing legacy codes that run with a 4-byte aligned stack with modern codes that keep a 16-byte stack for SSE compatibility. @@ -3754,7 +3777,7 @@ On the PowerPC, the following options are allowed: @itemx no-altivec @cindex @code{target("altivec")} attribute Generate code that uses (does not use) AltiVec instructions. In -32-bit code, you cannot enable Altivec instructions unless +32-bit code, you cannot enable AltiVec instructions unless @option{-mabi=altivec} is used on the command line. @item cmpb @@ -3873,7 +3896,7 @@ do small block moves. Generate code that uses (does not use) vector/scalar (VSX) instructions, and also enable the use of built-in functions that allow more direct access to the VSX instruction set. In 32-bit code, you -cannot enable VSX or Altivec instructions unless +cannot enable VSX or AltiVec instructions unless @option{-mabi=altivec} is used on the command line. @item friz @@ -3907,7 +3930,7 @@ away so that a longer more expensive calling sequence is required. @cindex @code{target("cpu=@var{CPU}")} attribute Specify the architecture to generate code for when compiling the function. If you select the @code{target("cpu=power7")} attribute when -generating 32-bit code, VSX and Altivec instructions are not generated +generating 32-bit code, VSX and AltiVec instructions are not generated unless you use the @option{-mabi=altivec} option on the command line. @item tune=@var{TUNE} @@ -3919,19 +3942,19 @@ compilation tunes for the @var{CPU} architecture, and not the default tuning specified on the command line. @end table -On the 386/x86_64 and PowerPC backends, you can use either multiple +On the 386/x86_64 and PowerPC back ends, you can use either multiple strings to specify multiple options, or you can separate the option with a comma (@code{,}). -On the 386/x86_64 and PowerPC backends, the inliner does not inline a +On the 386/x86_64 and PowerPC back ends, the inliner does not inline a function that has different target options than the caller, unless the callee has a subset of the target options of the caller. For example a function declared with @code{target("sse3")} can inline a function with @code{target("sse2")}, since @code{-msse3} implies @code{-msse2}. The @code{target} attribute is not implemented in GCC versions earlier -than 4.4 for the i386/x86_64 and 4.6 for the PowerPC backends. It is -not currently implemented for other backends. +than 4.4 for the i386/x86_64 and 4.6 for the PowerPC back ends. It is +not currently implemented for other back ends. @item tiny_data @cindex tiny data section on the H8/300H and H8S @@ -3980,6 +4003,7 @@ for some system calls. extern int foo () __attribute__((version_id ("20040821"))); @end smallexample +@noindent Calls to @var{foo} are mapped to calls to @var{foo@{20040821@}}. @item visibility ("@var{visibility_type}") @@ -4083,7 +4107,7 @@ visibility from the template is used. On MeP, the @code{vliw} attribute tells the compiler to emit instructions in VLIW mode instead of core mode. Note that this attribute is not allowed unless a VLIW coprocessor has been configured -and enabled through command line options. +and enabled through command-line options. @item warn_unused_result @cindex @code{warn_unused_result} attribute @@ -4103,6 +4127,7 @@ int foo () @} @end smallexample +@noindent results in warning on line 5. @item weak @@ -4560,7 +4585,7 @@ The default alignment is sufficient for all scalar types, but may not be enough for all vector types on a target that supports vector operations. The default alignment is fixed for a particular target ABI. -Gcc also provides a target specific macro @code{__BIGGEST_ALIGNMENT__}, +GCC also provides a target specific macro @code{__BIGGEST_ALIGNMENT__}, which is the largest alignment ever used for any data type on the target machine you are compiling for. For example, you could write: @@ -4574,7 +4599,7 @@ often make copy operations more efficient, because the compiler can use whatever instructions copy the biggest chunks of memory when performing copies to or from the variables or fields that you have aligned this way. Note that the value of @code{__BIGGEST_ALIGNMENT__} -may change depending on command line options. +may change depending on command-line options. When used on a struct, or struct member, the @code{aligned} attribute can only increase the alignment; in order to decrease it, the @code{packed} @@ -4861,7 +4886,7 @@ of the data but not how this data is accessed. In order to read data located with the @code{progmem} attribute (inline) assembler must be used. -@example +@smallexample /* Use custom macros from @w{@uref{http://nongnu.org/avr-libc/user-manual,AVR-LibC}} */ #include <avr/pgmspace.h> @@ -4873,7 +4898,7 @@ int read_var (int i) /* Access var[] by accessor macro from avr/pgmspace.h */ return (int) pgm_read_word (& var[i]); @} -@end example +@end smallexample AVR is a Harvard architecture processor and data and read-only data normally resides in the data memory (RAM). @@ -4967,9 +4992,9 @@ memory-mapped peripherals. If an address is specified, the variable is assigned that address, else it is not assigned an address (it is assumed some other module assigns an address). Example: -@example +@smallexample int timer_count __attribute__((io(0x123))); -@end example +@end smallexample @item cb @itemx cb (@var{addr}) @@ -4977,9 +5002,9 @@ Variables with the @code{cb} attribute are used to access the control bus, using special instructions. @code{addr} indicates the control bus address. Example: -@example +@smallexample int cpu_clock __attribute__((cb(0x123))); -@end example +@end smallexample @end table @@ -5050,6 +5075,7 @@ struct @} t1; @end smallexample +@noindent The size of @code{t1} is 8 bytes with the zero-length bit-field. If the zero-length bit-field were removed, @code{t1}'s size would be 4 bytes. @@ -5075,6 +5101,7 @@ struct @} t3; @end smallexample +@noindent For @code{t2}, @code{bar} is placed at offset 2, rather than offset 1. Accordingly, the size of @code{t2} is 4. For @code{t3}, the zero-length bit-field does not affect the alignment of @code{bar} or, as a result, the size @@ -5099,6 +5126,7 @@ struct @} t4; @end smallexample +@noindent Here, @code{t4} takes up 4 bytes. @end enumerate @@ -5113,6 +5141,7 @@ struct @} t5; @end smallexample +@noindent Here, @code{t5} takes up 2 bytes. @end enumerate @end table @@ -5342,6 +5371,7 @@ typedef union __attribute__ ((__transparent_union__)) pid_t wait (wait_status_ptr_t); @end smallexample +@noindent This interface allows either @code{int *} or @code{union wait *} arguments to be passed, using the @code{int *} calling convention. The program can call @code{wait} with arguments of either type: @@ -5351,6 +5381,7 @@ int w1 () @{ int w; return wait (&w); @} int w2 () @{ union wait w; return wait (&w); @} @end smallexample +@noindent With this interface, @code{wait}'s implementation might look like this: @smallexample @@ -5433,6 +5464,7 @@ main (void) @} @end smallexample +@noindent If you replaced @code{short_a} with @code{short} in the variable declaration, the above program would abort when compiled with @option{-fstrict-aliasing}, which is on by default at @option{-O2} or @@ -5475,6 +5507,7 @@ __declspec(dllexport) C::C() @{@} @end smallexample +@noindent In this code, @code{C::C} is exported from the current DLL, but the virtual table for @code{C} is not exported. (You can use @code{__attribute__} instead of @code{__declspec} if you prefer, but @@ -5739,6 +5772,7 @@ volatile int vobj; vobj = 1; @end smallexample +@noindent Unless @var{*ptr} and @var{vobj} can be aliased, it is not guaranteed that the write to @var{*ptr} occurs by the time the update of @var{vobj} happens. If you need this guarantee, you must use @@ -6168,7 +6202,7 @@ to fall through to the next statement. This form of @code{asm} is restricted to not have outputs. This is due to a internal restriction in the compiler that control transfer instructions cannot have outputs. This restriction on @code{asm goto} may be lifted -in some future version of the compiler. In the mean time, @code{asm goto} +in some future version of the compiler. In the meantime, @code{asm goto} may include a memory clobber, and so leave outputs in memory. @smallexample @@ -6183,6 +6217,7 @@ int frob(int x) @} @end smallexample +@noindent In this (inefficient) example, the @code{frob} instruction sets the carry bit to indicate an error. The @code{jc} instruction detects this and branches to the @code{error} label. Finally, the output @@ -6213,6 +6248,7 @@ void doit(void) @} @end smallexample +@noindent In this (also inefficient) example, the @code{mfsr} instruction reads an address from some out-of-band machine register, and the following @code{jmp} instruction branches to that address. The address read by @@ -6235,13 +6271,14 @@ does not in fact fall through. #define TRACE TRACE1(__COUNTER__) @end smallexample +@noindent In this example (which in fact inspired the @code{asm goto} feature) we want on rare occasions to call the @code{trace} function; on other occasions we'd like to keep the overhead to the absolute minimum. The normal code path consists of a single @code{nop} instruction. However, we record the address of this @code{nop} together with the address of a label that calls the @code{trace} function. This allows -the @code{nop} instruction to be patched at runtime to be an +the @code{nop} instruction to be patched at run time to be an unconditional branch to the stored label. It is assumed that an optimizing compiler moves the labeled block out of line, to optimize the fall through path from the @code{asm}. @@ -6260,7 +6297,7 @@ statements in the pattern of the @code{asm} and multiplying that by the length of the longest instruction on that processor. Statements in the @code{asm} are identified by newline characters and whatever statement separator characters are supported by the assembler; on most processors -this is the `@code{;}' character. +this is the @samp{;} character. Normally, GCC's estimate is perfectly adequate to ensure that correct code is generated, but it is possible to confuse the compiler if you use @@ -6280,7 +6317,7 @@ stack-like regs: @item Given a set of input regs that die in an asm_operands, it is necessary to know which are implicitly popped by the asm, and -which must be explicitly popped by gcc. +which must be explicitly popped by GCC@. An input reg that is implicitly popped by the asm must be explicitly clobbered, unless it is constrained to match an @@ -6304,6 +6341,7 @@ use the input reg for an output reload. Consider this example: asm ("foo" : "=t" (a) : "f" (b)); @end smallexample +@noindent This asm says that input B is not popped by the asm, and that the asm pushes a result onto the reg-stack, i.e., the stack is one deeper after the asm than it was before. But, it is possible that @@ -6352,6 +6390,7 @@ takes one input, which is internally popped, and produces two outputs. asm ("fsincos" : "=t" (cos), "=u" (sin) : "0" (inp)); @end smallexample +@noindent This asm takes two inputs, which are popped by the @code{fyl2xp1} opcode, and replaces them with one output. The user must code the @code{st(1)} clobber for reg-stack.c to know that @code{fyl2xp1} pops both inputs. @@ -6602,6 +6641,8 @@ assignment, for example @code{r0} below: register int *p1 asm ("r0") = @dots{}; register int *p2 asm ("r1") = @dots{}; @end smallexample + +@noindent In those cases, a solution is to use a temporary variable for each arbitrary expression. @xref{Example of asm with clobbered asm reg}. @@ -6829,6 +6870,7 @@ types. This should be done using an appropriate @code{typedef}: typedef int v4si __attribute__ ((vector_size (16))); @end smallexample +@noindent The @code{int} type specifies the base type, while the attribute specifies the vector size for the variable, measured in bytes. For example, the declaration above causes the compiler to set the mode for the @code{v4si} @@ -6903,7 +6945,7 @@ a = l + a; /* Error, cannot convert long to int. */ Vectors can be subscripted as if the vector were an array with the same number of elements and base type. Out of bound accesses -invoke undefined behavior at runtime. Warnings for out of bound +invoke undefined behavior at run time. Warnings for out of bound accesses for vector subscription can be enabled with @option{-Warray-bounds}. @@ -6994,6 +7036,7 @@ This extension is sufficient such that #define offsetof(@var{type}, @var{member}) __builtin_offsetof (@var{type}, @var{member}) @end smallexample +@noindent is a suitable definition of the @code{offsetof} macro. In C++, @var{type} may be dependent. In either case, @var{member} may consist of a single identifier, or a sequence of member accesses and array references. @@ -7005,7 +7048,7 @@ The following built-in functions are intended to be compatible with those described in the @cite{Intel Itanium Processor-specific Application Binary Interface}, section 7.4. As such, they depart from the normal GCC practice of using -the ``__builtin_'' prefix, and further that they are overloaded such that +the @samp{__builtin_} prefix, and further that they are overloaded such that they work on multiple types. The definition given in the Intel documentation allows only for the use of @@ -7155,19 +7198,19 @@ Target architectures are encouraged to provide their own patterns for each of these built-in functions. If no target is provided, the original non-memory model set of @samp{__sync} atomic built-in functions are utilized, along with any required synchronization fences surrounding it in -order to achieve the proper behaviour. Execution in this case is subject +order to achieve the proper behavior. Execution in this case is subject to the same restrictions as those built-in functions. If there is no pattern or mechanism to provide a lock free instruction sequence, a call is made to an external routine with the same parameters -to be resolved at runtime. +to be resolved at run time. The four non-arithmetic functions (load, store, exchange, and compare_exchange) all have a generic version as well. This generic version works on any data type. If the data type size maps to one of the integral sizes that may have lock free support, the generic version utilizes the lock free built-in function. Otherwise an -external call is left to be resolved at runtime. This external call is +external call is left to be resolved at run time. This external call is the same format with the addition of a @samp{size_t} parameter inserted as the first parameter indicating the size of the object being pointed to. All objects must be the same size. @@ -7209,8 +7252,8 @@ efficiently as they could with a more appropriate implemention of the relaxed requirements. Note that the C++11 standard allows for the memory model parameter to be -determined at runtime rather than at compile time. These built-in -functions map any runtime value to @code{__ATOMIC_SEQ_CST} rather +determined at run time rather than at compile time. These built-in +functions map any run-time value to @code{__ATOMIC_SEQ_CST} rather than invoke a runtime library call or inline a switch statement. This is standard compliant, safe, and the simplest approach for now. @@ -7336,8 +7379,8 @@ All memory models are valid. This built-in function performs an atomic test-and-set operation on the byte at @code{*@var{ptr}}. The byte is set to some implementation -defined non-zero "set" value and the return value is @code{true} if and only -if the previous contents were "set". +defined nonzero ``set'' value and the return value is @code{true} if and only +if the previous contents were ``set''. All memory models are valid. @@ -7376,7 +7419,8 @@ All memory orders are valid. This built-in function returns true if objects of @var{size} bytes always generate lock free atomic instructions for the target architecture. -@var{size} must resolve to a compile time constant and the result also resolves to compile time constant. +@var{size} must resolve to a compile-time constant and the result also +resolves to a compile-time constant. @var{ptr} is an optional pointer to the object that may be used to determine alignment. A value of 0 indicates typical alignment should be used. The @@ -7472,7 +7516,7 @@ it is known at compile time that the destination object will not be overflown. If the compiler can determine at compile time the object will be always overflown, it issues a warning. -The intended use can be e.g. +The intended use can be e.g.@: @smallexample #undef memcpy @@ -7490,11 +7534,11 @@ memcpy (p, "abcde", n); memcpy (&buf[5], "abcde", 5); /* Destination is known, but the length is not known at compile time. This will result in __memcpy_chk call that can check for overflow - at runtime. */ + at run time. */ memcpy (&buf[5], "abcde", n); /* Destination is known and it is known at compile time there will be overflow. There will be a warning and __memcpy_chk call that - will abort the program at runtime. */ + will abort the program at run time. */ memcpy (&buf[6], "abcde", 5); @end smallexample @@ -8180,7 +8224,7 @@ infinities, NaNs and negative zeros are involved. @deftypefn {Built-in Function} int __builtin_constant_p (@var{exp}) You can use the built-in function @code{__builtin_constant_p} to -determine if a value is known to be constant at compile-time and hence +determine if a value is known to be constant at compile time and hence that GCC can perform constant-folding on expressions involving that value. The argument of the function is the value to test. The function returns the integer 1 if the argument is known to be a compile-time @@ -8300,6 +8344,7 @@ int f (int c, int v) @} @end smallexample +@noindent Because the @code{asm} statement unconditionally transfers control out of the function, control never reaches the end of the function body. The @code{__builtin_unreachable} is in fact unreachable and @@ -8333,12 +8378,13 @@ This function returns its first argument, and allows the compiler to assume that the returned pointer is at least @var{align} bytes aligned. This built-in can have either two or three arguments, if it has three, the third argument should have integer type, and -if it is non-zero means misalignment offset. For example: +if it is nonzero means misalignment offset. For example: @smallexample void *x = __builtin_assume_aligned (arg, 16); @end smallexample +@noindent means that the compiler can assume @code{x}, set to @code{arg}, is at least 16-byte aligned, while: @@ -8346,6 +8392,7 @@ means that the compiler can assume @code{x}, set to @code{arg}, is at least void *x = __builtin_assume_aligned (arg, 32, 8); @end smallexample +@noindent means that the compiler can assume for @code{x}, set to @code{arg}, that @code{(char *) x - 8} is 32-byte aligned. @end deftypefn @@ -8548,7 +8595,7 @@ significant bit position. If @var{x} is 0, the result is undefined. @end deftypefn @deftypefn {Built-in Function} int __builtin_clrsb (int x) -Returns the number of leading redundant sign bits in @var{x}, i.e. the +Returns the number of leading redundant sign bits in @var{x}, i.e.@: the number of bits following the most significant bit that are identical to it. There are no special cases for 0 or other values. @end deftypefn @@ -8937,7 +8984,7 @@ or if not a specific built-in is implemented or not. For example, if @code{__BUILTIN_AVR_NOP} is defined to @code{1} and undefined otherwise. The following built-in functions map to the respective machine -instruction, i.e. @code{nop}, @code{sei}, @code{cli}, @code{sleep}, +instruction, i.e.@: @code{nop}, @code{sei}, @code{cli}, @code{sleep}, @code{wdr}, @code{swap}, @code{fmul}, @code{fmuls} resp. @code{fmulsu}. The three @code{fmul*} built-ins are implemented as library call if no hardware multiplier is available. @@ -8963,7 +9010,7 @@ void __builtin_avr_delay_cycles (unsigned long ticks) @noindent @code{ticks} is the number of ticks to delay execution. Note that this built-in does not take into account the effect of interrupts that -might increase delay time. @code{ticks} must be a compile time +might increase delay time. @code{ticks} must be a compile-time integer constant; delays with a variable number of cycles are not supported. @smallexample @@ -9047,7 +9094,7 @@ GCC provides many FR-V-specific built-in functions. In general, these functions are intended to be compatible with those described by @cite{FR-V Family, Softune C/C++ Compiler Manual (V6), Fujitsu Semiconductor}. The two exceptions are @code{__MDUNPACKH} and -@code{__MBTOHE}, the gcc forms of which pass 128-bit values by +@code{__MBTOHE}, the GCC forms of which pass 128-bit values by pointer rather than by value. Most of the functions are named after specific FR-V instructions. @@ -9475,7 +9522,7 @@ of computers, depending on the command-line switches used. If you specify command-line switches such as @option{-msse}, the compiler could use the extended instruction sets even if the built-ins are not used explicitly in the program. For this reason, applications -that perform runtime CPU detection must compile separate files for each +that perform run-time CPU detection must compile separate files for each supported architecture, using the appropriate flags. In particular, the file containing the CPU detection code should be compiled without these options. @@ -9563,8 +9610,9 @@ void *memcpy (void *, const void *, size_t) @end deftypefn @deftypefn {Built-in Function} int __builtin_cpu_is (const char *@var{cpuname}) -This function returns a positive integer if the runtime cpu is of type @var{cpuname} - and returns @code{0} otherwise. The following cpu names can be detected: +This function returns a positive integer if the run-time CPU +is of type @var{cpuname} +and returns @code{0} otherwise. The following CPU names can be detected: @table @samp @item intel @@ -9615,6 +9663,9 @@ AMD family 15h Bulldozer version 1. @item bdver2 AMD family 15h Bulldozer version 2. +@item bdver3 +AMD family 15h Bulldozer version 3. + @item btver2 AMD family 16h CPU. @end table @@ -9633,8 +9684,9 @@ else @end deftypefn @deftypefn {Built-in Function} int __builtin_cpu_supports (const char *@var{feature}) -This function returns a positive integer if the runtime cpu supports @var{feature} - and returns @code{0} otherwise. The following features can be detected: +This function returns a positive integer if the run-time CPU +supports @var{feature} +and returns @code{0} otherwise. The following features can be detected: @table @samp @item cmov @@ -11732,6 +11784,7 @@ does not work: vec_add ((vector signed int)@{1, 2, 3, 4@}, foo); @end smallexample +@noindent Since @code{vec_add} is a macro, the vector constant in the example is treated as four separate arguments. Wrap the entire argument in parentheses for this to work. @@ -13708,7 +13761,7 @@ void vec_vsx_st (vector bool char, int, signed char *); @end smallexample Note that the @samp{vec_ld} and @samp{vec_st} built-in functions always -generate the Altivec @samp{LVX} and @samp{STVX} instructions even +generate the AltiVec @samp{LVX} and @samp{STVX} instructions even if the VSX instruction set is available. The @samp{vec_vsx_ld} and @samp{vec_vsx_st} built-in functions always generate the VSX @samp{LXVD2X}, @samp{LXVW4X}, @samp{STXVD2X}, and @samp{STXVW4X} instructions. @@ -14048,6 +14101,7 @@ does not work: spu_add ((vector signed int)@{1, 2, 3, 4@}, foo); @end smallexample +@noindent Since @code{spu_add} is a macro, the vector constant in the example is treated as four separate arguments. Wrap the entire argument in parentheses for this to work. @@ -14148,7 +14202,8 @@ unsigned __insn_@var{op} (...) @end smallexample -Where @var{op} is the name of the instruction. Refer to the ISA manual +@noindent +where @var{op} is the name of the instruction. Refer to the ISA manual for the complete list of instructions. GCC also provides intrinsics to directly access the network registers. @@ -14279,10 +14334,10 @@ compatibility with other compilers, but note that the common @code{1234H} numeric syntax is not supported (use @code{0x1234} instead). Example: -@example +@smallexample #pragma ADDRESS port3 0x103 char port3; -@end example +@end smallexample @end table @@ -14293,7 +14348,7 @@ char port3; @item custom io_volatile (on|off) @cindex pragma, custom io_volatile -Overrides the command line option @code{-mio-volatile} for the current +Overrides the command-line option @code{-mio-volatile} for the current file. Note that for compatibility with future GCC releases, this option should only be used once before any @code{io} variables in each file. @@ -14304,9 +14359,9 @@ Specifies which coprocessor registers are available to the register allocator. @var{registers} may be a single register, register range separated by ellipses, or comma-separated list of those. Example: -@example +@smallexample #pragma GCC coprocessor available $c0...$c10, $c28 -@end example +@end smallexample @item GCC coprocessor call_saved @var{registers} @cindex pragma, coprocessor call_saved @@ -14315,9 +14370,9 @@ any function using them. @var{registers} may be a single register, register range separated by ellipses, or comma-separated list of those. Example: -@example +@smallexample #pragma GCC coprocessor call_saved $c4...$c6, $c31 -@end example +@end smallexample @item GCC coprocessor subclass '(A|B|C|D)' = @var{registers} @cindex pragma, coprocessor subclass @@ -14326,11 +14381,11 @@ used by inline @code{asm} constructs. @var{registers} may be a single register, register range separated by ellipses, or comma-separated list of those. Example: -@example +@smallexample #pragma GCC coprocessor subclass 'B' = $c2, $c4, $c6 asm ("cpfoo %0" : "=B" (x)); -@end example +@end smallexample @item GCC disinterrupt @var{name} , @var{name} @dots{} @cindex pragma, disinterrupt @@ -14339,21 +14394,21 @@ for the duration of those functions. If any functions so named are not encountered in the source, a warning is emitted that the pragma is not used. Examples: -@example +@smallexample #pragma disinterrupt foo #pragma disinterrupt bar, grill int foo () @{ @dots{} @} -@end example +@end smallexample @item GCC call @var{name} , @var{name} @dots{} @cindex pragma, call For the named functions, the compiler always uses a register-indirect call model when calling the named functions. Examples: -@example +@smallexample extern int foo (); #pragma call foo -@end example +@end smallexample @end table @@ -14511,7 +14566,7 @@ multiple @code{#pragma pack(@var{n})} instances and finalized by a single @code{#pragma pack(pop)}. @end enumerate -Some targets, e.g.@: i386 and powerpc, support the @code{ms_struct} +Some targets, e.g.@: i386 and PowerPC, support the @code{ms_struct} @code{#pragma} which lays out a structure as the documented @code{__attribute__ ((ms_struct))}. @enumerate @@ -14570,11 +14625,11 @@ in effect), or @samp{ignored} if the diagnostic is to be ignored. @var{option} is a double quoted string that matches the command-line option. -@example +@smallexample #pragma GCC diagnostic warning "-Wformat" #pragma GCC diagnostic error "-Wformat" #pragma GCC diagnostic ignored "-Wformat" -@end example +@end smallexample Note that these pragmas override any command-line options. GCC keeps track of the location of each pragma, and issues diagnostics according @@ -14586,20 +14641,20 @@ after a line do not affect diagnostics caused by that line. Causes GCC to remember the state of the diagnostics as of each @code{push}, and restore to that point at each @code{pop}. If a -@code{pop} has no matching @code{push}, the command line options are +@code{pop} has no matching @code{push}, the command-line options are restored. -@example +@smallexample #pragma GCC diagnostic error "-Wuninitialized" - foo(a); /* error is given for this one */ + foo(a); /* error is given for this one */ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wuninitialized" - foo(b); /* no diagnostic for this one */ + foo(b); /* no diagnostic for this one */ #pragma GCC diagnostic pop - foo(c); /* error is given for this one */ + foo(c); /* error is given for this one */ #pragma GCC diagnostic pop - foo(d); /* depends on command line options */ -@end example + foo(d); /* depends on command-line options */ +@end smallexample @end table @@ -14627,6 +14682,7 @@ information. For example, TODO(Remember to fix this) @end smallexample +@noindent prints @samp{/tmp/file.c:4: note: #pragma message: TODO - Remember to fix this}. @@ -14684,6 +14740,7 @@ For example: int x [X]; @end smallexample +@noindent In this example, the definition of X as 1 is saved by @code{#pragma push_macro} and restored by @code{#pragma pop_macro}. @@ -14703,8 +14760,8 @@ function. The parenthesis around the options is optional. @code{target} attribute and the attribute syntax. The @code{#pragma GCC target} attribute is not implemented in GCC versions earlier -than 4.4 for the i386/x86_64 and 4.6 for the PowerPC backends. At -present, it is not implemented for other backends. +than 4.4 for the i386/x86_64 and 4.6 for the PowerPC back ends. At +present, it is not implemented for other back ends. @end table @table @code @@ -14772,13 +14829,14 @@ struct @{ @} foo; @end smallexample +@noindent In this example, you are able to access members of the unnamed union with code like @samp{foo.b}. Note that only unnamed structs and unions are allowed, you may not have, for example, an unnamed @code{int}. You must never create such structures that cause ambiguous field definitions. -For example, this structure: +For example, in this structure: @smallexample struct @{ @@ -14789,7 +14847,8 @@ struct @{ @} foo; @end smallexample -It is ambiguous which @code{a} is being referred to with @samp{foo.a}. +@noindent +it is ambiguous which @code{a} is being referred to with @samp{foo.a}. The compiler gives errors for such constructs. @opindex fms-extensions @@ -14814,6 +14873,7 @@ extern void f1 (struct s1 *); void f2 (struct s2 *p) @{ f1 (p); @} @end smallexample +@noindent In the call to @code{f1} inside @code{f2}, the pointer @code{p} is converted into a pointer to the anonymous field. @@ -14837,7 +14897,7 @@ These usages are only permitted when they are not ambiguous. Thread-local storage (@acronym{TLS}) is a mechanism by which variables are allocated such that there is one instance of the variable per extant -thread. The run-time model GCC uses to implement this originates +thread. The runtime model GCC uses to implement this originates in the IA-64 processor-specific ABI, but has since been migrated to other processors as well. It requires significant support from the linker (@command{ld}), dynamic linker (@command{ld.so}), and @@ -14863,7 +14923,7 @@ static, function-scoped static, or static data member of a class. It may not be applied to block-scoped automatic or non-static data member. When the address-of operator is applied to a thread-local variable, it is -evaluated at run-time and returns the address of the current thread's +evaluated at run time and returns the address of the current thread's instance of that variable. An address so obtained may be used by any thread. When a thread terminates, any pointers to thread-local variables in that thread become invalid. @@ -14876,7 +14936,7 @@ standard. See @uref{http://www.akkadia.org/drepper/tls.pdf, ELF Handling For Thread-Local Storage} for a detailed explanation of -the four thread-local storage addressing models, and how the run-time +the four thread-local storage addressing models, and how the runtime is expected to function. @menu @@ -15138,7 +15198,7 @@ Predefined Macros,cpp,The GNU C Preprocessor}). * Namespace Association:: Strong using-directives for namespace association. * Type Traits:: Compiler support for type traits * Java Exceptions:: Tweaking exception handling to work with Java. -* Deprecated Features:: Things will disappear from g++. +* Deprecated Features:: Things will disappear from G++. * Backwards Compatibility:: Compatibilities with earlier definitions of C++. @end menu @@ -15186,7 +15246,7 @@ references. Again, if you wish to force a read, cast the reference to an rvalue. G++ implements the same behavior as GCC does when assigning to a -volatile object -- there is no reread of the assigned-to object, the +volatile object---there is no reread of the assigned-to object, the assigned rvalue is reused. Note that in C++ assignment expressions are lvalues, and if used as an lvalue, the volatile object is referred to. For instance, @var{vref} refers to @var{vobj}, as @@ -15293,7 +15353,7 @@ C++ requires information about types to be written out in order to implement @samp{dynamic_cast}, @samp{typeid} and exception handling. For polymorphic classes (classes with virtual functions), the @samp{type_info} object is written out along with the vtable so that @samp{dynamic_cast} -can determine the dynamic type of a class object at runtime. For all +can determine the dynamic type of a class object at run time. For all other types, we write out the @samp{type_info} object when it is used: when applying @samp{typeid} to an expression, throwing an object, or referring to a type in a catch clause or exception specification. @@ -15522,6 +15582,7 @@ template ostream& operator << (ostream&, const Foo<int>&); @end smallexample +@noindent for each of the instances you need, and create a template instantiation library from those. @@ -15711,7 +15772,7 @@ int main() @node Type Traits @section Type Traits -The C++ front-end implements syntactic extensions that allow +The C++ front end implements syntactic extensions that allow compile-time determination of various characteristics of a type (or of a pair of types). @@ -15937,7 +15998,7 @@ and other places where they are not permitted by the standard is deprecated and will be removed from a future version of G++. G++ allows floating-point literals to appear in integral constant expressions, -e.g. @samp{ enum E @{ e = int(2.2 * 3.7) @} } +e.g.@: @samp{ enum E @{ e = int(2.2 * 3.7) @} } This extension is deprecated and will be removed from a future version. G++ allows static data members of const floating-point type to be declared |