浏览代码

Don't treat all constified cdata content as constant.

Mike Pall 13 年之前
父节点
当前提交
e8af6e9da4
共有 3 个文件被更改,包括 16 次插入2 次删除
  1. 2 1
      src/Makefile.dep
  2. 1 0
      src/lj_ir.h
  3. 13 1
      src/lj_opt_fold.c

+ 2 - 1
src/Makefile.dep

@@ -133,7 +133,8 @@ lj_opt_dce.o: lj_opt_dce.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
  lj_ir.h lj_jit.h lj_iropt.h
  lj_ir.h lj_jit.h lj_iropt.h
 lj_opt_fold.o: lj_opt_fold.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
 lj_opt_fold.o: lj_opt_fold.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
  lj_str.h lj_tab.h lj_ir.h lj_jit.h lj_iropt.h lj_trace.h lj_dispatch.h \
  lj_str.h lj_tab.h lj_ir.h lj_jit.h lj_iropt.h lj_trace.h lj_dispatch.h \
- lj_bc.h lj_traceerr.h lj_carith.h lj_vm.h lj_folddef.h
+ lj_bc.h lj_traceerr.h lj_ctype.h lj_gc.h lj_carith.h lj_vm.h \
+ lj_folddef.h
 lj_opt_loop.o: lj_opt_loop.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
 lj_opt_loop.o: lj_opt_loop.c lj_obj.h lua.h luaconf.h lj_def.h lj_arch.h \
  lj_err.h lj_errmsg.h lj_str.h lj_ir.h lj_jit.h lj_iropt.h lj_trace.h \
  lj_err.h lj_errmsg.h lj_str.h lj_ir.h lj_jit.h lj_iropt.h lj_trace.h \
  lj_dispatch.h lj_bc.h lj_traceerr.h lj_snap.h lj_vm.h
  lj_dispatch.h lj_bc.h lj_traceerr.h lj_snap.h lj_vm.h

+ 1 - 0
src/lj_ir.h

@@ -332,6 +332,7 @@ typedef struct IRType1 { uint8_t irt; } IRType1;
 #define irt_islightud(t)	(irt_type(t) == IRT_LIGHTUD)
 #define irt_islightud(t)	(irt_type(t) == IRT_LIGHTUD)
 #define irt_isstr(t)		(irt_type(t) == IRT_STR)
 #define irt_isstr(t)		(irt_type(t) == IRT_STR)
 #define irt_istab(t)		(irt_type(t) == IRT_TAB)
 #define irt_istab(t)		(irt_type(t) == IRT_TAB)
+#define irt_iscdata(t)		(irt_type(t) == IRT_CDATA)
 #define irt_isfloat(t)		(irt_type(t) == IRT_FLOAT)
 #define irt_isfloat(t)		(irt_type(t) == IRT_FLOAT)
 #define irt_isnum(t)		(irt_type(t) == IRT_NUM)
 #define irt_isnum(t)		(irt_type(t) == IRT_NUM)
 #define irt_isint(t)		(irt_type(t) == IRT_INT)
 #define irt_isint(t)		(irt_type(t) == IRT_INT)

+ 13 - 1
src/lj_opt_fold.c

@@ -20,6 +20,9 @@
 #include "lj_jit.h"
 #include "lj_jit.h"
 #include "lj_iropt.h"
 #include "lj_iropt.h"
 #include "lj_trace.h"
 #include "lj_trace.h"
+#if LJ_HASFFI
+#include "lj_ctype.h"
+#endif
 #include "lj_carith.h"
 #include "lj_carith.h"
 #include "lj_vm.h"
 #include "lj_vm.h"
 
 
@@ -535,7 +538,16 @@ LJFOLDF(kfold_add_kgc)
 #else
 #else
   ptrdiff_t ofs = fright->i;
   ptrdiff_t ofs = fright->i;
 #endif
 #endif
-  return lj_ir_kkptr(J, (char *)o + ofs);
+#if LJ_HASFFI
+  if (irt_iscdata(fleft->t)) {
+    CType *ct = ctype_raw(ctype_ctsG(J2G(J)), gco2cd(o)->ctypeid);
+    if (ctype_isnum(ct->info) || ctype_isenum(ct->info) ||
+	ctype_isptr(ct->info) || ctype_isfunc(ct->info) ||
+	ctype_iscomplex(ct->info) || ctype_isvector(ct->info))
+      return lj_ir_kkptr(J, (char *)o + ofs);
+  }
+#endif
+  return lj_ir_kptr(J, (char *)o + ofs);
 }
 }
 
 
 LJFOLD(ADD KPTR KINT)
 LJFOLD(ADD KPTR KINT)