From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 0B6A33858C54; Wed, 13 Apr 2022 11:28:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0B6A33858C54 From: "assaiante at diag dot uniroma1.it" To: gcc-bugs@gcc.gnu.org Subject: [Bug debug/105261] New: schedule-insns2 and ipa-sra make alive constant variables not available Date: Wed, 13 Apr 2022 11:28:20 +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, 13 Apr 2022 11:28:21 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105261 Bug ID: 105261 Summary: schedule-insns2 and ipa-sra make alive constant variables not available 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, none of the local variables from function b is available when stepping on the call to function test() from another module, despite the function taking them all as arguments. This happens when the optimization level is -O2/-O3 or -Os/-Oz. At -O2/-O3, a combination of schedule-insns2 and ipa-sra is behind the incomplete DWARF information for variables l_5, l_53, l_54, l_55 and l_362 (note that all them are constant), as there is no const value or location attribute for them. DWARF information for i and j is correctly computed but= the variables are not shown when debugging due to a possible gdb 11.2 bug. At -Os/-Oz, the issue is caused by ipa-sra alone. By disabling it, all variables appear in the frame and with their value available.=20 Please find below a detailed analysis for -O2 on x64 and a quick assessment= on past gcc versions where the issue is sometimes not present. $ cat a.c int a; static int b() { int l_5 =3D 0, l_54 =3D 5, l_362 =3D 4, i, j; short l_53 =3D 4, l_55 =3D 0; i =3D 0; for (; i < 6; i++) j =3D a ; test(l_5, l_53, l_54, l_55, l_362, i, j); } int main () { b(); } $ cat lib.c #include void test(int l_5, int l_53, int l_54, int l_55, int l_362, int i, int j) { printf("%d %d %d %d %d %d %d", l_5, l_53, l_54, l_55, l_362, i, j); } GCC and GDB version: - gcc (GCC) 12.0.0 20211227 (experimental) - commit id: 500d3f0a302 - GNU gdb (GDB) 11.2 GDB trace: $ gcc -O2 -g a.c lib.c -o opt $ gdb -q opt Reading symbols from opt... (gdb) b 9 Breakpoint 1 at 0x400410: file a.c, line 9. (gdb) r Starting program: /tmp/opt=20 Breakpoint 1, main () at a.c:9 9 test(l_5, l_53, l_54, l_55, l_362, i, j); (gdb) info loc No locals. ASM at -O2: 0000000000400410
: 400410: 48 83 ec 10 sub $0x10,%rsp 400414: 8b 05 1a 0c 20 00 mov 0x200c1a(%rip),%eax # 601034 40041a: 31 c9 xor %ecx,%ecx 40041c: 31 ff xor %edi,%edi 40041e: 41 b9 06 00 00 00 mov $0x6,%r9d 400424: 41 b8 04 00 00 00 mov $0x4,%r8d 40042a: ba 05 00 00 00 mov $0x5,%edx 40042f: be 04 00 00 00 mov $0x4,%esi 400434: 50 push %rax 400435: 31 c0 xor %eax,%eax 400437: e8 04 01 00 00 callq 400540 40043c: 31 c0 xor %eax,%eax 40043e: 48 83 c4 18 add $0x18,%rsp 400442: c3 retq DWARF info at -O2: 0x00000093: DW_TAG_variable DW_AT_abstract_origin (0x00000104 "l_5") 0x00000098: DW_TAG_variable DW_AT_abstract_origin (0x0000010e "l_54") 0x0000009d: DW_TAG_variable DW_AT_abstract_origin (0x00000119 "l_362") 0x000000a2: DW_TAG_variable DW_AT_abstract_origin (0x00000124 "i") DW_AT_location (0x0000001a:=20 [0x0000000000400410, 0x0000000000400410): DW_OP_li= t0, DW_OP_stack_value [0x0000000000400410, 0x0000000000400410): DW_OP_li= t1, DW_OP_stack_value [0x0000000000400410, 0x0000000000400410): DW_OP_li= t2, DW_OP_stack_value [0x0000000000400410, 0x0000000000400410): DW_OP_li= t3, DW_OP_stack_value [0x0000000000400410, 0x0000000000400410): DW_OP_li= t4, DW_OP_stack_value [0x0000000000400410, 0x0000000000400410): DW_OP_li= t5, DW_OP_stack_value [0x0000000000400410, 0x000000000040043c): DW_OP_li= t6, DW_OP_stack_value) DW_AT_GNU_locviews (0x0000000c) 0x000000af: DW_TAG_variable DW_AT_abstract_origin (0x0000012c "j") DW_AT_location (0x00000050:=20 [0x0000000000400410, 0x000000000040043b): DW_OP_ad= dr 0x601034) DW_AT_GNU_locviews (0x0000004e) 0x000000bc: DW_TAG_variable DW_AT_abstract_origin (0x00000134 "l_53") 0x000000c1: DW_TAG_variable DW_AT_abstract_origin (0x0000013f "l_55") >>From DWARF info we can see how only variables i and j have correctly defined locations and values, but those are not shown during debugging due to a possible bug in gdb 11.2 that we report separately. All the other variables have no const value or location attribute associated with, thus they are not available regardless of the debugger. Through some testing we found out that the optimizations that make the vari= able not available are -fschedule-insns2 and -fipa-sra. If we add -fno-schedule-insns2 and -fno-ipa-sra to the previous compilation command l= ine, all the variables are available. In particular, if we add only -fno-schedule-insns2, only variables i and j become available (the DWARF changes and gdb 11.2 can display them). If we a= dd both flags, all the variables become available, but if we add only -fipa-sra nothing changes and no locals are displayed. ASM at -O2 with -fno-schedule-insns2 and -fno-ipa-sra: 0000000000400410
: 400410: 48 83 ec 10 sub $0x10,%rsp 400414: 8b 05 1a 0c 20 00 mov 0x200c1a(%rip),%eax # 601034 40041a: 50 push %rax 40041b: 41 b9 06 00 00 00 mov $0x6,%r9d 400421: 41 b8 04 00 00 00 mov $0x4,%r8d 400427: 31 c9 xor %ecx,%ecx 400429: ba 05 00 00 00 mov $0x5,%edx 40042e: be 04 00 00 00 mov $0x4,%esi 400433: 31 ff xor %edi,%edi 400435: 31 c0 xor %eax,%eax 400437: e8 04 01 00 00 callq 400540 40043c: 31 c0 xor %eax,%eax 40043e: 48 83 c4 18 add $0x18,%rsp 400442: c3 retq DWARF at -O2 with -fno-schedule-insns2 and -fno-ipa-sra: 0x0000009a: DW_TAG_variable DW_AT_abstract_origin (0x0000010f "l_5") DW_AT_const_value (0x00) 0x000000a0: DW_TAG_variable DW_AT_abstract_origin (0x00000119 "l_54") DW_AT_const_value (0x05) 0x000000a6: DW_TAG_variable DW_AT_abstract_origin (0x00000124 "l_362") DW_AT_const_value (0x04) 0x000000ac: DW_TAG_variable DW_AT_abstract_origin (0x0000012f "i") DW_AT_location (0x0000001a:=20 [0x0000000000400414, 0x0000000000400414): DW_OP_lit0, DW_OP_stack_value [0x0000000000400414, 0x0000000000400414): DW_OP_lit1, DW_OP_stack_value [0x0000000000400414, 0x0000000000400414): DW_OP_lit2, DW_OP_stack_value [0x0000000000400414, 0x0000000000400414): DW_OP_lit3, DW_OP_stack_value [0x0000000000400414, 0x0000000000400414): DW_OP_lit4, DW_OP_stack_value [0x0000000000400414, 0x0000000000400414): DW_OP_lit5, DW_OP_stack_value [0x0000000000400414, 0x000000000040043c): DW_OP_lit6, DW_OP_stack_value) DW_AT_GNU_locviews (0x0000000c) 0x000000b9: DW_TAG_variable DW_AT_abstract_origin (0x00000137 "j") DW_AT_location (0x00000050:=20 [0x0000000000400414, 0x000000000040043b): DW_OP_addr 0x601034) DW_AT_GNU_locviews (0x0000004e) 0x000000c6: DW_TAG_variable DW_AT_abstract_origin (0x0000013f "l_53") DW_AT_const_value (0x04) 0x000000cc: DW_TAG_variable DW_AT_abstract_origin (0x0000014a "l_55") DW_AT_const_value (0x00) For -O2/O3 we 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 starting with gcc-8. For previ= ous versions the variables and their values are correctly available. For -Os/Oz= the issue appears instead starting with gcc-10.=