]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
go: fix f(g()) where g returns zero-sized type
authorIan Lance Taylor <iant@golang.org>
Fri, 15 Jul 2022 15:02:13 +0000 (08:02 -0700)
committerIan Lance Taylor <iant@golang.org>
Fri, 15 Jul 2022 15:04:42 +0000 (08:04 -0700)
Test case is https://go.dev/cl/417481.

Fixes golang/go#23868

* go-gcc.cc (Gcc_backend::call_expression): Handle a void
argument, as for f(g()) where g returns a zero-sized type.

gcc/go/go-gcc.cc

index f3de7a8c183d33986d20a08759ff6d9f9b27981c..7b4b2adb0586d33d162ae95251440dd73b4c83a4 100644 (file)
@@ -2112,6 +2112,19 @@ Gcc_backend::call_expression(Bfunction*, // containing fcn for call
       args[i] = fn_args.at(i)->get_tree();
       if (args[i] == error_mark_node)
         return this->error_expression();
+      if (TREE_TYPE(args[i]) == void_type_node)
+       {
+         // This can happen for a case like f(g()) where g returns a
+         // zero-sized type, because in that case we've changed g to
+         // return void.
+         tree t = TYPE_ARG_TYPES(TREE_TYPE(TREE_TYPE(fn)));
+         for (size_t j = 0; j < i; ++j)
+           t = TREE_CHAIN(t);
+         tree arg_type = TREE_TYPE(TREE_VALUE(t));
+         args[i] = fold_build2_loc(EXPR_LOCATION(args[i]), COMPOUND_EXPR,
+                                   arg_type, args[i],
+                                   build_zero_cst(arg_type));
+       }
     }
 
   tree fndecl = fn;