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: 204145 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp949049dyc; Wed, 21 Feb 2024 02:29:29 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCViKXdZZXVZR2B/r8J667Y4BzyrfGHw9r7qTF2LZ86j5GlGPAa3Gdb0230KAVNC1NCAPO6M0mEPO6vMZvp+Ka8BnSPWhQ== X-Google-Smtp-Source: AGHT+IFMjOQraSmkieb0s3soQPdUvjUd94LevG5YtEszKf4QBCS2LqfAbmaNoWQD3mZtfu2JZ7xJ X-Received: by 2002:ac8:5cd2:0:b0:42d:d5c7:a992 with SMTP id s18-20020ac85cd2000000b0042dd5c7a992mr19702563qta.21.1708511369096; Wed, 21 Feb 2024 02:29:29 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708511369; cv=pass; d=google.com; s=arc-20160816; b=sXOy3lIplkjuiYTr5ogPT8cJQ0vpGuzGeG+LYzf1uQ4AfSvFr6QUPRT+NSqhQ4fr05 GAbLUeAZWcf5GWipVy/A1LAF6xycW6t0D7IeFmdnfaXGS/wu4tNBDlJfh2tFdNhVTAif IWl5gFfIS+nG6qcxu8gPPwFECmST/eFPS5BKZNNnPdrynjyr6ra7Hz5Yl8sV9ca4QkeQ 6Brw7FqYVDjvyUH/HDILplp+iyBv0ciqi5CC9ocxQGiO+SXZiW5gfmankxT5HQdh5uYz 7tFVUAYxBKsqRkc8UKEQo6eF23hKA0d84d5JgXihU8jL91g/WiupRsq89vZKyR+U6uRQ VrSQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition :mime-version:subject:cc:to:from:date:message-id:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=UMMW4At9GQ2jUtIPSxJo6yLcDESrcS9PRV0/biAC6YY=; fh=+nKwZUKpxfG3X6G4iNZAaWKHPtN0vjEIqfpPrPBqius=; b=DgBmU93vs7ycffR6h7UDiZu03iHeFn5UtimA4PMncs76T4Wdkyi1zK5FxWJKJUEPCd qGRLa8MEKisK+eJUF6fBUdBgSYMoHwT5Je8UqRPsipcXjXACSPc5cr8N7hLPv8ytnGI+ X5uJE9CYu2CSarZ9Llv4MnR+yBZH05PR5vtWW0lSqbgLpouKz9bCc4PQOj+lOyxvaLBz 8DDoUjyvHyt5vFPzYGhcRKNs9iDUdLlVS6pfuRyQMZ4TznXl2PQ9Zl1jGuKbY1aiE5I5 5/TW65KHfSbj6FfxM7zKJg+51eWrAGWQmJzSM3QM1DXwATccIYKzn+Pid9Jy3r9GLMzD sxiw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=E8a9+ENV; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id x11-20020ac8730b000000b0042de7461831si9958808qto.437.2024.02.21.02.29.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Feb 2024 02:29:29 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=E8a9+ENV; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CA41E3858C24 for ; Wed, 21 Feb 2024 10:29:28 +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-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+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791504017319817043 X-GMAIL-MSGID: 1791504017319817043 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); +}