From patchwork Sun Mar 26 16:54:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iain Sandoe X-Patchwork-Id: 66911 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9C31C385840C for ; Sun, 26 Mar 2023 16:55:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9C31C385840C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679849742; bh=w+cp6gBRtHQliSMxTc5b+2ClTzHXTTNoDsUaFmeCIRs=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=fC5mZJ7bagRjboitm0Eok4Qk7sPc16mnajg7wZbaS63+DEPjVgqYX/4sled++m7VK A/UWhJDZ9W+lKqOemIsFbBoRvmb33Uk85JsWxwr6OXnZs4iBern3a8gfDmhgC5zDQl 80EpgmVt/2K7Moz2xmWu6VigqwB8riA4F8jKNE54= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by sourceware.org (Postfix) with ESMTPS id 9C00E3858D39 for ; Sun, 26 Mar 2023 16:54:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9C00E3858D39 Received: by mail-pj1-x102b.google.com with SMTP id a16so5637968pjs.4 for ; Sun, 26 Mar 2023 09:54:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679849696; 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=w+cp6gBRtHQliSMxTc5b+2ClTzHXTTNoDsUaFmeCIRs=; b=bcLhpPTX0rgNygYKG0CfLTT17P4ckaG5/z2KlyFPa/ViANp+eJIMkFX4P2T/R6DUng czpS2N3/hPUjqCXvSqmgYlAShN8ASRRwHoGZoPKzht4wUeQYzJepaRpOwssYv8J+4Kq6 IL/+BWKW/s1+uHDjIecpDERwJQufXtfSFxMvsC0LuaDJzvmkvRnprJvOKvyxjsH9ETM9 aGDdsw3Kk79VafjG1GR6NIGAxTXbfBP9b2aYQxD0pycXY045oD40n3vBet25e1fHenTJ x/4CY2S91/wOnP2b0bm7yyIXzaM2AxzwlM41/AuBxxx03PurxCgYVMx07/snQsXJ7HQU QYnw== X-Gm-Message-State: AAQBX9fksmbtselI3u/6wsO6zHMR2v7B1uJFfDNIKN6VU//W2i3CJzNU aD0/froB6tKs4Cbbnp6x3k5tIQWHNSs= X-Google-Smtp-Source: AKy350YekrjSU2TPlLz/cyeIoXtCmSVN+rR/I/GINbBaE8N3I2pxDirayCEOb5cC0U2Wbf8ZZ4Sj5Q== X-Received: by 2002:a17:90b:180e:b0:23e:f867:e0b with SMTP id lw14-20020a17090b180e00b0023ef8670e0bmr8766387pjb.49.1679849696546; Sun, 26 Mar 2023 09:54:56 -0700 (PDT) Received: from localhost.localdomain ([103.2.133.137]) by smtp.gmail.com with ESMTPSA id a12-20020a65640c000000b0050aeaf9f25csm16644626pgv.27.2023.03.26.09.54.53 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sun, 26 Mar 2023 09:54:56 -0700 (PDT) X-Google-Original-From: Iain Sandoe To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++, coroutines: Stabilize names of promoted slot vars [PR101118]. Date: Sun, 26 Mar 2023 22:24:47 +0530 Message-Id: <20230326165447.43628-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.3 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 Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Tested on x86_64-darwin21, x86-64-linux-gnu OK for trunk? Iain When we need to 'promote' a value (i.e. store it in the coroutine frame) it is given a frame entry name. This was based on the DECL_UID for slot vars. However, when LTO is used, the names from multiple TUs become visible at the same time, and the DECL_UIDs usually differ between units. This leads to a "ODR mismatch" warning for the frame type. The fix here is to use a counter instead of the DECL_UID which makes a name that is stable between TUs for each frame layout (one per coroutine func). Signed-off-by: Iain Sandoe PR c++/101118 gcc/cp/ChangeLog: * coroutines.cc: Add counter for promoted slot vars. (flatten_await_stmt): Use slot vars counter instead of DECL_UID to generate the frame entry name for promoted target expression slot variables. (morph_fn_to_coro): Reset the slot vars counter at the start of each coroutine function. Signed-off-by: Iain Sandoe --- gcc/cp/coroutines.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/gcc/cp/coroutines.cc b/gcc/cp/coroutines.cc index a2189e43db8..359a5bf46ff 100644 --- a/gcc/cp/coroutines.cc +++ b/gcc/cp/coroutines.cc @@ -2726,6 +2726,11 @@ struct var_nest_node var_nest_node *else_cl; }; +/* This is used to make a stable, but unique-per-function, sequence number for + each TARGET_EXPR slot variable that we 'promote' to a frame entry. It needs + to be stable because the frame type is visible to LTO ODR checking. */ +static unsigned tmpno = 0; + /* This is called for single statements from the co-await statement walker. It checks to see if the statement contains any initializers for awaitables and if any of these capture items by reference. */ @@ -2889,7 +2894,7 @@ flatten_await_stmt (var_nest_node *n, hash_set *promoted, tree init = t; temps_used->add (init); tree var_type = TREE_TYPE (init); - char *buf = xasprintf ("D.%d", DECL_UID (TREE_OPERAND (init, 0))); + char *buf = xasprintf ("T%03u", tmpno++); tree var = build_lang_decl (VAR_DECL, get_identifier (buf), var_type); DECL_ARTIFICIAL (var) = true; free (buf); @@ -4374,6 +4379,7 @@ morph_fn_to_coro (tree orig, tree *resumer, tree *destroyer) { gcc_checking_assert (orig && TREE_CODE (orig) == FUNCTION_DECL); + tmpno = 0; *resumer = error_mark_node; *destroyer = error_mark_node; if (!coro_function_valid_p (orig))