public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/54861] New: std::atomic_signal_fence(std::memory_order_seq_cst) issues unnecessary mfence
@ 2012-10-08 21:21 ozabluda at gmail dot com
  2012-10-08 21:27 ` [Bug libstdc++/54861] " redi at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: ozabluda at gmail dot com @ 2012-10-08 21:21 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54861

             Bug #: 54861
           Summary: std::atomic_signal_fence(std::memory_order_seq_cst)
                    issues unnecessary mfence
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: ozabluda@gmail.com
              Host: x86_64-linux-gnu
            Target: x86_64-linux-gnu
             Build: x86_64-linux-gnu


Created attachment 28394
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28394
Preprocessed source

#include <atomic>
void f() { std::atomic_signal_fence(std::memory_order_seq_cst); }

f():
.LFB321:
        .cfi_startproc
        mfence # <== unnecessary mfence
        ret
        .cfi_endproc

The reason is that std::atomic_signal_fence() (in bits/atomic_base.h) simply
calls std::atomic_thread_fence(), where mfence is indeed necessary.

C++11 29.8.8 says:

extern "C" void atomic_signal_fence(memory_order order) noexcept;

Effects: equivalent to atomic_thread_fence(order), except that the resulting
ordering constraints are established only between a thread and a signal handler
executed in the same thread.

8 Note: compiler optimizations and reorderings of loads and stores are
inhibited in the same way as with atomic_thread_fence, but the hardware fence
instructions that atomic_thread_fence would have inserted are not emitted.

C11 7.17.4.2 has an identical language.

===============================


$ g++-4.7 -v -save-temps --std=c++0x -O2 -c atomic_fences.cpp  
Using built-in specs.
COLLECT_GCC=g++-4.7
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro
4.7.0-7ubuntu3' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs
--enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.7 --enable-shared --enable-linker-build-id
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7
--libdir=/usr/lib --enable-nls --disable-bootstrap --with-sysroot=/
--enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes
--enable-gnu-unique-object --enable-plugin --enable-objc-gc --disable-werror
--with-arch-32=i686 --with-tune=generic --enable-checking=release
--build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.7.0 (Ubuntu/Linaro 4.7.0-7ubuntu3) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++11' '-O2' '-c' '-shared-libgcc'
'-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/4.7/cc1plus -E -quiet -v -imultiarch
x86_64-linux-gnu -D_GNU_SOURCE atomic_fences.cpp -mtune=generic -march=x86-64
-std=c++11 -O2 -fpch-preprocess -fstack-protector -o atomic_fences.ii
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory
"/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/4.7
 /usr/include/c++/4.7/x86_64-linux-gnu
 /usr/include/c++/4.7/backward
 /usr/lib/gcc/x86_64-linux-gnu/4.7/include
 /usr/local/include
 /usr/lib/gcc/x86_64-linux-gnu/4.7/include-fixed
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++11' '-O2' '-c' '-shared-libgcc'
'-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/4.7/cc1plus -fpreprocessed atomic_fences.ii
-quiet -dumpbase atomic_fences.cpp -mtune=generic -march=x86-64 -auxbase
atomic_fences -O2 -std=c++11 -version -fstack-protector -o atomic_fences.s
GNU C++ (Ubuntu/Linaro 4.7.0-7ubuntu3) version 4.7.0 (x86_64-linux-gnu)
    compiled by GNU C version 4.6.3, GMP version 5.0.2, MPFR version 3.1.0-p3,
MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C++ (Ubuntu/Linaro 4.7.0-7ubuntu3) version 4.7.0 (x86_64-linux-gnu)
    compiled by GNU C version 4.6.3, GMP version 5.0.2, MPFR version 3.1.0-p3,
MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 33e4f0c75e4f7f1ac5eae22180dee261
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++11' '-O2' '-c' '-shared-libgcc'
'-mtune=generic' '-march=x86-64'
 as --64 -o atomic_fences.o atomic_fences.s
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.7/:/usr/lib/gcc/x86_64-linux-gnu/4.7/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.7/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.7/:/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-std=c++11' '-O2' '-c' '-shared-libgcc'
'-mtune=generic' '-march=x86-64'


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

* [Bug libstdc++/54861] std::atomic_signal_fence(std::memory_order_seq_cst) issues unnecessary mfence
  2012-10-08 21:21 [Bug c++/54861] New: std::atomic_signal_fence(std::memory_order_seq_cst) issues unnecessary mfence ozabluda at gmail dot com
@ 2012-10-08 21:27 ` redi at gcc dot gnu.org
  2012-10-09 18:34 ` amacleod at redhat dot com
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: redi at gcc dot gnu.org @ 2012-10-08 21:27 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54861

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c++                         |libstdc++
           Severity|normal                      |enhancement


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

* [Bug libstdc++/54861] std::atomic_signal_fence(std::memory_order_seq_cst) issues unnecessary mfence
  2012-10-08 21:21 [Bug c++/54861] New: std::atomic_signal_fence(std::memory_order_seq_cst) issues unnecessary mfence ozabluda at gmail dot com
  2012-10-08 21:27 ` [Bug libstdc++/54861] " redi at gcc dot gnu.org
@ 2012-10-09 18:34 ` amacleod at redhat dot com
  2012-10-09 18:40 ` amacleod at redhat dot com
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: amacleod at redhat dot com @ 2012-10-09 18:34 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54861

