public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jason Merrill <jason@redhat.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: gcc-patches@gcc.gnu.org
Subject: Re: [PATCH] c++: Fix up ICE in emit_support_tinfo_1 [PR109042]
Date: Tue, 7 Mar 2023 10:00:10 -0500	[thread overview]
Message-ID: <cee7adc9-7209-cb7a-a78d-73797f47750b@redhat.com> (raw)
In-Reply-To: <ZAb+vw8RAyZtrlll@tucnak>

On 3/7/23 04:07, Jakub Jelinek wrote:
> Hi!
> 
> In my recent rtti.cc change I assumed when emitting the support tinfos
> that the tinfos for the fundamental types haven't been created yet.
> Normally (in libsupc++.a (fundamental_type_info.o)) that is the case,
> but as can be seen on the testcase, one can violate it by using typeid
> etc. in the same TU and do it before ~__fundamental_type_info ()
> definition.
> 
> The following patch fixes that by popping from unemitted_tinfo_decls
> only in the normal case when it is there, and treating non-NULL
> DECL_INITIAL on a tinfo node as indication that emit_tinfo_decl has
> processed it already.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> 
> 2023-03-07  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR c++/109042
> 	* rtti.cc (emit_support_tinfo_1): Don't assert that last
> 	unemitted_tinfo_decls element is tinfo, instead pop from it only in
> 	that case.
> 	* decl2.cc (c_parse_final_cleanups): Don't call emit_tinfo_decl
> 	for unemitted_tinfO_decls which have already non-NULL DECL_INITIAL.
> 
> 	* g++.dg/rtti/pr109042.C: New test.
> 
> --- gcc/cp/rtti.cc.jj	2023-03-03 00:34:52.028567946 +0100
> +++ gcc/cp/rtti.cc	2023-03-06 19:06:27.433307136 +0100
> @@ -1581,10 +1581,10 @@ emit_support_tinfo_1 (tree bltn)
>         /* Emit it right away if not emitted already.  */
>         if (DECL_INITIAL (tinfo) == NULL_TREE)
>   	{
> -	  gcc_assert (unemitted_tinfo_decls->last () == tinfo);
>   	  bool ok = emit_tinfo_decl (tinfo);
>   	  gcc_assert (ok);
> -	  unemitted_tinfo_decls->pop ();
> +	  if (unemitted_tinfo_decls->last () == tinfo)
> +	    unemitted_tinfo_decls->pop ();

So if it's not last we'll leave it in the vec, even though it is no 
longer unemitted, and let c_parse_final_cleanups deal with removing it? 
  That could use a comment.  OK with that change.

>   	}
>       }
>   }
> --- gcc/cp/decl2.cc.jj	2023-01-18 16:11:47.053213397 +0100
> +++ gcc/cp/decl2.cc	2023-03-06 19:07:16.830582984 +0100
> @@ -4982,7 +4982,7 @@ c_parse_final_cleanups (void)
>   	 get emitted.  */
>         for (i = unemitted_tinfo_decls->length ();
>   	   unemitted_tinfo_decls->iterate (--i, &t);)
> -	if (emit_tinfo_decl (t))
> +	if (DECL_INITIAL (t) || emit_tinfo_decl (t))
>   	  {
>   	    reconsider = true;
>   	    unemitted_tinfo_decls->unordered_remove (i);
> --- gcc/testsuite/g++.dg/rtti/pr109042.C.jj	2023-03-06 19:11:06.995208812 +0100
> +++ gcc/testsuite/g++.dg/rtti/pr109042.C	2023-03-06 19:10:59.117324298 +0100
> @@ -0,0 +1,20 @@
> +// PR c++/109042
> +// { dg-do compile }
> +
> +namespace std { class type_info {}; }
> +
> +std::type_info
> +foo ()
> +{
> +  return typeid (void);
> +}
> +
> +namespace __cxxabiv1 {
> +  struct __fundamental_type_info {
> +    virtual ~__fundamental_type_info ();
> +  };
> +
> +  __fundamental_type_info::~__fundamental_type_info ()
> +  {
> +  }
> +}
> 
> 	Jakub
> 


      reply	other threads:[~2023-03-07 15:00 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-07  9:07 Jakub Jelinek
2023-03-07 15:00 ` Jason Merrill [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=cee7adc9-7209-cb7a-a78d-73797f47750b@redhat.com \
    --to=jason@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.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).