aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Pall <mike>2024-08-20 19:13:59 +0200
committerMike Pall <mike>2024-08-20 19:13:59 +0200
commit304da39cc5ee43491f7b1f4e0c9c52d477ce0d98 (patch)
tree0ec28a67d11a48d5a9faa047ff9f941e4cc364bc
parentcdc2db3aeac442e139c3b1fda715fdfa78da8791 (diff)
downloadluajit-304da39cc5ee43491f7b1f4e0c9c52d477ce0d98.tar.gz
luajit-304da39cc5ee43491f7b1f4e0c9c52d477ce0d98.tar.bz2
luajit-304da39cc5ee43491f7b1f4e0c9c52d477ce0d98.zip
FFI: Add missing coercion when recording 64-bit bit.*().
Thanks to Peter Cawley. #1252
-rw-r--r--src/Makefile.dep2
-rw-r--r--src/lj_crecord.c31
2 files changed, 22 insertions, 11 deletions
diff --git a/src/Makefile.dep b/src/Makefile.dep
index e9f83399..7b534b05 100644
--- a/src/Makefile.dep
+++ b/src/Makefile.dep
@@ -98,7 +98,7 @@ lj_crecord.o: lj_crecord.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
98 lj_cdata.h lj_cparse.h lj_cconv.h lj_carith.h lj_clib.h lj_ccall.h \ 98 lj_cdata.h lj_cparse.h lj_cconv.h lj_carith.h lj_clib.h lj_ccall.h \
99 lj_ff.h lj_ffdef.h lj_ir.h lj_jit.h lj_ircall.h lj_iropt.h lj_trace.h \ 99 lj_ff.h lj_ffdef.h lj_ir.h lj_jit.h lj_ircall.h lj_iropt.h lj_trace.h \
100 lj_dispatch.h lj_traceerr.h lj_record.h lj_ffrecord.h lj_snap.h \ 100 lj_dispatch.h lj_traceerr.h lj_record.h lj_ffrecord.h lj_snap.h \
101 lj_crecord.h lj_strfmt.h 101 lj_crecord.h lj_strfmt.h lj_strscan.h
102lj_ctype.o: lj_ctype.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \ 102lj_ctype.o: lj_ctype.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
103 lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_strfmt.h lj_ctype.h \ 103 lj_gc.h lj_err.h lj_errmsg.h lj_str.h lj_tab.h lj_strfmt.h lj_ctype.h \
104 lj_ccallback.h lj_buf.h 104 lj_ccallback.h lj_buf.h
diff --git a/src/lj_crecord.c b/src/lj_crecord.c
index 79159454..e8ae426d 100644
--- a/src/lj_crecord.c
+++ b/src/lj_crecord.c
@@ -32,6 +32,7 @@
32#include "lj_crecord.h" 32#include "lj_crecord.h"
33#include "lj_dispatch.h" 33#include "lj_dispatch.h"
34#include "lj_strfmt.h" 34#include "lj_strfmt.h"
35#include "lj_strscan.h"
35 36
36/* Some local macros to save typing. Undef'd at the end. */ 37/* Some local macros to save typing. Undef'd at the end. */
37#define IR(ref) (&J->cur.ir[(ref)]) 38#define IR(ref) (&J->cur.ir[(ref)])
@@ -1807,11 +1808,21 @@ static CTypeID crec_bit64_type(CTState *cts, cTValue *tv)
1807 return 0; /* Use regular 32 bit ops. */ 1808 return 0; /* Use regular 32 bit ops. */
1808} 1809}
1809 1810
1811static TRef crec_bit64_arg(jit_State *J, CType *d, TRef sp, TValue *sval)
1812{
1813 if (LJ_UNLIKELY(tref_isstr(sp))) {
1814 if (lj_strscan_num(strV(sval), sval)) {
1815 sp = emitir(IRTG(IR_STRTO, IRT_NUM), sp, 0);
1816 } /* else: interpreter will throw. */
1817 }
1818 return crec_ct_tv(J, d, 0, sp, sval);
1819}
1820
1810void LJ_FASTCALL recff_bit64_tobit(jit_State *J, RecordFFData *rd) 1821void LJ_FASTCALL recff_bit64_tobit(jit_State *J, RecordFFData *rd)
1811{ 1822{
1812 CTState *cts = ctype_ctsG(J2G(J)); 1823 CTState *cts = ctype_ctsG(J2G(J));
1813 TRef tr = crec_ct_tv(J, ctype_get(cts, CTID_INT64), 0, 1824 TRef tr = crec_bit64_arg(J, ctype_get(cts, CTID_INT64),
1814 J->base[0], &rd->argv[0]); 1825 J->base[0], &rd->argv[0]);
1815 if (!tref_isinteger(tr)) 1826 if (!tref_isinteger(tr))
1816 tr = emitconv(tr, IRT_INT, tref_type(tr), 0); 1827 tr = emitconv(tr, IRT_INT, tref_type(tr), 0);
1817 J->base[0] = tr; 1828 J->base[0] = tr;
@@ -1822,7 +1833,7 @@ int LJ_FASTCALL recff_bit64_unary(jit_State *J, RecordFFData *rd)
1822 CTState *cts = ctype_ctsG(J2G(J)); 1833 CTState *cts = ctype_ctsG(J2G(J));
1823 CTypeID id = crec_bit64_type(cts, &rd->argv[0]); 1834 CTypeID id = crec_bit64_type(cts, &rd->argv[0]);
1824 if (id) { 1835 if (id) {
1825 TRef tr = crec_ct_tv(J, ctype_get(cts, id), 0, J->base[0], &rd->argv[0]); 1836 TRef tr = crec_bit64_arg(J, ctype_get(cts, id), J->base[0], &rd->argv[0]);
1826 tr = emitir(IRT(rd->data, id-CTID_INT64+IRT_I64), tr, 0); 1837 tr = emitir(IRT(rd->data, id-CTID_INT64+IRT_I64), tr, 0);
1827 J->base[0] = emitir(IRTG(IR_CNEWI, IRT_CDATA), lj_ir_kint(J, id), tr); 1838 J->base[0] = emitir(IRTG(IR_CNEWI, IRT_CDATA), lj_ir_kint(J, id), tr);
1828 return 1; 1839 return 1;
@@ -1842,9 +1853,9 @@ int LJ_FASTCALL recff_bit64_nary(jit_State *J, RecordFFData *rd)
1842 if (id) { 1853 if (id) {
1843 CType *ct = ctype_get(cts, id); 1854 CType *ct = ctype_get(cts, id);
1844 uint32_t ot = IRT(rd->data, id-CTID_INT64+IRT_I64); 1855 uint32_t ot = IRT(rd->data, id-CTID_INT64+IRT_I64);
1845 TRef tr = crec_ct_tv(J, ct, 0, J->base[0], &rd->argv[0]); 1856 TRef tr = crec_bit64_arg(J, ct, J->base[0], &rd->argv[0]);
1846 for (i = 1; J->base[i] != 0; i++) { 1857 for (i = 1; J->base[i] != 0; i++) {
1847 TRef tr2 = crec_ct_tv(J, ct, 0, J->base[i], &rd->argv[i]); 1858 TRef tr2 = crec_bit64_arg(J, ct, J->base[i], &rd->argv[i]);
1848 tr = emitir(ot, tr, tr2); 1859 tr = emitir(ot, tr, tr2);
1849 } 1860 }
1850 J->base[0] = emitir(IRTG(IR_CNEWI, IRT_CDATA), lj_ir_kint(J, id), tr); 1861 J->base[0] = emitir(IRTG(IR_CNEWI, IRT_CDATA), lj_ir_kint(J, id), tr);
@@ -1859,15 +1870,15 @@ int LJ_FASTCALL recff_bit64_shift(jit_State *J, RecordFFData *rd)
1859 CTypeID id; 1870 CTypeID id;
1860 TRef tsh = 0; 1871 TRef tsh = 0;
1861 if (J->base[0] && tref_iscdata(J->base[1])) { 1872 if (J->base[0] && tref_iscdata(J->base[1])) {
1862 tsh = crec_ct_tv(J, ctype_get(cts, CTID_INT64), 0, 1873 tsh = crec_bit64_arg(J, ctype_get(cts, CTID_INT64),
1863 J->base[1], &rd->argv[1]); 1874 J->base[1], &rd->argv[1]);
1864 if (!tref_isinteger(tsh)) 1875 if (!tref_isinteger(tsh))
1865 tsh = emitconv(tsh, IRT_INT, tref_type(tsh), 0); 1876 tsh = emitconv(tsh, IRT_INT, tref_type(tsh), 0);
1866 J->base[1] = tsh; 1877 J->base[1] = tsh;
1867 } 1878 }
1868 id = crec_bit64_type(cts, &rd->argv[0]); 1879 id = crec_bit64_type(cts, &rd->argv[0]);
1869 if (id) { 1880 if (id) {
1870 TRef tr = crec_ct_tv(J, ctype_get(cts, id), 0, J->base[0], &rd->argv[0]); 1881 TRef tr = crec_bit64_arg(J, ctype_get(cts, id), J->base[0], &rd->argv[0]);
1871 uint32_t op = rd->data; 1882 uint32_t op = rd->data;
1872 if (!tsh) tsh = lj_opt_narrow_tobit(J, J->base[1]); 1883 if (!tsh) tsh = lj_opt_narrow_tobit(J, J->base[1]);
1873 if (!(op < IR_BROL ? LJ_TARGET_MASKSHIFT : LJ_TARGET_MASKROT) && 1884 if (!(op < IR_BROL ? LJ_TARGET_MASKSHIFT : LJ_TARGET_MASKROT) &&
@@ -1897,7 +1908,7 @@ TRef recff_bit64_tohex(jit_State *J, RecordFFData *rd, TRef hdr)
1897 CTypeID id2 = 0; 1908 CTypeID id2 = 0;
1898 n = (int32_t)lj_carith_check64(J->L, 2, &id2); 1909 n = (int32_t)lj_carith_check64(J->L, 2, &id2);
1899 if (id2) 1910 if (id2)
1900 trsf = crec_ct_tv(J, ctype_get(cts, CTID_INT32), 0, trsf, &rd->argv[1]); 1911 trsf = crec_bit64_arg(J, ctype_get(cts, CTID_INT32), trsf, &rd->argv[1]);
1901 else 1912 else
1902 trsf = lj_opt_narrow_tobit(J, trsf); 1913 trsf = lj_opt_narrow_tobit(J, trsf);
1903 emitir(IRTGI(IR_EQ), trsf, lj_ir_kint(J, n)); /* Specialize to n. */ 1914 emitir(IRTGI(IR_EQ), trsf, lj_ir_kint(J, n)); /* Specialize to n. */
@@ -1908,7 +1919,7 @@ TRef recff_bit64_tohex(jit_State *J, RecordFFData *rd, TRef hdr)
1908 if ((uint32_t)n > 254) n = 254; 1919 if ((uint32_t)n > 254) n = 254;
1909 sf |= ((SFormat)((n+1)&255) << STRFMT_SH_PREC); 1920 sf |= ((SFormat)((n+1)&255) << STRFMT_SH_PREC);
1910 if (id) { 1921 if (id) {
1911 tr = crec_ct_tv(J, ctype_get(cts, id), 0, J->base[0], &rd->argv[0]); 1922 tr = crec_bit64_arg(J, ctype_get(cts, id), J->base[0], &rd->argv[0]);
1912 if (n < 16) 1923 if (n < 16)
1913 tr = emitir(IRT(IR_BAND, IRT_U64), tr, 1924 tr = emitir(IRT(IR_BAND, IRT_U64), tr,
1914 lj_ir_kint64(J, ((uint64_t)1 << 4*n)-1)); 1925 lj_ir_kint64(J, ((uint64_t)1 << 4*n)-1));