Branch: Tag:

2013-07-16

2013-07-16 21:10:10 by Henrik Grubbström (Grubba) <grubba@grubba.org>

Compiler: Avoid folding constants at all in __INIT().

When constants are folded the semantics for __INIT()
changes, and can break code (like eg variables in Hilfe).

Fixes several testsuite failures for Hilfe.

1707:    }    expr0    { -  if (!TEST_COMPAT(7, 8) && ($5) && is_const($5) && -  !($5->tree_info & OPT_EXTERNAL_DEPEND) && +  if ((Pike_compiler->compiler_pass == 2) && +  !TEST_COMPAT(7, 8) && ($5) && ($5->token == F_CONSTANT) &&    !Pike_compiler->num_parse_error) { -  /* Attempt to evaluate it to see if it is zero, -  * in which case we can throw it away. +  /* Check if it is zero, in which case we can throw it away.    *    * NB: The compat test is due to that this changes the semantics    * of calling __INIT() by hand.    */ -  ptrdiff_t tmp = eval_low($5, 0); -  if (tmp >= 1) { -  if ((TYPEOF(Pike_sp[-tmp]) != PIKE_T_PROGRAM) || -  ((Pike_sp[-tmp].u.program->flags & -  (PROGRAM_NEEDS_PARENT|PROGRAM_USES_PARENT|PROGRAM_FINISHED)) == -  PROGRAM_FINISHED)) { -  /* NB: We cannot perform constant folding on programs that -  * need their parent here, since the parent will be lost. -  * Note also that the PROGRAM_{NEEDS,USES}_PARENT flags -  * don't get set until pass 2. -  */ -  free_node($5); -  $5 = NULL; -  if (!SAFE_IS_ZERO(Pike_sp - tmp) || -  IDENTIFIER_IS_ALIAS(ID_FROM_INT(Pike_compiler->new_program, +  if (SAFE_IS_ZERO(&$5->u.sval) && +  !IDENTIFIER_IS_ALIAS(ID_FROM_INT(Pike_compiler->new_program,    $<number>4)->identifier_flags)) {    /* NB: Inherited variables get converted into aliases by    * define_variable, and we need to support clearing    * of inherited variables.    */ -  $5 = mkconstantsvaluenode(Pike_sp - tmp); +  free_node($5); +  $5 = NULL;    }    } -  pop_n_elems(tmp); -  } -  } +     if ($5) {    Pike_compiler->init_node=mknode(F_COMMA_EXPR,Pike_compiler->init_node,    mkcastnode(void_type_string,