From patchwork Fri Jan 26 02:28:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 192353 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:e09d:b0:103:945f:af90 with SMTP id gm29csp402830dyb; Thu, 25 Jan 2024 18:29:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IFDZuAFbIdBgkJgQxiC44qnz2z7MySOEidPdmE+g/rXyiz5hKW82vp3mZ5+H5dJw1HdTJTd X-Received: by 2002:a05:6214:262e:b0:686:90c3:374b with SMTP id gv14-20020a056214262e00b0068690c3374bmr787123qvb.31.1706236189768; Thu, 25 Jan 2024 18:29:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706236189; cv=pass; d=google.com; s=arc-20160816; b=NwEERHmKRJYv4YvwLzTkCiWFvk8OhAfiw7KvKug12XQnRC6ucLRsOmYCiTOR7ZkC0n TpCxjsl1MUtxLXWpsb1zMEcrT43iQ2hLWejxCQSTbuN4iQ1CZPOPb5yoO+sfQsGt40aA oJzUdqKpXTMyZBcNoQdoZEte9YdQFisD4+fY3d2MViH1Xrkafq5wklRhuyiJsqqqmISJ 8/uheCnDnmiKi68NS2RMhzWW9eDU2xcj7To2kf8LlGIvfNNfrro07TCRmbIvnuuACXT3 J9HIFKu0JSbsUJ4Wc5TADConfyvZem119dzERYI/0lgzzUmaytXnqod4v61GhtgGSK9F hPHQ== 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:in-reply-to:content-disposition :mime-version:references:subject:cc:to:from:date:message-id :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=UV0ii9j7zdnLD7L6F6OOhpGwHvjELESnbHlonSr0lDQ=; fh=uFHBhFFqjnScr97zeGgucNZd22on4QeY+2puv2bwklk=; b=LRw17KYlYHsPQpb3unzevM9RjCHqsDQ1j+yd05vTniEAcqkDY552UUg7g3BBIfDKp7 HCJG4BoVaQs9hy+dv3kINZSkEUCKn8KwS+MZr/tt3P+jDwlJwa0/NPUt7ZWDWiOFO5DL m6o3ygFadh/JfFRCTKDGG8e1EDf7aiJIm85drtd9dzHRopF4F+AET2KR6T0HkWiPRYoK 4IjwJnTSEUCyZbDTbg6op81clY2HRfUnvShQRUZE9OGVROg1I56y3mWYWGWGmZQMYBPM gSUpH41/CcMcRC/LJIf24UzgnJCD6NQ5O0CYt8i1ujsVRi3fPvEV7XC6byUocvrGTBWW u3LA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=c3ZWCFXD; 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 jp13-20020ad45f8d000000b006819be5e0a4si311604qvb.418.2024.01.25.18.29.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 18:29:49 -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=c3ZWCFXD; 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 79DD03858C29 for ; Fri, 26 Jan 2024 02:29:49 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-oo1-xc2b.google.com (mail-oo1-xc2b.google.com [IPv6:2607:f8b0:4864:20::c2b]) by sourceware.org (Postfix) with ESMTPS id 08D1B3858D37 for ; Fri, 26 Jan 2024 02:29:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 08D1B3858D37 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 08D1B3858D37 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::c2b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706236146; cv=none; b=jl8ER55+MXu2ZrTAZqeR8RO/w4HH50GsA4CoSl/FytJetCxeeE1KdA2qW+kj1ocs9NyuCAyIiLaCuAs5DrJIgcJ9bB1Yyxr3ZXb8SeH8b1OeDHJF6XZK6zChMsB6BcpspSIfsE9W+IzdYLpy0NRtdkbEB0mq9jt6fUlEvvw5O7U= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1706236146; c=relaxed/simple; bh=vmHtdyb9UghvcECb7SSPpgsjYoeH5+aEDtCu4ENjHNo=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=DeSwU2LYsvLy2Kcxab5lkZ3FFz0+NwJqGmHDiE61m5Jn+otF2KuKpfjpyt+74BPfUHlnzsexXn6jl52zvGTa+a53OrmD+9sKvwPwrsBW04Fr/LPxpITsSQZiQUq4rqvXdRu8vVrCgIFpVpD0EekJl+DxGiib6ZVr3y11pV+IKmo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oo1-xc2b.google.com with SMTP id 006d021491bc7-5955a4a9b23so4228938eaf.1 for ; Thu, 25 Jan 2024 18:29:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706236142; x=1706840942; 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=UV0ii9j7zdnLD7L6F6OOhpGwHvjELESnbHlonSr0lDQ=; b=c3ZWCFXDf4SbKmEqv2zlXvazJJ/KWTuUzrbCKKJrSIcOZoau1amMXtgkNkAhcAfGE3 MW1fyWgxIpQmw0FhH1CK/CD01hmjM9YpqyliGI8t91poyzDIsQLFqxd3El2hr8uHP8kN b0WEjwxc58sdQCsy2Uup7YGjWN885mLLogtHC1dtMcR80AKTpGTrJjrbWfpJah5c4Q0N PxrATLMUSKUuvajNezjl1cxC8K8tF2ta5O3HqDW+Vsw69tEMJNV/YWUd/Dx+vpssprdl nR6ck1RRsoUrs/Zny0nzZLfEu6ZEBKmoGyZcdXstMo7lvUVijZ+rvhnpbETYQ2O5PzgM iDRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706236142; x=1706840942; 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=UV0ii9j7zdnLD7L6F6OOhpGwHvjELESnbHlonSr0lDQ=; b=juFPuNSj2P37N+xHsf9Wj3Px8jTE4utgt4t7/Qnh7sL7tJ1N2PPWml+bU8/Utp4smw 4gcaXldB0si0u1AqlikS5SL1DVczH+PjwfwUH+MSUhOoe025eQ3LN7Ne4NizYpAcexnY jV3B8ot2wD9fXjynFqfC6OI3UHs/rU51dDu1miTLeKTB+gZ18mjf8AoPrwUgqbeiWUQD wEfWpup8B9XNlg1IdO38qBBEie2LUavrdNs9zGBWoSEzKyyA15OCsuqQR+yc0aKt/3j2 h6v3GWS8HkH9CL9htAesj/sI/8idaoAIuskIh6qxciHWozVfSLr0d30tkTF95hluPfmp +4Fw== X-Gm-Message-State: AOJu0YxF47yFX2Kvj4uzIYNv4nk7Ji7S2Wq3T7pUzSW3AFkQ7vRSHQW6 VCdfkge+/JgHATgFgWmCyM0CjUZMQiLXKryZ5sNcVaBi9E+FqhjE X-Received: by 2002:a05:6358:ee89:b0:175:f2c1:d649 with SMTP id il9-20020a056358ee8900b00175f2c1d649mr880368rwb.25.1706236142148; Thu, 25 Jan 2024 18:29:02 -0800 (PST) Received: from Thaum. (123-243-206-49.tpgi.com.au. [123.243.206.49]) by smtp.gmail.com with ESMTPSA id lo11-20020a170903434b00b001d706c17af2sm164261plb.268.2024.01.25.18.28.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 18:29:01 -0800 (PST) Message-ID: <65b318ed.170a0220.e1152.0933@mx.google.com> X-Google-Original-Message-ID: Date: Fri, 26 Jan 2024 13:28:57 +1100 From: Nathaniel Shead To: Jason Merrill Cc: Patrick Palka , gcc-patches@gcc.gnu.org, Nathan Sidwell Subject: [PATCH v4] c++/modules: Emit definitions of ODR-used static members imported from modules [PR112899] References: <659490fd.170a0220.1ce2e.503a@mx.google.com> <36bed0fe-5564-60ed-df91-240d78819add@idea> <65aba461.a70a0220.7fd5c.ad24@mx.google.com> <473bdd7b-d352-4608-b472-843191c8d5f5@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <473bdd7b-d352-4608-b472-843191c8d5f5@redhat.com> X-Spam-Status: No, score=-11.0 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, URIBL_BLACK 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: 1787020253152730484 X-GMAIL-MSGID: 1789118319121057792 On Wed, Jan 24, 2024 at 03:24:42PM -0500, Jason Merrill wrote: > On 1/20/24 05:45, Nathaniel Shead wrote: > > I also included > > your change to only add class variable templates to 'pending_statics' > > (and the normal 'static_decl's for non-class otherwise) as otherwise I > > could imagine that they would cause issues with this later too. > > That seems wrong; the 'static_decls' vec is just for checking that > static/inline variables got defined. > > pending_statics has been used for template instantiations for a long time, > for non-module code; let's not mess with that in a modules patch. > OK, makes sense. > > I know that there's been discussion about the correct ABI for inline > > declarations, but personally I'd like to have this fixed for normal uses > > in GCC14 at least, and we can revisit the specific cases where various > > kinds of declarations are emitted in stage 1. > > Makes sense. > > > P.S. As I go to send this, I wonder if maybe something like > > 'note_static_member_variable' would be a clearer choice of name than > > 'note_static_storage_variable'? > > Let's call it note_vague_linkage_variable, to go with _fn just above. > Sounds good. > > -- >8 -- > > > > Static data members marked 'inline' should be emitted in TUs where they > > are ODR-used. We need to make sure that statics imported from modules > > are correctly added to the 'pending_statics' map so that they get > > emitted if needed, otherwise the attached testcase fails to link. > > What about non-member variables marked inline, and non-member variable > template instantiations? > > Jason > Non-member variables marked inline are already handled by 'static_decls' via 'add_module_namespace_decl' and 'add_decl_to_level' during stream-in, and then are later emitted from 'wrapup_namespace_globals'. I'd assumed that non-member variable template instantiations would also be handled by here, but that turns out not to be the case, since the instantiations themselves are not (of course) namespace-scope decls. I've added a case to the tests for this. Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk? -- >8 -- Static data members marked 'inline' should be emitted in TUs where they are ODR-used. We need to make sure that inlines imported from modules are correctly added to the 'pending_statics' map so that they get emitted if needed, otherwise the attached testcase fails to link. PR c++/112899 gcc/cp/ChangeLog: * cp-tree.h (note_variable_template_instantiation): Rename to... (note_vague_linkage_variable): ...this. * decl2.cc (note_variable_template_instantiation): Rename to... (note_vague_linkage_variable): ...this. * pt.cc (instantiate_decl): Rename usage of above function. * module.cc (trees_in::read_var_def): Remember pending statics that we stream in. gcc/testsuite/ChangeLog: * g++.dg/modules/init-4_a.C: New test. * g++.dg/modules/init-4_b.C: New test. * g++.dg/modules/init-6_a.H: New test. * g++.dg/modules/init-6_b.C: New test. Signed-off-by: Nathaniel Shead Reviewed-by: Patrick Palka Reviewed-by: Jason Merrill +struct __from_chars_alnum_to_val_table { + static inline int value = 42; +}; + +inline unsigned char +__from_chars_alnum_to_val() { + return __from_chars_alnum_to_val_table::value; +} + +template +static inline int nonclass_value = 42; + +inline unsigned char +get_nonclass_val() { + return nonclass_value; +} diff --git a/gcc/testsuite/g++.dg/modules/init-6_b.C b/gcc/testsuite/g++.dg/modules/init-6_b.C new file mode 100644 index 00000000000..d704968ec37 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/init-6_b.C @@ -0,0 +1,9 @@ +// { dg-module-do link } +// { dg-additional-options "-fmodules-ts" } + +import "init-6_a.H"; + +int main() { + __from_chars_alnum_to_val(); + get_nonclass_val(); +}