home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / c / 20167 < prev    next >
Encoding:
Internet Message Format  |  1993-01-25  |  3.1 KB

  1. 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
  2. Newsgroups: comp.lang.c,comp.lang.c++,comp.os.msdos.programmer,comp.sys.ibm.pc.programmer,relcom.fido.su.c-c++,relcom.msdos
  3. Path: sparky!uunet!mcsun!news.funet.fi!fuug!kiae!demos!ntc!news-server
  4. From:  paul@soft.ntc.togliatti.su (Paul A. Karasev)
  5. Subject: Bug in Borland C/C++ v3.0 code generator
  6. Message-ID: <AAO74Phnws@soft.ntc.togliatti.su>
  7. Keywords: bug bcc C C++ _fastcall
  8. Lines: 124
  9. Sender: news-server@ntc
  10. Reply-To: paul@soft.ntc.togliatti.su
  11. Organization: Solar Trading
  12. Date: Mon, 25 Jan 1993 14:39:04 GMT
  13.  
  14.  
  15. Hi!
  16.  
  17. I've found a bug in BC 3.0 code generator - I haven't the List of known 
  18. bugs nether for BC nor for MS so  ... :-(((
  19.  
  20. To understand the bug just look at following source and compare with 
  21. code produced by BCC. (my poor englishhhh don't allow me to write 
  22. all I want)
  23.  
  24.  
  25. source of fast_bug.c: 
  26. --------------------------------- CUT HERE ------------------------------------
  27.  
  28. typedef    int    (_fastcall *procPtr)(int*, int*);
  29.  
  30. int    _fastcall    proc1(int*,int*);
  31. int    _fastcall    proc2(int*,int*);
  32.  
  33. procPtr        decodeArray[] = { proc1, proc2 };
  34.  
  35. int    execute(int code)
  36. {
  37.     int    arg1, arg2;
  38.  
  39.     return decodeArray[code]( &arg1,&arg2 );    // !!!! Bug here !!!!
  40. }
  41.  
  42. int    _fastcall    proc1(int* a, int* b)
  43. {
  44.     return *a = *b ;      // Just to prevent warning
  45. }
  46.  
  47. ********************************************************************************
  48. The *wrong* code produced by BCC v3.0 (-c -S -O2)
  49. -------------------------------------------------
  50.  
  51.     .
  52.     . Skipped
  53.     .
  54. _execute    proc    near
  55.     push    bp
  56.     mov    bp,sp
  57.     sub    sp,4
  58.    ;
  59.    ;    {
  60.    ;        int    arg1, arg2;
  61.    ;
  62.    ;        return decodeArray[code]( &arg1, &arg2 ); // !!!! Bug here !!!!
  63.    ;
  64.     lea    ax,word ptr [bp-4]      ; Load arg2 - OK
  65.     lea    bx,word ptr [bp-2]      ; Load arg1 
  66.     mov    bx,word ptr [bp+4]      ; !!! BUG Overwrite arg2 with addr. of array !!!
  67.     shl    bx,1
  68.     call    word ptr DGROUP:_decodeArray[bx]
  69.    ;
  70.    ;    }
  71.    ;
  72.     mov    sp,bp
  73.     pop    bp
  74.     ret
  75. _execute    endp
  76.    ;
  77.    ;    int    _fastcall    proc1(int* a, int* b)
  78.    ;
  79.     assume    cs:_TEXT
  80. _proc1    proc    near
  81.     push    bp
  82.     mov    bp,sp
  83.     sub    sp,2
  84.     push    si
  85.     mov    word ptr [bp-2],ax
  86.    ;
  87.    ;    {
  88.    ;        return *a = *b ;      // Just to prevent warning
  89.    ;
  90.     mov    si,word ptr [bp-2]
  91.     mov    dx,word ptr [si]
  92.     mov    word ptr [bx],dx
  93.     mov    ax,dx
  94.    ;
  95.    ;    }
  96.    ;
  97.   .
  98.   . Skipped
  99.   .
  100.  
  101. ********************************************************************************
  102. Here *correct* code of same source compiled with MS C v 6.0 (/Oxaz /Gr /c /Fa)
  103. (Just to compare)
  104. -------------------------------------------------------------------------------
  105.   .
  106.   . Skipped
  107.   .
  108.  
  109. ;    register ax = code
  110. ;    arg1 = -2
  111. ;    arg2 = -4
  112.     mov    si,ax
  113. ; Line 14
  114.     shl    si,1
  115.     mov    ax,WORD PTR _decodeArray[si]
  116.     mov    WORD PTR [bp-6],ax
  117.     lea    bx,WORD PTR [bp-2]    ;code // ?? it's arg1 (wrong comment)
  118.     lea    ax,WORD PTR [bp-4]    ;arg2 // arg2
  119.     call    WORD PTR [bp-6]
  120.   .
  121.   . Skipped
  122.   .
  123.  
  124. ********************************************************************************
  125.  
  126. Can somebody send me list of known bugs in DOS C/C++ compilers ?
  127. (If you have the list and decide to send it, ask me before you 
  128. do it, please).
  129.  
  130. Yours,
  131.  
  132. paul@soft
  133.  
  134.  
  135. paul@soft
  136.  
  137.  
  138.