From mboxrd@z Thu Jan 1 00:00:00 1970 From: Richard Earnshaw To: egcs@egcs.cygnus.com Cc: richard.earnshaw@arm.com Subject: Propagation of pointer alignment information Date: Tue, 15 Dec 1998 08:50:00 -0000 Message-id: <199812151649.QAA29525@sun52.NIS.cambridge> X-SW-Source: 1998-12/msg00518.html 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