From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-x102b.google.com with SMTP id a16so5637968pjs.4 for ; Sun, 26 Mar 2023 09:54:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679849696; h=content-transfer-encoding:mime-version:reply-to:message-id:date :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=w+cp6gBRtHQliSMxTc5b+2ClTzHXTTNoDsUaFmeCIRs=; b=SCVyLgQWg+lBxtc3np0KpH/g/oTmgTw+EX2ISWG/4h1vEmc63xpByE+Iyby58uXRR/ +j7wJBt0TXMC27qdQ0Qjhd2DSJ8GLSnRVRYwKiQJN7SWGbRzkh6ELkifLSsgDknQXUP+ d8r1ULhnRzAu5uAOC64MZ6oucDrXNtHdQbodZ+crooa0otMu3Nc85axiOzw+xbfn4oXv L1mUVJfvE5kE8mIDZAIEGZ+Eauhq1h5bmGaA/Fs1YQnLPoLOdwSJxmYn2uCkbvExzYOg tpQw4pDakhty5SWXl/SuiAn2R05MY4qCqVEUGr7diRKNCndeTRHHlerOYlF+43TlBuHc Sy4A== 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) From: Iain Sandoe X-Google-Original-From: Iain Sandoe To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com 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) Reply-To: iain@sandoe.co.uk MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 List-Id: 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. --- 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)) -- 2.37.1 (Apple Git-137.1)