lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Geoff Leyland wrote:
> Rima's test suite seems to fail or pass depending on whether I
> put in print statements to try to figure out what's going on.

Ok, found the bug. The compiler miscompiles getmetatable for
non-tables. Fixed in git HEAD. Patch against beta3 attached.

--Mike
diff --git a/src/lj_record.c b/src/lj_record.c
index d8cd896..fa4180b 100644
--- a/src/lj_record.c
+++ b/src/lj_record.c
@@ -660,9 +660,11 @@ static int rec_mm_lookup(jit_State *J, RecordIndex *ix, MMS mm)
   } else {
     /* Specialize to base metatable. Must flush mcode in lua_setmetatable(). */
     mt = tabref(basemt_obj(J2G(J), &ix->tabv));
-    if (mt == NULL)
+    if (mt == NULL) {
+      ix->mt = TREF_NIL;
       return 0;  /* No metamethod. */
-    mix.tab = lj_ir_ktab(J, mt);
+    }
+    ix->mt = mix.tab = lj_ir_ktab(J, mt);
     goto nocheck;
   }
   ix->mt = mt ? mix.tab : TREF_NIL;
@@ -1160,7 +1162,7 @@ static void LJ_FASTCALL recff_type(jit_State *J, RecordFFData *rd)
 static void LJ_FASTCALL recff_getmetatable(jit_State *J, RecordFFData *rd)
 {
   TRef tr = J->base[0];
-  if (tref_istab(tr)) {
+  if (tr) {
     RecordIndex ix;
     ix.tab = tr;
     copyTV(J->L, &ix.tabv, &rd->argv[0]);