public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "assaiante at diag dot uniroma1.it" <gcc-bugzilla@gcc.gnu.org>
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	[thread overview]
Message-ID: <bug-104549-4@http.gcc.gnu.org/bugzilla/> (raw)

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.

             reply	other threads:[~2022-02-15 15:46 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-15 15:46 assaiante at diag dot uniroma1.it [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-104549-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).