From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7524 invoked by alias); 2 May 2005 10:24:36 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 7399 invoked by uid 48); 2 May 2005 10:24:30 -0000 Date: Mon, 02 May 2005 10:24:00 -0000 From: "akr at m17n dot org" To: gcc-bugs@gcc.gnu.org Message-ID: <20050502102427.21332.akr@m17n.org> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug c/21332] New: -O2 makes a loop doesn't execute a body X-Bugzilla-Reason: CC X-SW-Source: 2005-05/txt/msg00227.txt.bz2 List-Id: 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 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