From patchwork Wed May 1 23:50:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 1930426 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=eE2sp7PE; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VVDND4bfyz1ydX for ; Thu, 2 May 2024 09:50:51 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9CE37384AB56 for ; Wed, 1 May 2024 23:50:49 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by sourceware.org (Postfix) with ESMTPS id 9925A3858CD1 for ; Wed, 1 May 2024 23:50:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9925A3858CD1 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 9925A3858CD1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42a ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714607432; cv=none; b=lpYRatEJgcVpZcO4Oj14PmNTEt7j3ONsRn+zox14xQfxBhf/RjTGgL+p954K85EuZPkKVfqE/Gx+BRdzAbthjor7le0oRfiLcqF6Z/aI1bXkgsWsWdsEHUA5/eUEFl0wa0Xn2Bb/Byx5Dik/2pT43PZHPEenByKMcF/GqrLnLWc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1714607432; c=relaxed/simple; bh=CzujHNByQjHhlgNZuNbSkKADCMnORAP82N/m/7Zqe+w=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=uRhbrJN77U+apKx/u1tdybE9lFI4E5cfSUTFnbZpn42hKjlo1tgIFgAaKsXiHylu76Ak50vdsoglsyAjwj6PQnsmwleg9NPxPHXVbv/QH0y6H7ACym4oCW90fLDpcHeaJb5RGqA7B82+x6Ow+kgEzFxCXs660eAfg+8CaYA9DKI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42a.google.com with SMTP id d2e1a72fcca58-6f28bb6d747so6203917b3a.3 for ; Wed, 01 May 2024 16:50:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714607429; x=1715212229; darn=gcc.gnu.org; h=content-disposition:mime-version:subject:cc:to:from:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=WAuel5hk98CGkOBqr9+U5D/KnAFCIPLYRbzmzFdNbfs=; b=eE2sp7PErECuNHuEcatvVP1pLyJFpJwn46nKeyw4rzL8ONy2auxLePRearbEyCSGQF W2KvhsFawgroLP57u11WqRgnqpyVeTwjSesrrQ4tkTGIBW5IWL7qinKzaoFMs2Bat5+u fVn52wGlAiwdyqdrAus5eHGtUyzRPGAL803LuT/ZxrRuoNykViAMTgjaZpIXZ1yRyaXd 3oJUB3xJMCsa+I4Edms1oND2o5ElDouxwQVVfW8H/8VD1XraA/Mc90GuEm6QoFgxtuyn Pm4lp9In+v2F7m+u1jLFECbXitPCXpJuaIyDzmSMRGqJDQ09dcdrT9hB3RwYxDRCX1TP M7rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714607429; x=1715212229; h=content-disposition:mime-version:subject:cc:to:from:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=WAuel5hk98CGkOBqr9+U5D/KnAFCIPLYRbzmzFdNbfs=; b=IcN1i3jOJDWVuw5ufv9ZQbhAEAj96I02cV3JZxOz0bHP9ctmhLvTFX/SVgahvpEiY0 9wIr5do8/Nm0RCj0yUp/stvDyBz+KAnDRuRCwoZZmbUaUOvAbigrksuIF1syw/Rb/QWG r60lkbyWVfOhPGzhLPPqK8GtpcNhIepKqT7N5DKL4tDIqQ/+ryV/b+rGRMPB/okWcJsx YeKc52JbgDiT4ZvfeoSemvTAZPt5s5r9VvQLzIIfmvXEGqpRSPZm0KgCEFT6rj7KwuKs 1yxQqhxAf4hwHVlyOD8TdtsHCn1PHbRl+JDDzHHHEeYOFV5vOkMGvPblfl0gKenMAI7N 85fQ== X-Gm-Message-State: AOJu0YyQrEYd7A6W/dDnobGPKzJMbNyUmCN62Ea0ti59qisfd8ICL2HN 3aAOXhoCGoMqhHhKMx0GOa7Gz575SnBvzT86NdMF0I64XgCOxFLTN0RMlA== X-Google-Smtp-Source: AGHT+IEW0phBp4nnn3NGOwhPVbi8Ls6mgA3zPd8sAw5YOWk+obQ+uJpfjPCJprfMXYV6JV1KKnYmDw== X-Received: by 2002:a05:6a20:daa7:b0:1a7:aabc:24ae with SMTP id iy39-20020a056a20daa700b001a7aabc24aemr497441pzb.18.1714607429372; Wed, 01 May 2024 16:50:29 -0700 (PDT) Received: from Thaum. (121-44-11-123.tpgi.com.au. [121.44.11.123]) by smtp.gmail.com with ESMTPSA id r12-20020aa7988c000000b006f41798fde5sm3085328pfl.214.2024.05.01.16.50.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 May 2024 16:50:28 -0700 (PDT) Message-ID: <6632d544.a70a0220.b574f.d35a@mx.google.com> X-Google-Original-Message-ID: Date: Thu, 2 May 2024 09:50:24 +1000 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill , Nathan Sidwell Subject: [PATCH] c++/modules: Stream unmergeable temporaries by value again [PR114856] MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk/14.2? Another alternative would be to stream such !DECL_NAME temporaries with a merge key of MK_unique rather than attempting to find the matching (nonexistant) field of the class context. -- >8 -- In r14-9266-g2823b4d96d9ec4 I gave all temporary vars a DECL_CONTEXT, including those at namespace or global scope, so that they could be properly merged across importers. However, not all of these temporary vars are actually supposed to be mergeable. For instance, in the attached testcase we have an unnamed temporary var used in the NSDMI of a class member, which cannot properly merged -- but it also doesn't need to be, as it'll be thrown away when the class type itself is merged anyway. This patch reverts the change made above and instead makes a weaker adjustment that only causes temporary vars with linkage have a DECL_CONTEXT to merge from. This way these unnamed, "unmergeable" temporaries are properly streamed by value again. PR c++/114856 gcc/cp/ChangeLog: * call.cc (make_temporary_var_for_ref_to_temp): Set context for temporaries with linkage. * init.cc (create_temporary_var): Revert to only set context when in a function decl. gcc/testsuite/ChangeLog: * g++.dg/modules/pr114856.h: New test. * g++.dg/modules/pr114856_a.H: New test. * g++.dg/modules/pr114856_b.C: New test. Signed-off-by: Nathaniel Shead --- gcc/cp/call.cc | 1 + gcc/cp/init.cc | 2 +- gcc/testsuite/g++.dg/modules/pr114856.h | 12 ++++++++++++ gcc/testsuite/g++.dg/modules/pr114856_a.H | 5 +++++ gcc/testsuite/g++.dg/modules/pr114856_b.C | 5 +++++ 5 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/modules/pr114856.h create mode 100644 gcc/testsuite/g++.dg/modules/pr114856_a.H create mode 100644 gcc/testsuite/g++.dg/modules/pr114856_b.C diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc index dbdd7c29fe8..3b8889ac301 100644 --- a/gcc/cp/call.cc +++ b/gcc/cp/call.cc @@ -13799,6 +13799,7 @@ make_temporary_var_for_ref_to_temp (tree decl, tree type) tree name = mangle_ref_init_variable (decl); DECL_NAME (var) = name; + DECL_CONTEXT (var) = current_scope (); SET_DECL_ASSEMBLER_NAME (var, name); } else diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc index a93ce00800c..e758a8c8568 100644 --- a/gcc/cp/init.cc +++ b/gcc/cp/init.cc @@ -4287,7 +4287,7 @@ create_temporary_var (tree type) TREE_USED (decl) = 1; DECL_ARTIFICIAL (decl) = 1; DECL_IGNORED_P (decl) = 1; - DECL_CONTEXT (decl) = current_scope (); + DECL_CONTEXT (decl) = current_function_decl; return decl; } diff --git a/gcc/testsuite/g++.dg/modules/pr114856.h b/gcc/testsuite/g++.dg/modules/pr114856.h new file mode 100644 index 00000000000..b1a3c2cd834 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr114856.h @@ -0,0 +1,12 @@ +// PR c++/114856 + +#include +struct A { + ~A(); +}; +struct V { + V(std::initializer_list); +}; +struct data { + V v{{}}; +}; diff --git a/gcc/testsuite/g++.dg/modules/pr114856_a.H b/gcc/testsuite/g++.dg/modules/pr114856_a.H new file mode 100644 index 00000000000..6195277dbde --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr114856_a.H @@ -0,0 +1,5 @@ +// PR c++/114856 +// { dg-additional-options "-fmodule-header" } +// { dg-module-cmi {} } + +#include "pr114856.h" diff --git a/gcc/testsuite/g++.dg/modules/pr114856_b.C b/gcc/testsuite/g++.dg/modules/pr114856_b.C new file mode 100644 index 00000000000..f81dc8b81d5 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/pr114856_b.C @@ -0,0 +1,5 @@ +// PR c++/114856 +// { dg-additional-options "-fmodules-ts" } + +#include "pr114856.h" +import "pr114856_a.H";