From patchwork Thu Apr 6 06:27:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 80069 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp812110vqo; Wed, 5 Apr 2023 23:28:29 -0700 (PDT) X-Google-Smtp-Source: AKy350ZeRktGq7/XkfQccAfYmcUYBsKO9WJBaqDRQmq4SGYgegksVq/8+04eTugg6blQc8xJKUpG X-Received: by 2002:aa7:dc19:0:b0:4fb:c66f:71c4 with SMTP id b25-20020aa7dc19000000b004fbc66f71c4mr3736725edu.11.1680762509759; Wed, 05 Apr 2023 23:28:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680762509; cv=none; d=google.com; s=arc-20160816; b=H6vDs/zZerGH+iuxgECdpGckqEuAgMTtifeYtrLamA/p/c6miWy0RHJh6vwtuSyCVQ cHclBt7SSOXCcFgRpw06Wkv4CrL5UJ5dvNI3dU/3LoSxMS3Xrp95+C/0oiClktoovSK1 eY2GD/XSAgaQ4tVHjVjJz/DaGEkdEEGOr61pwhJRMAYxqyN2f0K78jAJtOICodKQqwf1 dW2Bosz41wXKFsHl0BNcZjr/64gojrKwlypJfHvAVBtfMV/xWpBWQ133sJy3cm2jYWGo o5SjeUKNdi37Ovje4hakZAb/onEwJiJ48fJ1JBzydc4gC3kBds9V3e7exinq9ay0R1nX 61og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=qsII0v3Hxiw0m5Whm2GNf/0UdmTduL5MSq3zh5gRrII=; b=lqMjmeGWI9DnWOvs5Oy0asfwE/GHVQ3BeqFpM+jFEGBYGij9awpOCz0JwK5GJPMD9e 3JuryI8m0OF8kmYs46bEfEeV78GCrnryvX29znDzxB0jqJN5kMdTRRqZxLy2O8jZbG9X cHCMJyYeqpm5tB8dCxwH1tB1cfNsMv6cfObVGM0PcriEW9hqvlBxHhbq9jCFz5j+lyJc lZ5OFx7tfWiuBoDn73F9FYFEW60XXOiqnoCgqpqgRtYsJ0baquFerYOHVP+xJSGpzs3T BsbXepYl01F0UyuMV/OO3JO3UkHcPgOlUaAhTwulN+jtV5nIgGDNLJ5rCxJU1Mn6tq7h 9szQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=qGMHHsTP; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id y24-20020a056402135800b004fd2a5bbdd0si491673edw.542.2023.04.05.23.28.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Apr 2023 23:28:29 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=qGMHHsTP; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 69E163858002 for ; Thu, 6 Apr 2023 06:28:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 69E163858002 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680762508; bh=qsII0v3Hxiw0m5Whm2GNf/0UdmTduL5MSq3zh5gRrII=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=qGMHHsTPkdL+2DoY2WqlPYJiimWct8I4Ouww25UNqiw0m/IH8muL/3BNT5sfPzPRQ 8vXZPOkwviOR43Q70Y8ZI6+sSw3P9d4Tztlr0/gcwZfzrjnfkvQWcrhpPGxOp8Dyyc 5XUIdhauf/IKQT8/77Xu9yz8hfgqSnUjp2ah+TH8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by sourceware.org (Postfix) with ESMTPS id 7DFC83858D32 for ; Thu, 6 Apr 2023 06:27:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7DFC83858D32 Received: by mail-pl1-x630.google.com with SMTP id f22so32525355plr.0 for ; Wed, 05 Apr 2023 23:27:44 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680762463; h=content-transfer-encoding:mime-version:reply-to:message-id:date :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=qsII0v3Hxiw0m5Whm2GNf/0UdmTduL5MSq3zh5gRrII=; b=reWp3U2T+DoRqJKhA2e2RXabS/TpNisCQlaYOA10/54NDs8ZCC+A5JHj6wkiyvv3dh 8Mad1oPRNxn7j+obVbKf7rsRTYWpNOfq/CVBD6xVxR0hEdD/Gzp1vOrEKlFA7HfRcB7a r2gQJOWEexPpF/emc/vGfkhwZdi0jpntvxoCncgPw+TvEYMuUp3rCeljLFXBJ0W5ZJyj rbTLAMaKe06vRoVCV9nAOQrajmgpV295zO9capHhb7ht/3g409/6s+RO+1PuUz28g2fW gYLQn495QGlmuOKreEFrVD2MgQFEQlURS+aood194NG0bC0iYXXYJbHDu5h/v3olQuic kbEA== X-Gm-Message-State: AAQBX9dzdXHIsXLqgWTHJ02W6quk9gzdXkHg+3/IxTvn7Xb1W5++3sGH vwfRXmpqMe6moRHnDVbWONQB9Q1cVsw= X-Received: by 2002:a05:6a20:6d15:b0:dd:2577:4018 with SMTP id fv21-20020a056a206d1500b000dd25774018mr1636973pzb.49.1680762463408; Wed, 05 Apr 2023 23:27:43 -0700 (PDT) Received: from localhost.localdomain ([103.2.133.137]) by smtp.gmail.com with ESMTPSA id w11-20020a63d74b000000b00513cc8c9597sm429542pgi.10.2023.04.05.23.27.41 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 05 Apr 2023 23:27:43 -0700 (PDT) X-Google-Original-From: Iain Sandoe To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++, coroutines: Fix block nests when the function has no top-level bind. Date: Thu, 6 Apr 2023 11:57:37 +0530 Message-Id: <20230406062737.79723-1-iain@sandoe.co.uk> X-Mailer: git-send-email 2.37.1 (Apple Git-137.1) MIME-Version: 1.0 X-Spam-Status: No, score=-7.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, 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: Iain Sandoe via Gcc-patches From: Iain Sandoe Reply-To: iain@sandoe.co.uk Cc: Iain Sandoe , jason@redhat.com, arsen@aarsen.me 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?1762407229268810756?= X-GMAIL-MSGID: =?utf-8?q?1762407229268810756?= I spotted this problem while trying to collate my WIP patches (sorry for not spotting it when the original patch was discussed). Although we do not yet have any regression filed against this (AFAIK), it's only a matter of time - so I'd suggest that we should apply to 13. Tested on x86_64-darwin21 and x86_64_linux-gnu. OK for trunk? (when?) Iain --- 8< --- When the function contains no local vars and also no nested scopes, there is no top-level bind expression. Because the rewritten coroutine body will require both local vars and contain nested scopes, we add a bind expression to such functions. When this was done the necessary scope blocks were omitted which leads to disconnected function content. Fixed by adding a new block to the added bind expression. Signed-off-by: Iain Sandoe gcc/cp/ChangeLog: * coroutines.cc (coro_rewrite_function_body): Ensure that added bind expressions have scope blocks. --- gcc/cp/coroutines.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc index b307c8ca8b6..59a240ebd40 100644 --- a/gcc/cp/coroutines.cc +++ b/gcc/cp/coroutines.cc @@ -4113,6 +4113,10 @@ coro_rewrite_function_body (location_t fn_start, tree fnbody, tree orig, tree bind_wrap = build3_loc (fn_start, BIND_EXPR, void_type_node, NULL, NULL, NULL); BIND_EXPR_BODY (bind_wrap) = fnbody; + /* Ensure we have a block to connect up the scopes. */ + tree new_blk = make_node (BLOCK); + BIND_EXPR_BLOCK (bind_wrap) = new_blk; + BLOCK_SUBBLOCKS (top_block) = new_blk; fnbody = bind_wrap; }