diff --git a/src/lj_cdata.c b/src/lj_cdata.c index a3257249..af78d05e 100644 --- a/src/lj_cdata.c +++ b/src/lj_cdata.c @@ -94,10 +94,12 @@ collect_attrib: if (ctype_ispointer(ct->info)) { CTSize sz = lj_ctype_size(cts, ctype_cid(ct->info)); /* Element size. */ if (sz != CTSIZE_INVALID) { - if (ctype_isptr(ct->info)) + if (ctype_isptr(ct->info)) { p = (uint8_t *)cdata_getptr(p, ct->size); - else if ((ct->info & (CTF_VECTOR|CTF_COMPLEX))) + } else if ((ct->info & (CTF_VECTOR|CTF_COMPLEX))) { + if ((ct->info & CTF_COMPLEX)) idx &= 1; *qual |= CTF_CONST; /* Valarray elements are constant. */ + } *pp = p + idx*(int32_t)sz; return ct; } diff --git a/src/lj_crecord.c b/src/lj_crecord.c index 86e95679..61210907 100644 --- a/src/lj_crecord.c +++ b/src/lj_crecord.c @@ -483,7 +483,10 @@ void LJ_FASTCALL recff_cdata_index(jit_State *J, RecordFFData *rd) #endif integer_key: if (ctype_ispointer(ct->info)) { - CTSize sz = lj_ctype_size(cts, (sid = ctype_cid(ct->info))); + CTSize sz; + if ((ct->info & CTF_COMPLEX)) + idx = emitir(IRT(IR_BAND, IRT_INTP), idx, lj_ir_kintp(J, 1)); + sz = lj_ctype_size(cts, (sid = ctype_cid(ct->info))); idx = crec_reassoc_ofs(J, idx, &ofs, sz); idx = emitir(IRT(IR_MUL, IRT_INTP), idx, lj_ir_kintp(J, sz)); ptr = emitir(IRT(IR_ADD, IRT_PTR), idx, ptr);