From patchwork Tue Aug 20 23:40:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 1974617 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=QlyYtTCC; 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 4WpQvS6Tbjz1yXf for ; Wed, 21 Aug 2024 09:40:52 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BE7043858433 for ; Tue, 20 Aug 2024 23:40:50 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by sourceware.org (Postfix) with ESMTPS id 8F2343870853 for ; Tue, 20 Aug 2024 23:40:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8F2343870853 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 8F2343870853 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::1035 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724197232; cv=none; b=Hunx7/tj0zdM6Wi5XLjajU2w7DPM4NgobeKQlcyhBZyvYHKxbzyM4kJAPV2DUaR+D5YJtv27P7vyQtupnSLn3jAAygQhPjl8Jk21ATTGWbKwJXcdOshKcovYk1fAKiCdVswVIPg+0grVR3znznoXqK6ZbCkcYbny9uIrCn8Mt0Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1724197232; c=relaxed/simple; bh=ciBAUC2iNOOWbXHJyiG7NHsa2PEoG1BeMVAqHF7oFwQ=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=dkspn0pGokpXY5tsKyg1xkz5/goOJdNjjLxLqDkJQTnUFxo05hHW0DoB3vw4PUQ3SLfeDuqQBE3huN4V0BqVNS4CIGdTDIGC/JMXezqQavqFP8F6/oYGPZanK36MKpkr66tdfkSD0TMPOHBzQG4XupSIxjvmGzNxnW/dg+App1Y= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pj1-x1035.google.com with SMTP id 98e67ed59e1d1-2d3cc6170eeso43563a91.1 for ; Tue, 20 Aug 2024 16:40:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1724197229; x=1724802029; darn=gcc.gnu.org; h=in-reply-to:content-disposition:mime-version:references:subject:cc :to:from:date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=NK1nlYxeetEjw598H8Y+/wh0tyq7ystZeP//MukBqQ4=; b=QlyYtTCCQXIm4FP8lTcRVqZSWdWXKhAKFrcEVmLX9gXkip7W7qBd4Xq44u63IIK9C9 0ViMw5JDbZDWAYqVw4jWvpYUb+YWEy9lRPXMnpAtMPA9GNGrJThhcNQIhQqo8CB+qKNl pA/gtAGclI/CAQotwNg51s9MdBIosM3s6hCkyIeTDOF521oByJ47wqc1vp3wG4NjIs8r y/whu78lqgR/iAMoy3/bGMUrQL7O0VJOAaAoUCrZAwd+EgGPmYGSJRyin2ZbDd3ekBM7 xWU1vNPHobj1LjQPSzHuk+pW678tcPUvtwQGaul27xX9UeOt227toj6fsUiK00fm76cN gAlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724197229; x=1724802029; h=in-reply-to:content-disposition:mime-version:references:subject:cc :to:from:date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=NK1nlYxeetEjw598H8Y+/wh0tyq7ystZeP//MukBqQ4=; b=rmpjONjIouQZxVdER+C7mg+JCgdFc7+6gve33Dosl95L9PpoPYn5V/yb6jQU2gwGv/ F/JE2biSWWuDzCqqlKYwlHeknAtkb7JbC96w5Gx58al8eOPPRHDGYfRzYjxKzPgeG7MQ XHBJn1OUCPAiLblHVVmmuh7NoWVrPfVPFyMctllu5IHXjcqhw2bmgQhNiRttQG5d0yBH FvOcdJIz2Li/e/uzQgvq2AmpscG+xprqTcWyJVgXcYCLy8wV1BpAsCsuFK1SDLrG2tYp nOehOP5/lxjUdkk1EbGRE3FJhBToKLoQcMGKV4A7U8bDDLgYpU37FOtL7ou1xJh6U3l6 HIKA== X-Gm-Message-State: AOJu0YwgjSHteftoCs/7BEaJLJlWLF0R6T0hlslTzlWiBVDuxJETzPpG E6gEcqQExYNH/ay69BkTDDOGbFZQ39i08Nu8JaAykAWKqGGBcT6EVocAeg== X-Google-Smtp-Source: AGHT+IFuXdEiHFX/v9E6r4W2t0A0jvEoX21xnQu5UgsqHO5qWx4kzs4BnXWtqFAx11jz+gkgKwW7hw== X-Received: by 2002:a17:90a:1116:b0:2d3:da94:171 with SMTP id 98e67ed59e1d1-2d5ea8a5da1mr361990a91.5.1724197229403; Tue, 20 Aug 2024 16:40:29 -0700 (PDT) Received: from Thaum. (110-175-236-231.static.tpgi.com.au. [110.175.236.231]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2d5eb917006sm204047a91.12.2024.08.20.16.40.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2024 16:40:29 -0700 (PDT) Message-ID: <66c5296d.170a0220.3bae0d.0cdc@mx.google.com> X-Google-Original-Message-ID: Date: Wed, 21 Aug 2024 09:40:25 +1000 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill , Nathan Sidwell Subject: [PATCH 2/3] c++/modules: Prevent maybe_clone_decl being called multiple times [PR115007] References: <66c52908.170a0220.2c87fb.d675@mx.google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <66c52908.170a0220.2c87fb.d675@mx.google.com> X-Spam-Status: No, score=-12.2 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, T_SCC_BODY_TEXT_LINE 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 -- The ICE in the linked PR is caused because maybe_clone_decl is not prepared to be called on a declaration that has already had clones created; what happens otherwise is that start_preparsed_function early exits and never sets up cfun, causing a segfault later on. To fix this we ensure that post_load_processing only calls maybe_clone_decl if TREE_ASM_WRITTEN has not been marked on the declaration yet, and (if maybe_clone_decls succeeds) marks this flag on the decl so that it doesn't get called again later when finalising deferred vague linkage declarations in c_parse_final_cleanups. As a bonus this now allows us to only keep the DECL_SAVED_TREE around in expand_or_defer_fn_1 for modules which have CMIs, which will have benefits for LTO performance in non-interface TUs. For clarity we also update the streaming code to do post_load_decls for maybe in-charge cdtors rather than any DECL_ABSTRACT_P declaration, as this is more accurate to the decls affected by maybe_clone_body. PR c++/115007 gcc/cp/ChangeLog: * module.cc (module_state::read_cluster): Replace DECL_ABSTRACT_P with DECL_MAYBE_IN_CHARGE_CDTOR_P. (post_load_processing): Check and mark TREE_ASM_WRITTEN. * semantics.cc (expand_or_defer_fn_1): Use the more specific module_maybe_has_cmi_p instead of modules_p. gcc/testsuite/ChangeLog: * g++.dg/modules/virt-6_a.C: New test. * g++.dg/modules/virt-6_b.C: New test. Signed-off-by: Nathaniel Shead --- gcc/cp/module.cc | 7 ++++--- gcc/cp/semantics.cc | 2 +- gcc/testsuite/g++.dg/modules/virt-6_a.C | 13 +++++++++++++ gcc/testsuite/g++.dg/modules/virt-6_b.C | 6 ++++++ 4 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/modules/virt-6_a.C create mode 100644 gcc/testsuite/g++.dg/modules/virt-6_b.C diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 7c42aea05ee..5cd4f313933 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -15525,7 +15525,7 @@ module_state::read_cluster (unsigned snum) if (abstract) ; - else if (DECL_ABSTRACT_P (decl)) + else if (DECL_MAYBE_IN_CHARGE_CDTOR_P (decl)) vec_safe_push (post_load_decls, decl); else { @@ -17947,10 +17947,11 @@ post_load_processing () dump () && dump ("Post-load processing of %N", decl); - gcc_checking_assert (DECL_ABSTRACT_P (decl)); + gcc_checking_assert (DECL_MAYBE_IN_CHARGE_CDTOR_P (decl)); /* Cloning can cause loading -- specifically operator delete for the deleting dtor. */ - maybe_clone_body (decl); + if (!TREE_ASM_WRITTEN (decl) && maybe_clone_body (decl)) + TREE_ASM_WRITTEN (decl) = 1; } cfun = old_cfun; diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 5ab2076b673..f7ae8e68dcf 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -5122,7 +5122,7 @@ expand_or_defer_fn_1 (tree fn) demand, so we also need to keep the body. Otherwise we don't need it anymore. */ if (!DECL_DECLARED_CONSTEXPR_P (fn) - && !(modules_p () && vague_linkage_p (fn))) + && !(module_maybe_has_cmi_p () && vague_linkage_p (fn))) DECL_SAVED_TREE (fn) = NULL_TREE; return false; } diff --git a/gcc/testsuite/g++.dg/modules/virt-6_a.C b/gcc/testsuite/g++.dg/modules/virt-6_a.C new file mode 100644 index 00000000000..68e466ace3f --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/virt-6_a.C @@ -0,0 +1,13 @@ +// PR c++/115007 +// { dg-additional-options "-fmodules-ts -Wno-global-module" } +// { dg-module-cmi M:a } + +module; +struct S { + virtual ~S() = default; + virtual void f() = 0; +}; +module M:a; +extern S* p; +template void format(T) { p->~S(); } +template void format(int); diff --git a/gcc/testsuite/g++.dg/modules/virt-6_b.C b/gcc/testsuite/g++.dg/modules/virt-6_b.C new file mode 100644 index 00000000000..c53f5fac742 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/virt-6_b.C @@ -0,0 +1,6 @@ +// PR c++/115007 +// { dg-additional-options "-fmodules-ts" } +// { dg-module-cmi M } + +export module M; +import :a;