public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/58409] New: wrong reordering of volatile writes
@ 2013-09-13  7:23 francesco.zappa.nardelli at gmail dot com
  2013-09-13  7:32 ` [Bug c/58409] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: francesco.zappa.nardelli at gmail dot com @ 2013-09-13  7:23 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 58409
           Summary: wrong reordering of volatile writes
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: francesco.zappa.nardelli at gmail dot com

In the program below, at least according to the C11 standard, there is a
sequence point between the volatile store to g_3[0][0][0] and the volatile
store to *g_6 (that is, to the volatile int g_5).  As a consequence, the store
to g_3 should be performed before the store to g_5.

struct {
  volatile int f1;
} g_1, *g_2 = &g_1, g_3[1][1][1], **g_4 = &g_2;

volatile int g_5;

static volatile int *g_6 = &g_5;

int func_2 () {
  g_3[0][0][0] = **g_4;
  return 0;
}

int func_1 () {
  *g_6 = func_2 ();
  return 0;
}

void main () {
  func_1 ();
}

If the program is compiled with a recent svn trunk 

$ gcc -v
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-svn/configure --disable-bootstrap
--enable-languages=c,c++ 
Thread model: posix
gcc version 4.9.0 20130912 (experimental) (GCC) 

at optimisation level -O2 or -O3 then the generated assembler swaps the store
to g_5 with the store to g_3:

main:
        movq    g_4(%rip), %rax
        movq    (%rax), %rax
        movl    (%rax), %eax
        movl    $0, g_5(%rip)
        movl    %eax, g_3(%rip)
        ret

As far as I can tell, this reordering should be considered as a compiler bug. 
The same happens with gcc 4.8.1.


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

* [Bug c/58409] wrong reordering of volatile writes
  2013-09-13  7:23 [Bug c/58409] New: wrong reordering of volatile writes francesco.zappa.nardelli at gmail dot com
@ 2013-09-13  7:32 ` pinskia at gcc dot gnu.org
  2013-09-13  9:20 ` francesco.zappa.nardelli at gmail dot com
  2013-09-13  9:38 ` rguenth at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2013-09-13  7:32 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Does:
  g_3[0][0][0].f1 = (**g_4).f1;

Fix the issue if so it is a dup of bug 47409 really.


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

* [Bug c/58409] wrong reordering of volatile writes
  2013-09-13  7:23 [Bug c/58409] New: wrong reordering of volatile writes francesco.zappa.nardelli at gmail dot com
  2013-09-13  7:32 ` [Bug c/58409] " pinskia at gcc dot gnu.org
@ 2013-09-13  9:20 ` francesco.zappa.nardelli at gmail dot com
  2013-09-13  9:38 ` rguenth at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: francesco.zappa.nardelli at gmail dot com @ 2013-09-13  9:20 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Francesco Zappa Nardelli <francesco.zappa.nardelli at gmail dot com> ---
Yes, it does fix the issue.  

So this reordering is another effect of gcc not considering accessing volatile
fields in non-volatile structs as volatile access (as in bug 47409).  Can I ask
about gcc plans for bug 47409?  It has been opened for a couple of years
without a clear decision at the end.


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

* [Bug c/58409] wrong reordering of volatile writes
  2013-09-13  7:23 [Bug c/58409] New: wrong reordering of volatile writes francesco.zappa.nardelli at gmail dot com
  2013-09-13  7:32 ` [Bug c/58409] " pinskia at gcc dot gnu.org
  2013-09-13  9:20 ` francesco.zappa.nardelli at gmail dot com
@ 2013-09-13  9:38 ` rguenth at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-09-13  9:38 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
Dup.

*** This bug has been marked as a duplicate of bug 47409 ***


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

end of thread, other threads:[~2013-09-13  9:38 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-13  7:23 [Bug c/58409] New: wrong reordering of volatile writes francesco.zappa.nardelli at gmail dot com
2013-09-13  7:32 ` [Bug c/58409] " pinskia at gcc dot gnu.org
2013-09-13  9:20 ` francesco.zappa.nardelli at gmail dot com
2013-09-13  9:38 ` rguenth 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).