diff options
author | Ian Lance Taylor <iant@golang.org> | 2022-07-15 08:02:13 -0700 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2022-07-15 08:04:42 -0700 |
commit | 5054bc001d9b66fe68d938790f08f48621c6b976 (patch) | |
tree | 736f2252353b2721e4675ba856cd73c0e0a26b13 | |
parent | 91259dd850bcbf4c0b5bdcd8304d67b883b73cc0 (diff) | |
download | gcc-5054bc001d9b66fe68d938790f08f48621c6b976.zip gcc-5054bc001d9b66fe68d938790f08f48621c6b976.tar.gz gcc-5054bc001d9b66fe68d938790f08f48621c6b976.tar.bz2 |
go: fix f(g()) where g returns zero-sized type
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.
-rw-r--r-- | gcc/go/go-gcc.cc | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/gcc/go/go-gcc.cc b/gcc/go/go-gcc.cc index f3de7a8..7b4b2ad 100644 --- a/gcc/go/go-gcc.cc +++ b/gcc/go/go-gcc.cc @@ -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; |