public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/59767] New: __atomic_load_n with __ATOMIC_SEQ_CST should result in a memory barrier
@ 2014-01-11  2:09 mikulas at artax dot karlin.mff.cuni.cz
  2015-07-02 16:35 ` [Bug target/59767] " jamrial at gmail dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: mikulas at artax dot karlin.mff.cuni.cz @ 2014-01-11  2:09 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 59767
           Summary: __atomic_load_n with __ATOMIC_SEQ_CST should result in
                    a memory barrier
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mikulas at artax dot karlin.mff.cuni.cz
              Host: x86_64-unknown-linux-gnu
            Target: x86_64-unknown-linux-gnu
             Build: x86_64-unknown-linux-gnu

The following function:
int f(void)
{
        int x;
        return __atomic_load_n(&x, __ATOMIC_SEQ_CST);
}
results in this code when compiled with -O2:
f:
.LFB0:
        .cfi_startproc
        movl    -4(%rsp), %eax
        ret
        .cfi_endproc
.LFE0:

The flag "__ATOMIC_SEQ_CST" should imply a full memory barrier before and after
the operation, but there is no barrier in the generated code.

The bug also exists in 32-bit mode and in x32 mode.

You should place a "mfence" instruction before the movl instruction that loads
the value.

I believe that it is not necessary to place the mfence instruction after the
memory load, but you should better check the ia32 specification for that.


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

end of thread, other threads:[~2015-07-09 11:40 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-11  2:09 [Bug target/59767] New: __atomic_load_n with __ATOMIC_SEQ_CST should result in a memory barrier mikulas at artax dot karlin.mff.cuni.cz
2015-07-02 16:35 ` [Bug target/59767] " jamrial at gmail dot com
2015-07-06 14:21 ` amacleod at redhat dot com
2015-07-06 15:00 ` mikulas at artax dot karlin.mff.cuni.cz
2015-07-06 16:16 ` amacleod at redhat dot com
2015-07-06 17:06 ` mikulas at artax dot karlin.mff.cuni.cz
2015-07-06 18:40 ` amacleod at redhat dot com
2015-07-06 22:36 ` torvald at gcc dot gnu.org
2015-07-09 11:40 ` amacleod at redhat dot com

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).