GCC 4.0 optimization bug?
GCC 4.0 optimization bug?
- Subject: GCC 4.0 optimization bug?
- From: Jeremy Sagan <email@hidden>
- Date: Wed, 25 Jan 2006 22:11:48 -0500
All compiles here are compiled with the -O2 option for intel
(although -O3 and -OS also fail)
The problem occurs because gPlayFileList is 0 and can not be
dereferenced. Apparently GCC with O2 or greater optimization will
move the dereferencing outside of the loop and actually dereference
gPlayFileList before checking numfiles. Is this not a bug in the
compiler?
// ** GCC 4.0 for intel moves this instruction to before outside the
loop
static SInt32 GetTotalSecondsThusFar(void)
{
FSSpecFilePlayListPtr AFPLPtr;
SInt32 seconds;
int i, numFiles = gJBNumDisplayed;
for (i = seconds = 0; i < numFiles; i++)
{
AFPLPtr = (*gPlayFileList) + i; //**
seconds += (AFPLPtr->minutes * 60) + AFPLPtr->seconds;
}
return (seconds);
}
// Here is the disassembly:
_GetTotalSecondsThusFar:
pushl ëp
movl L_gPlayFileList$non_lazy_ptr, êx
movl %esp, ëp
pushl íi
movl _gJBNumDisplayed, íi
pushl %esi
xorl %esi, %esi
pushl ëx
xorl ëx, ëx
movl (êx), êx
movl (êx), ìx //This causes a segmentation fault since
gPlayFileList is 0
jmp L365
L366:
movzbl 72(ìx), êx
incl ëx
leal 0(,êx,4), íx
sall $6, êx
subl íx, êx
movzbl 73(ìx), íx
addl $296, ìx
addl íx, êx
addl êx, %esi
L365:
cmpl íi, ëx
jl L366
movl %esi, êx
popl ëx
popl %esi
popl íi
popl ëp
ret
// This code is a workaround the problem but should be unnecessary!
static SInt32 GetTotalSecondsThusFar(void)
{
SInt32 seconds = 0;
if (gPlayFileList)
{
FSSpecFilePlayListPtr AFPLPtr;
int i, numFiles = gJBNumDisplayed;
for (i = 0; i < numFiles; i++)
{
AFPLPtr = (*gPlayFileList) + i;
seconds += (AFPLPtr->minutes * 60) + AFPLPtr->seconds;
}
}
return (seconds);
}
_GetTotalSecondsThusFar:
pushl ëp
movl L_gPlayFileList$non_lazy_ptr, êx
movl %esp, ëp
pushl íi
pushl %esi
pushl ëx
movl (êx), êx
testl êx, êx
jne L365
xorl %esi, %esi
jmp L367
L365:
movl _gJBNumDisplayed, íi
xorl %esi, %esi
xorl ëx, ëx
movl (êx), ìx
jmp L368
L369:
movzbl 72(ìx), êx
incl ëx
leal 0(,êx,4), íx
sall $6, êx
subl íx, êx
movzbl 73(ìx), íx
addl $296, ìx
addl íx, êx
addl êx, %esi
L368:
cmpl íi, ëx
jl L369
L367:
movl %esi, êx
popl ëx
popl %esi
popl íi
popl ëp
ret
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden