* Go patch committed: Don't crash on f(g()) if g returns a zero-sized value
@ 2022-07-15 15:05 Ian Lance Taylor
0 siblings, 0 replies; only message in thread
From: Ian Lance Taylor @ 2022-07-15 15:05 UTC (permalink / raw)
To: gcc-patches, gofrontend-dev
[-- Attachment #1: Type: text/plain, Size: 623 bytes --]
This patch to the GCC interface of the Go frontend fixes a crash in
f(g()) if g returns a zero-sized value. In that case the GCC
interface modifies g to return void, since GCC's middle-end does not
have solid support for zero-sized values. This patch detects the
f(g()) case and replaces the call to g() with (g(), zero). The test
case for this is https://go.dev/cl/417481. This fixes
https://go.dev/issue/23868. Bootstrapped and ran Go testsuite on
x86_64-pc-linux-gnu. Committed to mainline.
Ian
* go-gcc.cc (Gcc_backend::call_expression): Handle a void
argument, as for f(g()) where g returns a zero-sized type.
[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 919 bytes --]
1eb1495f7d0fa9b49f6f3c34bbbf4dd1e850607c
diff --git a/gcc/go/go-gcc.cc b/gcc/go/go-gcc.cc
index f3de7a8c183..7b4b2adb058 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;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-07-15 15:05 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-15 15:05 Go patch committed: Don't crash on f(g()) if g returns a zero-sized value 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).