[Bug c/68162] [5/6 Regression] Incompatible pointer type using a typedef

rguenth at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Nov 5 13:35:00 GMT 2015


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68162

--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
With the latest patch we again get the broken

 <1><50>: Abbrev Number: 8 (DW_TAG_variable)
    <51>   DW_AT_name        : (indirect string, offset: 0x73): harry
    <55>   DW_AT_decl_file   : 1
    <56>   DW_AT_decl_line   : 5
    <57>   DW_AT_type        : <0x65>
    <5b>   DW_AT_external    : 1
    <5b>   DW_AT_location    : 9 byte block: 3 20 0 0 0 0 0 0 0        
(DW_OP_addr: 20)
 <1><65>: Abbrev Number: 9 (DW_TAG_const_type)
    <66>   DW_AT_type        : <0x39>
...
 <1><39>: Abbrev Number: 5 (DW_TAG_array_type)
    <3a>   DW_AT_type        : <0x19>
    <3e>   DW_AT_sibling     : <0x49>

and no DW_TAG_typedef of Harry_t.

Note that we do generate the DIE but nothing ends up referencing it.  We
equate the type-decl DIE with its type <record_type 0x7ffff69e1a80 Harry_t>.

The issue is that when emitting the type for 'harry' we do (in
gen_type_die_with_usage):

  /* We are going to output a DIE to represent the unqualified version
     of this type (i.e. without any const or volatile qualifiers) so
     get the main variant (i.e. the unqualified version) of this type
     now.  (Vectors are special because the debugging info is in the
     cloned type itself).  */
  if (TREE_CODE (type) != VECTOR_TYPE)
    type = type_main_variant (type);

and that get's us the "C" way of the main variant of the array,
_Harray[].  dwarf2out.c expects us to strip the qualifiers on
the array type (but not its element types) here.  That is, the C way
of handling things may not be compatible with the middle-end ways
(or debug info expectations for this case in C is different?)

When I just not do that main variant punning here I get

 <1><60>: Abbrev Number: 10 (DW_TAG_variable)
    <61>   DW_AT_name        : (indirect string, offset: 0x7b): harry
    <65>   DW_AT_decl_file   : 1
    <66>   DW_AT_decl_line   : 5
    <67>   DW_AT_type        : <0x75>
...
 <1><75>: Abbrev Number: 6 (DW_TAG_const_type)
    <76>   DW_AT_type        : <0x49>
 <1><49>: Abbrev Number: 7 (DW_TAG_array_type)
    <4a>   DW_AT_type        : <0x39>
    <4e>   DW_AT_sibling     : <0x59>
 <1><39>: Abbrev Number: 5 (DW_TAG_typedef)
    <3a>   DW_AT_name        : (indirect string, offset: 0x0): Harry_t
    <3e>   DW_AT_decl_file   : 1
    <3f>   DW_AT_decl_line   : 4
    <40>   DW_AT_type        : <0x44>

instead.  Not sure about that "extra" const qualifier on the array type
though.

Index: gcc/dwarf2out.c
===================================================================
--- gcc/dwarf2out.c     (revision 229804)
+++ gcc/dwarf2out.c     (working copy)
@@ -20768,7 +20768,8 @@ gen_type_die_with_usage (tree type, dw_d
      get the main variant (i.e. the unqualified version) of this type
      now.  (Vectors are special because the debugging info is in the
      cloned type itself).  */
-  if (TREE_CODE (type) != VECTOR_TYPE)
+  if (TREE_CODE (type) != VECTOR_TYPE
+      && TREE_CODE (type) != ARRAY_TYPE)
     type = type_main_variant (type);

   /* If this is an array type with hidden descriptor, handle it first.  */

Not tested apart from on pr47939-*.c ontop of your last patch.

We are missing C++ variants of those testcases, eventually Fortran / Ada
variants if those have typedefs and qualified element types.

That said, I'm unsure about the expectations on debug info here.  Eventually
we need a debug langhook here?


More information about the Gcc-bugs mailing list