http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59515

            Bug ID: 59515
           Summary: -Og doesn't generate out-of-line copies of inline
                    functions like -O0 does
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: debug
          Assignee: unassigned at gcc dot gnu.org
          Reporter: naesten at gmail dot com

For example:

naesten@hydrogen:~/hacking/bugs/gcc$ cat Og-inline-methods.cc
struct Foo {
    int bar() {
        return 42;
    }
};

Foo foo;

int main() {
    return foo.bar() - foo.bar();
}
naesten@hydrogen:~/hacking/bugs/gcc$ g++ --version
g++ (Debian 4.8.2-1) 4.8.2
Copyright (C) 2013 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.

naesten@hydrogen:~/hacking/bugs/gcc$ g++ -Og -g Og-inline-methods.cc
naesten@hydrogen:~/hacking/bugs/gcc$ gdb a.out
GNU gdb (GDB) 7.6.1 (Debian 7.6.1-1)
Copyright (C) 2013 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.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i486-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /home/naesten/hacking/bugs/gcc/a.out...done.
(gdb) start
Temporary breakpoint 1 at 0x804846d: file Og-inline-methods.cc, line 11.
Starting program: /home/naesten/hacking/bugs/gcc/a.out 
warning: Could not load shared library symbols for linux-gate.so.1.
Do you need "set solib-search-path" or "set sysroot"?
Traceback (most recent call last):
  File "/usr/lib/debug//usr/lib/i386-linux-gnu/libstdc++.so.6.0.18-gdb.py",
line
 63, in <module>                                                               
    from libstdcxx.v6.printers import register_libstdcxx_printers
ImportError: No module named libstdcxx.v6.printers

Temporary breakpoint 1, main () at Og-inline-methods.cc:11
11      }
(gdb) print foo.bar()
Cannot evaluate function -- may be inlined
(gdb) continue
Continuing.
[Inferior 1 (process 19256) exited normally]


The problem here is that I get "Cannot evaluate function -- may be inlined" for
an expression appearing in my program.  This does not happen with -O0, with the
result that I routinely build a reasonably large C++ program that I work on
with -O0 rather than -Og.

(Of course, the functions in the real program are slightly more useful than
this one is ;-)

I would prefer if an out-of-line copy would also be emitted in those
compilation units that actually call a given inline function, like happens with
-O0, but I guess even -fkeep-inline-functions *might* be preferable to this,
despite how wasteful it would be.

Reply via email to