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

           Summary: g++ optimizer breaks do-while code
           Product: gcc
           Version: 4.5.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: p...@itee.uq.edu.au


Created attachment 24296
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24296
The .ii file produced with g++ -v -save-temps -Wall -Wextra -o dow dow.cc

I recently installed Ubuntu 11.04 on a new 64bit laptop :
Linux Kernel: 2.6.38-8-generic
processor: i7-2620M
On trying to build a project of mine on the new laptop I found a problem that
appears to be related to the optimizer. Below is a simple example that exhibits
the problem - execution of a do-while loop.
With the optimizer off it appears to work OK but with any optimization on it
does not break out of the do-while loop as required. 

It works OK with optimization if I recode as a while loop.  

---- dow.cc ------
#include <iostream>
using namespace std;

int main()
{
  int a[] = {1,2,3,4,5,6,7};
  bool flag = false;
  int d = 1;
  int i = 1;
  do
    {
      d = a[i];
      if (flag && (d == 4))
        {
          cerr << "break" << endl;
          break;
        }
      i++;
      flag = (d == 3);
    } while (d < 7);

}
---------

Compiled as
g++ -Wall -Wextra -o dow dow.cc
and run as 
./dow
outputs 
break
(as it should)
Compiled with -O2
./dow
generates no output

Reply via email to