Article View: gnu.g++.bug
Article #554function called twice for stream & itor
From: David Eppstein
Date: Thu, 26 Oct 1989 22:52
Date: Thu, 26 Oct 1989 22:52
63 lines
1980 bytes
1980 bytes
I have a function that returns an (ostream &), that must be called
exactly once (not twice). But when I say (ostream & o = fn()),
g++ (1.35 on a SPARC) generates code to call it twice (a bug).
------------ input code ------------
#include <stream.h>
ostream & bar();
foo()
{
ostream & o = bar();
o << "foo\n";
}
------------ generated assembly (SPARC) ------------
gcc_compiled.:
.text
LC0:
.ascii "foo\12\0"
.align 4
.global _foo
.proc 1
_foo:
!#PROLOGUE# 0
save %sp,-144,%sp
!#PROLOGUE# 1
call _bar,0
nop
call _bar,0 // Here is the bug
nop
sethi %hi(LC0),%o1
or %lo(LC0),%o1,%o1
mov %o0,%l0
mov 0,%l1
ld [%l0+4],%o0
tst %o0
bne L544
nop
call _sputs_PSstreambuf_PQI,0
ld [%l0],%o0
cmp %o0,-1
bne L543 // This code is correct, but strange.
nop // Why not "be (label after be L546)",
L544: // and flush the "mov 1,%l1" stuff?
mov 1,%l1
L543:
tst %l1
be L546
nop
ld [%l0+4],%o0
or %o0,2,%o0
st %o0,[%l0+4]
L546:
ret
restore
------------ output of g++ -v ------------
g++ version 1.35.1-
/import/lib/gcc-cpp -+ -v -undef -D__GNU__ -D__GNUG__ -D__cplusplus -Dsparc -Dsun -Dunix -D__sparc__ -D__sun__ -D__unix__ -D__OPTIMIZE__ test.c /tmp/cca02522.cpp
GNU CPP version 1.36
/import/lib/gcc-cc1plus /tmp/cca02522.cpp -quiet -dumpbase test.c -finline-functions -opt -version -o test.s
GNU C++ version 1.35.1- (sparc) compiled by GNU C version 1.35.
Technical Details
Message-ID:
<3713@arisia.Xerox.COM>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!bloom-beacon!shelby!decwrl!sgi!arisia!aldebaran!eppsteinShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!bloom-beacon!shelby!decwrl!sgi!arisia!aldebaran!eppstein From: eppstein@aldebaran.uucp (David Eppstein) Newsgroups: gnu.g++.bug Subject: function called twice for stream & itor Message-ID: <3713@arisia.Xerox.COM> Date: 26 Oct 89 22:52:32 GMT Sender: news@arisia.Xerox.COM Reply-To: eppstein.pa@xerox.com (David Eppstein) Distribution: gnu Organization: Xerox Palo Alto Research Center Lines: 63