public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Go patch committed: Handle f().x if f returns a zero-sized type
@ 2022-07-16 23:30 Ian Lance Taylor
  0 siblings, 0 replies; only message in thread
From: Ian Lance Taylor @ 2022-07-16 23:30 UTC (permalink / raw)
  To: gcc-patches, gofrontend-dev

[-- Attachment #1: Type: text/plain, Size: 626 bytes --]

This patch to the Go frontend handles the case of f().x when the
function f returns a zero-sized type.  In that case the GCC interface
will have changed f to return void, as the GCC middle-end does not
have complete support for zero-sized types.  This patch handles the
case of void when in a struct field expression.  The test case for
this is https://go.dev/cl/417874.  This fixes
https://go.dev/issue/23870.  Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu.  Committed to mainline.

Ian

* go-gcc.cc (Gcc_backend::struct_field_expression): Handle a void
expression, as for f().x where f returns a zero-sized type.

[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 798 bytes --]

2b7b330427a60c8a5ef00d940adde0160ce04f27
diff --git a/gcc/go/go-gcc.cc b/gcc/go/go-gcc.cc
index 7b4b2adb058..1ba7206caeb 100644
--- a/gcc/go/go-gcc.cc
+++ b/gcc/go/go-gcc.cc
@@ -1707,6 +1707,13 @@ Gcc_backend::struct_field_expression(Bexpression* bstruct, size_t index,
   if (struct_tree == error_mark_node
       || TREE_TYPE(struct_tree) == error_mark_node)
     return this->error_expression();
+
+  // A function call that returns a zero-sized object will have been
+  // changed to return void.  A zero-sized object can have a
+  // (zero-sized) field, so support that case.
+  if (TREE_TYPE(struct_tree) == void_type_node)
+    return bstruct;
+
   gcc_assert(TREE_CODE(TREE_TYPE(struct_tree)) == RECORD_TYPE);
   tree field = TYPE_FIELDS(TREE_TYPE(struct_tree));
   if (field == NULL_TREE)

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

only message in thread, other threads:[~2022-07-16 23:31 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-16 23:30 Go patch committed: Handle f().x if f returns a zero-sized type Ian Lance Taylor

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