Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Q: do we want the void* patch?



On Mon, Mar 01, 2004 at 01:36:24PM -0800, Wayne Davison wrote:
> To revisit my patch in zsh-workers/19445, I didn't get a response to my
> last query asking if we want to include it.  Was the consensus that we
> don't need it?  I think that including it would help us to ensure that
> the optimizer doesn't over-optimize certain aliased memory locations.

Umm, the consensus seemed to be that it made the warnings go away, but
that nobody is sure whether it's really fixing a problem.

You said in an earlier message:

> However, certain casts force the compiler to be less aggressive in
> its optimizations (such as (char *) and (void *)).

Why do you think that void * is special?

Reading http://mail-index.netbsd.org/tech-kern/2003/08/11/0001.html
which contains this bit from the standard:

% 7 An object shall have its stored value accessed only by an lvalue
%   expression that has one of the following types: {footnote 73}
%
%     a type compatible with the effective type of the object,
%
%     a qualified version of a type compatible with the effective type of
%     the object,
%
%     a type that is the signed or unsigned type corresponding to the
%     effective type of the object,
%
%     a type that is the signed or unsigned type corresponding to a
%     qualified version of the effective type of the object,
%
%     an aggregate or union type that includes one of the aforementioned
%     types among its members (including, recursively, a member of a
%     subaggregate or contained union), or
%
%     a character type.

Doesn't this suggest one can only use char *?

And as Peter said, does the cast really fix the problem or just
make it worse?  

One of the corresponding fixes in glibc - I guess we can assume
those guys know what they're doing, looks like

-	querybuf *buf, *origbuf;
+	union
+	{
+	  querybuf *buf;
+	  u_char *ptr;
+	} buf;
+	querybuf *origbuf;

i.e. using a union type to ensure that aliasing is ok. Didn't
seem as simple for them as just casting to void *.

Maybe that's what is necessary throughout zsh?  Would raise the
question of why to bother though - how many compilers won't have
an option to turn off the ISO aliasing rules?

Perl, for example, uses no-strict-aliasing, so it's not
like zsh would be alone.  Nor is zsh really in pursuit of
fortran's array performance, which is really the whole reason
behind this aliasing tedium.

And the damage done to code readability in casting things to
void * isn't to be taken lightly...

Anthony




This communication is for informational purposes only.  It is not intended as
an offer or solicitation for the purchase or sale of any financial instrument
or as an official confirmation of any transaction. All market prices, data 
and other information are not warranted as to completeness or accuracy and 
are subject to change without notice. Any comments or statements made herein
do not necessarily reflect those of J.P. Morgan Chase & Co., its
subsidiaries and affiliates.




Messages sorted by: Reverse Date, Date, Thread, Author