From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x729.google.com (mail-qk1-x729.google.com [IPv6:2607:f8b0:4864:20::729]) by sourceware.org (Postfix) with ESMTPS id 99AE53858D32 for ; Sat, 6 Jan 2024 22:33:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 99AE53858D32 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=acm.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 99AE53858D32 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::729 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704580423; cv=none; b=plEm3yM1gg+PebqYKZnp9XMvqgYUqtQ1G3L3jKL0M3SGlba/3wSbDoRY+Q9xy9JiHeQg7Kic7q1c33PQ8a2cgBzD5UscXJIB7Hs7Kz1POylBkxsYffnQDozqsrbTusaJTPBzoPImOpYZZ8QF5HyfbwqrhTME81rtNHd9EbQo3Js= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704580423; c=relaxed/simple; bh=VbrM/t5ZfaQmi4EyoFHfhOK7eENhxUP4PwNgB5L5ywA=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=tdDOigZVwL1ox2uceXG7nAzDSu5c2oLtbaMLovrL17u/lH56A8MvAVWQhTI3w1ZuqkoPtk/wbHROH1ejbo0PDlxx1q8KNwyRGUG/DSnOpNE2KOFnX6E/WFL7FGoMBwYHBDA9I0ebn0d9UvAyk0QjMVxGi0oiTDfGJYqb2qZN0YU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-qk1-x729.google.com with SMTP id af79cd13be357-78314e00350so58824585a.1 for ; Sat, 06 Jan 2024 14:33:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704580414; x=1705185214; darn=gcc.gnu.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :sender:from:to:cc:subject:date:message-id:reply-to; bh=KbNOTKQnWnml5brMJXlx+OeEpz96XbbvPuPVqbPrhCI=; b=YF9nRTfdukUl198mEXQkRv+GrPXUdZnXoeaNtRGVrTMO1O9L+lZW6n+v/e9kOrmaWP Fumxy50i3Zzx4JgJsXPtfYW4GqLz7ChVpJQNMm2nXdb4w6QXNRksr24u17LUIdfnMJvU DBB87mUz4Q4ZH9EJPnsJrH7Xh3rB7bHZhxx50le8g0g/tsHUcoORWlBr6KA1MZnfi1ka Fy+RRAJsaj7G23NVhAdKduFtIrkB7vN7cLyRBwyFjlMDfTGzntETQFZDbEWJk6fPWij7 iCMQrR4YGvoN2Xf1p6begAJeKnbrJcD1tkDqtBFwZ29yj3cdaUzj1uLAXNd8rYVobIO1 ZWgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704580414; x=1705185214; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :sender:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=KbNOTKQnWnml5brMJXlx+OeEpz96XbbvPuPVqbPrhCI=; b=WarPsUHzjz4rlL8D4HCrt6dMMwCInZVKMvLqcx831Bqw8DlVE2jhRM6caTKgAEU4Jh Pxz/5Y1O7TXLqTSEQQWumF44xUJgA1kBXl6rWYeU1KjZwRKr6VYQ0HoxBzYt/NTAZ8W+ bCsWWouDaOIhWU+Y5xOAPdeqUoQRRokRh38hNouAr7TH62t2C9HOlVDDjJO4CBFoTTNz YvGUU1wriOj5eRmlDacbCG0XHRgLwkOvs5+6ufaFiMYKJ3JPug4PmUNxVneGiYg15O7N 32RFF1obGALDpLj/iPagwT6GjZ5lsaOpwK0Lj5TQE1Jd5wG2een6bS8A7DwLc8fOwIda rVEA== X-Gm-Message-State: AOJu0Yyq2uQgUckCEEIJ5QNZyXY9YT9fIC8sH4WKb/BxVceCbEtppM3A uZXO0ggbPWfBQH/NPj5+3Sc= X-Google-Smtp-Source: AGHT+IFMQV8NPftQcOAFFDIeufUG3DpzbRRSWQuHfVIB6SClg5XKXL1QX5ucJjEKaYr3fWnXPxRToQ== X-Received: by 2002:ac8:574b:0:b0:429:8df2:e235 with SMTP id 11-20020ac8574b000000b004298df2e235mr262860qtx.19.1704580413827; Sat, 06 Jan 2024 14:33:33 -0800 (PST) Received: from ?IPV6:2600:4040:5b0e:b500:15a3:ac43:deab:f0a7? ([2600:4040:5b0e:b500:15a3:ac43:deab:f0a7]) by smtp.googlemail.com with ESMTPSA id cb14-20020a05622a1f8e00b0042837900d7bsm2013863qtb.11.2024.01.06.14.33.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 06 Jan 2024 14:33:33 -0800 (PST) Sender: Nathan Sidwell Message-ID: Date: Sat, 6 Jan 2024 17:33:33 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] c++/modules: Fix ICE when writing nontrivial variable initializers Content-Language: en-US To: Nathaniel Shead , gcc-patches@gcc.gnu.org Cc: Jason Merrill , Patrick Palka References: <659491a5.170a0220.6af69.6797@mx.google.com> From: Nathan Sidwell In-Reply-To: <659491a5.170a0220.6af69.6797@mx.google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3037.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,GIT_PATCH_0,HEADER_FROM_DIFFERENT_DOMAINS,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 List-Id: ok On 1/2/24 17:43, 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). > > 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(); > +} -- Nathan Sidwell