From patchwork Wed Feb 21 10:28:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 1902040 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=E8a9+ENV; 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 4TfsvM6xTfz23d2 for ; Wed, 21 Feb 2024 21:29:03 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6E2D03858407 for ; Wed, 21 Feb 2024 10:29:01 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by sourceware.org (Postfix) with ESMTPS id 8C7273858D20; Wed, 21 Feb 2024 10:28:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8C7273858D20 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 8C7273858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62f ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708511318; cv=none; b=GRs3gLDaSeGqyVtU3iqfN2aKqHVgrzWKU2X3lc4Cry5PyWYh45hH1KsLBX9i8oc7z/7LcXIlAmziTmPI8mCQZt+hBQrLzz3CocBlyjnW4yWRR2ECOVJkxGLqLJh7y6DONV4oPOP1D86rJacfkvtQvaKQHPVPFnFveZXcYdbqUMM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1708511318; c=relaxed/simple; bh=ZI0ZHijiHND3taDapbYIsH/dF818GJSPVYdAAmcT6es=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=Zj4t9QxYLrS4ioJPZ4t79OzVNWCjsgeloflYM9eIh3pT9Yu0KGcW8KEU27beO4MiLISx7AvmXbWbLpkEgyIDvxQAAQHEOq1lxKN59A6nRMQcaTnsti/HdfiFdaA8nT5I4DjWX7pE2SHDOJVEhm7oQZ2P8UoEWeTWZ5tBW5PJsxQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62f.google.com with SMTP id d9443c01a7336-1d51ba18e1bso4625035ad.0; Wed, 21 Feb 2024 02:28:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708511315; x=1709116115; 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=UMMW4At9GQ2jUtIPSxJo6yLcDESrcS9PRV0/biAC6YY=; b=E8a9+ENVuOod4IbcN4KIeUiY7vMIHcffvs/r7gFbsI2WxqAPsaQjGXnLrmCtefWSPG l67X6nOkMgnR1Ac1uo/8nD11ziWCqGE786eUIAyz5PeFHY1YuIlcSkHDXpIdLEdIkbAm JWS+HeYTdwLzqg/xv/RBvNhZTD51Zl5vOnsSAa2t4KSNii4oSwkJibZJ9h+gqCrmWm/2 qrfQMF5ZiU4zQizLYXKhQdLgxeyt0o+BvwR8/YWOsRudjf3FchprJGChyunmLRcnvUH4 k0pnDLoJ+fisnSNc/HpzllauPOFSJ7Mz06oloj63M595PeRUvq6MeyhqLIy2SBDJwnSC zlAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708511315; x=1709116115; 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=UMMW4At9GQ2jUtIPSxJo6yLcDESrcS9PRV0/biAC6YY=; b=tIYiSDo3wts6qWKb2Nx1X67tpQdz8v6FpvaQbF7UrtA+DwpDQU8cg7awW0gFCnuJUU yISFsE1Jd8Lmi1tCQ1vwPVpfPsOMtXiebmfANq6M1TF+0A4/gVGwB9iIhBLWiXuNGeaT OSzDPePqKrx8gZO2tXCdMKvtq6m38WGSY4X65h9BEEj4OqnAyTJMi3W34mfZQFMMWVmj uR9LiXa6ybYifJGme9CDBKeZANbXtuAD8ScCXFqhCJJPA6O0FDi3i44tcFIUpcJVgILy ImuZ9rOTrlyJsqRp2R94AkK5yUm3XfuXJuuNdH5H1fsPHxuuiW+r6GB59lZCW9FRBtak XHDw== X-Forwarded-Encrypted: i=1; AJvYcCVYSI0AxypQJbrJOV+vsL3KGP3+W+jGOlFT12RjBpUea2NRwcv6Xf2oabxrbAo/JmMizkdZwlK1dZtwaI9ZQnsHow== X-Gm-Message-State: AOJu0YygX7G6Ipt/YKT03lWuwnlnL0sFQsRG37Fob95/46lec25Jrtzz 2rNNSJMzLipAgimk+2FNmXZPKgUw59Q/ICcqh4WfPPMIuSwb9IHgFYq6gzI6 X-Google-Smtp-Source: AGHT+IEpsB2lhs9L6oZ61fzPsZ5VJDlWEe0SMTBEzqplvyYx6TmBvjTW1piHUrsAU8S7GEhHq0ZTPg== X-Received: by 2002:a17:902:da89:b0:1db:e7a7:63f4 with SMTP id j9-20020a170902da8900b001dbe7a763f4mr13480835plx.19.1708511315362; Wed, 21 Feb 2024 02:28:35 -0800 (PST) Received: from Thaum. ([202.53.50.204]) by smtp.gmail.com with ESMTPSA id u2-20020a17090282c200b001dbcf653017sm7062180plz.289.2024.02.21.02.28.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 02:28:34 -0800 (PST) Message-ID: <65d5d052.170a0220.f2168.38ba@mx.google.com> X-Google-Original-Message-ID: Date: Wed, 21 Feb 2024 21:28:30 +1100 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill , Nathan Sidwell , Jakub Jelinek Subject: [PATCH] c++: Revert deferring emission of inline variables [PR114013] MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-12.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 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 My earlier patch appears to have caused some regressions. I've taken a quick look to see if there are obvious workarounds, but given the time frame and the fact that I still don't really understand all the details of how and when symbols get emitted, I felt it was safer to revert the non-modules parts of this change instead. Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk? -- >8 -- This is a (partial) reversion of r14-8987-gdd9d14f7d53 to return to eagerly emitting inline variables to the middle-end when they are declared. 'import_export_decl' will still continue to accept them, as allowing this is a pure extension and doesn't seem to cause issues with modules, but otherwise deferring the emission of inline variables appears to cause issues on some targets and prevents some code using inline variable templates from correctly linking. There might be a more targetted way to fix this, but due to the complexity of handling linkage I'd prefer to wait till GCC 15 to explore our options. PR c++/113970 PR c++/114013 gcc/cp/ChangeLog: * decl.cc (make_rtl_for_nonlocal_decl): Don't defer inline variables. * decl2.cc (import_export_decl): Only support inline variables imported from a module. gcc/testsuite/ChangeLog: * g++.dg/cpp1z/inline-var10.C: New test. --- gcc/cp/decl.cc | 4 --- gcc/cp/decl2.cc | 6 +++-- gcc/testsuite/g++.dg/cpp1z/inline-var10.C | 33 +++++++++++++++++++++++ 3 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1z/inline-var10.C diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index e47f694e4e5..d19d09adde4 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -7954,10 +7954,6 @@ make_rtl_for_nonlocal_decl (tree decl, tree init, const char* asmspec) && DECL_IMPLICIT_INSTANTIATION (decl)) defer_p = 1; - /* Defer vague-linkage variables. */ - if (DECL_INLINE_VAR_P (decl)) - defer_p = 1; - /* If we're not deferring, go ahead and assemble the variable. */ if (!defer_p) rest_of_decl_compilation (decl, toplev, at_eof); diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc index 1dddbaab38b..24a9332ccb1 100644 --- a/gcc/cp/decl2.cc +++ b/gcc/cp/decl2.cc @@ -3362,7 +3362,7 @@ import_export_decl (tree decl) * inline functions - * inline variables + * inline variables (from modules) * implicit instantiations of static data members of class templates @@ -3385,7 +3385,9 @@ import_export_decl (tree decl) || DECL_DECLARED_INLINE_P (decl)); else gcc_assert (DECL_IMPLICIT_INSTANTIATION (decl) - || DECL_INLINE_VAR_P (decl) + || (DECL_INLINE_VAR_P (decl) + && DECL_LANG_SPECIFIC (decl) + && DECL_MODULE_IMPORT_P (decl)) || DECL_VTABLE_OR_VTT_P (decl) || DECL_TINFO_P (decl)); /* Check that a definition of DECL is available in this translation diff --git a/gcc/testsuite/g++.dg/cpp1z/inline-var10.C b/gcc/testsuite/g++.dg/cpp1z/inline-var10.C new file mode 100644 index 00000000000..8a198556778 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/inline-var10.C @@ -0,0 +1,33 @@ +// PR c++/114013 +// { dg-do link { target c++17 } } + +struct S { int a, b; }; + +template +constexpr struct S var[8] = {}; + +template <> +constexpr inline struct S var<6>[8] = { + { 1, 1 }, { 2, 0 }, { 3, 1 }, { 4, 0 }, + { 5, 1 }, { 6, 0 }, { 7, 1 }, { 8, 0 } +}; + +[[gnu::noipa]] void +foo (S) +{ +} + +template +void +bar (int x) +{ + foo (var[x]); +} + +volatile int x; + +int +main () +{ + bar <6> (x); +}