bug in 3.2.0 nmblookup
Alan DeKok
aland at ox.org
Fri Jul 4 08:18:53 GMT 2008
Sam Liddicott wrote:
> Thats sick!
> sa may be a local variable but it is a pointer. Since when did gcc think
> that local pointers only point locally?
It's more complicated than that. The issue isn't just local pointers,
but pointer aliasing.
> What if a function scope pointer was initialized from an argument struct
> (for convenience) would they optimize away that last use of that pointer
> too?
>
> function blah(struct suff* arg) {
> struct secret *secret=stuff->secret;
I think you mean 'arg->secret'
> // does this get opimized away as secret is going out of scope
> secret->word="shh";
> }
That's OK, because there's no aliasing. The assignment 'secret->word'
is really 'arg->secret->word', and arg is outside of the local scope.
The compiler can track this, and see that the assignment has side
effects outside of the local scope.
How about this artificial example:
void blah(void)
{
struct foo q;
q.bar = 1
}
I think everyone can agree that the assignment is useless, and can
safely be optimized away.
With pointer aliasing, you have two pointers to the same section of
memory. The C compiler doesn't track assignments across pointers of
different types, so it can re-order writes, as seen in:
http://archives.postgresql.org/pgsql-hackers/2006-04/msg00981.php
> If I'm not wrong, this must be a gcc bug.
Nope. ISO C99 forbids pointers of different types from pointing to
the same memory location. So the code in Samba (and in many other
programs) violates the spec. Hence the ''fno-strict-aliasing' argument
to GCC, which allows your programs to continue working.
See the Wikipedia article for a good discussion of this topic:
http://en.wikipedia.org/wiki/Aliasing_(computing)
Alan DeKok.
More information about the samba-technical
mailing list