🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #514

gcc 1.35, structure assignment misalignment on a sparc.

#514
From: Felix Lee
Date: Fri, 04 Aug 1989 21:00
43 lines
1592 bytes
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
Technical Details
Message-ID: <FLEE.89Aug4170022@shire.cs.psu.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!cica!tut.cis.ohio-state.edu!husc6!psuvax1!news

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!cica!tut.cis.ohio-state.edu!husc6!psuvax1!news
From: flee@shire.cs.psu.edu (Felix Lee)
Newsgroups: gnu.gcc.bug
Subject: gcc 1.35, structure assignment misalignment on a sparc.
Message-ID: <FLEE.89Aug4170022@shire.cs.psu.edu>
Date: 4 Aug 89 21:00:04 GMT
Sender: news@psuvax1.cs.psu.edu
Distribution: gnu
Organization: Penn State University Computer Science
Lines: 43