https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84121
Bug ID: 84121 Summary: optimizer breaks code without -frwapv, but -Wall -Wextra show no warnings Product: gcc Version: 7.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: noreply at nullhomotopie dot de Target Milestone: --- Created attachment 43285 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=43285&action=edit test code The attached program runs into an endless loop when compiled with gcc -O3 -o itest ./itest.c -Wall -Wextra Removing "-O3" or adding "-fwrapv" or changing the "int fac" in the code to "unsigned int fac" fixes the issue. A debug statement shows that the loop of the form while(fac) { printf("fac=%d\n",fac); ... } is not left, even though "fac" is eventually zero. (If this is a bug in the code I would expect at least a compiler warning.) The output of gcc -v is COLLECT_GCC=/home/cn/mygcc73/bin/gcc COLLECT_LTO_WRAPPER=/home/cn/mygcc73/libexec/gcc/x86_64-pc-linux-gnu/7.3.0/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: ./configure --prefix=/home/cn/mygcc73 --disable-multilib Thread model: posix gcc version 7.3.0 (GCC)