Message ID | 659491a5.170a0220.6af69.6797@mx.google.com |
---|---|
State | Accepted |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp4720209dyb; Tue, 2 Jan 2024 14:44:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IF6GQd3r0bA+bbbbI+jQL/vjLPoDnpv8IWWuZuGpeRhPVl9p+90hn2b07BnpsdBXhsaX+Ns X-Received: by 2002:a05:620a:240a:b0:781:6d93:73b3 with SMTP id d10-20020a05620a240a00b007816d9373b3mr9523275qkn.82.1704235480130; Tue, 02 Jan 2024 14:44:40 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1704235480; cv=pass; d=google.com; s=arc-20160816; b=leoqBMphFQOlpmlHiM9HHPpCoWzijqFR5EiQqwzVj1kr3FLOnp18DSCUILs7a3T0S2 VAu+6x+vnradqN4FikrQnUEB291ZsdqCwUUezNtfAv512nimnhZrFbFsbLT7lQ2eo5v/ 5kB6sAvZ671LzbuzKhry8XbV7cEZ5bH8qAJXf3Fl16dhGFRkGL9A60yXn3VAsK7MFPgY X5AS3U/rU6FwRAPEFg5wWh1zNe1XcMEeQkF/xDqedlDdUqxm77p927UYULJSGbnE0tbW yXgda0eDSKBl2ixXwEuZpte3b8816/a5yfI0r8107vPa6p3UiXdvc17h8+TPsweOOoYI /7UQ== 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:content-disposition :mime-version:subject:cc:to:from:date:message-id:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=xj5NKhWv1xwrEYVCT3bi1K/xZk2QJFPyLzE7UKTcmp4=; fh=qzO3wbthSnmyfzK9xuMl/p4JuHJ0vwryuUQopRA3shc=; b=hO6Wb6Ll+It5Oa+QeWv1Jsr+a71fkdeh0GH+6/qY6nCzTVickOBqYp63Qho82aQLVF 6nXGXrtbGjKVLneyc09dg7qpF/zmvbabc18fM8XGhga6IZEzHdTbNq/1vdHuYKO+ALpV qGsHfaMA3uf10w3pG5JP68VhnWQ8z3OhfjbcFyeZZYLG82F/FgXtSzeSUGewHp/JbzVg NSqN1TKRYCsrxhXYUa37LtklFq/pXmi5Cz9nPzJuuFCmYCKKiLiSjzFl5ZAOS/iF+UIN KAy31jfzSPSSZgS5WXtpPKZbDR7y5VPhwfL1KkxygcOm1n6YreSWK/94xrbwVTtK+l7j ShfQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=EWmiBYM+; 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 t15-20020a05620a450f00b007777245a946si29231052qkp.41.2024.01.02.14.44.40 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 14:44:40 -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=EWmiBYM+; 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 CF7F43858C66 for <ouuuleilei@gmail.com>; Tue, 2 Jan 2024 22:44:39 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by sourceware.org (Postfix) with ESMTPS id 9650D3858C66 for <gcc-patches@gcc.gnu.org>; Tue, 2 Jan 2024 22:43:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9650D3858C66 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 9650D3858C66 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::635 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704235434; cv=none; b=SVMxSOc8ENLkcpuPinGuS7cJJ65tTIwQWw9u9t9TH9akPpoD1izC90G9eSfUR5WV5ns93NOno6JxwUsNZMo0rM/21VYbuKXhWGfaZn3MskErtVII39p2Hv7s2wq6suwoa/LQCcBfw8A562+1XY82fYffw8Tw3asFtwUz2SMB0Dg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704235434; c=relaxed/simple; bh=okum110e1I8S3NLzhWcpXhIXE27ebsxaoFcR2cCTUkk=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=gdReL/tqVQ31KWnMNtSgSG/rR2p1ajNgaGw5LRRrPFevJHfGyjjb0wJzRJWp1lw7m89mJCHEpyOPuamIU2kYj+bsZPUDI+b5YfSPFsAiaMCRGXMwD3blmC6ChlKRNXCgAXuXWwxRmwhZunXqQN9PSlpmVNQ3c/wQWGEVzlLLkiE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1d45f182fa2so49434725ad.3 for <gcc-patches@gcc.gnu.org>; Tue, 02 Jan 2024 14:43:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704235430; x=1704840230; darn=gcc.gnu.org; h=content-disposition:mime-version:subject:cc:to:from:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=xj5NKhWv1xwrEYVCT3bi1K/xZk2QJFPyLzE7UKTcmp4=; b=EWmiBYM+9OseFleH8OEfTOiC6Y2LsKar+gBtRDh+eOti96ybXYe08kJaeG7PLIe7SM eIoO38+cCPY8kLN4pc3BYIeCtw3mDCVrfEpLJmZDxh39DNyTOI9K2NJtLvkhRymjiXb0 QSAwmu//GEsthwFsszQirKAk8m43kvY5XnrzzDxEObJyQ6AZI6/e29qSV1scUTskBUSv drf5+bcgJ2k1/MOT08MEjwPqGjQ3JBGRTj0vLTwTp//PQE4xx5h6rUJwxB2tc/rHebBN swnrfOYdPRRvNkDAHhy3KJydeEQG7pvhjhJQqxeUi1XPKwYRGbHhuejzwgeXQOk6jPsu ltfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704235430; x=1704840230; h=content-disposition:mime-version:subject:cc:to:from:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=xj5NKhWv1xwrEYVCT3bi1K/xZk2QJFPyLzE7UKTcmp4=; b=IjmRFhfDXwBU1rACL9if15j0hZymjRZN1Zq4yhYxr42InrRSlUMBEMA9DVT/LEpzCi wcJk9eS2PTDH5EW52eI9Nddk+erWJjsqsccAiSxUB8okDVWh7B82xTYyP9KBykFLkjTO Te7shnuTq6lDCI3rjiT5o9pWJOWXZMAKlQHUMUABA0pHbDBEGBIbFXQ7lA/YRFIzhe5s GowIRL9Hmvne4dRmHTxsMrWKtKLMHBy80csPGX+3aie1sxO3ljfb/1E+XaTm2gl/HkWR K4Holk5c4a8wd4zB3F9WPf16bsZmNWpRi6fMo2gZaRU5zrqIv9FifnsrKM7lAVYH3oCF nb+A== X-Gm-Message-State: AOJu0YwK4Gnk/MwajjF7ifzytD5n9oW9HoJB9kCFPcP4npBlTW33m/dZ dTzZG3etytzMpmzIh3mfjJBR2vo4JKg= X-Received: by 2002:a17:902:b706:b0:1d4:79b6:101a with SMTP id d6-20020a170902b70600b001d479b6101amr10808957pls.41.1704235430272; Tue, 02 Jan 2024 14:43:50 -0800 (PST) Received: from Thaum. ([203.166.236.30]) by smtp.gmail.com with ESMTPSA id p8-20020a170903248800b001d4beb1e170sm3274080plw.264.2024.01.02.14.43.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 14:43:49 -0800 (PST) Message-ID: <659491a5.170a0220.6af69.6797@mx.google.com> X-Google-Original-Message-ID: <ZZSRoCF2aNuRkL85@Thaum.> Date: Wed, 3 Jan 2024 09:43:44 +1100 From: Nathaniel Shead <nathanieloshead@gmail.com> To: gcc-patches@gcc.gnu.org Cc: Jason Merrill <jason@redhat.com>, Nathan Sidwell <nathan@acm.org>, Patrick Palka <ppalka@redhat.com> Subject: [PATCH] c++/modules: Fix ICE when writing nontrivial variable initializers MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-11.3 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787020422987093192 X-GMAIL-MSGID: 1787020422987093192 |
Series |
c++/modules: Fix ICE when writing nontrivial variable initializers
|
|
Checks
Context | Check | Description |
---|---|---|
snail/gcc-patch-check | success | Github commit url |
Commit Message
Nathaniel Shead
Jan. 2, 2024, 10:43 p.m. UTC
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 <nathanieloshead@gmail.com>
---
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
Comments
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 <nathanieloshead@gmail.com> > --- > 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 > >
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 <nathanieloshead@gmail.com> > --- > 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(); > +}
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(); +}