From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id AE3613858C83 for ; Fri, 1 Apr 2022 19:07:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org AE3613858C83 Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-553-5KebApH-OxibY9dQaAFkaw-1; Fri, 01 Apr 2022 15:07:45 -0400 X-MC-Unique: 5KebApH-OxibY9dQaAFkaw-1 Received: by mail-qv1-f69.google.com with SMTP id w10-20020a05621412ea00b00440d10d2799so2712929qvv.9 for ; Fri, 01 Apr 2022 12:07:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:references:from:in-reply-to :content-transfer-encoding; bh=09AM7M9Syq7CWQpm+hiVvuBCmESlzgaEAAGQaQgHkXE=; b=LDQ4ryqTrHH5kL8980mnhO9oW8WXHQ8THyfGSAdGs5bYNKXt/l2pv59LMrk1KD9EpQ SqFe9aYDhEgblcXfeP5Mc7VRn3aHUNBUZ6X4V7IgVnVwZu+3MhsR8CC9L0wUFZmmbTlq CsKA6/N60y5+mxtM2DM4Q1jDjkWUY1nta7wH1rur4xyq2KuS5lQtWWtp7Co/y591GMf8 4ZupOMlIKltlMZkOQoRPHREecYCVByoO0EQLbeLzvS8sY9avftja3wZFP5gUdPIJ9hie Iud/q0yuMIHHvts8KgIfui1erUDXrX2tgfyBsNzmLB2czLBwlnqbBQhE34ZLDAtVBhWO KYqA== X-Gm-Message-State: AOAM53064/h8tzyRrjCxPCmMjnanmgYTPhBwC/+p1d9raBsIh+CLHMkz uJHSRosyPTwJzdUEOGkmOZePeIFl8V0uKfvZPavF596CtavXxNFN8ASR+3xsZrJskqlfHzjf8Mk nGos4TwzXa7IZXDRKtQ== X-Received: by 2002:a05:620a:2448:b0:67e:cbef:8961 with SMTP id h8-20020a05620a244800b0067ecbef8961mr7417661qkn.392.1648840064471; Fri, 01 Apr 2022 12:07:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyXVvZzyMBNYRArwLdhqPUJoRauMoq8ezlxHJVzRwN4BCpKesvOxTz9ElwARHMgCTNi1u+UJA== X-Received: by 2002:a05:620a:2448:b0:67e:cbef:8961 with SMTP id h8-20020a05620a244800b0067ecbef8961mr7417645qkn.392.1648840064063; Fri, 01 Apr 2022 12:07:44 -0700 (PDT) Received: from [192.168.1.149] (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id 22-20020ac85756000000b002e1cabad999sm2403598qtx.89.2022.04.01.12.07.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 01 Apr 2022 12:07:43 -0700 (PDT) Message-ID: Date: Fri, 1 Apr 2022 15:07:42 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: [PATCH] c++: Fix ICE due to shared BLOCK node in coroutine generation [PR103328] To: Benno Evers , gcc-patches@gcc.gnu.org References: From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Fri, 01 Apr 2022 19:07:48 -0000 On 3/30/22 09:06, Benno Evers via Gcc-patches wrote: > From: Benno Evers > > When finishing a function that is a coroutine, the function is > transformed into a "ramp" function, and the original user-provided > function body gets moved into a newly created "actor" function. > > In this case `current_function_decl` points to the ramp function, > but `current_binding_level->blocks` would still point to the > scope block of the user-provided function body in the actor function, > so when the ramp function was finished during `poplevel()` in decl.cc, > we could end up with that block being reused as the `DECL_INITIAL()` of > the ramp function: > > subblocks = functionbody >= 0 ? current_binding_level->blocks : 0; > // [...] > DECL_INITIAL (current_function_decl) = block ? block : subblocks; > > This block would then be independently modified by subsequent passes > touching either the ramp or the actor function, potentially causing > an ICE depending on the order and function of these passes. > > gcc/cp/ChangeLog: > > PR c++/103328 > * coroutines.cc (morph_fn_to_coro): Reset > current_binding_level->blocks. > > gcc/testsuite/ChangeLog: > > PR c++/103328 > * g++.dg/coroutines/pr103328.C: New test. > > Co-Authored-By: Iain Sandoe Looks like you also need a DCO sign-off; see https://gcc.gnu.org/contribute.html#legal for more information. > --- > gcc/cp/coroutines.cc | 3 ++ > gcc/testsuite/g++.dg/coroutines/pr103328.C | 32 ++++++++++++++++++++++ > 2 files changed, 35 insertions(+) > create mode 100644 gcc/testsuite/g++.dg/coroutines/pr103328.C > > diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc > index 23dc28271a4..ece30c905e8 100644 > --- a/gcc/cp/coroutines.cc > +++ b/gcc/cp/coroutines.cc > @@ -4541,6 +4541,9 @@ morph_fn_to_coro (tree orig, tree *resumer, tree > *destroyer) gmail is breaking your patch with word wrap; see https://www.kernel.org/doc/html/v4.17/process/email-clients.html for information about ways to work around this, or just use an attachment. > BLOCK_VARS (top_block) = BIND_EXPR_VARS (ramp_bind); > BLOCK_SUBBLOCKS (top_block) = NULL_TREE; > > + /* Reset the current binding level to the ramp function */ > + current_binding_level->blocks = top_block; > + > /* The decl_expr for the coro frame pointer, initialize to zero so that we > can pass it to the IFN_CO_FRAME (since there's no way to pass a type, > directly apparently). This avoids a "used uninitialized" warning. */ > diff --git a/gcc/testsuite/g++.dg/coroutines/pr103328.C > b/gcc/testsuite/g++.dg/coroutines/pr103328.C > new file mode 100644 > index 00000000000..56fb54ab316 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/coroutines/pr103328.C > @@ -0,0 +1,32 @@ > +// { dg-additional-options "-g" } > + > +#include > + > +struct task { > + struct promise_type { > + task get_return_object() { return {}; } > + std::suspend_never initial_suspend() { return {}; } > + std::suspend_never final_suspend() noexcept { return {}; } > + void unhandled_exception() {} > + }; > + bool await_ready() { return false; } > + void await_suspend(std::coroutine_handle<> h) {} > + void await_resume() {} > +}; > + > +template > +void call(Func func) { func(); } > + > +class foo { > + void f(); > + task g(); > +}; > + > +void foo::f() { > + auto lambda = [this]() noexcept -> task { > + co_await g(); > + }; > + (void)call; > +} > + > +int main() {}