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

            Bug ID: 97697
           Summary: Segmentation fault on while (true) loop
           Product: gcc
           Version: 9.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: marcin.jachu19 at gmail dot com
  Target Milestone: ---

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

May be a duplicate of 97627, but this time it seg faults, -fwrapv doesn't help
and there is only one for loop inside. It seems to not reach the end of the
while(true) loop and crashes just before. Observed on gcc 9.x and 10.x (all
versions). 

GCC version (in practice any 9.x and 10.x):
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-9.2.0/configure --enable-languages=c,c++
--enable-multilib
Thread model: posix
gcc version 9.2.0 (GCC)
GNU C++17 (GCC) version 9.2.0 (x86_64-pc-linux-gnu)
        compiled by GNU C version 9.2.0, GMP version 4.3.1, MPFR version 2.4.1,
MPC version 0.8, isl version none

System type (doesn't matter, any Linux, for this example used):
centos-release-7-7.1908.0.el7.centos.x86_64

GCC compilation options:
../gcc-9.2.0/configure --enable-languages=c,c++ --enable-multilib

Test compilation options:
g++ -Wall -Wextra -fPIC -O2 -std=c++17 -o test test.cpp

Compiler output:
(none)

Source files attached, the problematic part:

for (unsigned int nrn_idx = 0; nrn_idx < nrn_pass_num; ++nrn_idx)
{
        bar();
}
baz();

Expected behavior:
test enters the end of the loop and prints "all OK"

Actual behavior:
Segmentation fault (core dumped)

Command line
./test

More comments:
- gcc 8.x works OK on this example
- gcc trunk works OK as well
- -fwrapv doesn't change anything, it was helping in 97627
- -O1 works fine

I hoped we can move from 8.x to 9.x using -fwrapv workaround, but it doesn't
help here. Can you please suggest any temporal workaround other than -O1 ?

Reply via email to