public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/21332] New: -O2 makes a loop doesn't execute a body
@ 2005-05-02 10:24 akr at m17n dot org
  2005-05-02 11:59 ` [Bug tree-optimization/21332] [4.1 Regression] -ftree-vrp " pinskia at gcc dot gnu dot org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: akr at m17n dot org @ 2005-05-02 10:24 UTC (permalink / raw)
  To: gcc-bugs

4.1.0 20050502 (experimental) seems have a problem with optimization.
The for loop in the else clause in the main doesn't execute the loop body. 

% cat t.c
extern int printf (__const char *__restrict __format, ...);

int f()
{
  return -2;
}

int main(int argc, char **argv)
{
  int c = f();
  long i;
  if (c > 0) {
    for (i=0;i<c;i++) {
      f();
    }
  }
  else {
    c = -c;
    printf("beg %d\n", c);
    for (i=0;i<c;i++) {
      printf("%d\n", i);
    }
    printf("end %d\n", i);
  }
  return 0;
}

% gcc -v -O2 t.c
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: ../gcc/configure --prefix=/home/src/gcc/trunk --enable-languages=c
Thread model: posix
gcc version 4.1.0 20050502 (experimental)
 /home/src/gcc/trunk/libexec/gcc/i686-pc-linux-gnu/4.1.0/cc1 -quiet -v t.c
-quiet -dumpbase t.c -mtune=pentiumpro -auxbase t -O2 -version -o /tmp/cc6LaTqE.s
ignoring nonexistent directory
"/home/src/gcc/trunk/lib/gcc/i686-pc-linux-gnu/4.1.0/../../../../i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /home/src/gcc/trunk/include
 /home/src/gcc/trunk/lib/gcc/i686-pc-linux-gnu/4.1.0/include
 /usr/include
End of search list.
GNU C version
 4.1.0 20050502 (experimental) (i686-pc-linux-gnu)
        compiled by GNU C version 4.1.0 20050502 (experimental).
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
 as -V -Qy -o /tmp/cc6jWNoa.o /tmp/cc6LaTqE.s
GNU assembler version 2.15 (i386-linux) using BFD version 2.15
 /home/src/gcc/trunk/libexec/gcc/i686-pc-linux-gnu/4.1.0/collect2 --eh-frame-hdr
-m elf_i386 -dynamic-linker /lib/ld-linux.so.2 /usr/lib/crt1.o /usr/lib/crti.o
/home/src/gcc/trunk/lib/gcc/i686-pc-linux-gnu/4.1.0/crtbegin.o
-L/home/src/gcc/trunk/lib/gcc/i686-pc-linux-gnu/4.1.0
-L/home/src/gcc/trunk/lib/gcc/i686-pc-linux-gnu/4.1.0/../../.. /tmp/cc6jWNoa.o
-lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s
--no-as-needed /home/src/gcc/trunk/lib/gcc/i686-pc-linux-gnu/4.1.0/crtend.o
/usr/lib/crtn.o
% ./a.out       
beg 2
end 0

It works well without optimization as follows.

% gcc t.c       
% ./a.out 
beg 2
0
1
end 2

-- 
           Summary: -O2 makes a loop doesn't execute a body
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: akr at m17n dot org
                CC: gcc-bugs at gcc dot gnu dot org


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


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2005-09-10 18:10 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-02 10:24 [Bug c/21332] New: -O2 makes a loop doesn't execute a body akr at m17n dot org
2005-05-02 11:59 ` [Bug tree-optimization/21332] [4.1 Regression] -ftree-vrp " pinskia at gcc dot gnu dot org
2005-05-02 12:06 ` belyshev at depni dot sinp dot msu dot ru
2005-05-17  8:15 ` steven at gcc dot gnu dot org
2005-05-17  8:18 ` steven at gcc dot gnu dot org
2005-05-25 15:13 ` steven at gcc dot gnu dot org
2005-06-02  2:58 ` cvs-commit at gcc dot gnu dot org
2005-06-02  3:06 ` dnovillo at gcc dot gnu dot org
2005-09-10 18:10 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).