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

            Bug ID: 78535
           Summary: [6.2] invalid code generation with -O1 -fdevirtualize
           Product: gcc
           Version: 6.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ipa
          Assignee: unassigned at gcc dot gnu.org
          Reporter: daniel.f.starke at freenet dot de
  Target Milestone: ---

Using GCC:
Target: x86_64-w64-mingw32
Configured with: ../../src/gcc-6.2.0/configure --host=x86_64-w64-mingw32
--enable-languages=c,c++ --enable-seh-exceptions --enable-threads=posix
--enable-tls --disable-nls --enable-shared=libstdc++ --enable-static
--enable-fully-dynamic-string --enable-lto --enable-plugins --enable-libgomp
--with-dwarf2 --disable-win32-registry --enable-version-specific-runtime-libs
--prefix=/mingw64-64 --with-sysroot=/mingw64-64 --target=x86_64-w64-mingw32
--enable-targets=all --enable-checking=release
--with-gmp=/usr/new-gcc/lib/gmp-5.0.5 --with-mpfr=/usr/new-gcc/lib/mpfr-2.4.2
--with-mpc=/usr/new-gcc/lib/mpc-0.9 --with-isl=/usr/new-gcc/lib/isl-0.14.1
--with-cloog=/usr/new-gcc/lib/cloog-0.18.3 --with-host-libstdcxx='-lstdc++
-lsupc++' --disable-cloog-version-check --enable-cloog-backend=isl
Thread model: posix

I get a segmentation fault when compiling a simple hello world C++ application
(libstdc++ was build with lto enabled).
#include <iostream>
int main() {
        std::cout << "Hello World!" << std::endl;
        return 0;
}
This may be related to PR 71207.

The issue occurs when enabling -flto -O1 -fdevirtualize and not with -flto -O0
-fdevirtualize. I tried to isolate the additional -O1 enabled optimization by
enabling all options that were enabled by -O1 (by comparing the outputs of -Q
-v) manually but the problem did not occur. I noticed that -finline was not
enabled this way, however, passing -fno-inline to the problematic command-line
(with -O1) did produce the same flags in the -Q -v output as when I enabled all
options manually additional to -O0. But it did result in a erroneous
executable. So I assume that there are more options set than shown by -Q -v
when enabling -O1 that finally lead to the issue or these options were passed
differently to the lto stage.

The backtrace looks like this:
#0  0x0000000000000000 in ?? ()
No symbol table info available.
#1  0x00000000004ded8a in widen (__c=10 '\n', this=0x4e9180 <(anonymous
namespace)::ctype_c>)
    at
E:/msys/new-gcc/bin64-64/gcc-6.2.0/x86_64-w64-mingw32/libstdc++-v3/include/bits/locale_facets.h:877
        __c = 10 '\n'
        this = 0x4e9180 <(anonymous namespace)::ctype_c>
#2  widen (__c=10 '\n', this=<optimized out>) at
E:/msys/new-gcc/bin64-64/gcc-6.2.0/x86_64-w64-mingw32/libstdc++-v3/include/bits/basic_ios.h:450
No locals.
#3  std::endl<char, std::char_traits<char> > (__os=...) at
E:/msys/new-gcc/bin64-64/gcc-6.2.0/x86_64-w64-mingw32/libstdc++-v3/include/ostream:591
No locals.
#4  0x00000000004e6f0e in operator<< () at
e:/msys/mingw64-64/lib/gcc/x86_64-w64-mingw32/6.2.0/include/c++/ostream:113
No locals.
#5  main () at test.cpp:4

Reply via email to