optimization/7799: [3.2/3.3 regression] Loop bug with optimization flag -Os in gcc
Christian Ehrhardt
ehrhardt@mathematik.uni-ulm.de
Fri Dec 13 05:57:00 GMT 2002
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!
More information about the Gcc
mailing list