From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 443783858002; Tue, 12 Apr 2022 17:44:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 443783858002 From: "assaiante at diag dot uniroma1.it" To: gcc-bugs@gcc.gnu.org Subject: [Bug debug/105248] New: Missing value or location attribute for constant live variable likely caused by tree-dse at -O1/-O2/-O3 Date: Tue, 12 Apr 2022 17:44:18 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: debug X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: assaiante at diag dot uniroma1.it X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 12 Apr 2022 17:44:18 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105248 Bug ID: 105248 Summary: Missing value or location attribute for constant live variable likely caused by tree-dse at -O1/-O2/-O3 Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: debug Assignee: unassigned at gcc dot gnu.org Reporter: assaiante at diag dot uniroma1.it Target Milestone: --- In this minimized C example, variable l_56 is marked as optimized out when stepping on a call to an external function that takes it as an argument. Th= is happens then the optimization level is -O1/-O2/-O3 while at -Og the debug information is correctly defined. The variable has constant value. Apparently, tree-dse optimization is responsible for a missing location attribute in the DWARF DIE associated with variable l_56. If we prevent the compiler from performing such optimization, the generated ASM will be ident= ical but the DWARF location info will be complete, making the variable available= in its uses. Please find below a detailed analysis for -O1 on x64 and a quick assessment= on past gcc versions where the issue is sometimes not present. $ cat a.c void a() { int *b; short l_47 =3D 5; int l_56 =3D 6; int **c =3D &b; test(l_47, l_56); *c =3D &l_56; } int main () { a(); } $ cat lib.c #include void test(int l_47, int l_56) { printf("%d %d", l_47, l_56); } GCC and GDB version: - gcc (GCC) 12.0.0 20211227 (experimental) - commit id: 500d3f0a302 - GNU gdb (GDB) 11.2 GDB trace: $ gcc -O1 -g a.c lib.c -o opt $ gdb -q opt Reading symbols from opt... (gdb) b 7 Breakpoint 1 at 0x40054a: file a.c, line 7. (gdb) r Starting program: /tmp/opt=20 Breakpoint 1, a () at a.c:7 7 test(l_47, l_56); (gdb) info locals b =3D l_47 =3D 5 l_56 =3D c =3D ASM at -O1: 0000000000400546 : 400546: 48 83 ec 08 sub $0x8,%rsp 40054a: be 06 00 00 00 mov $0x6,%esi 40054f: bf 05 00 00 00 mov $0x5,%edi 400554: b8 00 00 00 00 mov $0x0,%eax 400559: e8 30 00 00 00 callq 40058e 40055e: 48 83 c4 08 add $0x8,%rsp 400562: c3 retq DWARF info at -O1: 0x000000a7: DW_TAG_variable DW_AT_name ("l_56") DW_AT_decl_file ("/tmp/a.c") DW_AT_decl_line (5) DW_AT_decl_column (0x09) DW_AT_type (0x0000003d "int") >>From DWARF info we can see how the variable l_56 DIE is completely missing either a const value or a location attribute and this lack of information causes the unavailability of its value during debugging. Through some testing we found out that the optimization that makes the vari= able not available and that introduces the location overlapping is -ftree-dse. I= f we add -fno-tree-dse to the previous compilation command line, the issue is not present anymore since the DWARF location is correctly computed with the cor= rect value associated with it. ASM at -O1 with -fno-tree-dse: 0000000000400546 : 400546: 48 83 ec 08 sub $0x8,%rsp 40054a: be 06 00 00 00 mov $0x6,%esi 40054f: bf 05 00 00 00 mov $0x5,%edi 400554: b8 00 00 00 00 mov $0x0,%eax 400559: e8 30 00 00 00 callq 40058e 40055e: 48 83 c4 08 add $0x8,%rsp 400562: c3 retq DWARF info at -O1 with -fno-tree-dse: 0x000000a7: DW_TAG_variable DW_AT_name ("l_56") DW_AT_decl_file ("/tmp/a.c") DW_AT_decl_line (5) DW_AT_decl_column (0x09) DW_AT_type (0x0000003d "int") DW_AT_location (0x0000000e:=20 [0x000000000040054a, 0x000000000040055e): DW_OP_lit6, DW_OP_stack_value) DW_AT_GNU_locviews (0x0000000c) We have also tested older gcc versions (6.4, 7.5, 8.4, 9.3, 10.3, 11.1) and= the results are identical to the git version.=