public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: Bug in loop optimize (invalid postinc to preinc transformation)
@ 2000-12-29 18:43 dewar
  2000-12-30 15:18 ` Toon Moene
  0 siblings, 1 reply; 21+ messages in thread
From: dewar @ 2000-12-29 18:43 UTC (permalink / raw)
  To: dewar, egcs; +Cc: aoliva, denisc, dkorn, gcc, peter.osterlund

<<Quite.  There's a pointer constant in the offending code.  It's not in
any array.  Do we offer implementation defined behaviour for numerical
pointer constants or not?  They do come in useful occasionally.
>>

It is hard NOT to offer implementation defined behavior :-)

I think you are asking if we provide easily defined useful behavior??

^ permalink raw reply	[flat|nested] 21+ messages in thread
* Re: Bug in loop optimize (invalid postinc to preinc transformation)
@ 2000-12-31  8:30 dewar
  2001-01-03  0:52 ` Jamie Lokier
  0 siblings, 1 reply; 21+ messages in thread
From: dewar @ 2000-12-31  8:30 UTC (permalink / raw)
  To: egcs, schwab; +Cc: aoliva, denisc, dkorn, gcc, peter.osterlund

<<Comparing pointers that don't point to the same (part of) object is
undefined.
>>

Indeed. The important thing to remember in C is that the semantic
model of a pointer is a pair (pointer-to-object, offset). Address
arithmetic just modifies the offset, comparison compares only the
offsets (and is undefined if the pointer-to-object values are
different).

Of course in practice the implementation is typically a single pointer
from a flat space, representing the sum of the two components, but the
proper semantic model needs to be kept in mind, and code that does not
respect this semantic model has undefined effects.

As C compilers get more clever, they are likely to be less permissive
to abuses of the semantics :-)

^ permalink raw reply	[flat|nested] 21+ messages in thread
* Re: Bug in loop optimize (invalid postinc to preinc transformation)
@ 2000-12-28 20:33 dewar
  0 siblings, 0 replies; 21+ messages in thread
From: dewar @ 2000-12-28 20:33 UTC (permalink / raw)
  To: aoliva, dewar; +Cc: gcc, kenner

<<Only if the compiler guarantees that no array will ever be placed
across the wrapping boundary.
>>

I don't understand, pointer incrementation must work through an array
regardless. Wrapping is simply not a semantically relevant notion when
it comes to pointers.

^ permalink raw reply	[flat|nested] 21+ messages in thread
* Re: Bug in loop optimize (invalid postinc to preinc transformation)
@ 2000-12-28  5:40 Robert Dewar
  2000-12-28 12:21 ` Alexandre Oliva
  0 siblings, 1 reply; 21+ messages in thread
From: Robert Dewar @ 2000-12-28  5:40 UTC (permalink / raw)
  To: aoliva, kenner; +Cc: gcc

<<The implementation of pointers is indeed unsigned on most machines,but
they are not "unsigned types", which would mean integral unsigned types.
So overflow is indeed undefined.
>>

Once again, this is confused.

If you increment a pointer

p++;

then this is defined only if the resulting pointer remains within the
same object, or in the csae of arrays it can go just past the end. Overflow
per se does not arise with pointers because of this stricter rule.

No optimization of pointer arithmetic can possibly be correct if it does
not preserve this fundamental semantic appearence.

^ permalink raw reply	[flat|nested] 21+ messages in thread
* Re: Bug in loop optimize (invalid postinc to preinc transformation)
@ 2000-12-28  1:14 Richard Kenner
  0 siblings, 0 replies; 21+ messages in thread
From: Richard Kenner @ 2000-12-28  1:14 UTC (permalink / raw)
  To: aoliva; +Cc: gcc

    > Overflow of *unsigned* types is well-defined.  

    Indeed.  But I don't think pointers are unsigned by default, are they?

The implementation of pointers is indeed unsigned on most machines,but
they are not "unsigned types", which would mean integral unsigned types.
So overflow is indeed undefined.

^ permalink raw reply	[flat|nested] 21+ messages in thread
* Re: Bug in loop optimize (invalid postinc to preinc transformation)
@ 2000-12-27 22:40 Robert Dewar
  2000-12-29 18:36 ` Jamie Lokier
  0 siblings, 1 reply; 21+ messages in thread
From: Robert Dewar @ 2000-12-27 22:40 UTC (permalink / raw)
  To: aoliva, egcs; +Cc: denisc, dkorn, gcc, peter.osterlund

<<Overflow of unsigned integers has defined behaviour -- they wrap.  The
question is, what rule applies to pointer comparisons?
>>

This is a malformed question. Any pointer increment is constrained 
to require that the resulting pointer be valid. Wrapping is simply
not an issue.

If p points to a valid address in an allocated array, then P+1 is also
valid, and there is no question of wrap. But P+2 may be beyond the
array and therefore ill-defined, and this has nothing to do with wrapping.

^ permalink raw reply	[flat|nested] 21+ messages in thread
* RE: Bug in loop optimize (TREE stage)
@ 2000-12-27  3:04 David Korn
  2000-12-27 15:42 ` Bug in loop optimize (invalid postinc to preinc transformation) Peter Osterlund
  0 siblings, 1 reply; 21+ messages in thread
From: David Korn @ 2000-12-27  3:04 UTC (permalink / raw)
  To: 'Denis Chertykov', gcc

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

^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2001-01-03  0:52 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-12-29 18:43 Bug in loop optimize (invalid postinc to preinc transformation) dewar
2000-12-30 15:18 ` Toon Moene
  -- strict thread matches above, loose matches on Subject: below --
2000-12-31  8:30 dewar
2001-01-03  0:52 ` Jamie Lokier
2000-12-28 20:33 dewar
2000-12-28  5:40 Robert Dewar
2000-12-28 12:21 ` Alexandre Oliva
2000-12-28 14:32   ` Geoff Keating
2000-12-28 15:22     ` Tim Hollebeek
2000-12-28 22:20       ` Dave Korn
2000-12-29  0:52         ` Richard Henderson
2000-12-29  1:51         ` Tim Hollebeek
2000-12-28  1:14 Richard Kenner
2000-12-27 22:40 Robert Dewar
2000-12-29 18:36 ` Jamie Lokier
2000-12-27  3:04 Bug in loop optimize (TREE stage) David Korn
2000-12-27 15:42 ` Bug in loop optimize (invalid postinc to preinc transformation) Peter Osterlund
2000-12-27 19:55   ` Alexandre Oliva
2000-12-27 21:09     ` Torbjorn Granlund
2000-12-27 21:20       ` Alexandre Oliva
2000-12-27 22:24     ` Jamie Lokier
2000-12-31  8:25       ` Andreas Schwab

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).