Branch: Tag:

2015-02-14

2015-02-14 12:03:10 by Arne Goedeke <el@laramies.com>

Interpreter: fix handling of UNDEFINED in ++ and --

This is done by always using the slow path for integer 0, which could be
undefined. It would be nicer to have a svalue equivalent to
get_pointer_if_this_type to check the subtype, but not all lvalues are
svalues, so that wont work, either.

1024:      OPCODE0(F_INC, "++x", I_UPDATE_SP, {    union anything *u=get_pointer_if_this_type(Pike_sp-2, PIKE_T_INT); -  if(u && !INT_TYPE_ADD_OVERFLOW(u->integer, 1)) +  /* NOTE: if u->integer is 0, the lvalue could be UNDEFINED. +  * we use the slow path to make sure it becomes a proper integer */ +  if(u && u->integer && !INT_TYPE_ADD_OVERFLOW(u->integer, 1))    {    INT_TYPE val = ++u->integer;    pop_2_elems();
1040:      OPCODE0(F_DEC, "--x", I_UPDATE_SP, {    union anything *u=get_pointer_if_this_type(Pike_sp-2, PIKE_T_INT); -  if(u && !INT_TYPE_SUB_OVERFLOW(u->integer, 1)) +  /* NOTE: if u->integer is 0, the lvalue could be UNDEFINED. +  * we use the slow path to make sure it becomes a proper integer */ +  if(u && u->integer && !INT_TYPE_SUB_OVERFLOW(u->integer, 1))    {    INT_TYPE val = --u->integer;    pop_2_elems();
1056:      OPCODE0(F_DEC_AND_POP, "x-- and pop", I_UPDATE_SP, {    union anything *u=get_pointer_if_this_type(Pike_sp-2, PIKE_T_INT); -  if(u && !INT_TYPE_SUB_OVERFLOW(u->integer, 1)) +  /* NOTE: if u->integer is 0, the lvalue could be UNDEFINED. +  * we use the slow path to make sure it becomes a proper integer */ +  if(u && u->integer && !INT_TYPE_SUB_OVERFLOW(u->integer, 1))    {    --u->integer;    pop_2_elems();
1071:      OPCODE0(F_INC_AND_POP, "x++ and pop", I_UPDATE_SP, {    union anything *u=get_pointer_if_this_type(Pike_sp-2, PIKE_T_INT); -  if(u && !INT_TYPE_ADD_OVERFLOW(u->integer, 1)) +  /* NOTE: if u->integer is 0, the lvalue could be UNDEFINED. +  * we use the slow path to make sure it becomes a proper integer */ +  if(u && u->integer && !INT_TYPE_ADD_OVERFLOW(u->integer, 1))    {    ++u->integer;    pop_2_elems();
1086:      OPCODE0(F_POST_INC, "x++", I_UPDATE_SP, {    union anything *u=get_pointer_if_this_type(Pike_sp-2, PIKE_T_INT); -  if(u && !INT_TYPE_ADD_OVERFLOW(u->integer, 1)) +  /* NOTE: if u->integer is 0, the lvalue could be UNDEFINED. +  * we use the slow path to make sure it becomes a proper integer */ +  if(u && u->integer && !INT_TYPE_ADD_OVERFLOW(u->integer, 1))    {    INT_TYPE val = u->integer++;    pop_2_elems();
1105:      OPCODE0(F_POST_DEC, "x--", I_UPDATE_SP, {    union anything *u=get_pointer_if_this_type(Pike_sp-2, PIKE_T_INT); -  if(u && !INT_TYPE_SUB_OVERFLOW(u->integer, 1)) +  /* NOTE: if u->integer is 0, the lvalue could be UNDEFINED. +  * we use the slow path to make sure it becomes a proper integer */ +  if(u && u->integer && !INT_TYPE_SUB_OVERFLOW(u->integer, 1))    {    INT_TYPE val = u->integer--;    pop_2_elems();