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)] c: Use convert to handle transparent unions Date: Fri, 6 May 2022 14:44:56 +0000 (GMT) [thread overview] Message-ID: <20220506144456.1F23738346A1@sourceware.org> (raw) https://gcc.gnu.org/g:edec423371d1b35241b51a8d340e6fc772c76315 commit edec423371d1b35241b51a8d340e6fc772c76315 Author: Richard Sandiford <richard.sandiford@arm.com> Date: Wed Apr 27 16:27:47 2022 +0100 c: Use convert to handle transparent unions Transparent unions allow things such as: typedef union U { int *__capability a; } __attribute__((transparent_union)) U; void f(U); void g(int *ptr) { f(ptr); } where ptr implicitly converts to the union. However, the handling of this case used fold_convert_loc to convert ptr to a's type, which bypassed all our usual logic for converting non-capability pointers to capability pointers. Diff: --- gcc/c/c-typeck.c | 2 +- gcc/testsuite/gcc.target/aarch64/morello/transparent-union-1.c | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c index a40d5eb21c4..b6b59687151 100644 --- a/gcc/c/c-typeck.c +++ b/gcc/c/c-typeck.c @@ -7171,7 +7171,7 @@ convert_for_assignment (location_t location, location_t expr_loc, tree type, pedwarn (location, OPT_Wpedantic, "ISO C prohibits argument conversion to union type"); - rhs = fold_convert_loc (location, TREE_TYPE (memb), rhs); + rhs = convert (TREE_TYPE (memb), rhs); return build_constructor_single (type, memb, rhs); } } diff --git a/gcc/testsuite/gcc.target/aarch64/morello/transparent-union-1.c b/gcc/testsuite/gcc.target/aarch64/morello/transparent-union-1.c new file mode 100644 index 00000000000..e96ffa7f40f --- /dev/null +++ b/gcc/testsuite/gcc.target/aarch64/morello/transparent-union-1.c @@ -0,0 +1,5 @@ +/* { dg-do compile } */ + +typedef union U { int *__capability a; } __attribute__((transparent_union)) U; +void f(U); +void g(int *ptr) { f(ptr); }
reply other threads:[~2022-05-06 14:44 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=20220506144456.1F23738346A1@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).