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

            Bug ID: 88646
           Summary: Optimizer failure on integer sum overflow cast to bool
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gianni at mariani dot ws
  Target Milestone: ---

Created attachment 45310
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=45310&action=edit
Source code for bug: add_bug.cpp

Compiler --version "g++ (Raspbian 6.3.0-18+rpi1+deb9u1) 6.3.0 20170516".

On a (uname -a):
"Linux raspberrypi 4.14.79-v7+ #1159 SMP Sun Nov 4 17:50:20 GMT 2018 armv7l
GNU/Linux"

The attached file runs fine without optimization but fails on signed integers
>31 bits in size only in the optimized case.

Note:
g++ --std=c++14 -O3    add_bug.cpp   -o add_bug

out:
ERROR: add_bug.cpp:90 Failed the N test l_v=0 i=33 w_T=i
ERROR: add_bug.cpp:90 Failed the N test l_v=0 i=33 w_T=l
ERROR: add_bug.cpp:90 Failed the N test l_v=0 i=65 w_T=x

The reason is add_bug.cpp:88. i.e.:

for ( int i = 2; l_v += l_v, l_v; ++ i )

The termination condition is l_v += l_v which should terminate when
l_v==(1<<31) for l_v of 32 bit integer types.

Reply via email to