Skip to content

Commit d2209c0

Browse files
committed
bug: Wrong error message in some short-cut expressions
1 parent 39808bb commit d2209c0

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

ldebug.c

+21-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
** $Id: ldebug.c,v 2.90.1.1 2013/04/12 18:48:47 roberto Exp roberto $
2+
** $Id: ldebug.c,v 2.90.1.2 2013/05/06 17:20:22 roberto Exp roberto $
33
** Debug Interface
44
** See Copyright Notice in lua.h
55
*/
@@ -327,12 +327,20 @@ static void kname (Proto *p, int pc, int c, const char **name) {
327327
}
328328

329329

330+
static int filterpc (int pc, int jmptarget) {
331+
if (pc < jmptarget) /* is code conditional (inside a jump)? */
332+
return -1; /* cannot know who sets that register */
333+
else return pc; /* current position sets that register */
334+
}
335+
336+
330337
/*
331338
** try to find last instruction before 'lastpc' that modified register 'reg'
332339
*/
333340
static int findsetreg (Proto *p, int lastpc, int reg) {
334341
int pc;
335342
int setreg = -1; /* keep last instruction that changed 'reg' */
343+
int jmptarget = 0; /* any code before this address is conditional */
336344
for (pc = 0; pc < lastpc; pc++) {
337345
Instruction i = p->code[pc];
338346
OpCode op = GET_OPCODE(i);
@@ -341,33 +349,38 @@ static int findsetreg (Proto *p, int lastpc, int reg) {
341349
case OP_LOADNIL: {
342350
int b = GETARG_B(i);
343351
if (a <= reg && reg <= a + b) /* set registers from 'a' to 'a+b' */
344-
setreg = pc;
352+
setreg = filterpc(pc, jmptarget);
345353
break;
346354
}
347355
case OP_TFORCALL: {
348-
if (reg >= a + 2) setreg = pc; /* affect all regs above its base */
356+
if (reg >= a + 2) /* affect all regs above its base */
357+
setreg = filterpc(pc, jmptarget);
349358
break;
350359
}
351360
case OP_CALL:
352361
case OP_TAILCALL: {
353-
if (reg >= a) setreg = pc; /* affect all registers above base */
362+
if (reg >= a) /* affect all registers above base */
363+
setreg = filterpc(pc, jmptarget);
354364
break;
355365
}
356366
case OP_JMP: {
357367
int b = GETARG_sBx(i);
358368
int dest = pc + 1 + b;
359369
/* jump is forward and do not skip `lastpc'? */
360-
if (pc < dest && dest <= lastpc)
361-
pc += b; /* do the jump */
370+
if (pc < dest && dest <= lastpc) {
371+
if (dest > jmptarget)
372+
jmptarget = dest; /* update 'jmptarget' */
373+
}
362374
break;
363375
}
364376
case OP_TEST: {
365-
if (reg == a) setreg = pc; /* jumped code can change 'a' */
377+
if (reg == a) /* jumped code can change 'a' */
378+
setreg = filterpc(pc, jmptarget);
366379
break;
367380
}
368381
default:
369382
if (testAMode(op) && reg == a) /* any instruction that set A */
370-
setreg = pc;
383+
setreg = filterpc(pc, jmptarget);
371384
break;
372385
}
373386
}

0 commit comments

Comments
 (0)