asm inline

Andreas Schwab schwab at suse.de
Tue Dec 3 00:35:17 EST 2002


Samuel Rydh <samuel at ibrium.se> 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, schwab at suse.de
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/





More information about the Linuxppc-dev mailing list