[Bug rtl-optimization/69789] New: g++ -O2 is removing tests against a variable that can be changed

tmark at isc dot org gcc-bugzilla@gcc.gnu.org
Fri Feb 12 21:03:00 GMT 2016


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

            Bug ID: 69789
           Summary: g++ -O2 is removing tests against a variable that can
                    be changed
           Product: gcc
           Version: 5.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tmark at isc dot org
  Target Milestone: ---

Our Kea project uses boost::asio. When compiled with gcc 5.3.1 and -O2, the
optimizer is incorrectly removing tests against a variable which can be changed
from one of the boost::asio functions.

1. gcc --version output:

Using built-in specs.
COLLECT_GCC=/usr/bin/gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/5.3.1/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap
--enable-languages=c,c++,objc,obj-c++,fortran,ada,go,lto --prefix=/usr
--mandir=/usr/share/man --infodir=/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-linker-hash-style=gnu --enable-plugin --enable-initfini-array
--disable-libgcj --with-isl --enable-libmpx --enable-gnu-indirect-function
--with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 5.3.1 20151207 (Red Hat 5.3.1-2) (GCC)

2. OS info:

Linux fedora23-64-1 4.3.4-300.fc23.x86_64 #1 SMP Mon Jan 25 13:39:23 UTC 2016
x86_64 x86_64 x86_64 GNU/Linux

3. Compiler command line:

g++ -DHAVE_CONFIG_H -I. -I../../../..  -I../../../../src/lib
-I../../../../src/lib  -DTEST_DATA_DIR=\"./testdata\" -I/opt/gtest/gtest-1.7.0
-I/opt/gtest/gtest-1.7.0/include -DOS_LINUX  -I../../../../ext/coroutine
-DBOOST_ASIO_HEADER_ONLY -DBOOST_ASIO_DISABLE_THREADS=1
-DBOOST_ERROR_CODE_HEADER_ONLY -DBOOST_SYSTEM_NO_DEPRECATED -Wall -Wextra
-Wnon-virtual-dtor -Wwrite-strings -Woverloaded-virtual -Wno-sign-compare
-pthread -Werror -fPIC -Wno-missing-field-initializers -Wno-unused-parameter -g
-O2 -save-temps -MT run_unittests-udp_socket_unittest.o -MD -MP -MF
.deps/run_unittests-udp_socket_unittest.Tpo -c -o
run_unittests-udp_socket_unittest.o `test -f 'udp_socket_unittest.cc' || echo
'./'`udp_socket_unittest.cc

4. I have attached the .ii file

5. BOOST Info:

Version 1.58

The affected function is in the file:

  /usr/include/boost/asio/detail/impl/socket_ops.ipp

and is excerpted below. The tests for ec against interrupted,
would_block, and try_again are optimized out, cauing the function
to always return true:


bool non_blocking_recvfrom(socket_type s,
    buf* bufs, size_t count, int flags,
    socket_addr_type* addr, std::size_t* addrlen,
    boost::system::error_code& ec, size_t& bytes_transferred)
{
  for (;;)
  {
    // Read some data.
    signed_size_type bytes = socket_ops::recvfrom(
        s, bufs, count, flags, addr, addrlen, ec);

    // Retry operation if interrupted by signal.
    if (ec == boost::asio::error::interrupted)
      continue;

    // Check if we need to run the operation again.
    if (ec == boost::asio::error::would_block
        || ec == boost::asio::error::try_again)
      return false;

    // Operation is complete.
    if (bytes >= 0)
    {
      ec = boost::system::error_code();
      bytes_transferred = bytes;
    }
    else
      bytes_transferred = 0;

    return true;
  }
}


More information about the Gcc-bugs mailing list