tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: in which we present an ugly hack to make sys/queue.h CIRCLEQ work



On 2013-11-23 dennis.c.ferguson%gmail.com@localhost wrote:

If gcc is eliminating the possibility that a comparison for equality might
be true it can only be doing so either by proving that uses made of the
pointers in other parts of the code would violate the alias rules if the
pointers were the same, or perhaps that there are no possible uses of
the pointers which wouldn't violate the aliasing rules based on the
structure layouts.  In either case it is doing something quite clever,
so I wouldn't mind seeing an example of this.  It is certainly not the
case that the anti-alias rule prevents two pointers to different structure
types from ever comparing equal when suitably converted, the problem with
the macros must be more subtle.

I think you are right that it is not a strict aliasing violation. Looking at the N1570 draft (6.2.6.1 representation of types), it looks like because the value stored is not of the appropriate type then accessing it as if it was that type is undefined. Storing a pointer to the head is allowed as a "trap representation", but accessing it as a pointer to struct type * is undefined. If this is correct, doing the comparison with memcmp should result in behavior defined to DTRT.

-Matt


Home | Main Index | Thread Index | Old Index