This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
C++ instance copy bug on powerpc
- To: egcs-bugs at egcs dot cygnus dot com
- Subject: C++ instance copy bug on powerpc
- From: Jan Nieuwenhuizen <janneke at gnu dot org>
- Date: Tue, 29 Jun 1999 20:27:16 +0200
- cc: "ir. Wendy" <hanwen at cs dot uu dot nl>, "Jan Nieuwenhuizen" <jcn at wi dot leidenuniv dot nl>
Hi egcs gurus,
We've been experiencing weird bugs with LilyPond (1.1.35-1.1.51)
on the Linux-powerpc platform, that seemed guile-related. However,
yesterday, I got the latest glibc-2.1 based LinuxPPC release
(ftp.linuxppc.org/linuxppc/R5), including an upgrade from egcs 1.1b
to 1.1.2.
Now it seems that an egcs bug can be pinned down:
template<class T>
T*dest, T*src
*dest++ = *src++;
produces erroneous code, if class T is fat enough. See the file below.
Greetings,
Jan.
/*
egcs.cc -- powerpc bug
19:58:39 appel ~/usr/src/c++$ make
g++ egcs.cc -o egcs
19:59:03 appel ~/usr/src/c++$ ./egcs
Foo: 0 (0)
Foo: 1 (0)
Foo: 2 (0)
Foo: 3 (0)
19:59:22 appel ~/usr/src/c++$ rm egcs
19:59:28 appel ~/usr/src/c++$ make CFLAGS=-Dweird_powerpc_bug
g++ -Dweird_powerpc_bug egcs.cc -o egcs
19:59:30 appel ~/usr/src/c++$ ./egcs
Foo: 1 (0)
Foo: 2 (0)
Foo: 3 (0)
Foo: 1 (0)
vanilla LinuxPPC Release5 (1999)
19:59:32 appel ~/usr/src/c++$ uname -a
Linux appel.flower 2.2.6-15apmac #1 Fri Apr 30 12:52:03 EDT 1999 ppc unknown
20:01:26 appel ~/usr/src/c++$ egcs -v
Reading specs from /usr/lib/gcc-lib/ppc-redhat-linux/egcs-2.91.66/specs
gcc version egcs-2.91.66 19990314 (egcs-1.1.2 release)
egcs-1.1.2-12c.src.rpm
glibc-2.1.1-6c.src.rpm
*/
#include <stdio.h>
#define INLINE
template<class T> INLINE void
arrcpy (T*dest, T*src, int count)
{
for (int i_shadows_local=0; i_shadows_local < count ; i_shadows_local++)
#ifdef weird_powerpc_bug
*dest++ = *src++;
#else
{
// urg: wierd egcs-1.1.2 bug on ppc
*dest = *src;
dest++, src++;
}
#endif
}
/*
Modelled after LilyPond's Stem_info
*/
class Foo
{
private:
int bar_;
int copied_;
/*
Must be big enough to trigger the memcpy implementation
*/
int int3;
double d1, d2, d3, d4, d5;
char* p1;
public:
Foo ()
{
bar_ = -1;
copied_ = 0;
}
Foo (int i)
{
bar_ = i;
copied_ = 0;
}
Foo (Foo const& src)
{
bar_ = src.bar_;
copied_ = 1;
}
#if 0 // this will fix it too: no memcpy
Foo& operator = (Foo const& src)
{
bar_ = src.bar_;
copied_ = 1;
return *this;
}
#endif
void print ()
{
printf ("Foo: %d (%d)\n", bar_, copied_);
}
};
int
main ()
{
Foo a[4];
Foo b[4];
for (int i = 0; i < 4; i++)
a[i] = Foo (i);
arrcpy (b, a, 4);
for (int i = 0; i < 4; i++)
b[i].print ();
return 0;
}
Jan Nieuwenhuizen <janneke@gnu.org> | GNU LilyPond - The music typesetter
http://www.xs4all.nl/~jantien/ | http://www.lilypond.org/