home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.lang.c:20167 comp.lang.c++:19859 comp.os.msdos.programmer:12417 comp.sys.ibm.pc.programmer:804 relcom.fido.su.c-c++:78 relcom.msdos:496
- Newsgroups: comp.lang.c,comp.lang.c++,comp.os.msdos.programmer,comp.sys.ibm.pc.programmer,relcom.fido.su.c-c++,relcom.msdos
- Path: sparky!uunet!mcsun!news.funet.fi!fuug!kiae!demos!ntc!news-server
- From: paul@soft.ntc.togliatti.su (Paul A. Karasev)
- Subject: Bug in Borland C/C++ v3.0 code generator
- Message-ID: <AAO74Phnws@soft.ntc.togliatti.su>
- Keywords: bug bcc C C++ _fastcall
- Lines: 124
- Sender: news-server@ntc
- Reply-To: paul@soft.ntc.togliatti.su
- Organization: Solar Trading
- Date: Mon, 25 Jan 1993 14:39:04 GMT
-
-
- Hi!
-
- I've found a bug in BC 3.0 code generator - I haven't the List of known
- bugs nether for BC nor for MS so ... :-(((
-
- To understand the bug just look at following source and compare with
- code produced by BCC. (my poor englishhhh don't allow me to write
- all I want)
-
-
- source of fast_bug.c:
- --------------------------------- CUT HERE ------------------------------------
-
- typedef int (_fastcall *procPtr)(int*, int*);
-
- int _fastcall proc1(int*,int*);
- int _fastcall proc2(int*,int*);
-
- procPtr decodeArray[] = { proc1, proc2 };
-
- int execute(int code)
- {
- int arg1, arg2;
-
- return decodeArray[code]( &arg1,&arg2 ); // !!!! Bug here !!!!
- }
-
- int _fastcall proc1(int* a, int* b)
- {
- return *a = *b ; // Just to prevent warning
- }
-
- ********************************************************************************
- The *wrong* code produced by BCC v3.0 (-c -S -O2)
- -------------------------------------------------
-
- .
- . Skipped
- .
- _execute proc near
- push bp
- mov bp,sp
- sub sp,4
- ;
- ; {
- ; int arg1, arg2;
- ;
- ; return decodeArray[code]( &arg1, &arg2 ); // !!!! Bug here !!!!
- ;
- lea ax,word ptr [bp-4] ; Load arg2 - OK
- lea bx,word ptr [bp-2] ; Load arg1
- mov bx,word ptr [bp+4] ; !!! BUG Overwrite arg2 with addr. of array !!!
- shl bx,1
- call word ptr DGROUP:_decodeArray[bx]
- ;
- ; }
- ;
- mov sp,bp
- pop bp
- ret
- _execute endp
- ;
- ; int _fastcall proc1(int* a, int* b)
- ;
- assume cs:_TEXT
- _proc1 proc near
- push bp
- mov bp,sp
- sub sp,2
- push si
- mov word ptr [bp-2],ax
- ;
- ; {
- ; return *a = *b ; // Just to prevent warning
- ;
- mov si,word ptr [bp-2]
- mov dx,word ptr [si]
- mov word ptr [bx],dx
- mov ax,dx
- ;
- ; }
- ;
- .
- . Skipped
- .
-
- ********************************************************************************
- Here *correct* code of same source compiled with MS C v 6.0 (/Oxaz /Gr /c /Fa)
- (Just to compare)
- -------------------------------------------------------------------------------
- .
- . Skipped
- .
-
- ; register ax = code
- ; arg1 = -2
- ; arg2 = -4
- mov si,ax
- ; Line 14
- shl si,1
- mov ax,WORD PTR _decodeArray[si]
- mov WORD PTR [bp-6],ax
- lea bx,WORD PTR [bp-2] ;code // ?? it's arg1 (wrong comment)
- lea ax,WORD PTR [bp-4] ;arg2 // arg2
- call WORD PTR [bp-6]
- .
- . Skipped
- .
-
- ********************************************************************************
-
- Can somebody send me list of known bugs in DOS C/C++ compilers ?
- (If you have the list and decide to send it, ask me before you
- do it, please).
-
- Yours,
-
- paul@soft
-
-
- paul@soft
-
-
-