]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
go: fix f().x where f returns zero-sized type
authorIan Lance Taylor <iant@golang.org>
Sat, 16 Jul 2022 23:29:38 +0000 (16:29 -0700)
committerIan Lance Taylor <iant@golang.org>
Sat, 16 Jul 2022 23:30:34 +0000 (16:30 -0700)
Test case is https://go.dev/cl/417874.

Fixes golang/go#23870

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

gcc/go/go-gcc.cc

index 7b4b2adb0586d33d162ae95251440dd73b4c83a4..1ba7206caeba51c5ae2f499100b7f668ac4b2ed8 100644 (file)
@@ -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)