[PATCH][C] Fix PR47939

Richard Guenther rguenther@suse.de
Fri Mar 11 11:25:00 GMT 2011


On Thu, 10 Mar 2011, Joseph S. Myers wrote:

> On Wed, 2 Mar 2011, Richard Guenther wrote:
> 
> > 2011-03-02  Richard Guenther  <rguenther@suse.de>
> > 
> > 	PR c/47939
> > 	* c-decl.c (grokdeclarator): Drop to the main variant only
> > 	for array types.  Drop flag_gen_aux_info check.
> 
> I can't convince myself that this is safe - that is, that it will maintain 
> the invariant that TYPE_MAIN_VARIANT for an array type always points to a 
> version where the ultimate element type is unqualified.  The problem would 
> be where the type from the declaration specifiers is a qualified type, not 
> an array type, but becomes an array element type through array declarators 
> being processed by grokdeclarator, and so arrays are built up directly 
> with qualified element type without the unqualified variants being built 
> first to become the main variants.  It certainly appears that in a case 
> such as
> 
> typedef const int T;
> T a[10];
> const int b[10];
> 
> you get multiple copies of the const int[10] type, some of which have a 
> const int[10] variant as their main variant (incorrect) and some of which 
> have an int[10] variant as their main variant (correct); the canonical 
> types look rather odd as well.  It's reasonable have multiple copies here 
> - for the type T[10] to remember the type name T it was derived from - but 
> in such a case they should still all be on the variant chain for a single 
> int[10] main variant.

Indeed.  I tried to let the array case alone (because it's so
complicated) but failed to do so.  Appearantly

  if (declarator->kind == cdk_array && TYPE_QUALS (element_type))
    type = TYPE_MAIN_VARIANT (type);

leaves it alone (and doesn't emit a DW_TAG_typedef for T for your
testcase).  Thus out of the set of testcases I added the array
case now fails with the above (as I'd have expected but were of
course positively surprised as it didn't ...).

I verified the main variants and canonical types are sane with
the above variant for your testcase.

If you think such change isn't safe either I'll pursue a dwarf2out.c
local change, somehow forcing out the typedef DIE even if it is unused.
I don't feel at home in the grokdeclarator dungeon.

Thanks,
Richard.



More information about the Gcc-patches mailing list