From patchwork Mon Oct 10 21:27:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 1891 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp1777280wrs; Mon, 10 Oct 2022 14:28:30 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4z0C4bjXU5B+S9yRong94t97AB32BnWs6TIYcxtaq+RR+7PMDMDb5LTBnoMuqJDHNdd9PK X-Received: by 2002:aa7:d415:0:b0:459:4c7:60ce with SMTP id z21-20020aa7d415000000b0045904c760cemr19993216edq.202.1665437309894; Mon, 10 Oct 2022 14:28:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665437309; cv=none; d=google.com; s=arc-20160816; b=SSLairhBa3lDvTcK4624pFLayVjCgL0iPoQ5zU9uKAqXFTa9ruD94mdVcoq2Hr+X/Y WX4LQVsls/l/1Es4G3R9RckpiwDsLwY+XPGexfeMwsrCV47nHrrT+u1q1lR7sw81B+jq XXqIiRYarB4orpCBG5pCJi7WrTPqEfFs91NrXpers9ECxKvrxQRSOQeJJh9pyiGZAFq4 0L7x+SNVUqi1pgcBmYmlW4kdd+RSoBDrz+Bk6oe2oTcOU+XZpqUrEScAxi2IBgIeL/ZR ltH97Qqh9VECZ6dDRjmq7NBAOxbQZ3N5J6wrDxC6cV5stFz5yQkiJ2rqbHLOs8hT9qiw WrZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:to:subject :message-id:date:mime-version:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=fPeXUV4YDByXsyAddIrmNADEPYcNDocCJgQLZy3PmlE=; b=QkKM7vaZRXa+ZnudCfBk1JJCmdxwJxcc7zpoYd+WSRLuvQM9NDeEGXrn3vSLRdXxji 0PFrG3EXTqphhtgBVDMNL8FxnMg5boZL80PTAixnEn3s59V6zqP9tt3scODPsjti4Isg PiXEENz28Po7uvctX4c+FLXfSb17kGlUrRiQbdHUpjLCB8rFi64KDypLOTYCRwN+VXtb R5aItO1EeB2V/niuylCHJEbfXtvH431znPJn8mdueSr5XZkpLsJQbN/mpfe317MqTSrU SZ2QoyEmoT5hOc3X6vJvfZSHAuIST4H8Kah4xmGIGUsMSLlDLuBlxfpXSNcm4jCYeVBx Dvyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="q6/blAwW"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id qf29-20020a1709077f1d00b007830e41ed56si10330341ejc.431.2022.10.10.14.28.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Oct 2022 14:28:29 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="q6/blAwW"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E396A3857025 for ; Mon, 10 Oct 2022 21:28:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E396A3857025 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665437308; bh=fPeXUV4YDByXsyAddIrmNADEPYcNDocCJgQLZy3PmlE=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=q6/blAwWTQ9TBiQI1eLQiHWg7fS11mlEawXJV0tJP+/AwDle3cAN+wliyYiTJMpRX YzNkslBsfpuEG8q/LMJ9xom3++Y3Oraj1DxLhspXHkREhg2L3QfR7zhsfAWy+ysPHE JDTc/0Uts/LfI/QjjJc5Ad8M58DDzQ+vI1YRQ3nE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by sourceware.org (Postfix) with ESMTPS id 17E7D3858D37 for ; Mon, 10 Oct 2022 21:27:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 17E7D3858D37 Received: by mail-pf1-x429.google.com with SMTP id d10so11804807pfh.6 for ; Mon, 10 Oct 2022 14:27:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=fPeXUV4YDByXsyAddIrmNADEPYcNDocCJgQLZy3PmlE=; b=uVbhjIx6mo3TzlxerwDrGepG3PQbkwrxWowdgvtVi2qOLTan2bbnilwkUBbyZLjiP9 V15mazn4MkMtCDQTfbMYkuOvvf2i3U0qmEAMTdKlZ658858bvVBQ32dKlhrj88N3jtFW WkJOqitM9T8BjKiji7aHF1y1G71YNGH4SSnCV/yZ2/6FxrpMRSPPRfuuEAPmAoXMDDi4 KjEx60TymdIQa0XbPnRy4X8Fh3hKt99FhAqWHJoFfjXMUTV5R0kh4whbtQqSSjHnRS15 6BGSkAk4IyqCzJjyAmZYhNY7z2QVpo1fxXqzeSV4vs2BD5Kxo0DFs3y+pgKIg17CRcMM 4ZZQ== X-Gm-Message-State: ACrzQf1MurPF773sc55PWKJLKyjLg1SwczvID+ezrR4lcqIzlqj5VmBv CbkuL3/yy4pH6iwiQ7YW/rkj3Q7BMgD2HZ5Ba0REBuy9dfpZ2Q== X-Received: by 2002:a65:6a12:0:b0:445:84f6:676a with SMTP id m18-20020a656a12000000b0044584f6676amr18040140pgu.40.1665437260700; Mon, 10 Oct 2022 14:27:40 -0700 (PDT) MIME-Version: 1.0 Date: Mon, 10 Oct 2022 14:27:29 -0700 Message-ID: Subject: Go patch committed: Only build thunk struct type when needed To: gcc-patches , gofrontend-dev X-Spam-Status: No, score=-10.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ian Lance Taylor via Gcc-patches From: Ian Lance Taylor Reply-To: Ian Lance Taylor Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746337592233370072?= X-GMAIL-MSGID: =?utf-8?q?1746337592233370072?= This patch to the Go frontend delays building the struct type for a go/defer thunk until it is needed. We were building it in the determine_types pass. Now, we delay until the simplify_thunk_statements pass. That ensures that we are consistent in determining whether an argument is constant. With this change 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 for this is https://go.dev/cl/440297. This fixes https://go.dev/issue/56109. Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu. Committed to mainline. Ian 10c26259a8ea34a63a14e85b18e6066766ad6a7a 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.