[C/C++ PATCH] Fix ICE with typedef redeclaration with attributes (PR c/89933, take 2)

Jason Merrill jason@redhat.com
Fri Apr 12 21:24:00 GMT 2019

On 4/12/19 3:56 PM, Jakub Jelinek wrote:
> On Fri, Apr 12, 2019 at 02:46:19PM -0400, Jason Merrill wrote:
>> On 4/12/19 3:19 AM, Jakub Jelinek wrote:
>>> In r234626 Marek has added code to remove TREE_TYPE (newdecl) from
>>> its variant list for typedefs, because we'll ggc_free the TYPE_NAME of that
>>> type.  Unfortunately, that code will ICE if TREE_TYPE (newdecl) is its own
>>> TYPE_MAIN_VARIANT.  This can happen if due to attributes the newdecl's type
>>> has been build_distinct_type_copy created but hasn't been type_hash_canon
>>> merged (which we do for a few attributes like aligned, but certainly don't
>>> do it for most other attributes).  In the likely case there are no variants
>>> for that type yet, there is just nothing to remove.  If there are some (in
>>> theory), the options are do what the following patch does, keep the type
>>> in the variant list as the main variant, just change the TYPE_NAME, so that
>>> it doesn't refer to ggc_freed TYPE_DECL, or try to pick up some other type
>>> as the main variant and adjust the whole variant list (I don't think the
>>> C/C++ FEs unlike Ada FE like e.g. qualified types as main variant though).
>> If the typedef is a duplicate, the type ought to be garbage as well, no?
> I'd hope so.
> So, would you prefer this instead, where instead of changing the TYPE_NAME
> of the type we assert it has no variants?  I was just worried there might be
> variants, but duplicate_decls should happen immediately on the typedef, so
> there shouldn't be time to create the variants.
> Tried
> typedef const unsigned int a __attribute__ ((__aligned__(8), __may_alias__));
> typedef const unsigned int a __attribute__ ((__aligned__(8), __may_alias__));
> and it works too.

Yes, let's go with this.


More information about the Gcc-patches mailing list