Bug 16348 - [4.0 Regression] Loop gets executed when it shouldnt
Summary: [4.0 Regression] Loop gets executed when it shouldnt
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 4.0.0
: P2 critical
Target Milestone: 4.0.0
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2004-07-03 14:51 UTC by Anton Blanchard
Modified: 2004-09-13 14:15 UTC (History)
2 users (show)

See Also:
Host:
Target: powerpc64-unknown-linux-gnu
Build:
Known to work:
Known to fail:
Last reconfirmed: 2004-07-03 19:57:12


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Anton Blanchard 2004-07-03 14:51:19 UTC
I compiled a 3.5 powerpc64 toolchain from cvs (20040703) and found an issue
when booting a linux kernel compiled with it. Here is a simplified test case:

struct foo {
        long *a;
} bar[0];

#define SIZE (sizeof(bar)/sizeof(*bar))

int main()
{
        int i;

        printf("%d\n", SIZE);
        for (i = 0; i < SIZE; i++)
                printf("can not happen\n");
}

When compiled with no optimisation, the loop is executed even though size is 0:
0
can not happen
can not happen
can not happen
etc.
Comment 1 Andrew Pinski 2004-07-03 19:57:12 UTC
Confirmed, it is broken in 20040628 also.
Somehow the conditional is being removed.
Comment 2 Andrew Pinski 2004-07-04 01:51:47 UTC
It worked on 20040623 but not in 20040627.
Comment 3 Giovanni Bajo 2004-07-04 14:31:30 UTC
the first generic dump is already borked:

main ()
{
  int i;

  printf ("%d\n", 0);
  i = 0;
  <D1105>:;
  printf ("can not happen\n");
  i = i + 1;
  goto <D1105>;
}

Could be up to the recent RTH work on genericization? It went in in the 
timeframe Pinksi isolated.
Comment 4 GCC Commits 2004-07-04 17:29:03 UTC
Subject: Bug 16348

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	rth@gcc.gnu.org	2004-07-04 17:28:56

Modified files:
	gcc            : ChangeLog c-typeck.c 
Added files:
	gcc/testsuite/gcc.c-torture/execute: 20040704-1.c 

Log message:
	PR c/16348
	* c-typeck.c (c_finish_loop): Don't clear cond for cond_is_first loops.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.4284&r2=2.4285
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-typeck.c.diff?cvsroot=gcc&r1=1.335&r2=1.336
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/20040704-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1

Comment 5 Richard Henderson 2004-07-04 17:31:59 UTC
Fixed.