From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1665073164; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=S3KIMucoQgJdjR+THs8E/y+bS5dGbnUjLiap08LwUTU=; b=CRqrYVKfJwMx4VrFZLMplT9mWHIJZwXbN51Z8QlweBi4dm6c5tXwl+b+QcINjkeayHn86w lWQlUcG0TJQD+hBKrj99G6/woSWPIE9mqwYrxFsRD0UWY7FnKkx0DzlDQQtjHsP+TyouJd dfzFujIhPbQD5F00I7pMFzuP34pqMy4= 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-Google-Smtp-Source: AMsMyM6qPeg3U7qJxHWHm6KB7QFT1tR4oWnagtxGrFEMakhnl1XAMo53oc+Qojz7YojWCNHOKy5YNA== 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) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, nathan@acm.org, Patrick Palka 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 List-Id: 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(); +} -- 2.38.0.rc2