From ef66365b5dd715dc8181278e7ed4245c13ad6aa0 Mon Sep 17 00:00:00 2001 From: Dibyendu Majumdar Date: Sun, 18 Mar 2018 19:22:53 +0000 Subject: [PATCH] issue #148 fix bad code gen for OP_RAVI_SELF_S --- ravi-tests/ravi_tests1.ravi | 11 +++++++++++ src/lcode.c | 8 +++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/ravi-tests/ravi_tests1.ravi b/ravi-tests/ravi_tests1.ravi index 541fddb..43b883e 100644 --- a/ravi-tests/ravi_tests1.ravi +++ b/ravi-tests/ravi_tests1.ravi @@ -120,6 +120,7 @@ opcodes_coverage.SELF_S = 0 opcodes_coverage.TOTYPE = 0 opcodes_coverage.TOSTRING = 0 opcodes_coverage.TOCLOSURE = 0 +opcodes_coverage.SELF_SK = 0 local compile = function(f) if ravi.jit() then @@ -1577,6 +1578,16 @@ ravi.compile(x) assert(x() == 'a') print 'Test 63 OK' +-- Codegen bug #issue 148 +function x() + assert(({pcall(function() comp 'x for __result' end)})[2] + :find'not contain __ prefix') +end +check(x, 'GETTABUP_SK', 'NEWTABLE', 'GETTABUP_SK', 'CLOSURE', + 'CALL', 'SETLIST', 'GETTABLE_I', 'SELF_SK', 'LOADK', + 'CALL', 'CALL', 'RETURN') +print 'Test 64 OK' + for k,v in pairs(opcodes_coverage) do print(k, v) diff --git a/src/lcode.c b/src/lcode.c index b94cddb..a20edbe 100644 --- a/src/lcode.c +++ b/src/lcode.c @@ -1047,10 +1047,12 @@ void luaK_self (FuncState *fs, expdesc *e, expdesc *key) { key->k == VK && key->ravi_type == RAVI_TSTRING && ttisshrstring(&fs->f->k[key->u.info]); - int table_and_string = - e->ravi_type == RAVI_TTABLE && - is_string_constant_key; luaK_exp2anyreg(fs, e); + // The check below needs to be + // after exp2anyreg as this can modify e->ravi_type + int table_and_string = + e->ravi_type == RAVI_TTABLE && + is_string_constant_key; ereg = e->u.info; /* register where 'e' was placed */ freeexp(fs, e); e->u.info = fs->freereg; /* base register for op_self */