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 840823858C5E for ; Mon, 13 Mar 2023 15:16:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 840823858C5E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1678720594; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8WYUoBCVdiG1GUz6/xkZtQQaNVOIafV6J1eun029Kk8=; b=Bxf9eTsZq6mQuGGAE7XJo+jfu5RbwtbgvkNlE0toiZcvCmDv2xCon/fOOUDwFEBZPyg34O 8/uSeKK3wRXFUoQJ5PyTpk8xxqx0Z9+GFYgA4aQN9Uh6UTG50ovYfJFSdzikMs7qwIKstI FZcQ5Ot1hKLbMJ5N2nK8aCP0Mj/CPOY= Received: from mail-oo1-f72.google.com (mail-oo1-f72.google.com [209.85.161.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-99-_Uewtw0FO7Ss60oL-sbrow-1; Mon, 13 Mar 2023 11:16:32 -0400 X-MC-Unique: _Uewtw0FO7Ss60oL-sbrow-1 Received: by mail-oo1-f72.google.com with SMTP id l6-20020a4ad9c6000000b005254392994fso3410597oou.19 for ; Mon, 13 Mar 2023 08:16:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678720592; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=8WYUoBCVdiG1GUz6/xkZtQQaNVOIafV6J1eun029Kk8=; b=bztSUvkmCrWs4D4WIz0G+fiUwM4fS2KzBTiuvWXJLnt7bli/L0qZe9fKtsQZEoyogG 9GqhAkLUNVjuacz9uOUFQ7vHxONeVZI5z9wthY2jfa/Uq4LLPIa1Jo7GnXCYkePBx5JX QlXXGBPHXzqejrnVyA4nSUipfpZCfPAwiMqdhsaXiiVVXc9CErGOnjPUB+I4N47W133L WgfjtQJhofThy1vgTQqDgVXA8V3xwLYSFiZMbP05/BMcwepOQ/Ju8GTnekrnWOaab3Z9 rI4fWwSpiL7cfctofBb0mbcVE63AC+lVvmxMNU7zxbNEMclmcBiF2yCpsuFCJMgmG4hS R4Lg== X-Gm-Message-State: AO0yUKXdVjIr+82nMttP39ubSiT10Dx2CreDCd2wToqpkzy5l/LFEARS oCu2CbZhnjb9fU5D3KcEuwIE/+fYvpp6kE1pXUwJJbSDDr3kmCepiOnTddL69C27snYmaaFQcuR D3PHtkc8HQTuKw1lw/Q== X-Received: by 2002:a05:6808:54:b0:384:374c:43c7 with SMTP id v20-20020a056808005400b00384374c43c7mr15350690oic.25.1678720591856; Mon, 13 Mar 2023 08:16:31 -0700 (PDT) X-Google-Smtp-Source: AK7set/X9mxYwmV2yIjYvQdzopUZHXRW9ApyyquLgRrDOL6OqIgkH1u/jJL+mkqVqx7Mxi1yPTVaSQ== X-Received: by 2002:a05:6808:54:b0:384:374c:43c7 with SMTP id v20-20020a056808005400b00384374c43c7mr15350670oic.25.1678720591455; Mon, 13 Mar 2023 08:16:31 -0700 (PDT) Received: from [192.168.1.108] (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 u19-20020a05620a121300b0073b8459d221sm5458746qkj.31.2023.03.13.08.16.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 13 Mar 2023 08:16:30 -0700 (PDT) Message-ID: <7b69ca5b-c35e-716e-e259-2499172bf64c@redhat.com> Date: Mon, 13 Mar 2023 11:16:29 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.8.0 Subject: Re: [PATCH gcc-{11,12}] c++: top level bind when rewriting coroutines [PR106188] To: =?UTF-8?Q?Arsen_Arsenovi=c4=87?= , gcc-patches@gcc.gnu.org References: <20230313065742.1335925-1-arsen@aarsen.me> From: Jason Merrill In-Reply-To: <20230313065742.1335925-1-arsen@aarsen.me> 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: 8bit X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,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 List-Id: On 3/13/23 02:57, Arsen Arsenović wrote: > In the edge case of a coroutine not containing any locals, the ifcd/switch > temporaries would get added to the coroutine frame, corrupting its > layout. To prevent this, we can make sure there is always a BIND_EXPR at > the top of the function body, and thus, always a place for our new > temporaries to go without interfering with the coroutine frame. > > PR c++/106188 - Incorrect frame layout after transforming conditional statement without top-level bind expression > PR c++/106713 - if (co_await ...) crashes with a jump to ud2 > > PR c++/106188 > PR c++/106713 > > gcc/cp/ChangeLog: > > * coroutines.cc (coro_rewrite_function_body): Ensure we have a > BIND_EXPR wrapping the function body. > > gcc/testsuite/ChangeLog: > > * g++.dg/coroutines/pr106188.C: New test. > --- > Morning, > > A while back, we merged this patch into GCC 13 to fix PR106188, but > never backported it into GCC 11 and 12, which both still suffer from > this bug. > > I've tested the same patch against releases/gcc-{11,12} and they apply > and fix the testcase (and the testcase fails without them, as expected) > on x86_64-pc-linux-gnu. > > OK for backporting? OK. > Thanks in advance. > > gcc/cp/coroutines.cc | 9 ++++++ > gcc/testsuite/g++.dg/coroutines/pr106188.C | 34 ++++++++++++++++++++++ > 2 files changed, 43 insertions(+) > create mode 100644 gcc/testsuite/g++.dg/coroutines/pr106188.C > > diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc > index e982cdb89a7..ea3850082cf 100644 > --- a/gcc/cp/coroutines.cc > +++ b/gcc/cp/coroutines.cc > @@ -4067,6 +4067,15 @@ coro_rewrite_function_body (location_t fn_start, tree fnbody, tree orig, > BLOCK_SUPERCONTEXT (replace_blk) = top_block; > BLOCK_SUBBLOCKS (top_block) = replace_blk; > } > + else > + { > + /* We are missing a top level BIND_EXPR. We need one to ensure that we > + don't shuffle around the coroutine frame and corrupt it. */ > + tree bind_wrap = build3_loc (fn_start, BIND_EXPR, void_type_node, > + NULL, NULL, NULL); > + BIND_EXPR_BODY (bind_wrap) = fnbody; > + fnbody = bind_wrap; > + } > > /* Wrap the function body in a try {} catch (...) {} block, if exceptions > are enabled. */ > diff --git a/gcc/testsuite/g++.dg/coroutines/pr106188.C b/gcc/testsuite/g++.dg/coroutines/pr106188.C > new file mode 100644 > index 00000000000..9db3778d079 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/coroutines/pr106188.C > @@ -0,0 +1,34 @@ > +// { dg-do run { target c++20 } } > +// test case from pr106188, w/o workaround > +#include > + > +struct task { > + struct promise_type { > + task get_return_object() { return task{}; } > + void return_void() {} > + void unhandled_exception() {} > + auto initial_suspend() noexcept { return std::suspend_never{}; } > + auto final_suspend() noexcept { return std::suspend_never{}; } > + }; > +}; > + > +struct suspend_and_resume { > + bool await_ready() const { return false; } > + void await_suspend(std::coroutine_handle<> h) { h.resume(); } > + void await_resume() {} > +}; > + > +task f() { > + if (co_await suspend_and_resume{}, false) {} > +} > + > +task g() { > + switch (co_await suspend_and_resume{}, 0) { > + default: break; > + } > +} > + > +int main() { > + f(); > + g(); > +}