Comment 14 for bug 817768

Revision history for this message
kornelix (mikecorn-deactivatedaccount) wrote :

I have found another similar case where adding a meaningless reference to a variable within a loop caused a crash to go away.
This time it is gcc 4.6.1 in Ubuntu 11.10. I have now found this bug 3 times in 3 different programs in the past. All 3 cases were similar loops to the one below, with the same "fix": add a do-nothing line of code.

SUMMARY
gcc 4.5.2 optimization O3 NO BUG
gcc 4.6.1 optimization O2 NO BUG
gcc 4.6.1 optimization O3 CRASH
gcc 4.6.1 optimization O3 with dummy reference added NO BUG

Here is the loop with the dummy reference included:

      for (kk = ap; kk < sd->nap[spc]; kk++) {
          if (! kk) printf("meaningless reference %d",kk); // stop gcc optimization bug
          sd->apx[spc][kk] = sd->apx[spc][kk+1];
          sd->apy[spc][kk] = sd->apy[spc][kk+1];
      }

The backtrace made no sense. The crash was a seg fault in a function not being called.