[Bug debug/79289] New: DWARF info for typeof of C function with no args and no prototype is empty pointer

ian at airs dot com gcc-bugzilla@gcc.gnu.org
Mon Jan 30 18:06:00 GMT 2017


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

            Bug ID: 79289
           Summary: DWARF info for typeof of C function with no args and
                    no prototype is empty pointer
           Product: gcc
           Version: 7.0.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: debug
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ian at airs dot com
  Target Milestone: ---

Compile this program with current mainline with -g on GNU/Linux:

static void sub() {}
void f1() { sub(); }
void f2(void) { sub(); }
__typeof__(f1) *v1;
__typeof__(f2) *v2;

Using readelf --debug to examine the debug info I see this for v1:

<1><2d>: Abbrev Number: 2 (DW_TAG_variable)
    <2e>   DW_AT_name        : v1       
    <31>   DW_AT_decl_file   : 1        
    <32>   DW_AT_decl_line   : 4        
    <33>   DW_AT_type        : <0x41>   
    <37>   DW_AT_external    : 1        
    <37>   DW_AT_location    : 9 byte block: 3 8 0 0 0 0 0 0 0  (DW_OP_addr: 8)
 <1><41>: Abbrev Number: 3 (DW_TAG_pointer_type)
    <42>   DW_AT_byte_size   : 8        

Note that the type of v1 is a pointer, but there is no type listed for what it
points to.

By comparison, the debug info for v2 is:

 <1><43>: Abbrev Number: 4 (DW_TAG_subroutine_type)
    <44>   DW_AT_prototyped  : 1        
 <1><44>: Abbrev Number: 2 (DW_TAG_variable)
    <45>   DW_AT_name        : v2       
    <48>   DW_AT_decl_file   : 1        
    <49>   DW_AT_decl_line   : 5        
    <4a>   DW_AT_type        : <0x58>   
    <4e>   DW_AT_external    : 1        
    <4e>   DW_AT_location    : 9 byte block: 3 8 0 0 0 0 0 0 0  (DW_OP_addr: 8)
 <1><58>: Abbrev Number: 5 (DW_TAG_pointer_type)
    <59>   DW_AT_byte_size   : 8        
    <5a>   DW_AT_type        : <0x43>   

Here the type of v2 is clearly a pointer to a function, although there is no
real information about the function: just that it is prototyped.


By comparison, with GCC 6, I see this for v1:

 <1><29>: Abbrev Number: 2 (DW_TAG_subroutine_type)
    <2a>   DW_AT_sibling     : <0x30>   
 <2><2e>: Abbrev Number: 3 (DW_TAG_unspecified_parameters)
 <2><2f>: Abbrev Number: 0
 <1><30>: Abbrev Number: 4 (DW_TAG_variable)
    <31>   DW_AT_name        : v1       
    <34>   DW_AT_decl_file   : 1        
    <35>   DW_AT_decl_line   : 4        
    <36>   DW_AT_type        : <0x44>   
    <3a>   DW_AT_external    : 1        
    <3a>   DW_AT_location    : 9 byte block: 3 8 0 0 0 0 0 0 0  (DW_OP_addr: 8)
 <1><44>: Abbrev Number: 5 (DW_TAG_pointer_type)
    <45>   DW_AT_byte_size   : 8        
    <46>   DW_AT_type        : <0x29>   

and I see this for v2 (the same as for GCC 7):

 <1><4a>: Abbrev Number: 6 (DW_TAG_subroutine_type)
    <4b>   DW_AT_prototyped  : 1        
 <1><4b>: Abbrev Number: 4 (DW_TAG_variable)
    <4c>   DW_AT_name        : v2       
    <4f>   DW_AT_decl_file   : 1        
    <50>   DW_AT_decl_line   : 5        
    <51>   DW_AT_type        : <0x5f>   
    <55>   DW_AT_external    : 1        
    <55>   DW_AT_location    : 9 byte block: 3 8 0 0 0 0 0 0 0  (DW_OP_addr: 8)
 <1><5f>: Abbrev Number: 5 (DW_TAG_pointer_type)
    <60>   DW_AT_byte_size   : 8        
    <61>   DW_AT_type        : <0x4a>   


I'm not entirely sure what is correct here, but a pointer type that doesn't
point to anything must be wrong.  The change from GCC 6 to GCC 7 in the debug
info for v1 is a regression.


More information about the Gcc-bugs mailing list