Andrew Macleod <amacleod at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-10-09
         AssignedTo|unassigned at gcc dot       |amacleod at redhat dot com
                   |gnu.org                     |
     Ever Confirmed|0                           |1

--- Comment #1 from Andrew Macleod <amacleod at redhat dot com> 2012-10-09 18:34:08 UTC ---
Created attachment 28402
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28402
patch to resolve the problem

Just a typo in the header file where __atomic_thread_fence() built-in was being
called instead of the __atomic_signal_fence() built-in function.


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

* [Bug libstdc++/54861] std::atomic_signal_fence(std::memory_order_seq_cst) issues unnecessary mfence
  2012-10-08 21:21 [Bug c++/54861] New: std::atomic_signal_fence(std::memory_order_seq_cst) issues unnecessary mfence ozabluda at gmail dot com
  2012-10-08 21:27 ` [Bug libstdc++/54861] " redi at gcc dot gnu.org
  2012-10-09 18:34 ` amacleod at redhat dot com
@ 2012-10-09 18:40 ` amacleod at redhat dot com
  2012-10-09 18:49 ` ozabluda at gmail dot com
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: amacleod at redhat dot com @ 2012-10-09 18:40 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54861

--- Comment #2 from Andrew Macleod <amacleod at redhat dot com> 2012-10-09 18:40:16 UTC ---
Author: amacleod
Date: Tue Oct  9 18:40:02 2012
New Revision: 192268

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=192268
Log:

2012-10-09  Andrew MacLeod  <amacleod@redhat.com>

    PR libstdc++/54861
    * include/bits/atomic_base.h (atomic_signal_fence): Call
    __atomic_signal_fence instead of __atomic_thread_fence.


Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/bits/atomic_base.h


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

* [Bug libstdc++/54861] std::atomic_signal_fence(std::memory_order_seq_cst) issues unnecessary mfence
  2012-10-08 21:21 [Bug c++/54861] New: std::atomic_signal_fence(std::memory_order_seq_cst) issues unnecessary mfence ozabluda at gmail dot com
                   ` (2 preceding siblings ...)
  2012-10-09 18:40 ` amacleod at redhat dot com
@ 2012-10-09 18:49 ` ozabluda at gmail dot com
  2012-10-10 20:48 ` amacleod at redhat dot com
  2013-11-19 14:03 ` glisse at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: ozabluda at gmail dot com @ 2012-10-09 18:49 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54861

--- Comment #3 from Oleg Zabluda <ozabluda at gmail dot com> 2012-10-09 18:48:56 UTC ---
I can confirm that this fixes it in gcc 4.7.0.


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

* [Bug libstdc++/54861] std::atomic_signal_fence(std::memory_order_seq_cst) issues unnecessary mfence
  2012-10-08 21:21 [Bug c++/54861] New: std::atomic_signal_fence(std::memory_order_seq_cst) issues unnecessary mfence ozabluda at gmail dot com
                   ` (3 preceding siblings ...)
  2012-10-09 18:49 ` ozabluda at gmail dot com
@ 2012-10-10 20:48 ` amacleod at redhat dot com
  2013-11-19 14:03 ` glisse at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: amacleod at redhat dot com @ 2012-10-10 20:48 UTC (permalink / raw)
  To: gcc-bugs


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54861

--- Comment #4 from Andrew Macleod <amacleod at redhat dot com> 2012-10-10 20:47:48 UTC ---
Author: amacleod
Date: Wed Oct 10 20:47:39 2012
New Revision: 192332

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=192332
Log:

2012-10-10  Andrew MacLeod  <amacleod@redhat.com>

    PR libstdc++/54861
    * include/bits/atomic_base.h (atomic_signal_fence): Call
    __atomic_signal_fence instead of __atomic_thread_fence.


Modified:
    branches/gcc-4_7-branch/libstdc++-v3/ChangeLog
    branches/gcc-4_7-branch/libstdc++-v3/include/bits/atomic_base.h


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

* [Bug libstdc++/54861] std::atomic_signal_fence(std::memory_order_seq_cst) issues unnecessary mfence
  2012-10-08 21:21 [Bug c++/54861] New: std::atomic_signal_fence(std::memory_order_seq_cst) issues unnecessary mfence ozabluda at gmail dot com
                   ` (4 preceding siblings ...)
  2012-10-10 20:48 ` amacleod at redhat dot com
@ 2013-11-19 14:03 ` glisse at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: glisse at gcc dot gnu.org @ 2013-11-19 14:03 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54861

Marc Glisse <glisse at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #5 from Marc Glisse <glisse at gcc dot gnu.org> ---
>From the comments, seems that this was fixed and Andrew just forgot to close
the PR.


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

end of thread, other threads:[~2013-11-19 14:03 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-08 21:21 [Bug c++/54861] New: std::atomic_signal_fence(std::memory_order_seq_cst) issues unnecessary mfence ozabluda at gmail dot com
2012-10-08 21:27 ` [Bug libstdc++/54861] " redi at gcc dot gnu.org
2012-10-09 18:34 ` amacleod at redhat dot com
2012-10-09 18:40 ` amacleod at redhat dot com
2012-10-09 18:49 ` ozabluda at gmail dot com
2012-10-10 20:48 ` amacleod at redhat dot com
2013-11-19 14:03 ` glisse 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).