public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Nathan Sidwell <nathan@acm.org>
To: Nathaniel Shead <nathanieloshead@gmail.com>
Cc: gcc-patches@gcc.gnu.org, Jason Merrill <jason@redhat.com>
Subject: Re: [PATCH] c++/modules: fix virtual destructors [PR103499]
Date: Thu, 9 Nov 2023 18:45:49 -0500	[thread overview]
Message-ID: <7c9b0dfd-c13b-4df0-b534-0ba851f5a184@acm.org> (raw)
In-Reply-To: <654d6b4b.620a0220.877d9.d8b2@mx.google.com>

On 11/9/23 18:29, Nathaniel Shead wrote:
> On Thu, Nov 09, 2023 at 05:57:39PM -0500, Nathan Sidwell wrote:
>> On 11/9/23 04:55, Nathaniel Shead wrote:
>>> I'm not sure if this is just papering over a general issue of clones not being
>>> exported/imported, or if this is just an exception to the general case of
>>> clones being able to be freely regenerated with no other issues.
>>>
>>> Alternatively, would it be better to override the DECL_VINDEX of the original
>>> declaration after filling it in for the clones as well? I wasn't able to see
>>> anything depending on the current behaviour (though I didn't look very hard).
>>
>> I think your patch is a fine approach. IIRC just streaming out the clones
>> directly ran into a bunch of issues, hence the current implementation.
>>
>>
>> ok
>>
>> nathan
> 
> Sorry, I don't have write access, would you be able to push? Thanks.
> (And for my other patch.)

ok, no worries


> 
>>>
>>> Bootstrapped and regtexted on x86_64-pc-linux-gnu.
>>>
>>> -- >8 --
>>>
>>> Currently, cloned functions are not included in the CMI.  However, for
>>> virtual destructors the clones must have a different DECL_VINDEX from
>>> their base declaration: the former have an INTEGER_CST indicating the
>>> index into the vtable, while the latter indicate the FUNCTION_DECL that
>>> they're overriding.
>>>
>>> As such, this patch ensures that DECL_VINDEX is properly passed on for
>>> cloned functions as well to prevent this from causing issues.
>>>
>>> 	PR c++/103499
>>>
>>> gcc/cp/ChangeLog:
>>>
>>> 	* module.cc (trees_out::decl_node): Write DECL_VINDEX for
>>> 	virtual clones.
>>> 	(trees_in::tree_node): Read DECL_VINDEX for virtual clones.
>>>
>>> gcc/testsuite/ChangeLog:
>>>
>>> 	* g++.dg/modules/pr103499_a.C: New test.
>>> 	* g++.dg/modules/pr103499_b.C: New test.
>>>
>>> Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
>>> ---
>>>    gcc/cp/module.cc                          |  6 ++++++
>>>    gcc/testsuite/g++.dg/modules/pr103499_a.C | 12 ++++++++++++
>>>    gcc/testsuite/g++.dg/modules/pr103499_b.C |  8 ++++++++
>>>    3 files changed, 26 insertions(+)
>>>    create mode 100644 gcc/testsuite/g++.dg/modules/pr103499_a.C
>>>    create mode 100644 gcc/testsuite/g++.dg/modules/pr103499_b.C
>>>
>>> diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
>>> index c1c8c226bc1..416a7c414cc 100644
>>> --- a/gcc/cp/module.cc
>>> +++ b/gcc/cp/module.cc
>>> @@ -8648,6 +8648,8 @@ trees_out::decl_node (tree decl, walk_kind ref)
>>>          tree_node (target);
>>>          tree_node (DECL_NAME (decl));
>>> +      if (TREE_CODE (decl) == FUNCTION_DECL && DECL_VIRTUAL_P (decl))
>>> +	tree_node (DECL_VINDEX (decl));
>>>          int tag = insert (decl);
>>>          if (streaming_p ())
>>>    	dump (dumper::TREE)
>>> @@ -9869,6 +9871,10 @@ trees_in::tree_node (bool is_use)
>>>    		}
>>>    	  }
>>> +	/* A clone might have a different vtable entry.  */
>>> +	if (res && TREE_CODE (res) == FUNCTION_DECL && DECL_VIRTUAL_P (res))
>>> +	  DECL_VINDEX (res) = tree_node ();
>>> +
>>>    	if (!res)
>>>    	  set_overrun ();
>>>    	int tag = insert (res);
>>> diff --git a/gcc/testsuite/g++.dg/modules/pr103499_a.C b/gcc/testsuite/g++.dg/modules/pr103499_a.C
>>> new file mode 100644
>>> index 00000000000..0497c2c5504
>>> --- /dev/null
>>> +++ b/gcc/testsuite/g++.dg/modules/pr103499_a.C
>>> @@ -0,0 +1,12 @@
>>> +// PR c++/103499
>>> +// { dg-module-do compile }
>>> +// { dg-additional-options "-fmodules-ts" }
>>> +// { dg-module-cmi pr103499 }
>>> +
>>> +export module pr103499;
>>> +
>>> +export struct base {
>>> +  virtual ~base() = default;
>>> +};
>>> +
>>> +export struct derived : base {};
>>> diff --git a/gcc/testsuite/g++.dg/modules/pr103499_b.C b/gcc/testsuite/g++.dg/modules/pr103499_b.C
>>> new file mode 100644
>>> index 00000000000..b7468562ba9
>>> --- /dev/null
>>> +++ b/gcc/testsuite/g++.dg/modules/pr103499_b.C
>>> @@ -0,0 +1,8 @@
>>> +// PR c++/103499
>>> +// { dg-additional-options "-fmodules-ts" }
>>> +
>>> +import pr103499;
>>> +
>>> +void test(derived* p) {
>>> +  delete p;
>>> +}
>>
>> -- 
>> Nathan Sidwell
>>

-- 
Nathan Sidwell


      reply	other threads:[~2023-11-09 23:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-09  9:55 Nathaniel Shead
2023-11-09 22:57 ` Nathan Sidwell
2023-11-09 23:29   ` Nathaniel Shead
2023-11-09 23:45     ` Nathan Sidwell [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7c9b0dfd-c13b-4df0-b534-0ba851f5a184@acm.org \
    --to=nathan@acm.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jason@redhat.com \
    --cc=nathanieloshead@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).