[Boost-bugs] [Boost C++ Libraries] #10850: gcc-x86-implementation of "atomic_exchange_and_add" triggers intel's "unitialized variable" runtime check

Subject: [Boost-bugs] [Boost C++ Libraries] #10850: gcc-x86-implementation of "atomic_exchange_and_add" triggers intel's "unitialized variable" runtime check
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2014-12-04 18:21:44


#10850: gcc-x86-implementation of "atomic_exchange_and_add" triggers intel's
"unitialized variable" runtime check
-------------------------------------+-----------------------
 Reporter: fabian.hachenberg@… | Owner: pdimov
     Type: Patches | Status: new
Milestone: To Be Determined | Component: smart_ptr
  Version: Boost Development Trunk | Severity: Problem
 Keywords: |
-------------------------------------+-----------------------
 The current implementation of atomic_exchange_and_add for gcc x86 is
 (http://svn.boost.org/svn/boost/trunk/boost/smart_ptr/detail/sp_counted_base_gcc_x86.hpp)
 as following:

 inline int atomic_exchange_and_add( int * pw, int dv )
 {
     // int r = *pw;
     // *pw += dv;
     // return r;

     int r;

     __asm__ __volatile__
     (
         "lock\n\t"
         "xadd %1, %0":
         "=m"( *pw ), "=r"( r ): // outputs (%0, %1)
         "m"( *pw ), "1"( dv ): // inputs (%2, %3 == %1)
         "memory", "cc" // clobbers
     );

     return r;
 }

 This unfortunately triggers the "unitialized variable" runtime check of
 the Intel c++ compiler. Since r is actually superfluous, a simple patch
 can fix the problem:

 inline int atomic_exchange_and_add( int * pw, int dv )
 {
     // int r = *pw;
     // *pw += dv;
     // return r;

     __asm__ __volatile__
     (
         "lock\n\t"
         "xadd %1, %0":
         "+m"( *pw ), "+r"( dv ): // input/output (%0, %1)
                 :
         "memory", "cc" // clobbers
     );

     return dv;
 }

 My colleague, who wrote the patch, checked that the generated assembler
 code is almost identical to the original one. "Almost" in the sense, that
 the removal of r changes some offsets.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/10850>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:17 UTC