[gnu.gcc.bug] gcc 1.35, structure assignment misalignment on a sparc.

flee@shire.cs.psu.edu (Felix Lee) (08/05/89)

The following program compiled with gcc 1.35 coredumps on a Sun4.
	struct foo { char a, b, c, d; };
		/* sizeof(foo) % 4 == 0 && alignof(foo) == 1 */
	const char z = 1;
	const struct foo x = { 1, 2, 3, 4 };
	main() { struct foo y = x; }

The code generated for the structure assignment moves a word at a
time, assuming that 'x' is aligned on a word boundary, which would
coincidentally be true were it not declared 'const' and placed in the
text segment.  Since foo doesn't need to be word aligned.  Accident
can still conspire to leave it word aligned (which is why 'z').

The assembly generated:
	gcc_compiled.:
	.global _z
	.text
	_z:
		.byte 1
	.global _x
	.text
	_x:
	        .byte 1
	        .byte 2
	        .byte 3
	        .byte 4
	        .align 4
	.global _main
	        .proc 1
	_main:
	        !#PROLOGUE# 0
	        save %sp,-120,%sp
	        !#PROLOGUE# 1
	        add %fp,-24,%o0
	        sethi %hi(_x),%o2
	        or %lo(_x),%o2,%o2
	        ld [%o2+0],%g1		<<- %o2 is not a word address
	        st %g1,[%o0+0]
	L1:
	        ret
	        restore
--
Felix Lee	flee@shire.cs.psu.edu	*!psuvax1!flee