This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/10928] New: -O3 -freduce-all-givs creates invalid code


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=10928

           Summary: -O3 -freduce-all-givs creates invalid code
           Product: gcc
           Version: 3.2.2
            Status: UNCONFIRMED
          Severity: critical
          Priority: P2
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: thor@math.tu-berlin.de
                CC: gcc-bugs@gcc.gnu.org
 GCC build triplet: i386-pc-linux-gnu
  GCC host triplet: i386-pc-linux-gnu
GCC target triplet: i386-pc-linux-gnu

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 lines 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 */

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.



------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]