From patchwork Fri Sep 27 09:14:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 1990189 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=Vn1wImlW; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4XFPtP3KqRz1xst for ; Fri, 27 Sep 2024 19:14:36 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 686F33858280 for ; Fri, 27 Sep 2024 09:14:34 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by sourceware.org (Postfix) with ESMTPS id 6AB603858C60 for ; Fri, 27 Sep 2024 09:14:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6AB603858C60 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 6AB603858C60 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::102d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727428455; cv=none; b=jyptDeL//DNStini8QSwuhYnF1hV0zaqqv2+PeB12Z+xd13GYdU8dgynqIFACmJ/CbfQQZ7ch3D+kQBYOqVgQqjnH2NZbwrViDs7Bng47opoxNspUeknwrvQ+uU2AB4/X05PMCUM5hi7f1U+YdNGFAIx+2ET1Avb6JSwiluDT8E= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727428455; c=relaxed/simple; bh=wLFZqXsHsvLC1IfB+vFocGE5Ok7V/PyV4egseOqoKQg=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=II1pZ3JCImN9qOdB+DDCxZd7bm0BXqIzd3/UX/NV0ovbHlcAz70LnoLVPofcb838izJH69KFOzAbEJoEo6t90Ij/K3prTFa+XVF/De80Z5tFCQgpiVmRpCx44R44tdOKzQGYGwuBQNZdmM2bnz/JLmoOSrY+pYr6OO7z/iZB/cw= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pj1-x102d.google.com with SMTP id 98e67ed59e1d1-2e0a47fda44so272294a91.1 for ; Fri, 27 Sep 2024 02:14:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727428452; x=1728033252; 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=BQ6/r0tnTg1KybZceM7raL32gpWAYE5XgjwrjQEDW2c=; b=Vn1wImlWWHkq3g2gIvaStxlWK6BPXVWRhE3EQS/C+0jEWTwNNhDvo9DrCyyKGbyt2H zrFluaXXEvJwsiMjNZVFdTxaOvl4nERkALVF/capz2oE/dM4zf2LV45G97uwT1T3VuXR LbsWg5BuADrePtFblTjY+HwIqehSlYxOExTJAkc9bLoOSoyOOZWbKXcIkSzYEK99PUep DPym4weA79fxj+jE4CmVEBWVcTjb7pnqJKDMIMDg6wMzMYrKy2JrbIuxU3E7nYYcSS+s lUzRjNJq980HyRDLSZ/B7oQ+/fOFT7Qe3w+khEdgndc/v/kEG49KDJY5qyvTnG65WnXs qTlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727428452; x=1728033252; 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=BQ6/r0tnTg1KybZceM7raL32gpWAYE5XgjwrjQEDW2c=; b=s/ibovF1k59SYdBPqgXyzfPQCooK2rNh5lrYhK3LyuJ6Ou3XS8JW5dKOXRPaA+CHGr 0pbMbXP3GdP1ZRoPwT3UMTNcutY3ZVCzEs0OHa4FTXUXrLGrwTBGpTlhQyFxdYDXYm4n KLRVuZ1coDmUIF23PXTcEYEcoQwWOmmQOqnDuA359a4HFNypCPgGP7k7gHyH+WiOlgFb IqUNZhvNCmBi902f36Yc2zcmdqnZFmQ+HoSJXo+oy2tYfsm+3o1Bz6Hg8hlVFKF9NcA5 vm8I5COPNsDl6zHmVfnUfeHGGWLrSQqx3EA86t++wEQEJC+SyR5nGXdUvDMvPcbOACT/ a49Q== X-Gm-Message-State: AOJu0YzFHTttzJDHgXMbOaB8NCqlqTWeYqXVBjTrd24i0UnYOT47a6eg Y0IBjrphKLhKMUm/alQ5nFZOfNbk0J29eovJsr1mtgtvosTn49+gQp760A== X-Google-Smtp-Source: AGHT+IFd07zOkhJjSr3YvtStOf29CqF7Opi+XIM0daPJnTTxoy/13rmmG+iHgeNz3nF+DyTbfc8+xA== X-Received: by 2002:a17:90a:f183:b0:2da:929c:f27e with SMTP id 98e67ed59e1d1-2e0b8ec51c1mr1224096a91.6.1727428452213; Fri, 27 Sep 2024 02:14:12 -0700 (PDT) Received: from Thaum. (163-47-68-2.ipv4.originbroadband.com.au. [163.47.68.2]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e06e1704bdsm5053547a91.5.2024.09.27.02.14.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Sep 2024 02:14:11 -0700 (PDT) Message-ID: <66f67763.170a0220.8386b.3627@mx.google.com> X-Google-Original-Message-ID: Date: Fri, 27 Sep 2024 19:14:07 +1000 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill , Nathan Sidwell Subject: [PATCH] c++/modules: Propagate purview/import for templates in duplicate_decls [PR116803] MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, 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? -- >8 -- We need to ensure that for a declaration in the module purview, that the resulting declaration has PURVIEW_P set and IMPORT_P cleared so that we understand it might be something requiring exporting. This is normally handled for a declaration by set_instantiating_module, but when this declaration is a redeclaration duplicate_decls needs to propagate this to olddecl. This patch only changes the logic for template declarations, because in the non-template case the whole contents of olddecl's DECL_LANG_SPECIFIC is replaced with newdecl's (which includes these flags), so there's nothing to do. PR c++/116803 gcc/cp/ChangeLog: * decl.cc (duplicate_decls): Propagate DECL_MODULE_PURVIEW_P and DECL_MODULE_IMPORT_P for template redeclarations. gcc/testsuite/ChangeLog: * g++.dg/modules/merge-18_a.H: New test. * g++.dg/modules/merge-18_b.H: New test. * g++.dg/modules/merge-18_c.C: New test. Signed-off-by: Nathaniel Shead --- gcc/cp/decl.cc | 10 ++++++++++ gcc/testsuite/g++.dg/modules/merge-18_a.H | 8 ++++++++ gcc/testsuite/g++.dg/modules/merge-18_b.H | 13 +++++++++++++ gcc/testsuite/g++.dg/modules/merge-18_c.C | 10 ++++++++++ 4 files changed, 41 insertions(+) create mode 100644 gcc/testsuite/g++.dg/modules/merge-18_a.H create mode 100644 gcc/testsuite/g++.dg/modules/merge-18_b.H create mode 100644 gcc/testsuite/g++.dg/modules/merge-18_c.C diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 5ddb7eafa50..a81a7dd2e9e 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -2528,6 +2528,16 @@ duplicate_decls (tree newdecl, tree olddecl, bool hiding, bool was_hidden) } } + /* Propagate purviewness and importingness as with + set_instantiating_module. */ + if (modules_p ()) + { + if (DECL_MODULE_PURVIEW_P (new_result)) + DECL_MODULE_PURVIEW_P (old_result) = true; + if (!DECL_MODULE_IMPORT_P (new_result)) + DECL_MODULE_IMPORT_P (old_result) = false; + } + /* If the new declaration is a definition, update the file and line information on the declaration, and also make the old declaration the same definition. */ diff --git a/gcc/testsuite/g++.dg/modules/merge-18_a.H b/gcc/testsuite/g++.dg/modules/merge-18_a.H new file mode 100644 index 00000000000..8d86ad980ba --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/merge-18_a.H @@ -0,0 +1,8 @@ +// PR c++/116803 +// { dg-additional-options "-fmodule-header" } +// { dg-module-cmi {} } + +namespace ns { + template void foo(); + template extern const int bar; +} diff --git a/gcc/testsuite/g++.dg/modules/merge-18_b.H b/gcc/testsuite/g++.dg/modules/merge-18_b.H new file mode 100644 index 00000000000..2a762e2ac49 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/merge-18_b.H @@ -0,0 +1,13 @@ +// PR c++/116803 +// { dg-additional-options "-fmodule-header -fdump-lang-module" } +// { dg-module-cmi {} } + +import "merge-18_a.H"; + +namespace ns { + template void foo() {} + template const int bar = 123; +} + +// { dg-final { scan-lang-dump {Writing definition '::ns::template foo'} module } } +// { dg-final { scan-lang-dump {Writing definition '::ns::template bar'} module } } diff --git a/gcc/testsuite/g++.dg/modules/merge-18_c.C b/gcc/testsuite/g++.dg/modules/merge-18_c.C new file mode 100644 index 00000000000..b90d85f7502 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/merge-18_c.C @@ -0,0 +1,10 @@ +// PR c++/116803 +// { dg-module-do link } +// { dg-additional-options "-fmodules-ts" } + +import "merge-18_b.H"; + +int main() { + ns::foo(); + static_assert(ns::bar == 123); +}