diff options
author | Martin Sebor <msebor@redhat.com> | 2018-11-15 22:53:57 +0000 |
---|---|---|
committer | Martin Sebor <msebor@gcc.gnu.org> | 2018-11-15 15:53:57 -0700 |
commit | 1d24950977c730f5e955060057b1dd0b5c051adb (patch) | |
tree | aecd56593f283b79ac0939bd57a5555c6b93239f /gcc/doc | |
parent | cd5da9837b26d77136d3a9394747ce4325a95118 (diff) | |
download | gcc-1d24950977c730f5e955060057b1dd0b5c051adb.zip gcc-1d24950977c730f5e955060057b1dd0b5c051adb.tar.gz gcc-1d24950977c730f5e955060057b1dd0b5c051adb.tar.bz2 |
PR c++/87541 - ICE using a constant decl as an attribute alloc_size argument
PR c++/87541 - ICE using a constant decl as an attribute alloc_size argument
PR c++/87542 - bogus error on attribute format with a named constant argument
gcc/ChangeLog:
PR c++/87541
PR c++/87542
* tree.c (type_argument_type): New function.
* tree.h (type_argument_type): Declare it.
* gcc/doc/extend.texi (alloc_align): Update and clarify.
(alloc_size, nonnull, sentinel): Same.
gcc/c-family/ChangeLog:
PR c++/87541
PR c++/87542
* c-attribs.c (positional_argument): New function.
(handle_alloc_size_attribute): Use it and simplify.
(handle_alloc_align_attribute): Same.
(handle_assume_aligned_attribute): Same.
(handle_nonnull_attribute): Same.
* c-common.c (check_function_arguments): Pass fntype to
check_function_format.
* c-common.h (check_function_format): Add an argument.
(PosArgFlags, positional_argument): Declare new type and function.
* c-format.c (decode_format_attr): Add arguments.
(check_format_string, get_constant): Same.
(convert_format_name_to_system_name): Adjust.
gcc/testsuite/ChangeLog:
PR c++/87541
PR c++/87542
* g++.dg/ext/attr-alloc_size.C: New test.
* c-c++-common/pr71574.c: Adjust diagnostics.
* c-c++-common/attributes-1.c: Same.
* gcc.dg/attr-alloc_align-2.c: Same.
* gcc.dg/attr-alloc_align-4.c: New test.
* gcc.dg/attr-alloc_size-2.c: Adjust diagnostics.
* gcc.dg/attr-alloc_size.c: Same.
* gcc.dg/attr-assume_aligned-4.c: New test.
* gcc.dg/format/attr-3.c: Adjust diagnostics.
* gcc.dg/nonnull-2.c: Same.
* gcc.dg/torture/pr80612.c: Same.
* obj-c++.dg/attributes/method-format-1.mm: Same.
* obj-c++.dg/attributes/method-nonnull-1.mm: Same.
* objc.dg/attributes/method-format-1.m: same.
* objc.dg/attributes/method-nonnull-1.m: Same.
From-SVN: r266195
Diffstat (limited to 'gcc/doc')
-rw-r--r-- | gcc/doc/extend.texi | 80 |
1 files changed, 46 insertions, 34 deletions
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index d4b1046..d0146ba 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -2406,33 +2406,39 @@ further information. The @code{aligned} attribute can also be used for variables and fields (@pxref{Variable Attributes}.) -@item alloc_align +@item alloc_align (@var{position}) @cindex @code{alloc_align} function attribute -The @code{alloc_align} attribute is used to tell the compiler that the -function return value points to memory, where the returned pointer minimum -alignment is given by one of the functions parameters. GCC uses this -information to improve pointer alignment analysis. +The @code{alloc_align} attribute may be applied to a function that +returns a pointer and takes at least one argument of an integer type. +It indicates that the returned pointer is aligned on a boundary given +by the function argument at @var{position}. Meaningful alignments are +powers of 2 greater than one. GCC uses this information to improve +pointer alignment analysis. The function parameter denoting the allocated alignment is specified by -one integer argument, whose number is the argument of the attribute. +one constant integer argument whose number is the argument of the attribute. Argument numbering starts at one. For instance, @smallexample -void* my_memalign(size_t, size_t) __attribute__((alloc_align(1))) +void* my_memalign (size_t, size_t) __attribute__ ((alloc_align (1))); @end smallexample @noindent declares that @code{my_memalign} returns memory with minimum alignment given by parameter 1. -@item alloc_size +@item alloc_size (@var{position}) +@itemx alloc_size (@var{position-1}, @var{position-2}) @cindex @code{alloc_size} function attribute -The @code{alloc_size} attribute is used to tell the compiler that the -function return value points to memory, where the size is given by -one or two of the functions parameters. GCC uses this -information to improve the correctness of @code{__builtin_object_size}. +The @code{alloc_size} attribute may be applied to a function that +returns a pointer and takes at least one argument of an integer type. +It indicates that the returned pointer points to memory whose size is +given by the function argument at @var{position-1}, or by the product +of the arguments at @var{position-1} and @var{position-2}. Meaningful +sizes are positive values less than @code{PTRDIFF_MAX}. GCC uses this +information to improve the results of @code{__builtin_object_size}. The function parameter(s) denoting the allocated size are specified by one or two integer arguments supplied to the attribute. The allocated size @@ -2443,8 +2449,8 @@ one. For instance, @smallexample -void* my_calloc(size_t, size_t) __attribute__((alloc_size(1,2))) -void* my_realloc(void*, size_t) __attribute__((alloc_size(2))) +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 @@ -2470,22 +2476,25 @@ info format it either means marking the function as artificial or using the caller location for all instructions within the inlined body. -@item assume_aligned +@item assume_aligned (@var{alignment}) +@itemx assume_aligned (@var{alignment}, @var{offset}) @cindex @code{assume_aligned} function attribute -The @code{assume_aligned} attribute is used to tell the compiler that the -function return value points to memory, where the returned pointer minimum -alignment is given by the first argument. -If the attribute has two arguments, the second argument is misalignment offset. +The @code{assume_aligned} attribute may be applied to a function that +returns a pointer. It indicates that the returned pointer is aligned +on a boundary given by @var{alignment}. If the attribute has two +arguments, the second argument is misalignment @var{offset}. Meaningful +values of @var{alignment} are powers of 2 greater than one. Meaningful +values of @var{offset} are greater than zero and less than @var{alignment}. For instance @smallexample -void* my_alloc1(size_t) __attribute__((assume_aligned(16))) -void* my_alloc2(size_t) __attribute__((assume_aligned(32, 8))) +void* my_alloc1 (size_t) __attribute__((assume_aligned (16))); +void* my_alloc2 (size_t) __attribute__((assume_aligned (32, 8))); @end smallexample @noindent -declares that @code{my_alloc1} returns 16-byte aligned pointer and +declares that @code{my_alloc1} returns 16-byte aligned pointers and that @code{my_alloc2} returns a pointer whose value modulo 32 is equal to 8. @@ -3118,8 +3127,9 @@ of testing the compiler. @itemx nonnull (@var{arg-index}, @dots{}) @cindex @code{nonnull} function attribute @cindex functions with non-null pointer arguments -The @code{nonnull} attribute specifies that some function parameters should -be non-null pointers. For instance, the declaration: +The @code{nonnull} attribute may be applied to a function that takes at +least one argument of a pointer type. It indicates that the referenced +arguments must be non-null pointers. For instance, the declaration: @smallexample extern void * @@ -3354,13 +3364,14 @@ If you need to map the entire contents of a module to a particular section, consider using the facilities of the linker instead. @item sentinel +@itemx sentinel (@var{position}) @cindex @code{sentinel} function attribute -This function attribute ensures that a parameter in a function call is -an explicit @code{NULL}. The attribute is only valid on variadic -functions. By default, the sentinel is located at position zero, the -last parameter of the function call. If an optional integer position -argument P is supplied to the attribute, the sentinel must be located at -position P counting backwards from the end of the argument list. +This function attribute indicates that an argument in a call to the function +is expected to be an explicit @code{NULL}. The attribute is only valid on +variadic functions. By default, the sentinel is expected to be the last +argument of the function call. If the optional @var{position} argument +is specified to the attribute, the sentinel must be located at +@var{position} counting backwards from the end of the argument list. @smallexample __attribute__ ((sentinel)) @@ -3372,10 +3383,11 @@ The attribute is automatically set with a position of 0 for the built-in functions @code{execl} and @code{execlp}. The built-in function @code{execle} has the attribute set with a position of 1. -A valid @code{NULL} in this context is defined as zero with any pointer -type. If your system defines the @code{NULL} macro with an integer type -then you need to add an explicit cast. GCC replaces @code{stddef.h} -with a copy that redefines NULL appropriately. +A valid @code{NULL} in this context is defined as zero with any object +pointer type. If your system defines the @code{NULL} macro with +an integer type then you need to add an explicit cast. During +installation GCC replaces the system @code{<stddef.h>} header with +a copy that redefines NULL appropriately. The warnings for missing or incorrect sentinels are enabled with @option{-Wformat}. |