This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Propagation of pointer alignment information


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




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]