public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/ARM/heads/morello)] Avoid losing __capability when adding later attributes
@ 2022-05-06 14:45 Matthew Malcomson
0 siblings, 0 replies; only message in thread
From: Matthew Malcomson @ 2022-05-06 14:45 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:f33457b9832988e34fb7e5bb6f5b1261aeb3637a
commit f33457b9832988e34fb7e5bb6f5b1261aeb3637a
Author: Richard Sandiford <richard.sandiford@arm.com>
Date: Wed Apr 27 19:41:22 2022 +0100
Avoid losing __capability when adding later attributes
This patch fixes three cases in which applying an attribute
to a function pointer type would lose any previous attributes
attached to the pointer (rather than the function) type.
This includes the __capability attribute, but it seems like
a general bug.
Diff:
---
gcc/attribs.c | 10 ++++------
gcc/c-family/c-attribs.c | 22 ++++++++++------------
.../gcc.target/aarch64/morello/func-attrs-1.c | 22 ++++++++++++++++++++++
3 files changed, 36 insertions(+), 18 deletions(-)
diff --git a/gcc/attribs.c b/gcc/attribs.c
index c2b5962e466..5e8ec4b4326 100644
--- a/gcc/attribs.c
+++ b/gcc/attribs.c
@@ -555,7 +555,7 @@ decl_attributes (tree *node, tree attributes, int flags,
tree *anode = node;
const struct attribute_spec *spec
= lookup_scoped_attribute_spec (ns, name);
- int fn_ptr_quals = 0;
+ tree orig_fn_ptr = NULL_TREE;
tree fn_ptr_tmp = NULL_TREE;
const bool cxx11_attr_p = cxx11_attribute_p (attr);
@@ -638,8 +638,8 @@ decl_attributes (tree *node, tree attributes, int flags,
This would all be simpler if attributes were part of the
declarator, grumble grumble. */
- fn_ptr_tmp = TREE_TYPE (*anode);
- fn_ptr_quals = TYPE_QUALS (*anode);
+ orig_fn_ptr = *anode;
+ fn_ptr_tmp = TREE_TYPE (orig_fn_ptr);
anode = &fn_ptr_tmp;
flags &= ~(int) ATTR_FLAG_TYPE_IN_PLACE;
}
@@ -790,9 +790,7 @@ decl_attributes (tree *node, tree attributes, int flags,
{
/* Rebuild the function pointer type and put it in the
appropriate place. */
- fn_ptr_tmp = build_pointer_type (fn_ptr_tmp);
- if (fn_ptr_quals)
- fn_ptr_tmp = build_qualified_type (fn_ptr_tmp, fn_ptr_quals);
+ fn_ptr_tmp = change_pointer_target_type (orig_fn_ptr, fn_ptr_tmp);
if (DECL_P (*node))
TREE_TYPE (*node) = fn_ptr_tmp;
else
diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c
index 9852ed35889..a5996eaf0d2 100644
--- a/gcc/c-family/c-attribs.c
+++ b/gcc/c-family/c-attribs.c
@@ -878,12 +878,11 @@ handle_noreturn_attribute (tree *node, tree name, tree ARG_UNUSED (args),
TREE_THIS_VOLATILE (*node) = 1;
else if (TREE_CODE (type) == POINTER_TYPE
&& TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
- TREE_TYPE (*node)
- = (build_qualified_type
- (build_pointer_type
- (build_type_variant (TREE_TYPE (type),
- TYPE_READONLY (TREE_TYPE (type)), 1)),
- TYPE_QUALS (type)));
+ {
+ tree target = build_type_variant (TREE_TYPE (type),
+ TYPE_READONLY (TREE_TYPE (type)), 1);
+ TREE_TYPE (*node) = change_pointer_target_type (type, target);
+ }
else
{
warning (OPT_Wattributes, "%qE attribute ignored", name);
@@ -1465,12 +1464,11 @@ handle_const_attribute (tree *node, tree name, tree ARG_UNUSED (args),
TREE_READONLY (*node) = 1;
else if (TREE_CODE (type) == POINTER_TYPE
&& TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE)
- TREE_TYPE (*node)
- = (build_qualified_type
- (build_pointer_type
- (build_type_variant (TREE_TYPE (type), 1,
- TREE_THIS_VOLATILE (TREE_TYPE (type)))),
- TYPE_QUALS (type)));
+ {
+ tree target = build_type_variant (TREE_TYPE (type), 1,
+ TREE_THIS_VOLATILE (TREE_TYPE (type)));
+ TREE_TYPE (*node) = change_pointer_target_type (type, target);
+ }
else
{
warning (OPT_Wattributes, "%qE attribute ignored", name);
diff --git a/gcc/testsuite/gcc.target/aarch64/morello/func-attrs-1.c b/gcc/testsuite/gcc.target/aarch64/morello/func-attrs-1.c
new file mode 100644
index 00000000000..069ca4c6fe5
--- /dev/null
+++ b/gcc/testsuite/gcc.target/aarch64/morello/func-attrs-1.c
@@ -0,0 +1,22 @@
+/* { dg-do compile } */
+
+void (*__capability nonnull1) (void) __attribute__((nonnull));
+void (*nonnull2) (void) __attribute__((nonnull));
+
+void (*__capability noreturn1) (void) __attribute__((noreturn));
+void (*noreturn2) (void) __attribute__((noreturn));
+
+void (*__capability const1) (void) __attribute__((const));
+void (*const2) (void) __attribute__((const));
+
+void (*__capability callable1) (void) __attribute__((transaction_callable));
+void (*callable2) (void) __attribute__((transaction_callable));
+
+int
+foo (void)
+{
+ nonnull1 = nonnull2;
+ noreturn1 = noreturn2;
+ const1 = const2;
+ callable1 = callable2;
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-05-06 14:45 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-06 14:45 [gcc(refs/vendors/ARM/heads/morello)] Avoid losing __capability when adding later attributes Matthew Malcomson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).