Subject: Re: asm inline

From: Andreas Schwab <[email-masked]>
Date: Mon, 02 Dec 2002 14:35:17 +0100

Samuel Rydh <[email-masked]> writes:

|> Sure, here is a stand alone program that triggers the problem:
|>
|> ----------------------------------------------------------------
|>
|> #include <stdio.h>
|> typedef unsigned long ulong;
|>
|> static __inline__ void st_le32( ulong volatile *addr, ulong val )
|> {
|>         __asm__ ("stwbrx %1,0,%2" : "=m" (*addr) : "r" (val), "r" (addr)  );
|> }
|>
|> int
|> main( int argc, char **argv )
|> {
|>         int b;
|>         st_le32( (ulong*)&b, 0 );
|>         testing( b );

This violates the aliasing rules.  The compiler is free to assume that
st_le32 does not modify b, because you are invoking undefined behaviour.

Andreas.

--
Andreas Schwab, SuSE Labs, [email-masked]
SuSE Linux AG, Deutschherrnstr. 15-19, D-90429 Nürnberg
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

** Sent via the linuxppc-dev mail list. See http://lists.linuxppc.org/