This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
RE: Bug in loop optimize (TREE stage)
- To: 'Denis Chertykov' <denisc at overta dot ru>, gcc at gcc dot gnu dot org
- Subject: RE: Bug in loop optimize (TREE stage)
- From: David Korn <dkorn at pixelpower dot com>
- Date: Wed, 27 Dec 2000 11:07:30 -0000
>-----Original Message-----
>From: Denis Chertykov [mailto:denisc@overta.ru]
>Sent: 26 December 2000 20:06
>"Alexander Popov" <sasho@vip.orbitel.bg> have founded a bug in generic
>GCC code.
>I have tried avr and x86 ports.
>
>The XXX.rtl file already have a bug.
>
>
>volatile unsigned char *p;
>volatile unsigned char i;
>
>int main(void) {
>
> do {
> i++;
> } while(p++<(unsigned char *)0xffffffff);
> /* if 0xffffffff change to 0xfffffffe then no bug */
> return 0;
>}
This is undefined behaviour. Since you haven't initialised variable p,
the compiler is free to implement whatever it likes here. In particular,
>.globl main
> .type main,@function
>main:
> movb i, %al
> pushl %ebp
> incl %eax
> movl %esp, %ebp
> incl p
> movb %al, i
> xorl %eax, %eax
> popl %ebp
> ret
it is free to arbitrarily decide that the loop condition, being undefined,
will evaluate to FALSE, and so it decided here that the loop body would
run once; then it optimized the loop away altogether. In short, gcc is
right and your testcase is wrong.
DaveK
--
The Boulder Pledge: "Under no circumstances will I ever purchase anything
offered to me as the result of an unsolicited email message. Nor will I
forward chain letters, petitions, mass mailings, or virus warnings to large
numbers of others. This is my contribution to the survival of the online
community."
**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.
This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.
www.mimesweeper.com
**********************************************************************