public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug debug/104549] New: Missing variable at O2/O3 likely caused by -fearly-inlining
@ 2022-02-15 15:46 assaiante at diag dot uniroma1.it
  2022-02-15 17:30 ` [Bug debug/104549] " jakub at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: assaiante at diag dot uniroma1.it @ 2022-02-15 15:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104549

            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 argument
to a function defined in an external module, is not visible upon the call when
debugging. This behavior only occurs when the optimization level is O2 or O3.


$ cat a.c
void a()
{
    int i = 0;
    for (; i ; ) {}
    test(i)
     ;
}
int main()
{
    a();
}

$ cat lib.c
#include <stdio.h>

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 <http://gnu.org/licenses/gpl.html>
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 

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() function
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 with
its value correctly available.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-02-17 13:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-15 15:46 [Bug debug/104549] New: Missing variable at O2/O3 likely caused by -fearly-inlining assaiante at diag dot uniroma1.it
2022-02-15 17:30 ` [Bug debug/104549] " jakub at gcc dot gnu.org
2022-02-16 13:01 ` jakub at gcc dot gnu.org
2022-02-17 12:38 ` assaiante at diag dot uniroma1.it
2022-02-17 13:48 ` assaiante at diag dot uniroma1.it

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).