public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH for c++/88830 - ICE with abstract class
@ 2019-01-14  2:07 Marek Polacek
  2019-01-14 11:10 ` Jakub Jelinek
  0 siblings, 1 reply; 4+ messages in thread
From: Marek Polacek @ 2019-01-14  2:07 UTC (permalink / raw)
  To: GCC Patches, Jason Merrill

Here we were crashing because while the class C has a destructor, it hasn't yet
been declared at this point in maybe_emit_vtables, so CLASSTYPE_DESTRUCTOR is
null, so checking DECL_DEFAULTED_IN_CLASS_P crashed.  Fixed by checking
CLASSTYPE_LAZY_DESTRUCTOR first.

Bootstrapped/regtested on x86_64-linux, ok for trunk?

2019-01-13  Marek Polacek  <polacek@redhat.com>

	PR c++/88830 - ICE with abstract class.
	* decl2.c (maybe_emit_vtables): Check CLASSTYPE_LAZY_DESTRUCTOR.
	Fix formatting.

	* g++.dg/other/abstract7.C: New test.

diff --git gcc/cp/decl2.c gcc/cp/decl2.c
index e4cf4e0a361..7b656712471 100644
--- gcc/cp/decl2.c
+++ gcc/cp/decl2.c
@@ -2229,7 +2229,8 @@ maybe_emit_vtables (tree ctype)
      never get generated.  */
   if (CLASSTYPE_PURE_VIRTUALS (ctype)
       && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype)
-      && DECL_DEFAULTED_IN_CLASS_P(CLASSTYPE_DESTRUCTOR(ctype)))
+      && !CLASSTYPE_LAZY_DESTRUCTOR (ctype)
+      && DECL_DEFAULTED_IN_CLASS_P (CLASSTYPE_DESTRUCTOR (ctype)))
     note_vague_linkage_fn (CLASSTYPE_DESTRUCTOR(ctype));
 
   /* Since we're writing out the vtable here, also write the debug
diff --git gcc/testsuite/g++.dg/other/abstract7.C gcc/testsuite/g++.dg/other/abstract7.C
new file mode 100644
index 00000000000..95781602c95
--- /dev/null
+++ gcc/testsuite/g++.dg/other/abstract7.C
@@ -0,0 +1,14 @@
+// PR c++/88830
+
+struct a {
+  ~a();
+};
+class b {
+  virtual void c(int &);
+};
+class C : b {
+  void c(int &);
+  virtual int d() = 0;
+  a e;
+};
+void C::c(int &) {}

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: C++ PATCH for c++/88830 - ICE with abstract class
  2019-01-14  2:07 C++ PATCH for c++/88830 - ICE with abstract class Marek Polacek
@ 2019-01-14 11:10 ` Jakub Jelinek
  2019-01-14 15:41   ` Marek Polacek
  0 siblings, 1 reply; 4+ messages in thread
From: Jakub Jelinek @ 2019-01-14 11:10 UTC (permalink / raw)
  To: Marek Polacek; +Cc: GCC Patches, Jason Merrill

On Sun, Jan 13, 2019 at 09:07:00PM -0500, Marek Polacek wrote:
> diff --git gcc/cp/decl2.c gcc/cp/decl2.c
> index e4cf4e0a361..7b656712471 100644
> --- gcc/cp/decl2.c
> +++ gcc/cp/decl2.c
> @@ -2229,7 +2229,8 @@ maybe_emit_vtables (tree ctype)
>       never get generated.  */
>    if (CLASSTYPE_PURE_VIRTUALS (ctype)
>        && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype)
> -      && DECL_DEFAULTED_IN_CLASS_P(CLASSTYPE_DESTRUCTOR(ctype)))
> +      && !CLASSTYPE_LAZY_DESTRUCTOR (ctype)
> +      && DECL_DEFAULTED_IN_CLASS_P (CLASSTYPE_DESTRUCTOR (ctype)))
>      note_vague_linkage_fn (CLASSTYPE_DESTRUCTOR(ctype));

Just a formatting nit.  s/CLASSTYPE_DESTRUCTOR/& / on the above line too
when you are at it.  Otherwise I came up with identical patch to yours
(should have noticed the PR is ASSIGNED :( ).

	Jakub

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: C++ PATCH for c++/88830 - ICE with abstract class
  2019-01-14 11:10 ` Jakub Jelinek
@ 2019-01-14 15:41   ` Marek Polacek
  2019-01-14 20:05     ` Jason Merrill
  0 siblings, 1 reply; 4+ messages in thread
From: Marek Polacek @ 2019-01-14 15:41 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: GCC Patches, Jason Merrill

