Article View: gnu.gcc.bug
Article #6269Bad code generated for struct return [2.7.2, sparc-sun-sunos4.1.4]
From: Vince Del Vecchio
Date: Tue, 02 Jan 1996 00:00
Date: Tue, 02 Jan 1996 00:00
61 lines
1913 bytes
1913 bytes
The following program should print "1 2" but instead prints "2 2".
An examination of the assembly code (see below) indicates that main()
uses the same space for return value for both calls to fill(), and the
call to fill(2) happens before fill(1).right is extracted.
Details:
gcc version 2.7.2, configured as sparc-sun-sunos4.1.4
Running on a SPARCstation 5, SunOS 4.1.4
Compiled using "gcc gcc-bug3.c".
---- Cut here ----
struct rec {
int left;
int right;
};
struct rec fill(int v)
{
struct rec x;
x.left = x.right = v;
return x;
}
main()
{
printf("%d %d\n", fill(1).right, fill(2).right);
}
---- End program ----
_main:
!#PROLOGUE# 0
save %sp,-112,%sp
!#PROLOGUE# 1
call ___main,0
nop
add %fp,-16,%o0
st %o0,[%sp+64] <- Address for the return value is fp-16
mov 1,%o0
call _fill,0
nop
unimp 8
add %fp,-16,%o0
st %o0,[%sp+64] <- Address for the return value is again fp-16
mov 2,%o0
call _fill,0
nop
unimp 8
sethi %hi(LC0),%o1
or %o1,%lo(LC0),%o0
ld [%fp-12],%o1 <- Extract right from result of fill(1), but
this is actually fill(2) now!!!
ld [%fp-12],%o2 <- Extract right from result of fill(2)
call _printf,0
nop
L2:
ret
restore
Technical Details
Message-ID:
<9601022133.AA03151@dsd.camb.inmet.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 113d02,55071219a61d6dea,start X-Google-Attributes: gid113d02,public From: vdelvecc@dsd.camb.inmet.com (Vince Del Vecchio) Subject: Bad code generated for struct return [2.7.2, sparc-sun-sunos4.1.4] Date: 1996/01/02 Message-ID: <9601022133.AA03151@dsd.camb.inmet.com> X-Deja-AN: 133735994 distribution: gnu sender: daemon@cis.ohio-state.edu organization: GNUs Not Usenet newsgroups: gnu.gcc.bug