Posted to tcl by apn at Mon Oct 17 13:38:55 GMT 2022view raw

  1. I'm trying to nail down a Tk bug that @fvogel and I think is a compiler bug.
  2. The C fragment in (HandleGenerateEvent) code looks like:
  3.  
  4. if (badOpt) {
  5. /* >>> This always executed irrespective of value of badOpt */
  6. Tcl_SetObjResult(interp, Tcl_ObjPrintf(
  7. "%s event doesn't accept \"%s\" option", name, Tcl_GetString(optionPtr)));
  8. Tcl_SetErrorCode(interp, "TK", "EVENT", "BAD_OPTION", NULL);
  9. return TCL_ERROR;
  10. }
  11.  
  12. The generated assembler is
  13.  
  14. ; 3971 : if (badOpt) {
  15.  
  16. mov eax, edi
  17. sete al
  18. test eax, eax
  19. je SHORT $LN48@HandleEven
  20. $LN43@HandleEven:
  21. (error handling code. Tcl_SetObjResult/SetErrorCode)
  22.  
  23. This looks broken to me. edi contains badOpt indicating the passed option is invalid. It doesn't make sense that it is copied into eax which is immediately overwritten by the sete instruction before the test. So instead of testing badOpt (di), the code tests the value of the ZF flag at the time the code is entered (which is copied into al). The value of badOpt/di is never checked.
  24.  

Comments

Posted by chw at Mon Oct 17 14:03:19 GMT 2022 [text] [code]

MOV EAX,EDI does not affect the condition codes. SETE thus depends on what the zero flag had before the MOV. TEST would set the zero flag when the SETE had made the entire EAX all zeroes. Conclusion: your analysis is correct. The compiler produced nonsense.