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.133.124]) by sourceware.org (Postfix) with ESMTPS id EC5933857C61 for ; Thu, 4 Jan 2024 18:19:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EC5933857C61 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EC5933857C61 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704392371; cv=none; b=fQi4BJ4qKwIOkSX0Ij9HbJp+L8HkL/a2nIjFVbgEXDx15AQEezmzdmncKnx8LSEZ8L29blKBq1ZtANUGIolWW7Q+jTaXTQe1sSCPKZVZf6rkEzDln7y+BbCTshNyyGMpaH+NGa+OUkSZPxpxo07/SrMbyY+yggC7jH2TFfDpOc0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704392371; c=relaxed/simple; bh=TXlWnceJTc8VRzgpqVi3IRv2k6H10vxhMglr3Wfe0G8=; h=DKIM-Signature:From:Date:To:Subject:Message-ID:MIME-Version; b=ayWDzZWb61R70IflyJIy2SpPVdkeVmRjylo+aG/iaYVGcR1f7YnvUTpqwCweDnGLgkf6AweMWbohWvOrSDIIskupF8pSUPb3DovqJ3uKgnDlNLrTK5dEykGgHTh62Dy0z/+/o/ikg+G5LUWxxlz6y6BnPMEL6jJySjhqTL7gg4E= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704392369; 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: in-reply-to:in-reply-to:references:references; bh=LpZbzn/N4FtPfohzQs/j85cZh6V5ptLh8rg4FW3VY5M=; b=S1MbSrOFTQR5hMP4JDD/Ax+Ouxn/quD2wR2Zx3Jc7tBW8Lt4IxjjVyJ2/DFuM87ovWpdnr WUBWtThJxp9XduU8MUxACcUhv9bz5U+RcjG9gVq+/n7DOQuGgTrFUuDio+Aph9OmUYWNWY pEeBxIakCTpCGuM+ROi5smdjz0sXUiM= Received: from mail-oa1-f70.google.com (mail-oa1-f70.google.com [209.85.160.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-122-gxk-U0MMO0motAxSEf1Vmw-1; Thu, 04 Jan 2024 13:19:28 -0500 X-MC-Unique: gxk-U0MMO0motAxSEf1Vmw-1 Received: by mail-oa1-f70.google.com with SMTP id 586e51a60fabf-203ff9e82c6so934551fac.0 for ; Thu, 04 Jan 2024 10:19:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704392367; x=1704997167; h=mime-version:references:message-id:in-reply-to:subject:cc:to:date :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=LpZbzn/N4FtPfohzQs/j85cZh6V5ptLh8rg4FW3VY5M=; b=oZugRIGBP7Tf798ZKRbG+6dlPLwObwUsfWxfJDOYZtJUC0Qs5O4LpmlC7916Urz3XV zEQ4LWagkpVoQfOJKuhqcLQdmzpJhTYGhTtxLDTPTbYhDke6xEotVSP6/57vz84aVztq 4rLp8PYelWcJXjocnwUed07vADja0eXPxhbheVMlevFEYM3LIdVqHKr2e5vJQN9+ptoP TWajss2UTTahNIE5UKjYj/k0G5YJz1PUc6AhLDtngS3JkJrnqSUxSH16fN2qo6iqd3MB LqiEPDpzYUkkZOiN2s1w6nbTquSvEIqkW2wuQzfOMkpshMxa9El5kQbzA2R485uvED4Z 0Uyw== X-Gm-Message-State: AOJu0YyyW3evU3tblR6ZCjXQNTV7Slqjd16DANDYhSonl+9jeNY8dCEZ fLpGm2hdGK9Vp9xc/f1PArIKTn+E9Y+8Ab2KroCdzmWik0hbqP9T6MboY54pG9k0idGJZ64eBct 7Qpelim2+tiSUkC+/dYGxvP2Mlw== X-Received: by 2002:a05:6870:90d3:b0:204:a79:143c with SMTP id s19-20020a05687090d300b002040a79143cmr930843oab.61.1704392367450; Thu, 04 Jan 2024 10:19:27 -0800 (PST) X-Google-Smtp-Source: AGHT+IHkHSW48xsaF/VlCBWSEttUXt/WiM6rOhhBmdiHYrs5eOGp/S8dSUvSJEC12sjY1LBDNu4KTg== X-Received: by 2002:a05:6870:90d3:b0:204:a79:143c with SMTP id s19-20020a05687090d300b002040a79143cmr930839oab.61.1704392367231; Thu, 04 Jan 2024 10:19:27 -0800 (PST) Received: from [192.168.1.130] (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id bk2-20020a05620a1a0200b0077d7cfde46csm11205363qkb.106.2024.01.04.10.19.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Jan 2024 10:19:26 -0800 (PST) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Thu, 4 Jan 2024 13:19:25 -0500 (EST) To: Nathaniel Shead cc: gcc-patches@gcc.gnu.org, Jason Merrill , Nathan Sidwell , Patrick Palka Subject: Re: [PATCH] c++/modules: Fix ICE when writing nontrivial variable initializers In-Reply-To: <659491a5.170a0220.6af69.6797@mx.google.com> Message-ID: References: <659491a5.170a0220.6af69.6797@mx.google.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-14.3 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,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,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 List-Id: On Wed, 3 Jan 2024, Nathaniel Shead wrote: > Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk? > > -- >8 -- > > The attached testcase Patrick found in PR c++/112899 ICEs because it is > attempting to write a variable initializer that is no longer in the > static_aggregates map. > > The issue is that, for non-header modules, the loop in > c_parse_final_cleanups prunes the static_aggregates list, which means > that by the time we get to emitting module information those > initialisers have been lost. > > However, we don't actually need to write non-trivial initialisers for > non-header modules, because they've already been emitted as part of the > module TU itself. Instead let's just only write the initializers from > header modules (which skipped writing them in c_parse_final_cleanups). Makes sense to me. It seems this may also fix PR103994 where we ICE in the same spot when streaming out an initializer from the global module fragment. > > gcc/cp/ChangeLog: > > * module.cc (trees_out::write_var_def): Only write initializers > in header modules. > > gcc/testsuite/ChangeLog: > > * g++.dg/modules/init-5_a.C: New test. > * g++.dg/modules/init-5_b.C: New test. > > Signed-off-by: Nathaniel Shead > --- > gcc/cp/module.cc | 3 ++- > gcc/testsuite/g++.dg/modules/init-5_a.C | 9 +++++++++ > gcc/testsuite/g++.dg/modules/init-5_b.C | 10 ++++++++++ > 3 files changed, 21 insertions(+), 1 deletion(-) > create mode 100644 gcc/testsuite/g++.dg/modules/init-5_a.C > create mode 100644 gcc/testsuite/g++.dg/modules/init-5_b.C > > diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc > index 14818131a70..82b61a2c2ad 100644 > --- a/gcc/cp/module.cc > +++ b/gcc/cp/module.cc > @@ -11707,7 +11707,8 @@ trees_out::write_var_def (tree decl) > { > tree dyn_init = NULL_TREE; > > - if (DECL_NONTRIVIALLY_INITIALIZED_P (decl)) > + /* We only need to write initializers in header modules. */ > + if (header_module_p () && DECL_NONTRIVIALLY_INITIALIZED_P (decl)) > { > dyn_init = value_member (decl, > CP_DECL_THREAD_LOCAL_P (decl) > diff --git a/gcc/testsuite/g++.dg/modules/init-5_a.C b/gcc/testsuite/g++.dg/modules/init-5_a.C > new file mode 100644 > index 00000000000..466b120b5a0 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/modules/init-5_a.C > @@ -0,0 +1,9 @@ > +// { dg-additional-options "-fmodules-ts" } > +// { dg-module-cmi M } > + > +export module M; > + > +export struct A { > + static int f() { return -1; } > + static inline int x = f(); > +}; > diff --git a/gcc/testsuite/g++.dg/modules/init-5_b.C b/gcc/testsuite/g++.dg/modules/init-5_b.C > new file mode 100644 > index 00000000000..40973cc6936 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/modules/init-5_b.C > @@ -0,0 +1,10 @@ > +// { dg-module-do run } > +// { dg-additional-options "-fmodules-ts" } > + > +import M; > + > +int main() { > + const int& x = A::x; > + if (x != -1) > + __builtin_abort(); > +} > -- > 2.43.0 > >