* [PATCH] c++ modules: ICE with bitfield member in class template
@ 2022-10-07 15:09 Patrick Palka
2022-10-07 15:23 ` Nathan Sidwell
0 siblings, 1 reply; 3+ messages in thread
From: Patrick Palka @ 2022-10-07 15:09 UTC (permalink / raw)
To: gcc-patches; +Cc: jason, nathan, Patrick Palka
According to grokbitfield, DECL_BITFIELD_REPRESENTATIVE may "temporarily"
contain the width of the bitfield until we layout the class type (after
which it'll contain a FIELD_DECL). But for a class template, it'll always
be the width since we don't/can't layout dependent types.
Tested on x86_64-pc-linux-gnu, does this look OK for trunk?
gcc/cp/ChangeLog:
* module.cc (trees_out::mark_class_def): Guard against
DECL_BITFIELD_REPRESENTATIVE not being a decl.
gcc/testsuite/ChangeLog:
* g++.dg/modules/bfield-3.H: New test.
---
gcc/cp/module.cc | 3 ++-
gcc/testsuite/g++.dg/modules/bfield-3.H | 8 ++++++++
2 files changed, 10 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/g++.dg/modules/bfield-3.H
diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index cb1929bc5d5..172a72e92b9 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -11919,7 +11919,8 @@ trees_out::mark_class_def (tree defn)
mark_class_member (member);
if (TREE_CODE (member) == FIELD_DECL)
if (tree repr = DECL_BIT_FIELD_REPRESENTATIVE (member))
- mark_declaration (repr, false);
+ if (DECL_P (repr))
+ mark_declaration (repr, false);
}
/* Mark the binfo hierarchy. */
diff --git a/gcc/testsuite/g++.dg/modules/bfield-3.H b/gcc/testsuite/g++.dg/modules/bfield-3.H
new file mode 100644
index 00000000000..4fd4db7116a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/bfield-3.H
@@ -0,0 +1,8 @@
+// { dg-additional-options -fmodule-header }
+// { dg-module-cmi {} }
+
+template<int N>
+struct A {
+ int x : 1;
+ int y : N;
+};
--
2.38.0.rc2
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] c++ modules: ICE with bitfield member in class template
2022-10-07 15:09 [PATCH] c++ modules: ICE with bitfield member in class template Patrick Palka
@ 2022-10-07 15:23 ` Nathan Sidwell
2022-10-07 15:54 ` Patrick Palka
0 siblings, 1 reply; 3+ messages in thread
From: Nathan Sidwell @ 2022-10-07 15:23 UTC (permalink / raw)
To: Patrick Palka, gcc-patches; +Cc: jason
On 10/7/22 11:09, Patrick Palka wrote:
> According to grokbitfield, DECL_BITFIELD_REPRESENTATIVE may "temporarily"
> contain the width of the bitfield until we layout the class type (after
> which it'll contain a FIELD_DECL). But for a class template, it'll always
> be the width since we don't/can't layout dependent types.
>
> Tested on x86_64-pc-linux-gnu, does this look OK for trunk?
ok, but could you add a comment on why it might not be a decl?
>
> gcc/cp/ChangeLog:
>
> * module.cc (trees_out::mark_class_def): Guard against
> DECL_BITFIELD_REPRESENTATIVE not being a decl.
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/modules/bfield-3.H: New test.
> ---
> gcc/cp/module.cc | 3 ++-
> gcc/testsuite/g++.dg/modules/bfield-3.H | 8 ++++++++
> 2 files changed, 10 insertions(+), 1 deletion(-)
> create mode 100644 gcc/testsuite/g++.dg/modules/bfield-3.H
>
> diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
> index cb1929bc5d5..172a72e92b9 100644
> --- a/gcc/cp/module.cc
> +++ b/gcc/cp/module.cc
> @@ -11919,7 +11919,8 @@ trees_out::mark_class_def (tree defn)
> mark_class_member (member);
> if (TREE_CODE (member) == FIELD_DECL)
> if (tree repr = DECL_BIT_FIELD_REPRESENTATIVE (member))
> - mark_declaration (repr, false);
> + if (DECL_P (repr))
> + mark_declaration (repr, false);
> }
>
> /* Mark the binfo hierarchy. */
> diff --git a/gcc/testsuite/g++.dg/modules/bfield-3.H b/gcc/testsuite/g++.dg/modules/bfield-3.H
> new file mode 100644
> index 00000000000..4fd4db7116a
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/modules/bfield-3.H
> @@ -0,0 +1,8 @@
> +// { dg-additional-options -fmodule-header }
> +// { dg-module-cmi {} }
> +
> +template<int N>
> +struct A {
> + int x : 1;
> + int y : N;
> +};
--
Nathan Sidwell
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] c++ modules: ICE with bitfield member in class template
2022-10-07 15:23 ` Nathan Sidwell
@ 2022-10-07 15:54 ` Patrick Palka
0 siblings, 0 replies; 3+ messages in thread
From: Patrick Palka @ 2022-10-07 15:54 UTC (permalink / raw)
To: Nathan Sidwell; +Cc: Patrick Palka, gcc-patches, jason
On Fri, 7 Oct 2022, Nathan Sidwell wrote:
> On 10/7/22 11:09, Patrick Palka wrote:
> > According to grokbitfield, DECL_BITFIELD_REPRESENTATIVE may "temporarily"
> > contain the width of the bitfield until we layout the class type (after
> > which it'll contain a FIELD_DECL). But for a class template, it'll always
> > be the width since we don't/can't layout dependent types.
> >
> > Tested on x86_64-pc-linux-gnu, does this look OK for trunk?
>
> ok, but could you add a comment on why it might not be a decl?
Thanks a lot, I added a comment and committed the following:
-- >8 --
Subject: [PATCH] c++ modules: ICE with bitfield in class template
According to grokbitfield, DECL_BIT_FIELD_REPRESENTATIVE may temporarily
contain the width of the bitfield until we layout the class type (after
which it'll contain a decl). Thus for a bitfield in a class template
it'll always be the width, and this patch makes us avoid ICEing from
mark_class_def in this case.
gcc/cp/ChangeLog:
* module.cc (trees_out::mark_class_def): Guard against
DECL_BIT_FIELD_REPRESENTATIVE not being a decl.
gcc/testsuite/ChangeLog:
* g++.dg/modules/bfield-3.H: New test.
---
gcc/cp/module.cc | 6 +++++-
gcc/testsuite/g++.dg/modules/bfield-3.H | 8 ++++++++
2 files changed, 13 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/g++.dg/modules/bfield-3.H
diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index cb1929bc5d5..a7c199c00a4 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -11919,7 +11919,11 @@ trees_out::mark_class_def (tree defn)
mark_class_member (member);
if (TREE_CODE (member) == FIELD_DECL)
if (tree repr = DECL_BIT_FIELD_REPRESENTATIVE (member))
- mark_declaration (repr, false);
+ /* If we're marking a class template definition, then
+ DECL_BIT_FIELD_REPRESENTATIVE will contain the width
+ instead of a decl (as set by grokbitfield). */
+ if (DECL_P (repr))
+ mark_declaration (repr, false);
}
/* Mark the binfo hierarchy. */
diff --git a/gcc/testsuite/g++.dg/modules/bfield-3.H b/gcc/testsuite/g++.dg/modules/bfield-3.H
new file mode 100644
index 00000000000..4fd4db7116a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/bfield-3.H
@@ -0,0 +1,8 @@
+// { dg-additional-options -fmodule-header }
+// { dg-module-cmi {} }
+
+template<int N>
+struct A {
+ int x : 1;
+ int y : N;
+};
--
2.38.0.rc2
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-10-07 15:54 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-07 15:09 [PATCH] c++ modules: ICE with bitfield member in class template Patrick Palka
2022-10-07 15:23 ` Nathan Sidwell
2022-10-07 15:54 ` Patrick Palka
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).