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

            Bug ID: 91355
           Summary: optimized code does not call destructor while
                    unwinding after exception
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rupprecht at cipsoft dot com
  Target Milestone: ---

Created attachment 46671
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=46671&action=edit
Example code triggering the bug.

Compile command:
g++ -std=c++11 -O2 code.cpp

The optimized code generated by gcc does not call the destructor of the
automatic variable after throwing an exception. To trigger this bug,
compilation with -O2 optimization is necessary (-O1 does not suffice).
Moreover, the affected function must have a throw declaration.
The attached program should output "0", but it prints "1".
Tests with the compilers at godbolt.org revealed that the bug occurs from gcc
8.0 through gcc trunk. The bug does not occur up to gcc 7.4

Link to godbolt:
https://godbolt.org/z/IEWmYA

System: CentOS 7.6 (devtoolset-8)
gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-8/root/usr/libexec/gcc/x86_64-redhat-linux/8/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap
--enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-8/root/usr
--mandir=/opt/rh/devtoolset-8/root/usr/share/man
--infodir=/opt/rh/devtoolset-8/root/usr/share/info
--with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared
--enable-threads=posix --enable-checking=release --enable-multilib
--with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions
--enable-gnu-unique-object --enable-linker-build-id
--with-gcc-major-version-only --with-linker-hash-style=gnu
--with-default-libstdcxx-abi=gcc4-compatible --enable-plugin
--enable-initfini-array
--with-isl=/builddir/build/BUILD/gcc-8.3.1-20190311/obj-x86_64-redhat-linux/isl-install
--disable-libmpx --enable-gnu-indirect-function --with-tune=generic
--with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 8.3.1 20190311 (Red Hat 8.3.1-3) (GCC)

Reply via email to