public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/54149] New: write introduction incorrect wrt the C11 memory model
@ 2012-08-01  8:47 francesco.zappa.nardelli at gmail dot com
  2012-08-23 16:35 ` [Bug c/54149] " francesco.zappa.nardelli at gmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: francesco.zappa.nardelli at gmail dot com @ 2012-08-01  8:47 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 54149
           Summary: write introduction incorrect wrt the C11 memory model
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: francesco.zappa.nardelli@gmail.com


[ possibly related to http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52558 ]

Consider this program:

int g_13 = 1;

void main () {
int l_245;
for (l_245 = 0; l_245 <= 1; l_245 += 1)
 for (; g_13 <= 0; g_13 = 1);
}

If I compile it with 

 gcc --param allow-store-data-races=0 -S -O1 

(I am running gcc (GCC) 4.8.0 20120627 (experimental) on Linux - x86_64 -- the
same applies to -O2 and -O3 and compilation with g++ -std=c++11 -O1)

I get the following optimised assembler (I just hand removed some noise):

main:
     movl    g_13(%rip), %eax
     testl   %eax, %eax
     movl    $1, %edx
     cmovle  %edx, %eax
     movl    %eax, g_13(%rip)
     ret

g_13:
     .long   1

which always performs a write to g_13 and executes with this memory trace (I am
tracing only the accesses to the global - potentially shared - variables):

          g_13                    1  4                Init
          g_13                    1  4                Load
          g_13                    1  4               Store

However the reference trace for the C11 program above never performs a write to
g_13:

          g_13                    1  4                Init
          g_13                    1  4                Load
          g_13                    1  4                Load

This looks related to the problem I reported in
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52558 , as the optimiser introduces
a memory write which should not be there (and in turn performs an optimisation
not correct wrt the C11 or the C++11 memory model).  The same discriminating
context of bug 52558 applies.

For reference: 

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/home/yquem/moscova/zappa/source/gcc-svn-bin/libexec/gcc/x86_64-unknown-linux-gnu/4.8.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-svn/configure
--prefix=/home/yquem/moscova/zappa/source/gcc-svn-bin/
Thread model: posix
gcc version 4.8.0 20120627 (experimental) (GCC)


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

end of thread, other threads:[~2012-09-11 12:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-01  8:47 [Bug c/54149] New: write introduction incorrect wrt the C11 memory model francesco.zappa.nardelli at gmail dot com
2012-08-23 16:35 ` [Bug c/54149] " francesco.zappa.nardelli at gmail dot com
2012-09-07 19:45 ` aldyh at gcc dot gnu.org
2012-09-11 12:28 ` [Bug middle-end/54149] " aldyh at gcc dot gnu.org
2012-09-11 12:30 ` aldyh 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).