This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Propagation of pointer alignment information
- To: egcs at egcs dot cygnus dot com
- Subject: Propagation of pointer alignment information
- From: Richard Earnshaw <rearnsha at arm dot com>
- Date: Tue, 15 Dec 1998 16:49:46 +0000
- Cc: richard dot earnshaw at arm dot com
- Organization: ARM Ltd.
- Reply-To: richard dot earnshaw at arm dot com
Egcs maintains some information about the alignment of pointer registers
using the REGNO_POINTER_ALIGN macro, which can then be used by back-ends
to produce more efficient code sequences than might be otherwise possible.
Unfortunately, this can often cause some dodgy code to break,
particularly when casting is used to break the type system. A particular
case I'm running in to on the ARM is when an int* is cast to a short* and
then dereferenced. If the int* really was correctly aligned, then there
is no problem, but the dodgy code (ghostscript in fact) is putting a
short* into the int* when passing it to a function; the int* is then cast
back to a short* before being dereferenced, but the compiler is
remembering the original "alignment" of the int*.
Would it be reasonable to make the compiler not propagate alignment
through a cast? This would still leave the case where the alignment is
derived from the layout of a struct.
Example code...
int foo(int *a)
{
puts("Hello");
return *(short *)a;
}
int main()
{
short x[4];
x[0] = 1;
x[1] = 3;
x[2] = 5;
x[3] = 6;
printf("%d\n", foo((int *)(x+0)));
printf("%d\n", foo((int *)(x+1)));
}
which on an ARM with -O2 gives the unexpected
Hello
1
Hello
6