From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 475F13858016; Tue, 15 Feb 2022 15:46:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 475F13858016 From: "assaiante at diag dot uniroma1.it" To: gcc-bugs@gcc.gnu.org Subject: [Bug debug/104549] New: Missing variable at O2/O3 likely caused by -fearly-inlining Date: Tue, 15 Feb 2022 15:46:39 +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, 15 Feb 2022 15:46:39 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D104549 Bug ID: 104549 Summary: Missing variable at O2/O3 likely caused by -fearly-inlining 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 the following testing code, local variable i, which gets passed as argum= ent to a function defined in an external module, is not visible upon the call w= hen debugging. This behavior only occurs when the optimization level is O2 or O= 3. $ cat a.c void a() { int i =3D 0; for (; i ; ) {} test(i) ; } int main() { a(); } $ cat lib.c #include void nop() { printf("\n"); } void test(int i) { printf("%d", i); } GCC and GDB version (GCC commit id: 500d3f0a302): $ gcc --version gcc (GCC) 12.0.0 20211227 (experimental) Copyright (C) 2021 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ gdb --version GNU gdb (GDB) 11.2 Copyright (C) 2022 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. GDB trace: $ gcc -O2 -g a.c lib.c -o opt # <- same exact with O3 $ gdb -q opt Reading symbols from opt... (gdb) b 5 Breakpoint 1 at 0x400460: /home/stepping/66/reduce/a.c:5. (2 locations) (gdb) r Starting program: /home/stepping/66/reduce/opt=20 Breakpoint 1, main () at a.c:5 5 test(i) (gdb) info locals No locals. Through some testing we found out that the optimization flag that introduces the bug is likely -fearly-inlining, which makes main() call the test() func= tion directly. Indeed, if we add the flag -fno-early-inlining to the compilation command line used above, the variable i will appear in the current frame wi= th its value correctly available.=