[Bug rtl-optimization/25791] -O2 execution fails, -O and -g work

dick_guertin at yahoo dot com gcc-bugzilla@gcc.gnu.org
Thu Jan 19 17:54:00 GMT 2006



------- Comment #24 from dick_guertin at yahoo dot com  2006-01-19 17:54 -------
Although you have closed this, many people would disagree with you.  Laying out
static data this way has always 'worked' in the past, and continues to work
with -O, but not -O2.  Just for completeness, here is a simplfied testcase.c
that anyone can compile and execute with -O or -O2.

#include <stdio.h>

typedef struct sckw
   {
      unsigned char tok[1];
      char tag[3];
   }  NKW;

/* user sckws */

static struct sckw sckw01 = {  1, '0','1', 0 };
static struct sckw sckw02 = {  2, '0','2', 0 };
static struct sckw sckw03 = {  3, '0','3', 0 };
static struct sckw sckw04 = {  4, '0','4', 0 };
static struct sckw sckw05 = {  5, '0','5', 0 };
static struct sckw sckw06 = {  6, '0','6', 0 };
static struct sckw sckw07 = {  7, '0','7', 0 };
static struct sckw sckw08 = {  8, '0','8', 0 };
static struct sckw sckw09 = {  9, '0','9', 0 };
static struct sckw sckw10 = { 10, '1','0', 0 };
static struct sckw sckw11 = { 11, '1','1', 0 };
static struct sckw sckw12 = { 12, '1','2', 0 };
static struct sckw sckw13 = { 13, '1','3', 0 };
static struct sckw sckw14 = { 14, '1','4', 0 };
static struct sckw sckw15 = { 15, '1','5', 0 };
static struct sckw sckw16 = { 16, '1','6', 0 };
static struct sckw sckw17 = { 17, '1','7', 0 };
static struct sckw sckw18 = { 18, '1','8', 0 };
static struct sckw sckw19 = { 19, '1','9', 0 };
static struct sckw sckw20 = {  0, '2','0', 0 };

void scanner (void)
{  int token;
   NKW *kwp, *kwp2;

   kwp = (NKW*) &(sckw01);
   kwp2 = (NKW*) &(sckw20);
   token = 1;

   while (kwp)
   {
       if ((int)kwp->tok[0] == token)
       {  ++ token;
          kwp += 1;
       }
       else
       {  if ((kwp == kwp2) && (token == 20)) printf("Finished correctly\n");
          else printf("Finished at %d when tok=%d\n", token, (int)kwp->tok[0]);
          kwp = 0;
       }
   }
   return;
}

int main ()
{  scanner();
   return(0);
}


-- 


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



More information about the Gcc-bugs mailing list