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 tree-optimization/54900] New: write introduction incorrect wrt the C11 memory model (2) Date: Thu, 11 Oct 2012 11:07:00 -0000 [thread overview] Message-ID: <bug-54900-4@http.gcc.gnu.org/bugzilla/> (raw) http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54900 Bug #: 54900 Summary: write introduction incorrect wrt the C11 memory model (2) Classification: Unclassified Product: gcc Version: 4.8.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization AssignedTo: unassigned@gcc.gnu.org ReportedBy: francesco.zappa.nardelli@gmail.com This program: #include <stdio.h> #include <pthread.h> int g_8 = 1; int g_140; int *g_139 = &g_140; int **g_138 = &g_139; int g_182; void func_2 (p1) { **g_138 = 0; } int func_11 (int p1, int p2, int p3, int p4) { if (g_8) return 0; ++g_182; return 0; } void *context (void *ptr) { g_182 = 1; printf ("%d\n",g_182); } void main () { pthread_t thread1; int iret1; iret1 = pthread_create( &thread1, NULL, context, (void*) 0); func_2 (func_11 (0, 0, 0, 0) ); pthread_join( thread1, NULL); } is miscompiled by gcc --param allow-store-data-races=0 -O2 (or -O3) on x86_64. [ gcc version 4.8.0 20121011 (experimental) (GCC) ] The program has no data-races because the ++g_182 instruction in func_11 is never executed by the main thread, and the context thread is expected to always print 1. The -O2 and -O3 optimisers (invoked with --param allow-store-data-races=0) compile main as: main: subq $24, %rsp xorl %ecx, %ecx xorl %esi, %esi leaq 8(%rsp), %rdi movl $context, %edx call pthread_create xorl %eax, %eax cmpl $1, g_8(%rip) movq 8(%rsp), %rdi setb %al (**) addl %eax, g_182(%rip) movq g_138(%rip), %rax xorl %esi, %esi movq (%rax), %rax movl $0, (%rax) call pthread_join addq $24, %rsp ret The problem is in the (**) instruction: addl %eax, g_182(%rip) which inserts a write of the value 0 in the run-time trace of the main thread, possibly resulting in the context thread printing 0.
next reply other threads:[~2012-10-11 11:07 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2012-10-11 11:07 francesco.zappa.nardelli at gmail dot com [this message] 2012-10-11 11:59 ` [Bug tree-optimization/54900] " jakub at gcc dot gnu.org 2012-10-14 12:51 ` aldyh at gcc dot gnu.org 2012-10-14 12:51 ` aldyh at gcc dot gnu.org 2012-10-17 20:59 ` [Bug rtl-optimization/54900] " aldyh at gcc dot gnu.org 2012-10-18 13:39 ` francesco.zappa.nardelli at gmail dot com 2012-10-18 23:46 ` aldyh at gcc dot gnu.org 2013-05-29 20:24 ` steven 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-54900-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: linkBe 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).