From patchwork Thu Mar 17 11:37:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benno Evers X-Patchwork-Id: 1606515 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=E6TZ3VYX; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KK4rk5jRYz9s5V for ; Thu, 17 Mar 2022 22:37:57 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9527C3952000 for ; Thu, 17 Mar 2022 11:37:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9527C3952000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1647517074; bh=9LwSc836F877oDQoaAWuXLeReh4monWiWTSwbyMUVj0=; h=Date:Subject:To:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=E6TZ3VYXYLZMnIHediosF//OgMY+8SP4UYcosNRnCYwBWuKp4zMoURfCDGHZm1tMD scstlv+KZ6jCj7X+RI8cPXGFm9ZLdtYp4JDjk1Ted/xfqoSx8/8JsHu7aZlA0NpGnp acKM0yzAP9cpu+AMs1pPjwXA2AZhz9JklK3SnCwI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 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 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-Patchwork-Original-From: Benno Evers via Gcc-patches From: Benno Evers Reply-To: Benno Evers Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" 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(+) directly apparently). This avoids a "used uninitialized" warning. */ 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,