From patchwork Sun Feb 11 13:26:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 1897452 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=heUPzS/Y; 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 4TXpK21Mtlz23f7 for ; Mon, 12 Feb 2024 00:26:43 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 939623858C39 for ; Sun, 11 Feb 2024 13:26:40 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id DF3693858D20 for ; Sun, 11 Feb 2024 13:26:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DF3693858D20 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 DF3693858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::42c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707657984; cv=none; b=CVec2h/2DqBT+UDuv4FxSCycGDMFDd4gjE5TI8/F5w+bzCIQSiFufNeGd10Q0c6BsQKxrAhkE+XDKsqV3X2FCKTyqreLRhzqpCUJ0mzZhr7tj0WikokjkOAZvmJgoG/Gh8UMWo0ACb7NQ5jTwwO76Up2Xft+zuRZmDsJ/G9QWLU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707657984; c=relaxed/simple; bh=hd0ddSRTk8SysiNmlroAanSNyK7I9pC8bBB/Nn4bL7I=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=cA46jB9by/bBczoOA5+JgS+iJMrtl/unxPFDgyM5WopOa6NkISxJ03R5DnYVPUqY1WlsQQFuFuPszDWb/3CbsnqYXSretIpJnnt3CgfdyIzaTbzDFymgA4Uljsdl83ZQAL7wptwsY2JzsrXy1234xk0dZBz3Daxe7su+RSBBReI= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-6e0a479a6cbso482258b3a.0 for ; Sun, 11 Feb 2024 05:26:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707657982; x=1708262782; 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=6hWXYkKx5ko7mvruX2rz56B3jDF6Cg5kLNkmz859574=; b=heUPzS/YQE38NsYQe3mfPFpCPymq55W28T3uFVAZBcyv/WNCvBqP2y3XbG2Xm3+QHG vCm9ey+s+wTUBNPPbicbC48Lktn+8PratmKhFK35blgbjy+/AT4nDFse64EHVxrq52R8 iYTORezmZEe/BxI3pLcmkWFsEKBrdbAfz4XjCp8myHFLGgeEgA/f6tbfRZe8YsZoeYYA HEi4hDZIIQ4DGqXowqjzHbIUHJBfDtjiC/BYWvCNvmhYpVoWNKUPbP/U8fXx9mMqpzzN XLPi0ow+HWtuJi9fSWrqgeGaANkNPdFZq9RJN79Gjezz9HpESqomyPs34o8eqjCgQ78i CTRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707657982; x=1708262782; 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=6hWXYkKx5ko7mvruX2rz56B3jDF6Cg5kLNkmz859574=; b=BGaH8umpFxz4k17j2G9XtukVLuxH/E+yvGPPETgWeoUOPxTD6SDeo6LvIZodCxo3Iz NWl4CbRTdjaplR+LcBres8wIe57gOoCAW81e4zYidxy6fkmYwwW1M1Z+mHfTZcPYK++x ffwnqMHO0BFn3tAs+NW4x/TMcCi5230+7SdQY6uuFTkTJQZf4WSITHZyxmxUlkQGSfly wN9AUFKYvKuxf+/lyPep2FOsnv60mCyJPbWmZFN68ulgNHzPPbkx7taU0ROnAv0fLglS 00BVW5BSJu9OrsETR9NaqMpHF6vXM9RpaSXW2229U/ynapxnNibLFKpcfPdpOYgcpEgr hhcw== X-Gm-Message-State: AOJu0YxM6a9sw4VSAv2wSCCvJWQPwK2UhfJOYVAoOFWyFemybZcpQf7O bh/eRuK31JBviJyvctbWeYshotIVZE5R5MottbWldxdCi0F8ZlSeEx0bP39l X-Google-Smtp-Source: AGHT+IFhxjLr+za5uxZIZpDE9RWe3+8Q2fF1K08fFwGUh0sTwZSUnCLLmIN9CL132BVwTOo5JsT9mw== X-Received: by 2002:aa7:8b54:0:b0:6e0:9025:58d5 with SMTP id i20-20020aa78b54000000b006e0902558d5mr3074888pfd.14.1707657981575; Sun, 11 Feb 2024 05:26:21 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCVOZXIP21a2+t6dG70Mzm59QOFJPEW0NO0sJJ77dV64QShmih1zFNJY50rjbV7R+oT8IdtB2jz+cJeiS7vz3MWUJCjWB+T9IimRM7dWong4L5w= Received: from Thaum. (123-243-206-49.tpgi.com.au. [123.243.206.49]) by smtp.gmail.com with ESMTPSA id fb32-20020a056a002da000b006e0a65e20a4sm2754442pfb.146.2024.02.11.05.26.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Feb 2024 05:26:21 -0800 (PST) Message-ID: <65c8cafd.050a0220.3ef59.516b@mx.google.com> X-Google-Original-Message-ID: Date: Mon, 12 Feb 2024 00:26:15 +1100 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill , Nathan Sidwell , Patrick Palka Subject: [PATCH] c++/modules: Finalise non-local imported vars [PR113708] MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-11.1 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, URIBL_BLACK 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 (just modules.exp so far) on x86_64-pc-linux-gnu, OK for trunk if full regtest succeeds? -- >8 -- Currently inline vars imported from modules aren't correctly finalised, which means that import_export_decl gets called at the end of TU processing despite not being meant to for these kinds of declarations. This patch takes the logic from 'make_rtl_for_nonlocal_decl' to determine when to perform rest of decl compilation on these decls. However other parts of this function (asmspec handling) are not yet covered. PR c++/113708 gcc/cp/ChangeLog: * module.cc (trees_in::read_var_def): Perform rest of decl compilation on non-local statics. gcc/testsuite/ChangeLog: * g++.dg/modules/init-7_a.H: New test. * g++.dg/modules/init-7_b.C: New test. Signed-off-by: Nathaniel Shead --- gcc/cp/module.cc | 12 +++++++++++- gcc/testsuite/g++.dg/modules/init-7_a.H | 6 ++++++ gcc/testsuite/g++.dg/modules/init-7_b.C | 6 ++++++ 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/modules/init-7_a.H create mode 100644 gcc/testsuite/g++.dg/modules/init-7_b.C diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 560d8f3b614..49a3421e6cc 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -11809,6 +11809,7 @@ trees_in::read_var_def (tree decl, tree maybe_template) { if (DECL_EXTERNAL (decl)) DECL_NOT_REALLY_EXTERN (decl) = true; + DECL_INITIAL (decl) = init; if (VAR_P (decl)) { DECL_INITIALIZED_P (decl) = true; @@ -11819,8 +11820,17 @@ trees_in::read_var_def (tree decl, tree maybe_template) && !DECL_VTABLE_OR_VTT_P (decl) && !DECL_TEMPLATE_INFO (decl))) note_vague_linkage_variable (decl); + + /* Emit RTL as needed, as with make_rtl_for_nonlocal_decl. */ + // FIXME: Handle asmspec? + if ((!DECL_FUNCTION_SCOPE_P (decl) + || (TREE_STATIC (decl) && var_in_maybe_constexpr_fn (decl))) + && !DECL_VIRTUAL_P (decl) + && (!DECL_TEMPLATE_INFO (decl) + || DECL_EXPLICIT_INSTANTIATION (decl))) + rest_of_decl_compilation (decl, !DECL_FUNCTION_SCOPE_P (decl), + /*at_end=*/0); } - DECL_INITIAL (decl) = init; if (!dyn_init) ; else if (CP_DECL_THREAD_LOCAL_P (decl)) diff --git a/gcc/testsuite/g++.dg/modules/init-7_a.H b/gcc/testsuite/g++.dg/modules/init-7_a.H new file mode 100644 index 00000000000..7a0bb721c30 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/init-7_a.H @@ -0,0 +1,6 @@ +// PR c++/113708 +// { dg-additional-options "-fmodule-header" } +// { dg-module-cmi {} } + +inline int f() { return 42; } +inline int a = f(); diff --git a/gcc/testsuite/g++.dg/modules/init-7_b.C b/gcc/testsuite/g++.dg/modules/init-7_b.C new file mode 100644 index 00000000000..58bb0620ca5 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/init-7_b.C @@ -0,0 +1,6 @@ +// PR c++/113708 +// { dg-module-do link } +// { dg-additional-options "-fmodules-ts" } + +import "init-7_a.H"; +int main() { a; }