public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Matthew Malcomson <matmal01@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc(refs/vendors/ARM/heads/morello)] Keep the cheri_capability attribute
Date: Thu,  5 May 2022 12:04:44 +0000 (GMT)	[thread overview]
Message-ID: <20220505120444.B83E1385627E@sourceware.org> (raw)

https://gcc.gnu.org/g:2f0e6bc008a27e3222072bc791e4325b845789be

commit 2f0e6bc008a27e3222072bc791e4325b845789be
Author: Richard Sandiford <richard.sandiford@arm.com>
Date:   Fri Mar 4 15:10:59 2022 +0000

    Keep the cheri_capability attribute
    
    This patch keeps the cheri_capability attribute in TYPE_ATTRIBUTES
    and uses it to determine the mode of pointers.  In some ways it
    feels a bit nasty to be calling layout_type in the middle of
    build_type_attribute_qual_variant, but I think it's the right
    interface.  If the starting type passed to the function is not
    a capability type then it should not (on hybrid targets) have
    a capability mode, so the caller can't change the mode first.
    Changing the mode later would leave a significant window in which
    the type is internally inconsistent.

Diff:
---
 gcc/attribs.c            | 19 +++++++++++++++++++
 gcc/c-family/c-attribs.c | 16 +++++++---------
 2 files changed, 26 insertions(+), 9 deletions(-)

diff --git a/gcc/attribs.c b/gcc/attribs.c
index 71dae123af8..c4c7591a107 100644
--- a/gcc/attribs.c
+++ b/gcc/attribs.c
@@ -1151,7 +1151,23 @@ build_type_attribute_qual_variant (tree otype, tree attribute, int quals)
 
       tree dtype = ntype = build_distinct_type_copy (ttype);
 
+      gcc_assert (ntype == TYPE_MAIN_VARIANT (ntype));
       TYPE_ATTRIBUTES (ntype) = attribute;
+      if (POINTER_TYPE_P (ntype)
+	  && !capability_type_p (ptr_type_node))
+	{
+	  bool old_cap = capability_type_p (ttype);
+	  bool new_cap = lookup_attribute ("cheri_capability", attribute);
+	  if (old_cap != new_cap)
+	    {
+	      auto as = TYPE_ADDR_SPACE (TREE_TYPE (ntype));
+	      auto mode = targetm.addr_space.pointer_mode (as, new_cap);
+	      SET_TYPE_MODE (ntype, mode);
+	      /* Force the size to be recomputed.  */
+	      TYPE_SIZE (ntype) = NULL_TREE;
+	      layout_type (ntype);
+	    }
+	}
 
       hashval_t hash = type_hash_canon_hash (ntype);
       ntype = type_hash_canon (hash, ntype);
@@ -1352,6 +1368,9 @@ comp_type_attributes (const_tree type1, const_tree type2)
   if ((lookup_attribute ("nocf_check", TYPE_ATTRIBUTES (type1)) != NULL)
       ^ (lookup_attribute ("nocf_check", TYPE_ATTRIBUTES (type2)) != NULL))
     return 0;
+  if (bool (lookup_attribute ("cheri_capability", TYPE_ATTRIBUTES (type1)))
+      != bool (lookup_attribute ("cheri_capability", TYPE_ATTRIBUTES (type2))))
+    return 0;
   /* As some type combinations - like default calling-convention - might
      be compatible, we have to call the target hook to get the final result.  */
   return targetm.comp_type_attributes (type1, type2);
diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c
index 7b299b9ce9e..5981e2ac477 100644
--- a/gcc/c-family/c-attribs.c
+++ b/gcc/c-family/c-attribs.c
@@ -804,11 +804,8 @@ handle_cheri_capability_attribute (tree *node, tree ARG_UNUSED (name),
 {
   *no_add_attrs = true;
 
-  opt_scalar_addr_mode opt_cap_mode = targetm.capability_mode ();
-  if (opt_cap_mode.exists ())
+  if (targetm.capability_mode ().exists ())
     {
-      scalar_addr_mode cap_mode = opt_cap_mode.require();
-
       /* Scan down the tree *node and find how many
 	 POINTER_TYPE_P nodes there are in the chain.  */
       int capability_pointer_depth = 1, c = 1;
@@ -860,15 +857,16 @@ handle_cheri_capability_attribute (tree *node, tree ARG_UNUSED (name),
 	treetoedit = &TREE_TYPE (*treetoedit);
       gcc_assert (TREE_CODE (*treetoedit) == POINTER_TYPE);
 
+      tree attrs = tree_cons (get_identifier ("cheri_capability"), NULL_TREE,
+			      TYPE_ATTRIBUTES (*treetoedit));
+
       /* Call build_pointer_type_for_mode to create a Capability Pointer
       to whatever is being referenced by (*treetoedit).  Then use
       build_type_attribute_qual_variant to reapply the qualifiers and
       attributes of the original pointer type.  */
-      (*treetoedit) = build_type_attribute_qual_variant
-		      (build_pointer_type_for_mode (TREE_TYPE (*treetoedit),
-						    cap_mode, true),
-					TYPE_ATTRIBUTES (*treetoedit),
-					TYPE_QUALS (*treetoedit));
+      auto quals = TYPE_QUALS (*treetoedit);
+      (*treetoedit) = build_type_attribute_qual_variant (*treetoedit, attrs,
+							 quals);
     }
   else
     error ("__capability attribute is not supported for this architecture");


                 reply	other threads:[~2022-05-05 12:04 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220505120444.B83E1385627E@sourceware.org \
    --to=matmal01@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).