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: 75134 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1034885vqo; Sun, 26 Mar 2023 09:56:05 -0700 (PDT) X-Google-Smtp-Source: AKy350bKZfNvNyh6tBkWBeU+XfXg7UW5eZN6/tqZB7gU/hX6eC6bHYm1TJs52Iq3EwNwr6Mvur9u X-Received: by 2002:aa7:d14e:0:b0:500:58cb:3b05 with SMTP id r14-20020aa7d14e000000b0050058cb3b05mr9076984edo.27.1679849765425; Sun, 26 Mar 2023 09:56:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679849765; cv=none; d=google.com; s=arc-20160816; b=TWLbzlzf4pLRdFCwi8+XMs3wG8WQxbpmvljN7gGv4YdyCLNb3UKMtqgTw94SmFXR3N cjBezsC/sza7LloRnwtQCW41RC7RDW9QfVfu3R/+6jTqikI0FNQOyZqXQj0/VnS6VSUI ybfdDqINAvfQCK/vPKUhx+u8xIDHBPjX5QsvxUVrZzg7vwjhJEEVx65zWB4mFE8ItUMV 99h/Rf5AbD5z2GUeC8bUxg51jEtASJy3bieXnjryTi2PtGxmvtYOEaM7J/SDAXkzSo5j /h3Uy7GKdwewjGadAcWJQ1+hsv51Ql77BF+2Ur4mc+P8lgXBCjadTXa92cGTCOjHF3H3 3bNQ== 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=w+cp6gBRtHQliSMxTc5b+2ClTzHXTTNoDsUaFmeCIRs=; b=MQ5BTbSxySK//9Lnf6ZM0KiMOEDPLCnHWvN9uTqy8DI4MBQ4lncY1K+AHPPgyb64mX GXL8ULDNsX5x/qt+ae2InNMJagldObbGcL/D3StseUwfYnnW4NKzC50DLvnNDy1i2tqi HbqwnfV4Up0a1uq5Sp/CYHtp239sQH8fwB3+2QFLEs/irh6eG4+61LXMYSKJie6UKN3f kO7n8kQvQoHMf5ldjXIGPNFh0dVB7S+lTLow4aGuYrBGDxbBKMzQC0B8tFUrEYGmmQXo Bon5n8gOYXkuew+++L5UXrMePHBcioZzO9126uUgv4OxDsH86QqK1fGLRjIQYSKYyOM0 +Rjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=iTg7MyMV; 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 c14-20020aa7c74e000000b004fcf925a8acsi7966699eds.251.2023.03.26.09.56.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Mar 2023 09:56:05 -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=iTg7MyMV; 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 170603858407 for ; Sun, 26 Mar 2023 16:56:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 170603858407 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679849764; 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=iTg7MyMVeLeDElOOyKwQHzXS2eBm+mIUyG4UpGEbF+OvUUlxKyAkdT97mA+Sp1ZBr 8J69eJ5YoGhPQGbLyVtEZ89/fYPSJpkS50v4VdvmmvPMb95sibrNjJg7K1uPqeNf6O EmZdg4Zf3h0ihMwDw2Bh//rifED2mqB2cG6x1g/k= 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-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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1761450147737026178?= X-GMAIL-MSGID: =?utf-8?q?1761450147737026178?= 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))