asm inline

Kevin B. Hendricks kevin.hendricks at sympatico.ca
Tue Dec 3 01:14:21 EST 2002


Hi,

I thought strict-aliasing was only turned on at -O3?
It was that way in the past.  Did this change for gcc-3.2.X?

There seems to be an enormous amount of code that is not strict-aliasing
safe (in the JDK, in OpenOffice.org, etc).

Is there any warning flag that can be enabled to help find these cases (the
OOo source base is simply huge)?

My only choise now is to add -fno-strict-aliasing even with the -O2 flags
which I did not think I needed.

Kevin

On December 2, 2002 08:35, Andreas Schwab wrote:
> 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.


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





More information about the Linuxppc-dev mailing list