From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2049) id B83E1385627E; Thu, 5 May 2022 12:04:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B83E1385627E Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Matthew Malcomson To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/vendors/ARM/heads/morello)] Keep the cheri_capability attribute X-Act-Checkin: gcc X-Git-Author: Richard Sandiford X-Git-Refname: refs/vendors/ARM/heads/morello X-Git-Oldrev: 12cd31ada5eecb72724ad76425ced56d9aca10aa X-Git-Newrev: 2f0e6bc008a27e3222072bc791e4325b845789be Message-Id: <20220505120444.B83E1385627E@sourceware.org> Date: Thu, 5 May 2022 12:04:44 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 05 May 2022 12:04:44 -0000 https://gcc.gnu.org/g:2f0e6bc008a27e3222072bc791e4325b845789be commit 2f0e6bc008a27e3222072bc791e4325b845789be Author: Richard Sandiford 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");