This patch to the Go frontend by Cherry Zhang makes non-escaping Bound_method_expression not heap allocate. It stack allocates the closure when it does not escape. Bootstrapped on x86_64-pc-linux-gnu. Committed to mainline.
Ian
Index: gcc/go/gofrontend/MERGE =================================================================== --- gcc/go/gofrontend/MERGE (revision 256406) +++ gcc/go/gofrontend/MERGE (working copy) @@ -1,4 +1,4 @@ -584fdecefce831c3471dbd4857ba0ce0be2b5212 +d5774539b17112d9ce709a1fe722daf68eb8594f The first line of this file holds the git revision number of the last merge done from the gofrontend repository. Index: gcc/go/gofrontend/expressions.cc =================================================================== --- gcc/go/gofrontend/expressions.cc (revision 256406) +++ gcc/go/gofrontend/expressions.cc (working copy) @@ -7030,7 +7030,12 @@ Bound_method_expression::do_flatten(Gogo Expression* ret = Expression::make_struct_composite_literal(st, vals, loc); if (!gogo->compiling_runtime() || gogo->package_name() != "runtime") - ret = Expression::make_heap_expression(ret, loc); + { + ret = Expression::make_heap_expression(ret, loc); + Node* n = Node::make_node(this); + if ((n->encoding() & ESCAPE_MASK) == Node::ESCAPE_NONE) + ret->heap_expression()->set_allocate_on_stack(); + } else { // When compiling the runtime, method closures do not escape.