From patchwork Thu Mar 13 15:16:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 107836 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F2D833857B98 for ; Thu, 13 Mar 2025 15:19:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F2D833857B98 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=O0Si3KJ1 X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by sourceware.org (Postfix) with ESMTPS id C12A43858D39 for ; Thu, 13 Mar 2025 15:16:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C12A43858D39 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 C12A43858D39 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::636 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1741879002; cv=none; b=iixqZsdB64ge+J3+ahT4ZQ6Zkf0qeaoLMu0eEV93OhbxGGC0whNHGzksOnY2QXkpebBlT6vPO7DEAtsyZv/gBOOecIDjA1Nrg4UnBgbeeorar4T6XcWGCbFieMuK3u3V7JdJWIDBdmG7/QgEHpE+DbCQQP/ZNJAW9PX2N9t4Nmc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1741879002; c=relaxed/simple; bh=OMCps8aF40ztTIjjobhABeC1nW0TTOZaKL/294bPjjQ=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=ZJ3VK3ez4BTNjPw1aPj8K6emG5wSvML1CoEbuj7zgfzjlzGbXui0fRMZYXIjju4tTL/g4rYSu7jJxo3ksHXMdouqMnFUCIP/xf87J0N8Hiz8N9Jl2Qxzd6xhnUx5bvJRqkJtajyua14GYhpTZYBTA3xssUxEN+GFMC8MDSll1Ys= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-2240b4de10eso3149735ad.1 for ; Thu, 13 Mar 2025 08:16:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741879000; x=1742483800; 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=7faflka2jC0/XXvhVScZzWV3dcBjQ6z1Z69oHJQKstQ=; b=O0Si3KJ1o9jrCmZHqNj3ymlsEjL08WwA6aLsetvNJ22DMZzn5nyAUQ6bsQ+e08JYBn rAEvQHv2biMPsPNfMU2w9uoXP5E2tBXUKM5KkHWtVZKBkI2xkvBQhH3d092exAPJhT94 e619zflgOhjLfDyBRjpGLSzCpR7S1U33zpXgd8SK+FKBYJkTIRGDAc0ykjp2XxUEduEk XT6KOr7L8o0yRSmPCY5lxnRZxMYjBnALAGU8UctueVVq6/Qv5WbEjiOn7D9r3WsHVCgy 0hUurCs4L95REE5JI9rPQNYa8328UIyeG4iVeruA2bIiQM3QW/v/kLPZolorTp2DYCbv 3dMA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741879000; x=1742483800; 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=7faflka2jC0/XXvhVScZzWV3dcBjQ6z1Z69oHJQKstQ=; b=RN3yB5YUOGawFiTLkjtfew3THeW6Yw46rH2NKyM+QUtyqp/doDYOgH77fXYNxNGP7P jHVUgakeOEbxbxcILnr3n5lhZa19Cxz3+2GAm5bAx0Tefl3NNeoAAFxu57pzECPYOTYB vnDKp32pP0uHW5NSucYehTNUVYKDJXdicZZGiFL4qKajjJpw/EtmcgJwGEpn+EvaAazy 0iQHTuN8UBR5mzsXtS8gbstEhwZQxzCc7fNQdZgyBjGv7+lAY1SFcsKG1ysgY2HPz0JW a47FqtTms3zlCmYVCgV4wKG+ZJTuwhSI2Iir8blXwHBxjBH3K9WMDDT6mupJjcaqmxCL NHnA== X-Gm-Message-State: AOJu0YzW9dMLRzoA0iKfGoSYjUxc04smnaYphRet25hOi7GmOjzKB5pH ZObjmhuLZFMm3YIvVOttuf5kx+CIiljQOgX8gTf7mv5d/IjxJqx8RpYPzg== X-Gm-Gg: ASbGnctuuOc67mwp1webEhEgfOM7Om4zv0MzX+XeZrqJeDoDMQwh4boMysRG9OD5/37 8DWu6MERXS8krTtlFhaWkcw3iFek5GkHjB+UJXBUUlazM7vETUwpoHDCnUwZMcYEcCx2yG61HW6 tbekUGLnHS7BbJWfQ88kPx2BaC5MAkS1GQ7n4RI7nIncH7psNBOKPqzY7g72BCLuUqPzNPFMPXi LV+t3pIZUJf7iSEiZJEjQJiVTGzk+90HWo96wKzFsgvfRVcz+RrvAlNRqvNunaN7IUxd6ZUnzxP rivRtLLTn6oCQAogblZwR+3Hiqx2RpaeZ37zPwSLln45u2pK3E+ePC6i/PVIQcjMFCHO3dG9ZXZ leOUUc6LW+QyJ62RMap3bFTA= X-Google-Smtp-Source: AGHT+IF0OhR/HiJXUxORjX7Np1SdOc9yQJCpWCL8q1v5gIj3m7ldpjl2Hcbkw66aKr278HM9+E/MZQ== X-Received: by 2002:a17:902:d584:b0:224:1212:7da1 with SMTP id d9443c01a7336-2259330060fmr61335065ad.13.1741878999995; Thu, 13 Mar 2025 08:16:39 -0700 (PDT) Received: from Thaum. (163-47-68-46.ipv4.originbroadband.com.au. [163.47.68.46]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-225c68a47c1sm14556325ad.68.2025.03.13.08.16.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Mar 2025 08:16:39 -0700 (PDT) Message-ID: <67d2f6d7.170a0220.5992f.ecc4@mx.google.com> X-Google-Original-Message-ID: Date: Fri, 14 Mar 2025 02:16:34 +1100 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill Subject: [PATCH] c++: Make explicit instantiations not vague linkage MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-11.9 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 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~patchwork=sourceware.org@gcc.gnu.org I discovered from some further testing that I broke 'import std' in some cases with my last patch; this fixes that. This still isn't sufficient I've found to fix PR119154 completely, as there's still more cases where this assert fires due to performing import_export_decl on non-DECL_REALLY_EXTERN at EOF. I'll continue trying to reduce and find each case. But either way I think this is a needed improvement; bootstrapped and regtested on x86_64-pc-linux-gnu (so far just modules.exp), OK for trunk if full regtest succeeds? -- >8 -- My change in r15-8012 for PR c++/119154 caused a bug with explicit instantation declarations. The change cleared DECL_INTERFACE_KNOWN for all vague-linkage entities, including explicit instantiations. When we then perform lazy loading at EOF (due to processing deferred function bodies), expand_or_defer_fn ends up calling import_export_decl which will error because DECL_INTERFACE_KNOWN is still unset but no definition is available in the file, violating some assertions. It turns out that for function templates marked inline we would not respect an 'extern template' imported in general, either; this patch fixes both of these issues by always treating explicit instantiations as external, and so marking DECL_INTERFACE_KNOWN eagerly. For an explicit instantiation declaration we don't want to emit the body of the function as it must be emitted in a different TU anyway. And for explicit instantiation definitions we similarly know that it will have been emitted in the interface TU we streamed it in from, so there's no need to emit it. gcc/cp/ChangeLog: * decl2.cc (vague_linkage_p): Explicit instantiations are not vague linkage. gcc/testsuite/ChangeLog: * g++.dg/modules/extern-tpl-3_a.C: New test. * g++.dg/modules/extern-tpl-3_b.C: New test. * g++.dg/modules/extern-tpl-4_a.C: New test. * g++.dg/modules/extern-tpl-4_b.C: New test. Signed-off-by: Nathaniel Shead Signed-off-by: Nathaniel Shead --- gcc/cp/decl2.cc | 3 ++ gcc/testsuite/g++.dg/modules/extern-tpl-3_a.C | 11 +++++ gcc/testsuite/g++.dg/modules/extern-tpl-3_b.C | 12 +++++ gcc/testsuite/g++.dg/modules/extern-tpl-4_a.C | 24 ++++++++++ gcc/testsuite/g++.dg/modules/extern-tpl-4_b.C | 46 +++++++++++++++++++ 5 files changed, 96 insertions(+) create mode 100644 gcc/testsuite/g++.dg/modules/extern-tpl-3_a.C create mode 100644 gcc/testsuite/g++.dg/modules/extern-tpl-3_b.C create mode 100644 gcc/testsuite/g++.dg/modules/extern-tpl-4_a.C create mode 100644 gcc/testsuite/g++.dg/modules/extern-tpl-4_b.C diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc index 4a9fb1c3c00..712fdc45d40 100644 --- a/gcc/cp/decl2.cc +++ b/gcc/cp/decl2.cc @@ -2480,6 +2480,9 @@ vague_linkage_p (tree decl) /* Unfortunately, import_export_decl has not always been called before the function is processed, so we cannot simply check DECL_COMDAT. */ + if (DECL_LANG_SPECIFIC (decl) + && DECL_EXPLICIT_INSTANTIATION (decl)) + return false; if (DECL_COMDAT (decl) || (TREE_CODE (decl) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (decl) diff --git a/gcc/testsuite/g++.dg/modules/extern-tpl-3_a.C b/gcc/testsuite/g++.dg/modules/extern-tpl-3_a.C new file mode 100644 index 00000000000..def3cd1413d --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/extern-tpl-3_a.C @@ -0,0 +1,11 @@ +// { dg-additional-options "-fmodules -Wno-global-module" } +// { dg-module-cmi M } + +module; +template +struct S { + S() {} +}; +export module M; +extern template class S; +S s; diff --git a/gcc/testsuite/g++.dg/modules/extern-tpl-3_b.C b/gcc/testsuite/g++.dg/modules/extern-tpl-3_b.C new file mode 100644 index 00000000000..5d96937ce02 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/extern-tpl-3_b.C @@ -0,0 +1,12 @@ +// { dg-additional-options "-fmodules" } + +template +struct S { + S() {} +}; + +void foo() { S x;} + +import M; + +// Lazy loading of extern S at EOF should not ICE diff --git a/gcc/testsuite/g++.dg/modules/extern-tpl-4_a.C b/gcc/testsuite/g++.dg/modules/extern-tpl-4_a.C new file mode 100644 index 00000000000..16f1b041307 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/extern-tpl-4_a.C @@ -0,0 +1,24 @@ +// { dg-additional-options "-fmodules" } +// { dg-module-cmi M } + +export module M; + +export template inline void a() {} +extern template void a(); +extern template void a(); +template void a(); + +export template void b() {} +extern template void b(); +extern template void b(); +template void b(); + +export template inline int c = 123; +extern template int c; +extern template int c; +template int c; + +export template int d = 123; +extern template int d; +extern template int d; +template int d; diff --git a/gcc/testsuite/g++.dg/modules/extern-tpl-4_b.C b/gcc/testsuite/g++.dg/modules/extern-tpl-4_b.C new file mode 100644 index 00000000000..1dd4afe9f6b --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/extern-tpl-4_b.C @@ -0,0 +1,46 @@ +// { dg-additional-options "-fmodules" } + +import M; + +int main() { + a(); + a(); + a(); + + b(); + b(); + b(); + + int x = c + c + c; + int y = d + d + d; + return x + y; +} + +// 'int': imported explicit instantiation decls should not be emitted here: +// { dg-final { scan-assembler-not "_ZW1M1aIiEvv:" } } +// { dg-final { scan-assembler-not "_ZW1M1bIiEvv:" } } +// { dg-final { scan-assembler-not "_ZW1M1cIiE:" } } +// { dg-final { scan-assembler-not "_ZW1M1dIiE:" } } + +// 'char': explicit instantiation definitions don't need to be emitted here: +// { dg-final { scan-assembler-not "_ZW1M1aIcEvv:" } } +// { dg-final { scan-assembler-not "_ZW1M1bIcEvv:" } } +// { dg-final { scan-assembler-not "_ZW1M1cIcE:" } } +// { dg-final { scan-assembler-not "_ZW1M1dIcE:" } } + +// 'double': these are not explicitly instantiated and should be emitted here: +// { dg-final { scan-assembler "_ZW1M1aIdEvv:" } } +// { dg-final { scan-assembler "_ZW1M1bIdEvv:" } } +// { dg-final { scan-assembler "_ZW1M1cIdE:" } } +// { dg-final { scan-assembler "_ZW1M1dIdE:" } } + +template void a(); +template void b(); +template int c; +template int d; + +// 'bool': instantiated in this file, and so must be emitted here: +// { dg-final { scan-assembler "_ZW1M1aIbEvv:" } } +// { dg-final { scan-assembler "_ZW1M1bIbEvv:" } } +// { dg-final { scan-assembler "_ZW1M1cIbE:" } } +// { dg-final { scan-assembler "_ZW1M1dIbE:" } } From patchwork Fri Mar 14 13:28:10 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 107897 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A1D2E385781B for ; Fri, 14 Mar 2025 13:29:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A1D2E385781B Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=gCupmBKW X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by sourceware.org (Postfix) with ESMTPS id 72B993858C48 for ; Fri, 14 Mar 2025 13:28:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 72B993858C48 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 72B993858C48 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::631 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1741958896; cv=none; b=Cn0fI0kpczT4jKwziSdFePyHKz1yz3YKoypf8VtRMODUQVZPZ1bOFmSw6NwyLtAfeQ7DrzYOaGVPOxx8g1l0Cjeb3LQXpP8/lbRKl7P5xBmk5K6C+f4IbLVopWONbwEHDTSW3R9hYzfFUv1eaH6bfj4+56CT97UeSH+O5w1MQSk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1741958896; c=relaxed/simple; bh=Ogm2FXxsTOP3KOZs4fYpbmdleKlryrncBZQvyX3s/WQ=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=L4hJbZqI+kS+d4iM7kExbUC9O7TTQ5MOKU53glsltzqRaVq3rxaMrqndTFigJdiwHZVD2hy8pmMCZzzuyzrn3fzCxk9jhJqlZHcaHPoPENJsdP5iteHVI42soAtJhGBA6fOOlaxPfptAkPc7gQwpTQkJ52mhNZ8cjvJkIO2IKro= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 72B993858C48 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-22400301e40so5679595ad.1 for ; Fri, 14 Mar 2025 06:28:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1741958895; x=1742563695; 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=R0HKW80XFyl1bj/pW5MUfuTdCmqsgiVTdo1Fue+HqNA=; b=gCupmBKWzDMEDGHdpq0zHmsyYthBcHh0OWdiaUOtrn1hnGfJa+dhwAZyHRjOkFogKe bQ5gaxQDpfAtxSFMDseLcmqB2x/46+Vlfx8jW2Ac9nyNTGnmbnmLs71R6f2ws+MUv0AV vczPfdgRGGHry8MjMWdKasJz6fxPlT8mXDSuk8SnRzPep2odI5UF3+GjSQbzAzbNHM9j fhVyYkfaS8KvmppGq6OPi+aLOGr1CTaGqLHUUHLxXlvIemZVFBSjH3IHClQGIuh3TaFp e4POalSVMqjHQ/0VhC26ZBbI/XQ2g2SVEJn1ivl+uND+X+vp4ry+NJZGoXIT21YeTafP 46gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1741958895; x=1742563695; 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=R0HKW80XFyl1bj/pW5MUfuTdCmqsgiVTdo1Fue+HqNA=; b=hGUBhOSnxUJ8Wny4OARrhH1i6Jm7SJhkllWJFiPuwVyYs3yMBe2kTe72JTf6zt25fd f18/IZ6FZdZbC3mwuY+RpgBevs4fF6LeppkQwrWKlhrbhAFNpUWBpaHxVttAhMbW8Qyn k7mVnWs0k5GUHioxkizrr1Iv54bKeSLrr4/Yjo13F3TodWf+hkpFatLhs92XvZlgEAzy SHgE4Ektp4e1E3p9tsA/Avw2jeNmoxMWIhJu18sdEAxttV+HcZiF2aExB0AkL3DuGHsB fkGTewwSjum6G7gu4wUTGwRu0Zqwr5/s/TE1n7C0pgyNF6IrDE1583i2P+/IFo7wNajq ZSHg== X-Gm-Message-State: AOJu0Yz5b4pAXNGLwTc0yL4QhRh8JiQMuqClPfOTBS3mmcWvR4qCLFwV 6d7pEV3rO+XY5AzfiBFIsnLaRKja2LKIQlL6Hh7yf68Pq71+5IsA X-Gm-Gg: ASbGncscNzi0qy3TxolIueADgFhaDLaqPpHjqdV4mGeUl+9OznEaUGzsABUd6O6KaPm I5D/3eikpb7z9rMJGHvfMrPMx4G3ne2DRWXOIsab4EbHWxSfYfhx1qNQ8OMh5ztAXs95xEnYSW0 y9Kwl75AzlXNdxIo/Pz2twha2UxuBHVs/lZFot1YSxbQ1OwtugVAXH9BEXZ4aCGgBCVFz+TLv0v osEd5GV+yNN5a8PZ6Nz7jAUzOeRqUKT/nyVJB1ZSohstDyHTxLaU0kkRUELUaWrDhVC7gD6JHe7 HLdPe6Ml4lIS2gZT6qJmSlopJ0eLBEzsB56/dEwf3CpRHMKr07YIKD87n92mmUdI54JHoiYUj+R hsTd3aBP9BtZL X-Google-Smtp-Source: AGHT+IGVXzBpHM4mLfa4yejHnxUAq3WN1xrgamMvnCyuh032ub66B8Tv2RrhM/PI8sVuJlQK5y97eA== X-Received: by 2002:a17:902:e802:b0:215:8d29:af0b with SMTP id d9443c01a7336-225e0b07470mr12572655ad.14.1741958895175; Fri, 14 Mar 2025 06:28:15 -0700 (PDT) Received: from Thaum. (163-47-68-46.ipv4.originbroadband.com.au. [163.47.68.46]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7371157369bsm2851563b3a.75.2025.03.14.06.28.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Mar 2025 06:28:14 -0700 (PDT) Message-ID: <67d42eee.a70a0220.156528.a5d4@mx.google.com> X-Google-Original-Message-ID: Date: Sat, 15 Mar 2025 00:28:10 +1100 From: Nathaniel Shead To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH 2/1] c++/modules: Handle gnu_inline, again [PR119154] References: <67d2f6d7.170a0220.5992f.ecc4@mx.google.com> <4eca90c5-7b9d-4df4-bc46-3faffd027928@redhat.com> <67d37e6c.170a0220.4d47f.658b@mx.google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <67d37e6c.170a0220.4d47f.658b@mx.google.com> X-Spam-Status: No, score=-11.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, 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~patchwork=sourceware.org@gcc.gnu.org Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk? Alternatively, could still mark gnu_inline functions as non-vague, we just need to do so more aggressively; but given this is specifically to solve a modules issue I felt may as well keep it confined to there given your previous comments. Note that this patch is on top of my patch for explicit instantiations here: https://gcc.gnu.org/pipermail/gcc-patches/2025-March/677617.html -- >8 -- My change in r15-8012 was not sufficient to solve all issues with gnu_inline; in some cases, a gnu_inline function could be DECL_COMDAT and still pass through the adjusted vague_linkage_p, to then have import_export_decl called on it during lazy loading at EOF and ICEing. This patch reworks gnu_inline handling. As well as ensuring that DECL_INTERFACE_KNOWN will be set for imported gnu_inline functions, we make sure that we properly handle importing a gnu_inline function over the top of an existing forward-declaration. The other case that duplicate_decls handles (importing a regular definition over the top of a gnu_inline function) doesn't seem like something we need to handle specially in modules; we'll just use the existing gnu_inline function and rely on the guarantee that there is a single non-inline function definition provided elsewhere. PR c++/119154 gcc/cp/ChangeLog: * decl2.cc (vague_linkage_p): Revert change to treat gnu_inline functions as not vague linkage. * module.cc (trees_out::core_bools): Don't redetermine linkage of gnu_inline functions, which are always external. (trees_in::read_function_def): Merge needed attributes when installing a gnu_inline definition on top of an existing declaration. gcc/testsuite/ChangeLog: * g++.dg/modules/pr119154_a.C: Move to... * g++.dg/modules/gnu-inline-1_a.C: ...here. * g++.dg/modules/pr119154_b.C: Move to... * g++.dg/modules/gnu-inline-1_b.C: ...here, and check that the gnu_inline function is not emitted. * g++.dg/modules/gnu-inline-1_c.C: New test. * g++.dg/modules/gnu-inline-2_a.C: New test. * g++.dg/modules/gnu-inline-2_b.C: New test. Signed-off-by: Nathaniel Shead Signed-off-by: Nathaniel Shead --- gcc/cp/decl2.cc | 4 +-- gcc/cp/module.cc | 27 +++++++++++++++++-- .../{pr119154_a.C => gnu-inline-1_a.C} | 0 gcc/testsuite/g++.dg/modules/gnu-inline-1_b.C | 12 +++++++++ gcc/testsuite/g++.dg/modules/gnu-inline-1_c.C | 13 +++++++++ gcc/testsuite/g++.dg/modules/gnu-inline-2_a.C | 11 ++++++++ gcc/testsuite/g++.dg/modules/gnu-inline-2_b.C | 14 ++++++++++ gcc/testsuite/g++.dg/modules/pr119154_b.C | 10 ------- 8 files changed, 76 insertions(+), 15 deletions(-) rename gcc/testsuite/g++.dg/modules/{pr119154_a.C => gnu-inline-1_a.C} (100%) create mode 100644 gcc/testsuite/g++.dg/modules/gnu-inline-1_b.C create mode 100644 gcc/testsuite/g++.dg/modules/gnu-inline-1_c.C create mode 100644 gcc/testsuite/g++.dg/modules/gnu-inline-2_a.C create mode 100644 gcc/testsuite/g++.dg/modules/gnu-inline-2_b.C delete mode 100644 gcc/testsuite/g++.dg/modules/pr119154_b.C diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc index 4a9fb1c3c00..fe9c56b6637 100644 --- a/gcc/cp/decl2.cc +++ b/gcc/cp/decl2.cc @@ -2482,9 +2482,7 @@ vague_linkage_p (tree decl) DECL_COMDAT. */ if (DECL_COMDAT (decl) || (TREE_CODE (decl) == FUNCTION_DECL - && DECL_DECLARED_INLINE_P (decl) - /* But gnu_inline functions are always external. */ - && !lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (decl))) + && DECL_DECLARED_INLINE_P (decl)) || (DECL_LANG_SPECIFIC (decl) && DECL_TEMPLATE_INSTANTIATION (decl)) || (VAR_P (decl) && DECL_INLINE_VAR_P (decl))) diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 7440a9015b4..320e89ffdba 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -5660,11 +5660,17 @@ trees_out::core_bools (tree t, bits_out& bits) we need to import or export any vague-linkage entities on stream-in. */ bool interface_known = t->decl_common.lang_flag_5; - if (interface_known && vague_linkage_p (t) + if (interface_known + && vague_linkage_p (t) /* But explicit instantiations are not vague linkage; we can always rely on there being a definition in another TU. */ && !(DECL_LANG_SPECIFIC (t) - && DECL_EXPLICIT_INSTANTIATION (t))) + && DECL_EXPLICIT_INSTANTIATION (t)) + /* A gnu_inline function is also not vague linkage; we never want + to emit it in any TU. */ + && !(TREE_CODE (t) == FUNCTION_DECL + && DECL_DECLARED_INLINE_P (t) + && lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (t)))) interface_known = false; WB (interface_known); } @@ -12555,6 +12561,23 @@ trees_in::read_function_def (tree decl, tree maybe_template) DECL_INITIAL (decl) = initial; DECL_SAVED_TREE (decl) = saved; + /* If we're importing a gnu_inline definition on top of a forward decl, + propagate the appropriate flags and information. We can't do this + in is_matching_decl because we don't know whether we'll get a + definition at that point. */ + if (maybe_dup != decl + && DECL_DECLARED_INLINE_P (maybe_dup) + && lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (maybe_dup)) + && !lookup_attribute ("gnu_inline", DECL_ATTRIBUTES (decl))) + { + DECL_INTERFACE_KNOWN (decl) + |= DECL_INTERFACE_KNOWN (maybe_dup); + DECL_DISREGARD_INLINE_LIMITS (decl) + |= DECL_DISREGARD_INLINE_LIMITS (maybe_dup); + duplicate_one_attribute (&DECL_ATTRIBUTES (decl), + DECL_ATTRIBUTES (maybe_dup), "gnu_inline"); + } + if (context) SET_DECL_FRIEND_CONTEXT (decl, context); if (cexpr.decl) diff --git a/gcc/testsuite/g++.dg/modules/pr119154_a.C b/gcc/testsuite/g++.dg/modules/gnu-inline-1_a.C similarity index 100% rename from gcc/testsuite/g++.dg/modules/pr119154_a.C rename to gcc/testsuite/g++.dg/modules/gnu-inline-1_a.C diff --git a/gcc/testsuite/g++.dg/modules/gnu-inline-1_b.C b/gcc/testsuite/g++.dg/modules/gnu-inline-1_b.C new file mode 100644 index 00000000000..52e52aed9db --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/gnu-inline-1_b.C @@ -0,0 +1,12 @@ +// PR c++/119154 +// { dg-additional-options "-fmodules" } + +void bar(); +import foo; + +void test_b() { + bar(); +} + +// A function only defined with gnu_inline should not be emitted here. +// { dg-final { scan-assembler-not "_Z3barv:" } } diff --git a/gcc/testsuite/g++.dg/modules/gnu-inline-1_c.C b/gcc/testsuite/g++.dg/modules/gnu-inline-1_c.C new file mode 100644 index 00000000000..a28f8d972a8 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/gnu-inline-1_c.C @@ -0,0 +1,13 @@ +// PR c++/119154 +// { dg-additional-options "-fmodules" } + +void bar() {} +import foo; + +void test_c() { + bar(); +}; + +// Make sure importing a gnu_inline definition didn't stop us from emitting +// the non-gnu_inline definition we had before the module import. +// { dg-final { scan-assembler "_Z3barv:" } } diff --git a/gcc/testsuite/g++.dg/modules/gnu-inline-2_a.C b/gcc/testsuite/g++.dg/modules/gnu-inline-2_a.C new file mode 100644 index 00000000000..7f59fb7f716 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/gnu-inline-2_a.C @@ -0,0 +1,11 @@ +// PR c++/119154 +// { dg-additional-options "-fmodules" } +// { dg-module-cmi xstd } + +export module xstd; + +inline __attribute__((__gnu_inline__)) void wmemset() {} + +extern "C++" template struct char_traits { + void assign() { wmemset(); } +}; diff --git a/gcc/testsuite/g++.dg/modules/gnu-inline-2_b.C b/gcc/testsuite/g++.dg/modules/gnu-inline-2_b.C new file mode 100644 index 00000000000..e2f12d2d0b6 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/gnu-inline-2_b.C @@ -0,0 +1,14 @@ +// PR c++/119154 +// { dg-additional-options "-fmodules" } + +template struct char_traits { + void assign(); +}; + +void foo(char_traits s) { + s.assign(); +} + +import xstd; + +// Lazy loading at EOF of a gnu_inline declaration should not ICE. diff --git a/gcc/testsuite/g++.dg/modules/pr119154_b.C b/gcc/testsuite/g++.dg/modules/pr119154_b.C deleted file mode 100644 index 1558e717761..00000000000 --- a/gcc/testsuite/g++.dg/modules/pr119154_b.C +++ /dev/null @@ -1,10 +0,0 @@ -// PR c++/119154 -// { dg-module-do link } -// { dg-additional-options "-fmodules" } - -void bar(); -import foo; - -int main() { - bar(); -}