www.digitalmars.com         C & C++   DMDScript  

D - [BUG] bogus codegen with -inline (access violation)

reply "Kris" <someidiot earthlink.dot.dot.dot.net> writes:
Here's a binary-chop with an interesting codegen issue. It operates fine
with any compiler flags other than -inline which, when applied, will cause
an access violation.

Compiler flags for the code listing are -g -O -release -inline

Will post the standalone module if Walter needs it.

- Kris

156:          static int bsearch (short[] array, short size, short match)
0042DCB8   push        eax
0042DCB9   push        ebx
0042DCBA   mov         ebx,0FFFFFFFFh
161:                  u = size;
0042DCBF   push        ebp
0042DCC0   push        esi
0042DCC1   mov         si,word ptr [esp+14h]
162:                  while (l+1 != u)
0042DCC6   push        edi
0042DCC7   mov         edi,eax
157:          {
158:                  short l, u, m;
160:                  l = -1;
0042DCC9   cmp         word ptr [esp+18h],0
0042DCCF   je          _D3dsc5cache6Primes6Primes7bsearchFAsssZi+5Bh
0042DCD1   mov         word ptr [esp+10h],bx
165:                        if (array[m] < match)
0042DCD6   mov         edx,dword ptr [esp+20h]
0042DCDA   mov         ebx,dword ptr [esp+1Ch]
0042DCDE   mov         ebp,edx
0042DCE0   mov         bx,word ptr [esp+10h]
163:                        {
164:                        m = (l + u) / 2;
0042DCE5   movsx       ecx,bx
0042DCE8   movsx       eax,si
0042DCEB   add         ecx,eax
0042DCED   test        ecx,ecx
0042DCEF   jns         _D3dsc5cache6Primes6Primes7bsearchFAsssZi+3Ah
0042DCF1   inc         ecx
0042DCF2   sar         ecx,1
0042DCF4   mov         edx,ecx
0042DCF6   movsx       ecx,cx
0042DCF9   cmp         word ptr l[ecx*2],di
0042DCFE   jge         _D3dsc5cache6Primes6Primes7bsearchFAsssZi+57h
166:                            l = m;
0042DD00   mov         ebx,edx
0042DD02   movsx       edx,bx
0042DD05   inc         edx
0042DD06   movsx       ecx,si
0042DD09   cmp         edx,ecx
0042DD0B   jne         _D3dsc5cache6Primes6Primes7bsearchFAsssZi+2Dh
0042DD0D   jmp         _D3dsc5cache6Primes6Primes7bsearchFAsssZi+5Bh
167:                        else
168:                           u = m;
0042DD0F   mov         esi,edx
0042DD11   jmp         _D3dsc5cache6Primes6Primes7bsearchFAsssZi+4Ah
169:                        }
171:                 if (u >= size || array[u] != match)
0042DD13   cmp         si,word ptr [esp+18h]
0042DD18   jge         _D3dsc5cache6Primes6Primes7bsearchFAsssZi+73h
0042DD1A   movsx       edx,si
0042DD1D   mov         ecx,dword ptr [esp+20h]
0042DD21   mov         eax,dword ptr [esp+1Ch]
0042DD25   cmp         word ptr [ecx+edx*2],di
0042DD29   je          _D3dsc5cache6Primes6Primes7bsearchFAsssZi+80h
172:                     return -u;
0042DD2B   pop         edi
0042DD2C   mov         eax,esi
0042DD2E   neg         eax
0042DD30   pop         esi
0042DD31   cwde
0042DD32   pop         ebp
0042DD33   pop         ebx
0042DD34   pop         ecx
0042DD35   ret         0Ch
173:                 return u;
0042DD38   movsx       eax,si
174:          }
0042DD3B   pop         edi
0042DD3C   pop         esi
0042DD3D   pop         ebp
0042DD3E   pop         ebx
0042DD3F   pop         ecx
0042DD40   ret         0Ch
Apr 20 2004
parent "Kris" <someidiot earthlink.dot.dot.dot.net> writes:
Wanted to bring this one up again, since -inline apparently causes static
array addresses to be passed incorrectly. Attached is the standalone example
(sans main)
Apr 23 2004