https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128057
Bug ID: 128057
Summary: implicit_ptr_descriptor emits DW_OP_implicit_pointer
without a target value description
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: ---
GCC describes the local pointer using DW_OP_implicit_pointer referencing
the DIE for object. That DIE exists, but has neither DW_AT_location nor
DW_AT_const_value, so the reference provides no way to reconstruct the
value of *pointer.
Reproducer source (repro.c):
__attribute__ ((noinline, noclone))
int probe (int control)
{
int object = control;
int *pointer = &object;
if (pointer == 0)
return 1;
return control;
}
Compile to an object:
gcc -O2 -g -gdwarf-5 -c repro.c -o repro.o
Compiler Explorer example: https://godbolt.org/z/o6MYjje7v
Relevant readelf excerpts from .debug_info:
<2><63>: Abbrev Number: 4 (DW_TAG_variable)
<64> DW_AT_name : (indirect string, offset: 0x5e): object
<68> DW_AT_decl_file : 1
<69> DW_AT_decl_line : 4
<6a> DW_AT_decl_column : 7
<6b> DW_AT_type : <0x84>
<2><6f>: Abbrev Number: 5 (DW_TAG_variable)
<70> DW_AT_name : (indirect string, offset: 0x6d): pointer
<74> DW_AT_decl_file : 1
<75> DW_AT_decl_line : 5
<76> DW_AT_decl_column : 8
<77> DW_AT_type : <0x8b>
<7b> DW_AT_location : 0xe (location list)
<7f> DW_AT_GNU_locviews: 0xc
<2><83>: Abbrev Number: 0
>From .debug_loclists:
0000000e v000000000000003 v000000000000000 views at 0000000c for:
0000000000000000 0000000000000003 (DW_OP_implicit_pointer:
<0x63> 0)
00000018 <End of list>
The location list at 0x0e makes pointer refer to object DIE 0x63, with byte
offset 0. All attributes of object are shown above: neither value
attribute is present, and there is no DW_AT_abstract_origin or
DW_AT_specification from which one could be inherited.
DWARF 5 section 2.6.1.1.4, item 3 (page 41), defines the first operand as
a reference to "a debugging information entry that describes the
dereferenced object's value", using DW_AT_location or DW_AT_const_value.
The issue is not simply that object was optimized away, but that GCC
retains an implicit-pointer reference without the required value source.
In gcc/dwarf2out.cc, implicit_ptr_descriptor creates this reference without
checking the target's value attributes. GCC should validate the target's
final attributes and either preserve its value description or omit
pointer's unavailable location description.