From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2049) id 3B0A33856DFA; Thu, 5 May 2022 12:08:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3B0A33856DFA 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)] Add -fgimple support for __CAP_ADDR X-Act-Checkin: gcc X-Git-Author: Richard Sandiford X-Git-Refname: refs/vendors/ARM/heads/morello X-Git-Oldrev: f2a98ec40e702c976fcd98b15a17c1e2afa6ac60 X-Git-Newrev: 221fc4613527f40b230d0776d727b864340a126f Message-Id: <20220505120843.3B0A33856DFA@sourceware.org> Date: Thu, 5 May 2022 12:08:43 +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:08:43 -0000 https://gcc.gnu.org/g:221fc4613527f40b230d0776d727b864340a126f commit 221fc4613527f40b230d0776d727b864340a126f Author: Richard Sandiford Date: Wed Apr 13 09:54:12 2022 +0100 Add -fgimple support for __CAP_ADDR Provide a way of explicitly choosing CAP_ADDR_EXPR over NONCAP_ADDR_EXPR when the latter is the default. The syntax is a bit clunky -- "&x" becomes "__CAP_ADDR x" -- but that's consistent with other unary operators like __ABS. Diff: --- gcc/c/c-typeck.c | 2 +- gcc/c/gimple-parser.c | 7 +++++++ gcc/testsuite/gcc.target/aarch64/morello/cap-addr-expr-1.c | 12 ++++++++++++ gcc/tree.c | 13 +++++++++++++ gcc/tree.h | 1 + 5 files changed, 34 insertions(+), 1 deletion(-) diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index d8e5e07923b..3cd39f6cf04 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -4899,7 +4899,7 @@ build_unary_op (location_t location, enum tree_code code, tree xarg, gcc_assert (TREE_CODE (arg) != COMPONENT_REF || !DECL_C_BIT_FIELD (TREE_OPERAND (arg, 1))); - argtype = build_pointer_type (argtype); + argtype = addr_expr_type (code, argtype); /* ??? Cope with user tricks that amount to offsetof. Delete this when we have proper support for integer constant expressions. */ diff --git a/gcc/c/gimple-parser.c b/gcc/c/gimple-parser.c index 5ab987772b9..754d60b742f 100644 --- a/gcc/c/gimple-parser.c +++ b/gcc/c/gimple-parser.c @@ -762,6 +762,7 @@ c_parser_gimple_statement (gimple_parser &parser, gimple_seq *seq) tree id = c_parser_peek_token (parser)->value; if (strcmp (IDENTIFIER_POINTER (id), "__ABS") == 0 || strcmp (IDENTIFIER_POINTER (id), "__ABSU") == 0 + || strcmp (IDENTIFIER_POINTER (id), "__CAP_ADDR") == 0 || strcmp (IDENTIFIER_POINTER (id), "__MIN") == 0 || strcmp (IDENTIFIER_POINTER (id), "__MAX") == 0 || strcmp (IDENTIFIER_POINTER (id), "__BIT_INSERT") == 0 @@ -1151,6 +1152,12 @@ c_parser_gimple_unary_expression (gimple_parser &parser) op = c_parser_gimple_postfix_expression (parser); return parser_build_unary_op (op_loc, ABSU_EXPR, op); } + else if (strcmp (IDENTIFIER_POINTER (id), "__CAP_ADDR") == 0) + { + c_parser_consume_token (parser); + op = c_parser_gimple_postfix_expression (parser); + return parser_build_unary_op (op_loc, CAP_ADDR_EXPR, op); + } else if (strcmp (IDENTIFIER_POINTER (id), "__MIN") == 0) return c_parser_gimple_parentized_binary_expression (parser, op_loc, diff --git a/gcc/testsuite/gcc.target/aarch64/morello/cap-addr-expr-1.c b/gcc/testsuite/gcc.target/aarch64/morello/cap-addr-expr-1.c new file mode 100644 index 00000000000..8896adea723 --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/morello/cap-addr-expr-1.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-additional-options "-fgimple" } */ + +#ifdef __ARM_CAP_PERMISSION_EXECUTIVE__ +int x; +__GIMPLE int *__capability foo() { + int *__capability res; + + res = __CAP_ADDR x; + return res; +} +#endif diff --git a/gcc/tree.c b/gcc/tree.c index e0d3bbeb7c8..c7291a67aac 100644 --- a/gcc/tree.c +++ b/gcc/tree.c @@ -8079,6 +8079,19 @@ build_pointer_type (tree to_type) return build_pointer_type_for_mode (to_type, pointer_mode, false); } +/* Return the pointer type produced by using *ADDR_EXPR code CODE + to take the address of an object of type OP_TYPE. */ + +tree +addr_expr_type (tree_code code, tree op_type) +{ + gcc_assert (ADDR_EXPR_CODE_P (code) && TYPE_P (op_type)); + auto as = TYPE_ADDR_SPACE (op_type); + bool is_capability = (code == CAP_ADDR_EXPR); + auto ptr_mode = targetm.addr_space.pointer_mode (as, is_capability); + return build_pointer_type_for_mode (op_type, ptr_mode, false); +} + /* Build REPLACE_ADDRESS_VALUE internal function. This represents replacing the value of a pointer with something else. It is different to a simple assignment since it works with pointers represented by capabilities and not diff --git a/gcc/tree.h b/gcc/tree.h index aebea940439..7c99f4f6e96 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -4578,6 +4578,7 @@ extern tree unsigned_type_for (tree); extern tree truth_type_for (tree); extern tree build_pointer_type_for_mode (tree, machine_mode, bool); extern tree build_pointer_type (tree); +extern tree addr_expr_type (tree_code, tree); extern tree build_intcap_type_for_mode (machine_mode, int); extern tree build_reference_type_for_mode (tree, machine_mode, bool); extern tree build_reference_type (tree);