From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2116) id 5892A3858D37; Mon, 10 Oct 2022 21:27:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5892A3858D37 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665437247; bh=B4U5m93d4hMRJihfGQXyC9PVmIKM1tw0NI7Zxn5wES0=; h=From:To:Subject:Date:From; b=MIT5/APVzMZXN+jL5rLjFKpHgmqM8frtwG4+IxogeDZThi3R5UyJdLYcrYncDYsv5 B0BBFrZLa2QIpU4bMWn/wolop+aVX4FdHss/Xjn4SsKGWvNnZzio390XLBsRCPspzx xPNe9xr4mJbWGjDaoN4SQd0nJUzzahHsSWDULiuY= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Ian Lance Taylor To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-3204] compiler: only build thunk struct type when it is needed X-Act-Checkin: gcc X-Git-Author: Ian Lance Taylor X-Git-Refname: refs/heads/master X-Git-Oldrev: 1d2f07ed4ce028a7c1f9b18f5d959f30213545ca X-Git-Newrev: 0f6efd34c21ab6452aa846fd7e59acbccf15fbef Message-Id: <20221010212727.5892A3858D37@sourceware.org> Date: Mon, 10 Oct 2022 21:27:27 +0000 (GMT) List-Id: https://gcc.gnu.org/g:0f6efd34c21ab6452aa846fd7e59acbccf15fbef commit r13-3204-g0f6efd34c21ab6452aa846fd7e59acbccf15fbef Author: Ian Lance Taylor Date: Sat Oct 8 11:47:56 2022 -0700 compiler: only build thunk struct type when it is needed Instead of building the thunk struct type in the determine_types pass, build it when we need it. That ensures that we are consistent in determining whether an argument is constant. We no longer need to add a field for a call to recover, as the simplify_thunk_statements pass runs after the build_recover_thunks pass, so the additional argument will already have been added to the call. The test case is https://go.dev/cl/440297. Fixes golang/go#56109 Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/440298 Diff: --- gcc/go/gofrontend/MERGE | 2 +- gcc/go/gofrontend/statements.cc | 34 +++++++++------------------------- gcc/go/gofrontend/statements.h | 5 +---- 3 files changed, 11 insertions(+), 30 deletions(-) diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE index 10ed3fee67c..1c2466090f1 100644 --- a/gcc/go/gofrontend/MERGE +++ b/gcc/go/gofrontend/MERGE @@ -1,4 +1,4 @@ -50707b4b51266166ce9bcf9de187e35760ec50f9 +164f2aeb1deec4c11e55b8bfb152ff7ff4c1dd4c The first line of this file holds the git revision number of the last merge done from the gofrontend repository. diff --git a/gcc/go/gofrontend/statements.cc b/gcc/go/gofrontend/statements.cc index b442830b0b7..af8c7d15998 100644 --- a/gcc/go/gofrontend/statements.cc +++ b/gcc/go/gofrontend/statements.cc @@ -2349,7 +2349,7 @@ Thunk_statement::Thunk_statement(Statement_classification classification, Call_expression* call, Location location) : Statement(classification, location), - call_(call), struct_type_(NULL) + call_(call) { } @@ -2430,15 +2430,6 @@ void Thunk_statement::do_determine_types() { this->call_->determine_type_no_context(); - - // Now that we know the types of the call, build the struct used to - // pass parameters. - Call_expression* ce = this->call_->call_expression(); - if (ce == NULL) - return; - Function_type* fntype = ce->get_function_type(); - if (fntype != NULL && !this->is_simple(fntype)) - this->struct_type_ = this->build_struct(fntype); } // Check types in a thunk statement. @@ -2581,6 +2572,8 @@ Thunk_statement::simplify_statement(Gogo* gogo, Named_object* function, if (this->is_simple(fntype)) return false; + Struct_type* struct_type = this->build_struct(fntype); + Expression* fn = ce->fn(); Interface_field_reference_expression* interface_method = fn->interface_field_reference_expression(); @@ -2600,7 +2593,7 @@ Thunk_statement::simplify_statement(Gogo* gogo, Named_object* function, std::string thunk_name = gogo->thunk_name(); // Build the thunk. - this->build_thunk(gogo, thunk_name); + this->build_thunk(gogo, thunk_name, struct_type); // Generate code to call the thunk. @@ -2630,8 +2623,7 @@ Thunk_statement::simplify_statement(Gogo* gogo, Named_object* function, // Build the struct. Expression* constructor = - Expression::make_struct_composite_literal(this->struct_type_, vals, - location); + Expression::make_struct_composite_literal(struct_type, vals, location); // Allocate the initialized struct on the heap. constructor = Expression::make_heap_expression(constructor, location); @@ -2745,15 +2737,6 @@ Thunk_statement::build_struct(Function_type* fntype) fields->push_back(Struct_field(tid)); } - // The predeclared recover function has no argument. However, we - // add an argument when building recover thunks. Handle that here. - if (ce->is_recover_call()) - { - fields->push_back(Struct_field(Typed_identifier("can_recover", - Type::lookup_bool_type(), - location))); - } - const Expression_list* args = ce->args(); if (args != NULL) { @@ -2781,7 +2764,8 @@ Thunk_statement::build_struct(Function_type* fntype) // artificial, function. void -Thunk_statement::build_thunk(Gogo* gogo, const std::string& thunk_name) +Thunk_statement::build_thunk(Gogo* gogo, const std::string& thunk_name, + Struct_type* struct_type) { Location location = this->location(); @@ -2807,7 +2791,7 @@ Thunk_statement::build_thunk(Gogo* gogo, const std::string& thunk_name) // which is a pointer to the special structure we build. const char* const parameter_name = "__go_thunk_parameter"; Typed_identifier_list* thunk_parameters = new Typed_identifier_list(); - Type* pointer_to_struct_type = Type::make_pointer_type(this->struct_type_); + Type* pointer_to_struct_type = Type::make_pointer_type(struct_type); thunk_parameters->push_back(Typed_identifier(parameter_name, pointer_to_struct_type, location)); @@ -2914,7 +2898,7 @@ Thunk_statement::build_thunk(Gogo* gogo, const std::string& thunk_name) } Expression_list* call_params = new Expression_list(); - const Struct_field_list* fields = this->struct_type_->fields(); + const Struct_field_list* fields = struct_type->fields(); Struct_field_list::const_iterator p = fields->begin(); for (unsigned int i = 0; i < next_index; ++i) ++p; diff --git a/gcc/go/gofrontend/statements.h b/gcc/go/gofrontend/statements.h index c08b493e6c9..3d1ee33a3e5 100644 --- a/gcc/go/gofrontend/statements.h +++ b/gcc/go/gofrontend/statements.h @@ -1411,7 +1411,7 @@ class Thunk_statement : public Statement // Build the thunk. void - build_thunk(Gogo*, const std::string&); + build_thunk(Gogo*, const std::string&, Struct_type*); // Set the name to use for thunk field N. void @@ -1420,9 +1420,6 @@ class Thunk_statement : public Statement // The function call to be executed in a separate thread (go) or // later (defer). Expression* call_; - // The type used for a struct to pass to a thunk, if this is not a - // simple call. - Struct_type* struct_type_; }; // A go statement.