[Bug c++/56672] New: Bad optimization

2013-03-21 Thread nroets at gmail dot com


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



 Bug #: 56672

   Summary: Bad optimization

Classification: Unclassified

   Product: gcc

   Version: 4.6.3

Status: UNCONFIRMED

  Severity: minor

  Priority: P3

 Component: c++

AssignedTo: unassig...@gcc.gnu.org

ReportedBy: nro...@gmail.com





Created attachment 29704

  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29704

g++ -v output



For background see http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36996



When compiled with -Os, the program below does not terminate. 



Here is my opinion: `mask` becomes undefined and it cause an unrelated variable

`maskI' to become undefined. If that is a valid compilation of the program, it

would make it very hard for programmers to reason about correctness.



#include 

int main ()

{

  int mask = 0, maskI;

  for (maskI = 0; maskI < 4; maskI++) {  

printf ("y %d\n", mask);

mask += 0x;

  }

  return 0;

}


[Bug c/36996] New: Bad optimization

2008-08-01 Thread nroets at gmail dot com
When the program below is compiled with -O2, it goes into an endless loop.

#include 

int main (void)
{
  int mask;
  for (mask = 0; (mask & 7) != 4; mask += 0x) {
printf ("%x\n", mask & 7);
  }
}

The output of gcc -v is 
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--with-gxx-include-dir=/usr/include/c++/4.2 --program-suffix=-4.2
--enable-clocale=gnu --enable-libstdcxx-debug --enable-objc-gc --enable-mpfr
--enable-targets=all --enable-checking=release --build=i486-linux-gnu
--host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.2.3 (Ubuntu 4.2.3-2ubuntu7)


-- 
   Summary: Bad optimization
   Product: gcc
   Version: 4.2.3
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
AssignedTo: unassigned at gcc dot gnu dot org
    ReportedBy: nroets at gmail dot com
GCC target triplet: i486-linux-gnu


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