This is the mail archive of the gcc-help@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]

Re: gcc-4.2.2 -O2 bug??


Hi!

The following program with gcc-4.2.2  is giving different results for
optimized and debug flags

Yesterday, I found out that some memory write operations are "optimized" away by gcc 4.2.1 with optimization switches O1 and O2 and my back-end. I haven't complained yet, because I made changes to gcc for bit-addressing, especially I disabled gcc_assert (curr || ref_contains_array_ref (orig_t)); in tree-ssa-structalias.c:2455


Anyway, I played a little bit with your code and stripped it down:

#include <stdio.h>
#include <stdlib.h>

#ifdef FORCE_WRONG_RESULTS
typedef struct Val {
} Val;
#endif

typedef struct table {
  int val;
} Table;

Table gt = { 0 };

unsigned int
subopt_hash(void *key)
{
  Table* t = (Table *) key;
  int tempVal;
  unsigned char *k;
  unsigned int h;
  int i, size;

  tempVal = t->val;
  t->val = NULL;

  k = (unsigned char *) t;
  h = 0;
  size = sizeof(Table);
  for(i=0; i<size;i++) {
    h += *(k+i);
  }

  t->val = tempVal;
  return (h);
}

int main()
{
  Table* t;
  unsigned int ret;

  t = &gt;
  t->val = 0XAD;
  ret = subopt_hash(t);
  printf("0x%X\n", ret);
  return ret;
}

gcc 4.2.1 with option "-O2" produces incorrect code on my Intel-Mac; so I can confirm your results even with gcc 4.2.1. But with my modified gcc with my back-end the code is incorrect with the option "- DFORCE_WRONG_RESULTS" only.

Gowri, I hope that someone can help us here.

Boris


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