>Submitter-Id: net >Originator: Thomas Richter >Organization: >Confidential: no >Synopsis: -O3 -freduce-all-givs creates invalid code >Severity: serious >Priority: medium >Category: c++ >Class: wrong-code >Release: 3.2.3 (Debian testing/unstable) >Environment: System: Linux skywise 2.4.20 #7 Thu May 15 19:53:29 CEST 2003 i686 unknown Architecture: i686
host: i386-pc-linux-gnu
build: i386-pc-linux-gnu
target: i386-pc-linux-gnu
configured with: ../src/configure -v --enable-languages=c,c++,java,f77,objc,ada --prefix=/usr --mandir=/usr/share/man --inf
odir=/usr/share/info --with-gxx-include-dir=/usr/include/c++/3.2 --enable-shared --with-system-zlib --enable-nls --without-
included-gettext --enable-__cxa_atexit --enable-clocale=gnu --enable-java-gc=boehm --enable-objc-gc i386-linux
>Description:
The compiler generates wrong code and hence a segfault if the following code gets compiled
with the options -O3 -freduce-all-givs:
/* snip: Save the following lines as buggy.hpp */
class GTIA {
public:
struct PMObject {
char Graphics;
PMObject(void)
{ }
void Render(void *target);
} Player[4],Missile[4];
char GractlShadow;
void TriggerGTIAScanline(char *playfield,int pmdisplace,int width,bool fiddling);
};
/* snip: save the following lnes as buggy.cpp */
#include "buggy.hpp"
int main(int,char **) { class GTIA gtia; gtia.GractlShadow = 127; gtia.TriggerGTIAScanline(0,0,0,false);
return 0; }
void GTIA::PMObject::Render(void *) { return; }
void GTIA::TriggerGTIAScanline(char *,int,int,bool) { struct PMObject *player,*missile; int i;
if (GractlShadow & 0x01) {
int mask,dmask,shift;
for (i = 0,mask = 0x01,dmask = 0x03,shift = 6,missile = Missile;i < 4;i++) {
missile->Graphics = 0;
missile++;
mask <<= 1;
dmask <<= 2;
shift -= 2;
}
for(i=0,player=Player;i<4;i++) {
player->Render(0);
player++;
}
for(i=0,missile=Missile;i<4;i++) {
missile->Render(0);
missile++;
}
}
/* snip */
>How-To-Repeat:
With the above header and .cpp file, run the compiler as follows:
$ g++-3.2 -O3 -freduce-all-givs buggy.cpp
Then run the resulting binary:
$ a.out
Result is a segfault. The problem does not occur if "-freduce-all-givs" is dropped,
or the 2.95.xx release of the compiler is used.
>Fix:
Avoid "-freduce-all-givs"