D - [BUG] bogus codegen with -inline (access violation)
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; 159: 160: l = -1; 0042DCC9 cmp word ptr [esp+18h],0 0042DCCF je _D3dsc5cache6Primes6Primes7bsearchFAsssZi+5Bh (0042dd13) 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 (0042dcf2) 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 (0042dd0f) 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 (0042dce5) 0042DD0D jmp _D3dsc5cache6Primes6Primes7bsearchFAsssZi+5Bh (0042dd13) 167: else 168: u = m; 0042DD0F mov esi,edx 0042DD11 jmp _D3dsc5cache6Primes6Primes7bsearchFAsssZi+4Ah (0042dd02) 169: } 170: 171: if (u >= size || array[u] != match) 0042DD13 cmp si,word ptr [esp+18h] 0042DD18 jge _D3dsc5cache6Primes6Primes7bsearchFAsssZi+73h (0042dd2b) 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 (0042dd38) 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
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) begin 666 Primes.d M+RHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ M*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BH-" T*(" (" M(" ("!4:&ES('-O9G1W87)E(&ES('!R;W9I9&5D("=A<RUI<R<L('=I=&AO M=70 86YY(&5X<')E<W, ;W( :6UP;&EE9 T*(" (" ("!W87)R86YT>2X M26X ;F\ 979E;G0 =VEL;"!T:&4 875T:&]R<R!B92!H96QD(&QI86)L92!F M;W( 9&%M86=E<PT*(" (" ("!O9B!A;GD :VEN9"!A<FES:6YG(&9R;VT M=&AE('5S92!O9B!T:&ES('-O9G1W87)E+ T*(" (" (" -"B (" (" M4&5R;6ES<VEO;B!I<R!H97)E8GD 9W)A;G1E9"!T;R!A;GEO;F4 =&\ =7-E M('1H:7, <V]F='=A<F4 9F]R(&%N>2 -"B (" (" <'5R<&]S92P :6YC M;'5D:6YG(&-O;6UE<F-I86P 87!P;&EC871I;VYS+"!A;F0 =&\ 86QT97( M:70 86YD+V]R( T*(" (" ("!R961I<W1R:6)U=&4 :70 9G)E96QY+"!S M=6)J96-T('1O('1H92!F;VQL;W=I;F< <F5S=')I8W1I;VYS. T*(" (" M(" -"B (" (" ,2X 5&AE(&]R:6=I;B!O9B!T:&ES('-O9G1W87)E(&UU M<W0 ;F]T(&)E(&UI<W)E<')E<V5N=&5D.R!Y;W4 ;75S=" -"B (" (" M(" ;F]T(&-L86EM('1H870 >6]U('=R;W1E('1H92!O<FEG:6YA;"!S;V9T M=V%R92X 268 >6]U('5S92!T:&ES( T*(" (" (" ("!S;V9T=V%R92!I M;B!A('!R;V1U8W0L(&%N(&%C:VYO=VQE9&=M96YT('=I=&AI;B!D;V-U;65N M=&%T:6]N(&]F( T*(" (" (" ("!S86ED('!R;V1U8W0 =V]U;&0 8F4 M87!P<F5C:6%T960 8G5T(&ES(&YO="!R97%U:7)E9"X-" T*(" (" (" R M+B!!;'1E<F5D('-O=7)C92!V97)S:6]N<R!M=7-T(&)E('!L86EN;'D ;6%R M:V5D(&%S('-U8V L(&%N9"!M=7-T( T*(" (" (" ("!N;W0 8F4 ;6ES M<F5P<F5S96YT960 87, 8F5I;F< =&AE(&]R:6=I;F%L('-O9G1W87)E+ T* M<B!A;'1E<F5D(&9R;VT 86YY(&1I<W1R:6)U=&EO; T*(" (" (" ("!O M*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ M=F%T92!S=&%T:6, 8V]N<W0 <VAO<G0 <')I;65S6UT /0T*(" (" ("!; M,S$L(" Q,S<L(" Q,SDL(" Q-#DL(" Q-3$L(" Q-3<L(" Q-C,L(" Q-C<L M,C,L(" X,C<L(" X,CDL(" X,SDL(" X-3,L(" X-3<L(" X-3DL(" X-C,L M-#DL M.#DL M,#DL M-#DL M,#DL M-#DL M,#DL M,#DL M,#DL M-#DL M*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ M>2UC:&]P('-E87)C:"!O;B!S;W)T960 9&%T82X-" T*(" (" (" J*BHJ M*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ M:6, :6YT(&)S96%R8V *'-H;W)T6UT 87)R87DL('-H;W)T(&UA=&-H*0T* M(" ("!W:&EL92 H;"LQ("$]('4I( T*(" (" (" (" (" (" (" M('L-"B (" (" (" (" (" (" ("!P<FEN=&8 *"(E9"P )60L("5D M7&XB+"!L+"!U+"!M*3L-"B (" (" (" (" (" (" ("!M(#T *&P M(#P M(" (" (" (" (" (" (" (&5L<V4-"B (" (" (" (" (" M(" (" ("!U(#T M(" (" (" (" (&EF("AU(#X](&%R<F%Y+FQE;F=T:"!\?"!A<G)A>5MU M("\J*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ M("!R971U<FX 82!P<FEM92!N=6UB97( 8F5T=V5E;B R(&%N9" W.3$Y("AI M;F-L=7-I=F4I('1H870-"B (" (" (" (" ("!I<R!E<75A;"!T;R!O M<B!L87)G97( =&AA;B!T:&4 9VEV96X )W1A<F=E="< ;G5M8F5R+B -" T* M(" (" (" J*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ*BHJ M"B (" (" (" (" ("!S:&]R="!I;F1E>" ](&)S96%R8V *'!R:6UE M<RP =&%R9V5T*3L-"B (" (" (" (" ("!I9B H:6YD97 /" P*0T* M(" (" (" (" (" (" ("!I;F1E>" ]("UI;F1E>#L-" T*(" (" M(" (" (" (&EF("AI;F1E>" ^/2!P<FEM97,N;&5N9W1H*0T*(" (" '('T-"GT-" `` ` end
Apr 23 2004