From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by sourceware.org (Postfix) with ESMTPS id 9B85A3857C4A for ; Thu, 17 Mar 2022 11:37:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9B85A3857C4A Received: by mail-pj1-x102c.google.com with SMTP id mp6-20020a17090b190600b001c6841b8a52so1337115pjb.5 for ; Thu, 17 Mar 2022 04:37:33 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=9LwSc836F877oDQoaAWuXLeReh4monWiWTSwbyMUVj0=; b=EJ/LP8U5NTx8AXzvJVwr1tLb7xFWJPYYLg/beCIq911V6ElFiyebmmyUNK044KxXbj QOY8m+ws1mgcq7zUnz/cbqNFt9OFbdsBKTAIq2+8rY1RmHglqHyxKghB1PwK5oHWj+ev Sos1FtHAwO+DRpMshMjzvCKKFKsh1ioiqIH7XSfK7ZiBBPktFzE/rantN1wXR4qEOhjK 32gZG9fl/+4SN1GbCsb6aqOKguT/fqO066mXns9267voPP9hlklSkcw4l7Edeip0sORU w3bJ5zIyzVXpXxezBBX3ByUZ/AE93IvOy0ZH0VYULd8UaVjpl5Qt/HA0pv+9qRzVcN6j O9Qg== X-Gm-Message-State: AOAM5307Uk1sw7MIQAKRwMY1ORZZIqTA/cyDsAegfxfztrhxF4Dvq7kb ef4jFHWZ6HK16zlYN1zBjL5O2eLG8xtKN2GlYYg8pwMFidM= X-Google-Smtp-Source: ABdhPJwt711iPxrBfx4fFEa45m93UYax7DCSQxb6pga474HUSfOumZGqqCrIXvKkDu/BT5A6bC5V/PvFJGwCrdziArg= X-Received: by 2002:a17:90b:1e4b:b0:1bf:8dbc:581b with SMTP id pi11-20020a17090b1e4b00b001bf8dbc581bmr15222012pjb.41.1647517052519; Thu, 17 Mar 2022 04:37:32 -0700 (PDT) MIME-Version: 1.0 From: Benno Evers Date: Thu, 17 Mar 2022 12:37:20 +0100 Message-ID: Subject: [PATCH RFC] Fix ICE due to shared BLOCK node in coroutine generation [PR103328] To: gcc-patches@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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: Thu, 17 Mar 2022 11:37:35 -0000 The coroutine transformation moves the original function body into a newly created actor function, but the block of the `current_binding_level` still points into the original function, causing the block to be shared between the two functions if it is subsequently used. This may cause havoc later on, as subsequent compiler passes for one function will also implicitly modify the other. See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103328#c19 for a more detailed writeup. This patch fixes the issue locally, but I'm not familiar with the GCC code base so I'm not sure if this is the right way to go about it or if there's a cleaner way to reset the current binding level. If this is the way to go I'm happy to extend the patch with a testcase and changelog entry. --- gcc/cp/coroutines.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc index b1bfdc767a4..eb5f80f499b 100644 --- a/gcc/cp/coroutines.cc +++ b/gcc/cp/coroutines.cc @@ -4541,6 +4541,8 @@ morph_fn_to_coro (tree orig, tree *resumer, tree *destroyer) BLOCK_VARS (top_block) = BIND_EXPR_VARS (ramp_bind); BLOCK_SUBBLOCKS (top_block) = NULL_TREE; + 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. */ -- 2.32.0