From patchwork Thu Oct 6 16:19:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1786 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp396351wrs; Thu, 6 Oct 2022 09:20:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6gHxu3hr7wghR+ODOsGMv9c1quIS8xB4QvkMLTWu+t9INXhrBX4PHo8sr048LCOzPKSZ3c X-Received: by 2002:a17:906:cc57:b0:78d:3612:f0e1 with SMTP id mm23-20020a170906cc5700b0078d3612f0e1mr564183ejb.188.1665073211059; Thu, 06 Oct 2022 09:20:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665073211; cv=none; d=google.com; s=arc-20160816; b=mSO7MppO7x77FtPRi8YLOidK8G2NDjnYnFfl0fUW+HnfqvlPROsmDOEtGluxeQz1xZ An2N4FV+kNneYl9BInkdmiIDm7AgQ3BIagfobcbDY1XrdYc8FIh82lZ948T9E9zqrC5k 0S9rsLjghPo22yVeom93MmKv6InnSWSFot0WBTZ4jRpiIL/34XHEIyMjox6hHmMenISb P445icatD8w14sQGSlG2caFr2Ij7AGpufXk1jpULzQkbjkm6sGkLM5Zj2SrGLDukTJST dVOC9HWRhjyLwk5tPobjlny/oUTLxlTFkafzi0wSlEvD6mcOKE0xtRcJy+ICsXXcPIxE DDSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=S3KIMucoQgJdjR+THs8E/y+bS5dGbnUjLiap08LwUTU=; b=yen1L3KcxsUDNYP9cdr0ikva0bXF73rP1KvcePIcgcuyZjXOz+5kk65Q2U1AUq5T0c 7RCguchnvok+rTuqvHIR1gjnpIwD7O5v+SiQu4XeHF2Qsm5NSDgbjqmGbkf9LGFs29Tt HEheUSyfhOU84RjdYkpu02CT9GVZgr3LHt04wvWyVUQwpuYq541tEBb1qFFhR/OvuIoH mm6joarUPef9lFCA80jnqQwV6GveNbdBeBMKiz6bON8XZr9gZS9Eyb9Nhpblt+tNiu9o btPLYbGFw3t0KXd7cYwsfP3+VqxJIWS9xU+wK47huexinN3s9PwUwE6JfmdYITVNIzqo 5oZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=eWudB411; 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=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id g8-20020a056402320800b004589c999927si15328043eda.494.2022.10.06.09.20.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Oct 2022 09:20:11 -0700 (PDT) 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=@gcc.gnu.org header.s=default header.b=eWudB411; 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=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D13393858022 for ; Thu, 6 Oct 2022 16:20:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D13393858022 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665073209; bh=S3KIMucoQgJdjR+THs8E/y+bS5dGbnUjLiap08LwUTU=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=eWudB411zy5dftrFtMpq1GrShqKjJlG9zoUg76b2PGdKEKCf1ERxfk+scrvU1cCx5 vK/XcuAVYryRMFk+tXMQbeXm2eYzGbjvMsGAH4rnlPPvlrZ+SYyEac8DHmGJNnaaZk dOac7KLexZfyA6AEupnqzGyRSsc7/SJjB5/qZI6E= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 3A1293858D32 for ; Thu, 6 Oct 2022 16:19:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3A1293858D32 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-235-TvgtipOEPJy5V8REzYzsRA-1; Thu, 06 Oct 2022 12:19:21 -0400 X-MC-Unique: TvgtipOEPJy5V8REzYzsRA-1 Received: by mail-qt1-f200.google.com with SMTP id y5-20020ac85245000000b003925165520fso1390614qtn.22 for ; Thu, 06 Oct 2022 09:19:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=S3KIMucoQgJdjR+THs8E/y+bS5dGbnUjLiap08LwUTU=; b=fKzCHcDmPFWZLYl8FpqiQ3bVR7QKr6r8Ys/d6inugmUaGhv5vbrTnmt2WY0OIWGi1D 7+29U/W6V8PVNcVAQvKTb13Ut+bfCCQMfQzdYmfuztJifhctvyzeIEYhO0VuRafejG86 gJNuV825ZUcip8O3+jBda/XV9Ef95n0DJpf89FnJ6zWYPB7w2vNY54JKObiYxwbpwQjo jR4kUrnPunT0N8XHoYTEcvxKQ2jC/YqvddsnoNdmqnBlJW/mB6Dcs3klH4nKPYbb3Vxf Ox1Sst4Em6QvMhiusTSxluvnbuPyl8ryv1daIvBTnjR5pbyjreKApJaTZ0M4619YQmnY Fl6Q== X-Gm-Message-State: ACrzQf1q3xcK3nqvf8/ILYyLJvL5v0NqB4UALBNDX2Oo2I69ix0XdEbu 3BhvCpKA5uUUyhvfEHAwFG7LQHupU8di5ChMr3Zu7859S+2sOvXDXP6YSqCimoBSYtKc8v3r7Lf TPvRtemABZ/IUei2A2CmxoR+PqqR3kS3ezVa+enUD6Lzyjd02YSYrhxMAbIqfHDx45l0= X-Received: by 2002:ac8:5b15:0:b0:394:deb7:1d43 with SMTP id m21-20020ac85b15000000b00394deb71d43mr738798qtw.681.1665073159255; Thu, 06 Oct 2022 09:19:19 -0700 (PDT) X-Received: by 2002:ac8:5b15:0:b0:394:deb7:1d43 with SMTP id m21-20020ac85b15000000b00394deb71d43mr738766qtw.681.1665073158952; Thu, 06 Oct 2022 09:19:18 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id z6-20020ac87ca6000000b003913996dce3sm18098qtv.6.2022.10.06.09.19.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Oct 2022 09:19:18 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++ modules: static var in inline function [PR104433] Date: Thu, 6 Oct 2022 12:19:16 -0400 Message-Id: <20221006161916.4118820-1-ppalka@redhat.com> X-Mailer: git-send-email 2.38.0.rc2 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Cc: nathan@acm.org Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1745955807432903661?= X-GMAIL-MSGID: =?utf-8?q?1745955807432903661?= The below testcase fails to link with the error undefined reference to `f()::y' ultimately because during stream out for the static VAR_DECL y we override DECL_EXTERNAL to true, which later during IPA confuses symbol_table::remove_unreachable_nodes into thinking it's safe to not emit the symbol. The streaming code in question already avoids overriding DECL_EXTERNAL here for DECL_VAR_DECLARED_INLINE_P vars, so it seems natural to do the same for static vars from an DECL_DECLARED_INLINE_P function scope. After this patch (and r13-3134-g09df0d8b14dda6), the following now links: import ; int main() { std::make_shared(); } Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? PR c++/104433 gcc/cp/ChangeLog: * module.cc (trees_out::core_bools): Don't override DECL_EXTERNAL to true for static variables from an inline function. gcc/testsuite/ChangeLog: * g++.dg/modules/static-2_a.H: New test. * g++.dg/modules/static-2_b.C: New test. --- gcc/cp/module.cc | 3 +++ gcc/testsuite/g++.dg/modules/static-2_a.H | 8 ++++++++ gcc/testsuite/g++.dg/modules/static-2_b.C | 9 +++++++++ 3 files changed, 20 insertions(+) create mode 100644 gcc/testsuite/g++.dg/modules/static-2_a.H create mode 100644 gcc/testsuite/g++.dg/modules/static-2_b.C diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 79cbb346ffa..11f68794cd2 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -5397,6 +5397,9 @@ trees_out::core_bools (tree t) case VAR_DECL: if (TREE_PUBLIC (t) + && !(TREE_STATIC (t) + && DECL_FUNCTION_SCOPE_P (t) + && DECL_DECLARED_INLINE_P (DECL_CONTEXT (t))) && !DECL_VAR_DECLARED_INLINE_P (t)) is_external = true; break; diff --git a/gcc/testsuite/g++.dg/modules/static-2_a.H b/gcc/testsuite/g++.dg/modules/static-2_a.H new file mode 100644 index 00000000000..b4546932a12 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/static-2_a.H @@ -0,0 +1,8 @@ +// PR c++/104433 +// { dg-additional-options -fmodule-header } +// { dg-module-cmi {} } + +inline int* f() { + static int y = 0; + return &y; +} diff --git a/gcc/testsuite/g++.dg/modules/static-2_b.C b/gcc/testsuite/g++.dg/modules/static-2_b.C new file mode 100644 index 00000000000..bfd35b0fc15 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/static-2_b.C @@ -0,0 +1,9 @@ +// PR c++/104433 +// { dg-additional-options -fmodules-ts } +// { dg-do link } + +import "static-2_a.H"; + +int main() { + f(); +}