public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/96196] New: infinite loop removed by optimizer
@ 2020-07-14 14:41 ingo at hannover dot ccc.de
  2020-07-14 14:48 ` [Bug c++/96196] " ktkachov at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: ingo at hannover dot ccc.de @ 2020-07-14 14:41 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96196
           Summary: infinite loop removed by optimizer
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ingo at hannover dot ccc.de
  Target Milestone: ---

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

If compiled with any of -Ofast -Os -O3 or -O2, g++ will optimize the while loop
away and exit immediately, when it should run forever.

#include <iostream>
#include <vector>

int main() {
        const std::vector<int> a{1};
        std::vector<int> b;

        std::cout << "before loop: " << b.size() << " < " << a.size() << "\n";

        while(b.size() < a.size()) {
                // uncommenting this fixes the loop with -O2
                //std::cout << ".";
        }
        std::cout << "after loop: " << b.size() << " < " << a.size() << "\n";
}

This bug occurs at least with g++ from the following debian packages:
* g++-10 (version 1:10.1.0-4)
* g++-10 (version 1:10.1.0-5)
* gcc-snapshot (version 1:20200616-1)
gcc version 9 seems fine, also clang-9 and clang-10.

Output from g++-10 version 1:10.1.0-5:

$ g++-10 -v -save-temps -O2 infloop.cc -o infloop
Using built-in specs.
COLLECT_GCC=g++-10
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/10/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:amdgcn-amdhsa:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 10.1.0-5'
--with-bugurl=file:///usr/share/doc/gcc-10/README.Bugs
--enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix=/usr
--with-gcc-major-version-only --program-suffix=-10
--program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new
--enable-gnu-unique-object --disable-vtable-verify --enable-plugin
--enable-default-pie --with-system-zlib --enable-libphobos-checking=release
--with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch
--disable-werror --with-arch-32=i686 --with-abi=m64
--with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic
--enable-offload-targets=nvptx-none=/build/gcc-10-pmMab1/gcc-10-10.1.0/debian/tmp-nvptx/usr,amdgcn-amdhsa=/build/gcc-10-pmMab1/gcc-10-10.1.0/debian/tmp-gcn/usr,hsa
--without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 10.1.1 20200713 (Debian 10.1.0-5) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-O2' '-o' 'infloop' '-shared-libgcc'
'-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/10/cc1plus -E -quiet -v -imultiarch
x86_64-linux-gnu -D_GNU_SOURCE infloop.cc -mtune=generic -march=x86-64 -O2
-fpch-preprocess -fasynchronous-unwind-tables -o infloop.ii
ignoring duplicate directory "/usr/include/x86_64-linux-gnu/c++/10"
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/10/include-fixed"
ignoring nonexistent directory
"/usr/lib/gcc/x86_64-linux-gnu/10/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/10
 /usr/include/x86_64-linux-gnu/c++/10
 /usr/include/c++/10/backward
 /usr/lib/gcc/x86_64-linux-gnu/10/include
 /usr/local/include
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-O2' '-o' 'infloop' '-shared-libgcc'
'-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/10/cc1plus -fpreprocessed infloop.ii -quiet
-dumpbase infloop.cc -mtune=generic -march=x86-64 -auxbase infloop -O2 -version
-fasynchronous-unwind-tables -o infloop.s
GNU C++14 (Debian 10.1.0-5) version 10.1.1 20200713 (x86_64-linux-gnu)
        compiled by GNU C version 10.1.1 20200713, GMP version 6.2.0, MPFR
version 4.0.2, MPC version 1.1.0, isl version isl-0.22.1-GMP

warning: MPFR header version 4.0.2 differs from library version 4.1.0.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C++14 (Debian 10.1.0-5) version 10.1.1 20200713 (x86_64-linux-gnu)
        compiled by GNU C version 10.1.1 20200713, GMP version 6.2.0, MPFR
version 4.0.2, MPC version 1.1.0, isl version isl-0.22.1-GMP

warning: MPFR header version 4.0.2 differs from library version 4.1.0.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 6cd36725701c85e62ce50f8955bd2a9a
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-O2' '-o' 'infloop' '-shared-libgcc'
'-mtune=generic' '-march=x86-64'
 as -v --64 -o infloop.o infloop.s
GNU assembler version 2.34.90 (x86_64-linux-gnu) using BFD version (GNU
Binutils for Debian) 2.34.90.20200706
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/10/:/usr/lib/gcc/x86_64-linux-gnu/10/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/10/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/10/:/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/10/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/10/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-O2' '-o' 'infloop' '-shared-libgcc'
'-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/10/collect2 -plugin
/usr/lib/gcc/x86_64-linux-gnu/10/liblto_plugin.so
-plugin-opt=/usr/lib/gcc/x86_64-linux-gnu/10/lto-wrapper
-plugin-opt=-fresolution=infloop.res -plugin-opt=-pass-through=-lgcc_s
-plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lc
-plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lgcc --build-id
--eh-frame-hdr -m elf_x86_64 --hash-style=gnu --as-needed -dynamic-linker
/lib64/ld-linux-x86-64.so.2 -pie -o infloop
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/Scrt1.o
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crti.o
/usr/lib/gcc/x86_64-linux-gnu/10/crtbeginS.o -L/usr/lib/gcc/x86_64-linux-gnu/10
-L/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu
-L/usr/lib/gcc/x86_64-linux-gnu/10/../../../../lib -L/lib/x86_64-linux-gnu
-L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib
-L/usr/lib/gcc/x86_64-linux-gnu/10/../../.. infloop.o -lstdc++ -lm -lgcc_s
-lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-linux-gnu/10/crtendS.o
/usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crtn.o
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-O2' '-o' 'infloop' '-shared-libgcc'
'-mtune=generic' '-march=x86-64'

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/96196] infinite loop removed by optimizer
  2020-07-14 14:41 [Bug c++/96196] New: infinite loop removed by optimizer ingo at hannover dot ccc.de
@ 2020-07-14 14:48 ` ktkachov at gcc dot gnu.org
  2020-07-14 14:54 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: ktkachov at gcc dot gnu.org @ 2020-07-14 14:48 UTC (permalink / raw)
  To: gcc-bugs

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

