https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83157
Aldy Hernandez <aldyh at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jakub at gcc dot gnu.org,
| |rguenth at gcc dot gnu.org
--- Comment #4 from Aldy Hernandez <aldyh at gcc dot gnu.org> ---
I am attaching a simplified preprocessed file that exhibits the problem.
Perhaps someone with more debug-fu can comment here.
[tl;dr: Shouldn't local variables in a cloned variable have their own location
lists?].
The following is being cloned into guality_main.constprop(), which in turn is
called from main():
int
guality_main(int argc, char *argv[])
{
int boring = -1;
boring = -f(&boring);
guality_check ("boring", boring, 0);
return boring;
}
[FWIW, guality_main and guality_main.constprop have exactly the same IL, albeit
with different #DEBUG statements. I don't know why we even clone it.]
$ ./a.out
FAIL: guality/guality.h: boring is -1, not 1
FAIL: guality/guality.h: 0 PASS, 1 FAIL, 0 UNRESOLVED
Since guality_main.constprop() is the function being called, let's look for
"boring" in it:
;; guality_main.constprop()
<1><9f0>: Abbrev Number: 42 (DW_TAG_subprogram)
<9f1> DW_AT_abstract_origin: <0x474>
<9f5> DW_AT_low_pc : 0x400e22
<9fd> DW_AT_high_pc : 0x1f
<a05> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
<a07> DW_AT_GNU_all_call_sites: 1
<a07> DW_AT_sibling : <0xa4a>
<2><a0b>: Abbrev Number: 46 (DW_TAG_variable)
<a0c> DW_AT_abstract_origin: <0x9c1>
According to this, "boring" comes from 0x9c1 which is defined in
guality_main(), the original function:
;; guality_main()
<1><994>: Abbrev Number: 42 (DW_TAG_subprogram)
<995> DW_AT_abstract_origin: <0x474>
<999> DW_AT_low_pc : 0x400e03
<9a1> DW_AT_high_pc : 0x1f
<9a9> DW_AT_frame_base : 1 byte block: 9c (DW_OP_call_frame_cfa)
<9ab> DW_AT_GNU_all_call_sites: 1
<9ab> DW_AT_sibling : <0x9f0>
...
<2><9c1>: Abbrev Number: 45 (DW_TAG_variable)
<9c2> DW_AT_abstract_origin: <0x49d> <-- points to DW_TAG_var for
"boring"
<9c6> DW_AT_location : 0x542 (location list)
The location list for this 0x542 has a literal of 1 as expected:
00000542 0000000000400e03 0000000000400e18 (DW_OP_lit1; DW_OP_stack_value)
However, my question is, shouldn't "boring" in guality_main.constprop (0xa0b)
have a DW_AT_location of itself? Because even if if the location of boring in
guality_main.constprop (0xa0b) comes through the abstract origin that
ultimately leeds to...
00000542 0000000000400e03 0000000000400e18 (DW_OP_lit1; DW_OP_stack_value)
This is the wrong address. 0x400e03 through 0x400e18 is in guality_main(), not
in guality_main.constprop() which is the function being called:
0000000000400e03 <guality_main>:
400e03: 48 83 ec 08 sub $0x8,%rsp
400e07: 31 d2 xor %edx,%edx
400e09: be 01 00 00 00 mov $0x1,%esi
400e0e: bf 08 12 40 00 mov $0x401208,%edi
400e13: e8 b3 fd ff ff callq 400bcb <guality_check>
400e18: b8 01 00 00 00 mov $0x1,%eax
400e1d: 48 83 c4 08 add $0x8,%rsp
400e21: c3 retq
Hints, tips, and/or solutions, would be greatly appreciated :).