🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Vince Del Vecchio Tue, 02 Jan 1996 00:00
Bad code generated for struct return [2.7.2, sparc-sun-sunos4.1.4]
#6269
Author: Vince Del Vecchio
Date: Tue, 02 Jan 1996 00:00
61 lines
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
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads