This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: Bug in loop optimize (TREE stage)



>-----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
**********************************************************************

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]