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: unassig...@gcc.gnu.org
        ReportedBy: francesco.zappa.narde...@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)

Reply via email to