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

            Bug ID: 81879
           Summary: Bad compilation of small program if LTO is used
           Product: gcc
           Version: 7.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: freddy77 at gmail dot com
  Target Milestone: ---

Created attachment 41994
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=41994&action=edit
preprocessed file

Trying to narrow down an issue I cannot compile and run a really small program
like

#include <iostream>

int main()
{
    std::cout << std::endl;
    return 0;
}

Trying to compile with 

x86_64-w64-mingw32-g++ -flto -O2 -g -pipe -Wall -Werror -Wextra -static
-mconsole -o test.exe test.cpp

It compiles without any warnings but when executed it crashes.
Note that if I remove -flto or -static program run correctly.
>From what Wine reports (but I have a crash even running on Windows directly) it
seems the crash calling do_widen virtual function (null pointer, rax was 0).

I noted different problems with LTO with MinGW, opened also these bugs
- https://bugzilla.redhat.com/show_bug.cgi?id=1475237 (similar to this one)
- https://sourceforge.net/p/mingw/bugs/2346/
- https://bugzilla.redhat.com/show_bug.cgi?id=1455137

I'm using MinGW compiler provided with Fedora 26, specifically:
mingw64-binutils-2.27-2.fc26.x86_64
mingw64-gcc-c++-7.1.0-1.fc26.x86_64
mingw64-headers-5.0.2-1.fc26.noarch

Tried to update binutils (compiler 2.29 version) without success (same crash).

Reply via email to