On Mon, Jan 14, 2019 at 12:10:14PM +0100, Jakub Jelinek wrote:
> On Sun, Jan 13, 2019 at 09:07:00PM -0500, Marek Polacek wrote:
> > diff --git gcc/cp/decl2.c gcc/cp/decl2.c
> > index e4cf4e0a361..7b656712471 100644
> > --- gcc/cp/decl2.c
> > +++ gcc/cp/decl2.c
> > @@ -2229,7 +2229,8 @@ maybe_emit_vtables (tree ctype)
> >       never get generated.  */
> >    if (CLASSTYPE_PURE_VIRTUALS (ctype)
> >        && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype)
> > -      && DECL_DEFAULTED_IN_CLASS_P(CLASSTYPE_DESTRUCTOR(ctype)))
> > +      && !CLASSTYPE_LAZY_DESTRUCTOR (ctype)
> > +      && DECL_DEFAULTED_IN_CLASS_P (CLASSTYPE_DESTRUCTOR (ctype)))
> >      note_vague_linkage_fn (CLASSTYPE_DESTRUCTOR(ctype));
> 
> Just a formatting nit.  s/CLASSTYPE_DESTRUCTOR/& / on the above line too
> when you are at it.  Otherwise I came up with identical patch to yours
> (should have noticed the PR is ASSIGNED :( ).

:(  I missed the second formatting problem, fixed here:

2019-01-14  Marek Polacek  <polacek@redhat.com>

	PR c++/88830 - ICE with abstract class.
	* decl2.c (maybe_emit_vtables): Check CLASSTYPE_LAZY_DESTRUCTOR.
	Fix formatting.

	* g++.dg/other/abstract7.C: New test.

diff --git gcc/cp/decl2.c gcc/cp/decl2.c
index e4cf4e0a361..902bb8cab4f 100644
--- gcc/cp/decl2.c
+++ gcc/cp/decl2.c
@@ -2229,8 +2229,9 @@ maybe_emit_vtables (tree ctype)
      never get generated.  */
   if (CLASSTYPE_PURE_VIRTUALS (ctype)
       && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype)
-      && DECL_DEFAULTED_IN_CLASS_P(CLASSTYPE_DESTRUCTOR(ctype)))
-    note_vague_linkage_fn (CLASSTYPE_DESTRUCTOR(ctype));
+      && !CLASSTYPE_LAZY_DESTRUCTOR (ctype)
+      && DECL_DEFAULTED_IN_CLASS_P (CLASSTYPE_DESTRUCTOR (ctype)))
+    note_vague_linkage_fn (CLASSTYPE_DESTRUCTOR (ctype));
 
   /* Since we're writing out the vtable here, also write the debug
      info.  */
diff --git gcc/testsuite/g++.dg/other/abstract7.C gcc/testsuite/g++.dg/other/abstract7.C
new file mode 100644
index 00000000000..95781602c95
--- /dev/null
+++ gcc/testsuite/g++.dg/other/abstract7.C
@@ -0,0 +1,14 @@
+// PR c++/88830
+
+struct a {
+  ~a();
+};
+class b {
+  virtual void c(int &);
+};
+class C : b {
+  void c(int &);
+  virtual int d() = 0;
+  a e;
+};
+void C::c(int &) {}

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: C++ PATCH for c++/88830 - ICE with abstract class
  2019-01-14 15:41   ` Marek Polacek
@ 2019-01-14 20:05     ` Jason Merrill
  0 siblings, 0 replies; 4+ messages in thread
From: Jason Merrill @ 2019-01-14 20:05 UTC (permalink / raw)
  To: Marek Polacek, Jakub Jelinek; +Cc: GCC Patches

On 1/14/19 10:41 AM, Marek Polacek wrote:
> On Mon, Jan 14, 2019 at 12:10:14PM +0100, Jakub Jelinek wrote:
>> On Sun, Jan 13, 2019 at 09:07:00PM -0500, Marek Polacek wrote:
>>> diff --git gcc/cp/decl2.c gcc/cp/decl2.c
>>> index e4cf4e0a361..7b656712471 100644
>>> --- gcc/cp/decl2.c
>>> +++ gcc/cp/decl2.c
>>> @@ -2229,7 +2229,8 @@ maybe_emit_vtables (tree ctype)
>>>        never get generated.  */
>>>     if (CLASSTYPE_PURE_VIRTUALS (ctype)
>>>         && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype)
>>> -      && DECL_DEFAULTED_IN_CLASS_P(CLASSTYPE_DESTRUCTOR(ctype)))
>>> +      && !CLASSTYPE_LAZY_DESTRUCTOR (ctype)
>>> +      && DECL_DEFAULTED_IN_CLASS_P (CLASSTYPE_DESTRUCTOR (ctype)))
>>>       note_vague_linkage_fn (CLASSTYPE_DESTRUCTOR(ctype));
>>
>> Just a formatting nit.  s/CLASSTYPE_DESTRUCTOR/& / on the above line too
>> when you are at it.  Otherwise I came up with identical patch to yours
>> (should have noticed the PR is ASSIGNED :( ).
> 
> :(  I missed the second formatting problem, fixed here:
> 
> 2019-01-14  Marek Polacek  <polacek@redhat.com>
> 
> 	PR c++/88830 - ICE with abstract class.
> 	* decl2.c (maybe_emit_vtables): Check CLASSTYPE_LAZY_DESTRUCTOR.
> 	Fix formatting.

OK.

Jason

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-01-14 20:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-14  2:07 C++ PATCH for c++/88830 - ICE with abstract class Marek Polacek
2019-01-14 11:10 ` Jakub Jelinek
2019-01-14 15:41   ` Marek Polacek
2019-01-14 20:05     ` Jason Merrill

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).