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

            Bug ID: 90349
           Summary: missing return with turned on 03 causes infinite loop
           Product: gcc
           Version: 8.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: volconscious at gmail dot com
  Target Milestone: ---

Hello,

I have g++ 8.2.0 (mingw - windows). If I compile this program (notice - program
is not fully correct, there is a missing return statement)

#include <stdio.h>

int test()
{
        for (int i = 0; i < 4; i++)
        {
                printf("i: %d\n", i);
        }
        //return 0;
}


int main()
{
        test();
        return 0;
}

with O3 optimization (g++ test.cpp -O3 -o test.exe), it generates infinite
loop:

.LC0:
        .string "i: %d\n"
test():
        push    rbx
        xor     ebx, ebx
.L2:
        mov     esi, ebx
        mov     edi, OFFSET FLAT:.LC0
        xor     eax, eax
        add     ebx, 1
        call    printf
        jmp     .L2
main:
        sub     rsp, 8
        call    test()

Reply via email to