This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: aliasing problem with va_arg
- To: mark at markmitchell dot com
- Subject: Re: aliasing problem with va_arg
- From: Jim Wilson <wilson at cygnus dot com>
- Date: Thu, 29 Oct 1998 12:54:41 -0800
- cc: egcs at cygnus dot com
I am leery, though, of trying to extend
things too far, though; much better that people learn not to use
type-punning. It's not safe, and it's not portable.
There is a lot of code that has been written specifically for gcc that
has occasionally found the need for type punning. I know that there is
type punning code in libio/libstc++. I suspect that there is type punning
code in glibc and the linux kernel. These codes were never meant to be
compiled by any other compiler, so portability is not a concern.
We have been telling people for a long time that gcc supports type punning for
anything inside a union. They won't like being told that their code is
now suddenly broken, so we will need to be careful now we approach this.
We need to support existing code, and educate people about better ways to
write code before we start breaking it.
Meanwhile, I am concerned that your definition of what is a union access for
type punning purposes is so narrow that end users might not understand it.
For instance, consider this example:
union { struct { short a, b; } s; int i; } u;
short sub (int i) { u.i = i; return u.s.b; }
The access to u.s.b is not given an alias set of zero, because it is not a
union member access, it is instead a structure member access. That seems
confusing to me. If we allow type punning of union members, then it seems
weak not to allow type punning of union members that are structures.
As a practical matter though, I don't expect much code to break because of
this problem, because the access to u.i does get an alias set of zero, and
that is sufficient to make this example work.
This is essentially the same problem I am handling in the sparc va_arg case,
except that I have replaced the array with a structure.
Your patch is probably OK. I understand that you want to do this
to fix the va-sparc.h problem, and I'm sympathetic.
I expanded the comment to make it clear that it was specifically for the
va-sparc.h va_arg, and then checked it in. We can remove it later if the
va_arg support is rewritten, and we decide that this kind of type punning
inside unions is not necessary.
J