On Oct 4, 2005, at 19:06, Andrew Dougherty wrote:

Ok, I've finally found the cause of this one, but I don't have a portable
patch at hand.

Buried in amongst the 6827 warnings emitted by gcc is one that actually
correctly identifies the problem:

There must be some really heavily used macros that cause that huge amount of warnings, e.g. used in ops files. Getting rid of these would really help I presume.

src/inter_create.c:400: warning: dereferencing type-punned pointer will
      break strict-aliasing rules

The line reads:

        LVALUE_CAST(char *, p) += ALIGNED_CTX_SIZE;

The intent is of course, to bump the context pointer by the needed size. The problem is that the needed size does not correlate with the size of the struct.

And indeed that appears to be the problem.  You can even reproduce the
problem under Linux/x86 with gcc-3.4 or newer.  Simply compile with
optimization level of -O3.

The *temporary workaround* for *gcc only* is to supply gcc with the
-fno-strict-aliasing flag.

For those not familiar with aliasing, I found this article

    http://mail-index.netbsd.org/tech-kern/2003/08/11/0001.html

When I get this right, the article also states:

There exist an important exception to the rule above: char* may alias all
types (too much code would break if ISO had prevented this...)

Anyway, does:

   p = (struct Parrot_Context *) ( (char *) p + ALIGNED_CTX_SIZE );

help, or better is it "more correct"?

We have a lot of similar code e.g. inside GC, where pointers to PMCs or to PObjs are icnremented by the actual size of the object and not by the size of some structure.

leo

Reply via email to