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

            Bug ID: 128059
           Summary: Call-site parameter DIE lacks DW_AT_location after
                    IPA-SRA parameter removal
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: debug
          Assignee: unassigned at gcc dot gnu.org
          Reporter: wujielun402 at gmail dot com
  Target Milestone: ---

After IPA-SRA removes the unused argument removed_parameter from the
actual call, GCC still emits a DW_TAG_call_site_parameter for it, but
without the DW_AT_location required by DWARF 5.

Reproducer source (repro.c):

        static __attribute__ ((noinline)) int
        callee (int removed_parameter, int retained_parameter)
        {
          return retained_parameter + 9;
        }

        int
        caller (int value)
        {
          int result = callee (value, value + 1);
          return result ^ value;
        }

Compile to an object:

        gcc -O2 -g -gdwarf-5 -fno-inline -fipa-sra -c repro.c -o repro.o

Compiler Explorer: https://godbolt.org/z/oPdsxTMcY

Relevant readelf excerpts from .debug_info (all attributes of DIE 0x90
are shown):

         <2><7d>: Abbrev Number: 6 (DW_TAG_call_site)
            <7e>   DW_AT_call_return_pc: 0x1a
            <86>   DW_AT_call_origin : <0xc7>
         <3><8a>: Abbrev Number: 7 (DW_TAG_call_site_parameter)
            <8b>   DW_AT_location    : 1 byte block: 55 (DW_OP_reg5 (rdi))
            <8d>   DW_AT_call_value  : 2 byte block: 75 0 (DW_OP_breg5 (rdi):
0)
         <3><90>: Abbrev Number: 8 (DW_TAG_call_site_parameter)
            <91>   DW_AT_call_parameter: <0xb2>
            <95>   DW_AT_call_value  : 2 byte block: 71 0 (DW_OP_breg1 (rdx):
0)
         <3><98>: Abbrev Number: 0

         <2><b2>: Abbrev Number: 1 (DW_TAG_formal_parameter)
            <b3>   DW_AT_name        : (indirect string, offset: 0x75):
removed_parameter

The entry at 0x8a describes the retained argument passed in rdi. The entry
at 0x90 identifies removed_parameter through DIE 0xb2 and describes its
value, but has no DW_AT_location describing where it is passed.

DWARF 5 (https://dwarfstd.org/doc/DWARF5.pdf) section 3.4.2 (page 91)
states: "Each such entry has a DW_AT_location attribute which is a location
description." The optional DW_AT_call_parameter identifies the source
parameter, and DW_AT_call_value describes its value; neither replaces
the required location attribute.

Removing the unused argument is valid; emitting this incomplete DWARF 5
entry is the problem. The entry should have a valid DW_AT_location
description or be omitted.

Reply via email to