public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: optimization/7799: [3.2/3.3 regression] Loop bug with optimization flag -Os in gcc
@ 2002-12-13  5:57 Christian Ehrhardt
  2002-12-13  6:13 ` Eric Botcazou
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Christian Ehrhardt @ 2002-12-13  5:57 UTC (permalink / raw)
  To: nejataydin, gcc-gnats, gcc, gcc-bugs, nobody


http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=7799

Hi,

this PR is about the following code snippet that is miscompiled with -Os

void fill (int* p, int* q[10])
{
        int i;
        for (i = 0; i < 10; i++)
                *q++ = &p[i];
}

The asm-Code is this:

        pushl   %ebp
        movl    %esp, %ebp
        movl    8(%ebp), %eax
        movl    12(%ebp), %edx
        leal    36(%eax), %ecx
.L6:
        movl    %eax, (%edx)
        addl    $4, %eax
        addl    $4, %edx
        cmpl    %ecx, %eax
        jle     .L6
        popl    %ebp
        ret

This code roughly corresponds to the following C-Code:

void fill (int * p, int *q[10])
{
	int ecx = (int)p + 9;
	do {
		*q = p; p++; q++;
	} while ((int)p <= ecx);
}

This transformation is IMHO illegal because there is no way to make the
comparison in general equivialent to that in the original for loop.
If p is initially 0x7ffffffc the comparison must be treated as unsigned,
however, if p is initially 0xfffffffc the comparison must be treated as
signed.

    regards   Christian

-- 
THAT'S ALL FOLKS!

^ permalink raw reply	[flat|nested] 11+ messages in thread
* Re: optimization/7799: [3.2/3.3 regression] Loop bug with optimization flag -Os in gcc
@ 2002-12-20  1:24 Joern Rennecke
  0 siblings, 0 replies; 11+ messages in thread
From: Joern Rennecke @ 2002-12-20  1:24 UTC (permalink / raw)
  To: Segher Boessenkool
  Cc: Christian Ehrhardt, nejataydin, gcc-gnats, gcc, gcc-bugs

> 6.2.5.19:
>         ... An array type describes a contiguously allocated nonempty set of
>         objects with a particular member object type, called the element
>         type. ...
>
> So an array can not wrap around address 0.

It can't wrap around there, but if pointers are signed, it might straddle 0
nonetheless.  This requires, of course, for an aligned start address
that the address 0 is not the same as NULL, which AFAICR is something gcc
doesn't currently support.

OTOH, if the start address is not aligned to a multiple of the types size,
you can have the array straddle address 0 without it ever being a valid
address.  Well, that is if character pointers have a different
representation ;-)

^ permalink raw reply	[flat|nested] 11+ messages in thread
* Re: optimization/7799: [3.2/3.3 regression] Loop bug with optimization flag -Os in gcc
@ 2002-12-20 21:08 Robert Dewar
  0 siblings, 0 replies; 11+ messages in thread
From: Robert Dewar @ 2002-12-20 21:08 UTC (permalink / raw)
  To: amylaar, segher; +Cc: ehrhardt, gcc-bugs, gcc-gnats, gcc, nejataydin

> It can't wrap around there, but if pointers are signed, it might straddle 0
> nonetheless.  This requires, of course, for an aligned start address
> that the address 0 is not the same as NULL, which AFAICR is something gcc
> doesn't currently support.

Note that addresses *are* considered signed on the INMOS Transputer as a
proof of existence :-)

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

end of thread, other threads:[~2002-12-21  0:26 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-12-13  5:57 optimization/7799: [3.2/3.3 regression] Loop bug with optimization flag -Os in gcc Christian Ehrhardt
2002-12-13  6:13 ` Eric Botcazou
2002-12-13  7:34   ` Christian Ehrhardt
2002-12-13 10:28     ` Eric Botcazou
2002-12-13  6:52 ` Andrew Haley
2002-12-13  7:35   ` Christian Ehrhardt
2002-12-13  7:44     ` Andreas Schwab
2002-12-19 22:52 ` Segher Boessenkool
2002-12-20  5:46   ` Christian Ehrhardt
2002-12-20  1:24 Joern Rennecke
2002-12-20 21:08 Robert Dewar

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).