From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 0E9FF385800E; Wed, 30 Mar 2022 14:38:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0E9FF385800E From: "assaiante at diag dot uniroma1.it" To: gcc-bugs@gcc.gnu.org Subject: [Bug debug/105108] New: incomplete/incorrect DWARF information at -O1 and -Og after inlining a function returning a constant Date: Wed, 30 Mar 2022 14:38:42 +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: Wed, 30 Mar 2022 14:38:43 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105108 Bug ID: 105108 Summary: incomplete/incorrect DWARF information at -O1 and -Og after inlining a function returning a constant 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_144 is not available when debugging (optimized out) when used in the assignment of variable a. We found this odd since -O2/-O3 generate nearly identical ASM but with comp= lete debug information for l_144. At -O1/-Og the DIE of the variable misses inst= ead the const value attribute. We were not able to pinpoint the root cause to a specific compilation optio= n, but suspect an interaction of inlining and constant propagation. We provide below additional analysis for x64. Then, much to our surprise, when we modify line 4 to assign l_144 with e.g.= 8, the debugger shows 8 instead of 0 as its value at line 7, therefore exposing incorrect debug information. At a first look, this happened also with -O2/O= 3: however, we then found -O2/-O3 DWARF information to be correct (also, lldb displays 0), with the issue likely being a bug in gdb that we will report separately. $ cat a.c int a; char b() { return 0; } int main() { char l_144; short l_165 =3D 128; l_144 =3D b(); a =3D l_144 !=3D l_165; } GCC and GDB version (GCC commit id: 500d3f0a302): > gcc (GCC) 12.0.0 20211227 (experimental) > GNU gdb (GDB) 11.2 GDB trace: $ gcc -Og -g a.c -o opt $ gdb opt Reading symbols from opt... (gdb) b 7 Breakpoint 1 at 0x40048c: file a.c, line 7. (gdb) r Starting program: /home/stepping/35/reduce/opt=20 Breakpoint 1, main () at a.c:7 7 a =3D l_144 !=3D l_165; (gdb) info locals l_144 =3D l_165 =3D 128 ASM at Og (identical at O1): 000000000040048c
: 40048c: c7 05 96 0b 20 00 01 movl $0x1,0x200b96(%rip) # 60102c 400493: 00 00 00=20=20 400496: b8 00 00 00 00 mov $0x0,%eax 40049b: c3 retq=20=20=20=20 40049c: 0f 1f 40 00 nopl 0x0(%rax) DWARF at Og (identical at O1): 0x00000049: DW_TAG_subprogram DW_AT_external (true) DW_AT_name ("main") DW_AT_decl_file ("/home/stepping/35/reduce/a.c") DW_AT_decl_line (3) DW_AT_decl_column (0x05) DW_AT_type (0x00000042 "int") DW_AT_low_pc (0x000000000040048c) DW_AT_high_pc (0x000000000040049c) DW_AT_frame_base (DW_OP_call_frame_cfa) DW_AT_call_all_calls (true) DW_AT_sibling (0x00000085) 0x0000006b: DW_TAG_variable DW_AT_name ("l_144") DW_AT_decl_file ("/home/stepping/35/reduce/a.c") DW_AT_decl_line (4) DW_AT_decl_column (0x08) DW_AT_type (0x00000085 "char") 0x00000077: DW_TAG_variable DW_AT_name ("l_165") DW_AT_decl_file ("/home/stepping/35/reduce/a.c") DW_AT_decl_line (5) DW_AT_decl_column (0x09) DW_AT_type (0x0000008c "short int") DW_AT_const_value (0x80) At higher optimization levels the ASM is nearly the same, except the use of= xor instead of mov to set the return value to zero: 00000000004003a0
: 4003a0: c7 05 82 0c 20 00 01 movl $0x1,0x200c82(%rip) # 60102c 4003a7: 00 00 00=20=20 4003aa: 31 c0 xor %eax,%eax 4003ac: c3 retq=20=20=20=20 4003ad: 0f 1f 00 nopl (%rax) But the variable is correctly visible when stepping on line 7 since the con= st value attribute is present in its debug information: 0x00000045: DW_TAG_subprogram DW_AT_external (true) DW_AT_name ("main") DW_AT_decl_file ("/home/stepping/35/reduce/a.c") DW_AT_decl_line (3) DW_AT_decl_column (0x05) DW_AT_type (0x0000003e "int") DW_AT_low_pc (0x00000000004003a0) DW_AT_high_pc (0x00000000004003ad) DW_AT_frame_base (DW_OP_call_frame_cfa) DW_AT_call_all_calls (true) DW_AT_sibling (0x00000080) 0x00000067: DW_TAG_variable DW_AT_name ("l_144") DW_AT_decl_line (4) DW_AT_decl_column (0x08) DW_AT_type (0x00000080 "char") DW_AT_const_value (0x00) 0x00000073: DW_TAG_variable DW_AT_name ("l_165") DW_AT_decl_line (5) DW_AT_decl_column (0x09) DW_AT_type (0x00000087 "short int") DW_AT_const_value (0x80) We also tested the program with older gcc (6, 7, 8, 9, 10, 11) versions. In gcc-{6,7}, the information about the variable l_144 value is never generate= d at any optimization level. From gcc-8 to gcc-11, we encounter the same exact behavior as in the git version we have tested, including the variant where variable l_144 is assigned upon its definition. In fact, also in older gcc versions, such assignment ultimately leads to a wrong value available during debugging when optimization level is Og or O1. At higher levels, the debug information is correctly generated but, as mentioned before, a potential gdb bug leads to a wrong value being displayed.=