From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31035 invoked by alias); 31 Aug 2005 16:05:42 -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 30403 invoked by uid 48); 31 Aug 2005 16:05:27 -0000 Date: Wed, 31 Aug 2005 16:05:00 -0000 From: "qrczak at knm dot org dot pl" To: gcc-bugs@gcc.gnu.org Message-ID: <20050831160521.23657.qrczak@knm.org.pl> Reply-To: gcc-bugzilla@gcc.gnu.org Subject: [Bug c/23657] New: Wrong code generated: too much optimized out X-Bugzilla-Reason: CC X-SW-Source: 2005-08/txt/msg03622.txt.bz2 List-Id: /* The result should be 7. When compiled with gcc version 4.1.0 20050815 (experimental) with some patches from PLD (incl. PR7776, PR20297, PR23128, PR22533, PR23386) with -O, the result is 0. */ #include int arr[100]; int *alloc(void) {return arr;} void fill(int n) { int *result = alloc(); int *dest = result; for(;;) { int *next; dest[0] = 7; if (--n == 0) break; next = dest + 1; dest = next; } } int main(void) { fill(5); printf("%d\n", arr[1]); return 0; } /* Looking at the generated assembly code, the whole loop is optimized out, except for filling the first element. Using less temporaries or inlining alloc() makes the bug disappear. The bug manifests only with optimization turned on. */ -- Summary: Wrong code generated: too much optimized out Product: gcc Version: 4.1.0 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: qrczak at knm dot org dot pl CC: gcc-bugs at gcc dot gnu dot org GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23657