public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "francesco.zappa.nardelli at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/54149] New: write introduction incorrect wrt the C11 memory model
Date: Wed, 01 Aug 2012 08:47:00 -0000	[thread overview]
Message-ID: <bug-54149-4@http.gcc.gnu.org/bugzilla/> (raw)

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)


             reply	other threads:[~2012-08-01  8:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-01  8:47 francesco.zappa.nardelli at gmail dot com [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-54149-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).