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

            Bug ID: 93674
           Summary: GCC eliminates conditions it should not, when
                    strict-enums is on
           Product: gcc
           Version: 8.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gbuella at gmail dot com
  Target Milestone: ---

$ cat code.cc

enum some_enum { x = 1000 };

void sink(some_enum);

void func()
{
        for (int i = 0; i < 3; ++i) {
                for (int j = 3; j >= 0; --j) {
                        sink((some_enum)(i + j));
                }
        }
}

$ g++-8 -Wall -Wextra -pedantic -std=c++14 code.cc   -fstrict-enums  -S -o
/dev/stdout -fno-dwarf2-cfi-asm -O3 | head -20
        .file   "code.cc"
        .text
        .p2align 4,,15
        .globl  _Z4funcv
        .type   _Z4funcv, @function
_Z4funcv:
.LFB0:
        pushq   %rbx
.LCFI0:
        movl    $3, %ebx
        .p2align 4,,10
        .p2align 3
.L2:
        movl    %ebx, %edi
        subl    $1, %ebx
        call    _Z4sink9some_enum@PLT
        jmp     .L2
.LFE0:
        .size   _Z4funcv, .-_Z4funcv
        .section        .eh_frame,"a",@progbits

$ g++-8 --version
g++-8 (Ubuntu 8.3.0-6ubuntu1~18.04.1) 8.3.0
Copyright (C) 2018 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.


Notice the infinite loop in generated assembly (unconditional jmp to .L2).
This doesn't happen without "-fstruct-enums", doesn't happen without -O2 or
-O3.
I'v seen this bug with GCC 8, GCC 9 . 
GCC-7 seems to be OK.

I spent hours trying to find more compact code for reproducing it, but I just
couldn't...
The loop, and the addition (i + j) seems to be needed to trigger this.

Reply via email to