This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: [4.3] Invalid code or invalid optimisation?
- From: Andrew Haley <aph at redhat dot com>
- To: Dave Korn <dave dot korn dot cygwin at googlemail dot com>
- Cc: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Thu, 04 Jun 2009 09:27:41 +0100
- Subject: Re: [4.3] Invalid code or invalid optimisation?
- References: <4A2728AA.3010205@gmail.com>
Dave Korn wrote:
> Adding a "memory" clobber to the inline asm works around the problem,
> causing 4.3 series to generate the same assembly as head, but I think it's a
> sledgehammer approach. Am I asking too much of GCC to not sink the store, or
> is 4.3 doing something wrong? I /think/ that the fact that there's a volatile
> store in ilockcmpexch means the earlier store shouldn't be moved past it, and
> that GCC is perhaps missing that the asm's output operand effectively
> represents a volatile write through *t, but I could be misunderstanding the
> rules about volatile. Anyone got their language lawyer's hat on at the moment?
You could just look at the standard, y'know. Volatile stores only block other
volatile stores: they don't block *all* stores. If you really want a complete
memory barrier, which in a mutex you surely do, then you're going to have to
clobber memory.
Andrew.