public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/ARM/heads/morello)] c: Use convert to handle transparent unions
@ 2022-05-06 14:44 Matthew Malcomson
  0 siblings, 0 replies; only message in thread
From: Matthew Malcomson @ 2022-05-06 14:44 UTC (permalink / raw)
  To: gcc-cvs

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); }


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-05-06 14:44 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-06 14:44 [gcc(refs/vendors/ARM/heads/morello)] c: Use convert to handle transparent unions Matthew Malcomson

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).