Sender: yakush AT ipmnet DOT ru Message-ID: <36D64959.8BB95024@ipmnet.ru> Date: Fri, 26 Feb 1999 10:12:25 +0300 From: "S.Yakush" X-Mailer: Mozilla 4.07 [en] (X11; I; Linux 2.0.34 i686) MIME-Version: 1.0 To: pgcc AT delorie DOT com Subject: PGCC Optimization bug (?) Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Reply-To: pgcc AT delorie DOT com Hi there, I came across an optimisation-related bug in pgcc-1.1.1 :-( The program below has been distilled from my code in which I use 1D double array to store 2D data, the Var class allocates the memory and provides an access function Var::Arr. This program works fine when compiled by egcs-1.1.1 with or without optimisation. However, pgcc-1.1.1 (bootstrapped with --enable-haifa --enable-threads --enable-shared) gives a weird result: the unoptimised code runs fine, but optimised (-O1, -O2, -O3) one crashes when data element a->Arr(2,2) is accessed. At the same time, a->Arr(0,2) can be accessed with any optimisation. If the result is assigned to a local variable (rather than the global one), the code runs as well. Here is the program tst.C: //------------------------------------- start class Var{ public: double* Array; int NX; int NY; Var(int Nx, int Ny){ NX = Nx; NY = Ny; Array = new double[NX*NY]; for(register int i = 0; i < NX*NY; i++) Array[i] = (double)i; // Initialise somehow, just in case } double Arr(int i, int j){return (*(Array+i+NX*j));} // Access function }; double V; int main() { Var *a = new Var(5,5); // Uncomment one line of the following three: // V = a->Arr(0,2); // This works fine (V is global) // double V = a->Arr(2,2); // This works fine (V is local) V = a->Arr(2,2); // This causes Segmentation fault return 0; } //-------------------------------------- end An here is what happens: $g++ -v -O3 tst.C -o tst Reading specs from /usr/local/pgcc-1.1.1/lib/gcc-lib/i686-pc-linux-gnu/pgcc-2.91.60/specs gcc version pgcc-2.91.60 19981201 (egcs-1.1.1 release) /usr/local/pgcc-1.1.1/lib/gcc-lib/i686-pc-linux-gnu/pgcc-2.91.60/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -D__GNUC_MINOR__=91 -D__ELF__ -Dunix -Di386 -D__i386__ -Dlinux -D__ELF__ -D__unix__ -D__i386__ -D__i386__ -D__linux__ -D__uni x -D__i386 -D__linux -Asystem(posix) -D__EXCEPTIONS -D__OPTIMIZE__ -Asystem(unix) -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ -Di686 -Dpentiumpro -D__i686 -D__i686__ -D__pentiumpro -D__pentiumpro__ tst.C /tmp/ccphIXyQ.ii GNU CPP version pgcc-2.91.60 19981201 (egcs-1.1.1 release) (i386 Linux/ELF) #include "..." search starts here: #include <...> search starts here: /usr/local/pgcc-1.1.1/include/g++ /usr/local/include /usr/local/pgcc-1.1.1/i686-pc-linux-gnu/include /usr/local/pgcc-1.1.1/lib/gcc-lib/i686-pc-linux-gnu/pgcc-2.91.60/include /usr/include End of search list. /usr/local/pgcc-1.1.1/lib/gcc-lib/i686-pc-linux-gnu/pgcc-2.91.60/cc1plus /tmp/ccphIXyQ.ii -quiet -dumpbase tst.cc -O3 -version -o /tmp/ccOZ6PAy.s GNU C++ version pgcc-2.91.60 19981201 (egcs-1.1.1 release) (i686-pc-linux-gnu) compiled by GNU C version pgcc-2.91.60 19981201 (egcs-1.1.1 release). as -V -Qy -o /tmp/ccd88pOi.o /tmp/ccOZ6PAy.s GNU assembler version 2.9.1 (i686-pc-linux-gnu), using BFD version 2.9.1.0.15 /usr/local/pgcc-1.1.1/lib/gcc-lib/i686-pc-linux-gnu/pgcc-2.91.60/collect2 -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o tst /usr/lib/crt1.o /usr/lib/crti.o /usr/local/pgcc-1.1.1/lib/gcc-lib/i686-pc-linux-gnu/pgcc-2.91.60/crtbegin.o -L/usr/local/pgcc- 1.1.1/lib/gcc-lib/i686-pc-linux-gnu/pgcc-2.91.60 -L/usr/local/pgcc-1.1.1/i686-pc-linux-gnu/lib -L/usr/local/pgcc-1.1.1/lib /tmp/ccd88pOi.o -lstdc++ -lm -lgcc -lc -lgcc /usr/local/pgcc-1.1.1/lib/gcc-lib/i686-pc-linux-gnu/pgcc-2.91.60/crtend.o /usr/lib/crtn .o $ $./tst Segmentation fault (core dumped) $ Another hint: if NX in the access function Arr(i,j) is substituted manually by a constant 5, everything works fine even with optimisation. Thanks S.Yakush