public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Propagation of pointer alignment information
@ 1998-12-15  8:50 Richard Earnshaw
  1998-12-15 10:04 ` Joern Rennecke
  0 siblings, 1 reply; 5+ messages in thread
From: Richard Earnshaw @ 1998-12-15  8:50 UTC (permalink / raw)
  To: egcs; +Cc: richard.earnshaw

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



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~1998-12-18 16:17 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-12-15  8:50 Propagation of pointer alignment information Richard Earnshaw
1998-12-15 10:04 ` Joern Rennecke
1998-12-16  5:56   ` Richard Earnshaw
1998-12-16 22:07     ` Jeffrey A Law
1998-12-18 16:17       ` Richard Henderson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).