aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMartin Sebor <msebor@redhat.com>2019-01-04 22:48:45 +0000
committerMartin Sebor <msebor@gcc.gnu.org>2019-01-04 15:48:45 -0700
commit9069a4c95d7f4d30f1e2e9d25dc7bb11a9f0e982 (patch)
tree7f1228fc1a3e2747d8fa02ee659b66eb9665968e /gcc
parent6908c1dc6fc8d377ba80f12b7889e7872505cbb0 (diff)
downloadgcc-9069a4c95d7f4d30f1e2e9d25dc7bb11a9f0e982.zip
gcc-9069a4c95d7f4d30f1e2e9d25dc7bb11a9f0e982.tar.gz
gcc-9069a4c95d7f4d30f1e2e9d25dc7bb11a9f0e982.tar.bz2
PR c/88363 - alloc_align attribute doesn't accept enumerated arguments
gcc/c-family/ChangeLog: PR c/88363 * c-attribs.c (positional_argument): Also accept enumerated types. gcc/testsuite/ChangeLog: PR c/88363 * c-c++-common/attributes-4.c: New test. gcc/ChangeLog: PR c/88363 * doc/extend.texi (attribute alloc_align, alloc_size): Update. From-SVN: r267583
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/c-family/ChangeLog5
-rw-r--r--gcc/c-family/c-attribs.c18
-rw-r--r--gcc/doc/extend.texi6
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/c-c++-common/attributes-4.c47
6 files changed, 78 insertions, 8 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index c0dae25..8a8dd4a 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2019-01-04 Martin Sebor <msebor@redhat.com>
+
+ PR c/88363
+ * doc/extend.texi (attribute alloc_align, alloc_size): Update.
+
2019-01-04 Jakub Jelinek <jakub@redhat.com>
* gdbinit.in: Turn off pagination for the skip commands, restore
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog
index bbee106..55e6ee8 100644
--- a/gcc/c-family/ChangeLog
+++ b/gcc/c-family/ChangeLog
@@ -1,3 +1,8 @@
+2019-01-04 Martin Sebor <msebor@redhat.com>
+
+ PR c/88363
+ * c-attribs.c (positional_argument): Also accept enumerated types.
+
2019-01-01 Jakub Jelinek <jakub@redhat.com>
Update copyright years.
diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c
index 476df6e..03978dd 100644
--- a/gcc/c-family/c-attribs.c
+++ b/gcc/c-family/c-attribs.c
@@ -498,10 +498,11 @@ attribute_takes_identifier_p (const_tree attr_id)
/* Verify that argument value POS at position ARGNO to attribute NAME
applied to function TYPE refers to a function parameter at position
- POS and the expected type CODE. If so, return POS after default
- conversions, if any. Otherwise, issue appropriate warnings and
- return null. A non-zero 1-based ARGNO should be passed ib by
- callers only for attributes with more than one argument. */
+ POS and the expected type CODE. Treat CODE == INTEGER_TYPE as
+ matching all C integral types except bool. If successful, return
+ POS after default conversions, if any. Otherwise, issue appropriate
+ warnings and return null. A non-zero 1-based ARGNO should be passed
+ in by callers only for attributes with more than one argument. */
tree
positional_argument (const_tree fntype, const_tree atname, tree pos,
@@ -630,17 +631,22 @@ positional_argument (const_tree fntype, const_tree atname, tree pos,
return NULL_TREE;
}
- /* Where the expected code is STRING_CST accept any pointer
- to a narrow character type, qualified or otherwise. */
bool type_match;
if (code == STRING_CST && POINTER_TYPE_P (argtype))
{
+ /* Where the expected code is STRING_CST accept any pointer
+ to a narrow character type, qualified or otherwise. */
tree type = TREE_TYPE (argtype);
type = TYPE_MAIN_VARIANT (type);
type_match = (type == char_type_node
|| type == signed_char_type_node
|| type == unsigned_char_type_node);
}
+ else if (code == INTEGER_TYPE)
+ /* For integers, accept enums, wide characters and other types
+ that match INTEGRAL_TYPE_P except for bool. */
+ type_match = (INTEGRAL_TYPE_P (argtype)
+ && TREE_CODE (argtype) != BOOLEAN_TYPE);
else
type_match = TREE_CODE (argtype) == code;
diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi
index d4a8d87..19ef6a6 100644
--- a/gcc/doc/extend.texi
+++ b/gcc/doc/extend.texi
@@ -2487,7 +2487,8 @@ The @code{aligned} attribute can also be used for variables and fields
@item alloc_align (@var{position})
@cindex @code{alloc_align} function attribute
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.
+returns a pointer and takes at least one argument of an integer or
+enumerated 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
@@ -2511,7 +2512,8 @@ given by parameter 1.
@itemx alloc_size (@var{position-1}, @var{position-2})
@cindex @code{alloc_size} function attribute
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.
+returns a pointer and takes at least one argument of an integer or
+enumerated 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
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index a86473e..d0add03 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2019-01-04 Martin Sebor <msebor@redhat.com>
+
+ PR c/88363
+ * c-c++-common/attributes-4.c: New test.
+
2019-01-04 Thomas Koenig <tkoenig@gcc.gnu.org>
PR fortran/48543
diff --git a/gcc/testsuite/c-c++-common/attributes-4.c b/gcc/testsuite/c-c++-common/attributes-4.c
new file mode 100644
index 0000000..d829a56
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/attributes-4.c
@@ -0,0 +1,47 @@
+/* PR c/88363 - alloc_align attribute doesn't accept enumerated arguments
+ Verify that attribute positional arguments can refer to all C integer
+ types except _Bool in both C and C++.
+ { dg-do compile }
+ { dg-options "-Wall" }
+ { dg-options "-Wall -Wno-c++-compat" { target c } } */
+
+#define ATTR(...) __attribute__ ((__VA_ARGS__))
+
+#if __cplusplus == 199711L
+typedef __CHAR16_TYPE__ char16_t;
+typedef __CHAR32_TYPE__ char32_t;
+#elif !__cplusplus
+typedef _Bool bool;
+typedef __CHAR16_TYPE__ char16_t;
+typedef __CHAR32_TYPE__ char32_t;
+typedef __WCHAR_TYPE__ wchar_t;
+#endif
+
+enum A { A0 };
+
+ATTR (alloc_align (1)) void* falloc_align_char (char);
+ATTR (alloc_align (1)) void* falloc_align_char16 (char16_t);
+ATTR (alloc_align (1)) void* falloc_align_char32 (char32_t);
+ATTR (alloc_align (1)) void* falloc_align_wchar (wchar_t);
+/* Using an enum might make sense in an API that limits the alignments
+ it accepts to just the set of the defined enumerators. */
+ATTR (alloc_align (1)) void* falloc_align_enum (enum A);
+ATTR (alloc_align (1)) void* falloc_align_int128 (__int128_t);
+
+
+ATTR (alloc_align (1)) void* falloc_size_char (char);
+ATTR (alloc_size (1)) void* falloc_size_char16 (char16_t);
+ATTR (alloc_size (1)) void* falloc_size_char32 (char32_t);
+ATTR (alloc_size (1)) void* falloc_size_wchar (wchar_t);
+ATTR (alloc_size (1)) void* falloc_size_enum (enum A);
+ATTR (alloc_align (1)) void* falloc_size_int128 (__int128_t);
+
+
+typedef struct { int i; } S;
+
+/* Using bool is most likely a bug and so diagnosed even though
+ it could be accepted. None of the other types makes sense. */
+ATTR (alloc_align (1)) void* falloc_align_bool (bool); /* { dg-warning "attribute argument value .1. refers to parameter type .\(_Bool|bool\)" } */
+ATTR (alloc_align (1)) void* falloc_align_float (float); /* { dg-warning "attribute argument value .1. refers to parameter type .float" } */
+ATTR (alloc_align (1)) void* falloc_align_voidp (void*); /* { dg-warning "attribute argument value .1. refers to parameter type .void ?\\\*" } */
+ATTR (alloc_align (1)) void* falloc_align_struct (S); /* { dg-warning "attribute argument value .1. refers to parameter type .S" } */