vnmakarov / mir

A lightweight JIT compiler based on MIR (Medium Internal Representation) and C11 JIT compiler and interpreter based on MIR
MIT License
2.29k stars 145 forks source link

Bug in mir-gen-x86_64.c on bbv branch #388

Closed addr2line closed 8 months ago

addr2line commented 9 months ago

Bug is here: https://github.com/vnmakarov/mir/blob/bbv/mir-gen-x86_64.c#L905-L907

      gen_add_insn_before (gen_ctx, insn, new_insn);
      va_reg = va_op.var;
      gen_mov (gen_ctx, insn, MIR_MOV,
               _MIR_new_var_mem_op (ctx, MIR_T_I64, 0, va_reg, MIR_NON_VAR, 1), treg_op);

va_op has type MIR_op_t, which definition is:

typedef struct {
  void *data; /* Aux data  */
  MIR_op_mode_t mode : 8;
  /* Defined after MIR_func_finish.  Only MIR_OP_INT, MIR_OP_UINT,
     MIR_OP_FLOAT, MIR_OP_DOUBLE, MIR_OP_LDOUBLE: */
  MIR_op_mode_t value_mode : 8;
  union {
    MIR_reg_t reg;
    MIR_reg_t var; /* Used only internally */
    int64_t i;
    uint64_t u;
    float f;
    double d;
    long double ld;
    MIR_item_t ref; /* non-export/non-forward after simplification */
    MIR_str_t str;
    MIR_mem_t mem;
    MIR_mem_t var_mem; /* Used only internally */
    MIR_label_t label;
  } u;
} MIR_op_t;

I think the currect code is va_reg = va_op.u.var;.

addr2line commented 9 months ago

Oh, I think ci has already catch the bug:

D:\a\mir\mir\mir-gen-x86_64.c(906,22): error C2039: 'var': is not a member of 'MIR_op_t' [D:\a\mir\mir\mir.vcxproj]
D:\a\mir\mir\mir.h(251,16): message : see declaration of 'MIR_op_t' [D:\a\mir\mir\mir.vcxproj]
vnmakarov commented 8 months ago

Thank you for reporting this. I've just fixed this.

To be honest I do not test code on Win32 manually. Therefore I should have looked at CI results to avoid this kind of issues.

Now I see that windows port on bbv branch is broken (master branch is ok on windows). Some tests crashed by sigfault. I'll investigate it later.

addr2line commented 8 months ago

Thanks for your explanation!