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.

-- 
You received this bug notification because you are a member of Ubuntu
Bugs, which is subscribed to Ubuntu.
https://bugs.launchpad.net/bugs/817768

Title:
  GCC optimizer removes necessary code

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/gcc-4.5/+bug/817768/+subscriptions

-- 
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to