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)] Add -fgimple support for __CAP_ADDR Date: Thu, 5 May 2022 12:08:43 +0000 (GMT) [thread overview] Message-ID: <20220505120843.3B0A33856DFA@sourceware.org> (raw) https://gcc.gnu.org/g:221fc4613527f40b230d0776d727b864340a126f commit 221fc4613527f40b230d0776d727b864340a126f Author: Richard Sandiford <richard.sandiford@arm.com> 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);
reply other threads:[~2022-05-05 12:08 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=20220505120843.3B0A33856DFA@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: linkBe 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).