ktkachov at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ktkachov at gcc dot gnu.org

--- Comment #1 from ktkachov at gcc dot gnu.org ---
This is -ffinite-loops which is on by default and was added in GCC 10.1
https://gcc.gnu.org/onlinedocs/gcc-10.1.0/gcc/Optimize-Options.html#Optimize-Options

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/96196] infinite loop removed by optimizer
  2020-07-14 14:41 [Bug c++/96196] New: infinite loop removed by optimizer ingo at hannover dot ccc.de
  2020-07-14 14:48 ` [Bug c++/96196] " ktkachov at gcc dot gnu.org
@ 2020-07-14 14:54 ` jakub at gcc dot gnu.org
  2024-03-21 21:47 ` pinskia at gcc dot gnu.org
  2024-03-21 21:48 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-07-14 14:54 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
This is not a valid C++ program, see https://eel.is/c++draft/intro.progress#1

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/96196] infinite loop removed by optimizer
  2020-07-14 14:41 [Bug c++/96196] New: infinite loop removed by optimizer ingo at hannover dot ccc.de
  2020-07-14 14:48 ` [Bug c++/96196] " ktkachov at gcc dot gnu.org
  2020-07-14 14:54 ` jakub at gcc dot gnu.org
@ 2024-03-21 21:47 ` pinskia at gcc dot gnu.org
  2024-03-21 21:48 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-21 21:47 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |earlephilhower at yahoo dot com

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 114421 has been marked as a duplicate of this bug. ***

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/96196] infinite loop removed by optimizer
  2020-07-14 14:41 [Bug c++/96196] New: infinite loop removed by optimizer ingo at hannover dot ccc.de
                   ` (2 preceding siblings ...)
  2024-03-21 21:47 ` pinskia at gcc dot gnu.org
@ 2024-03-21 21:48 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-03-21 21:48 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|INVALID                     |DUPLICATE

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---


*** This bug has been marked as a duplicate of bug 93041 ***

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-03-21 21:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-14 14:41 [Bug c++/96196] New: infinite loop removed by optimizer ingo at hannover dot ccc.de
2020-07-14 14:48 ` [Bug c++/96196] " ktkachov at gcc dot gnu.org
2020-07-14 14:54 ` jakub at gcc dot gnu.org
2024-03-21 21:47 ` pinskia at gcc dot gnu.org
2024-03-21 21:48 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).