1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

compile.c: compile error than rb_bug [ci skip]

* compile.c (get_local_var_idx, get_dyna_var_idx): raise a compile
  error which is useful than rb_bug, when ID is not found.

* compile.c (iseq_set_sequence): ditto when IC index overflow,
  with dumping generated code.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65617 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2018-11-08 01:57:03 +00:00
parent 96c26fbba3
commit dcfb7f6d54

View file

@ -370,7 +370,7 @@ NORETURN(static void append_compile_error(rb_iseq_t *iseq, int line, const char
#endif #endif
static void static void
append_compile_error(rb_iseq_t *iseq, int line, const char *fmt, ...) append_compile_error(const rb_iseq_t *iseq, int line, const char *fmt, ...)
{ {
VALUE err_info = ISEQ_COMPILE_DATA(iseq)->err_info; VALUE err_info = ISEQ_COMPILE_DATA(iseq)->err_info;
VALUE file = rb_iseq_path(iseq); VALUE file = rb_iseq_path(iseq);
@ -567,6 +567,8 @@ APPEND_ELEM(ISEQ_ARG_DECLARE LINK_ANCHOR *const anchor, LINK_ELEMENT *before, LI
#define APPEND_ELEM(anchor, before, elem) APPEND_ELEM(iseq, (anchor), (before), (elem)) #define APPEND_ELEM(anchor, before, elem) APPEND_ELEM(iseq, (anchor), (before), (elem))
#endif #endif
#define ISEQ_LAST_LINE(iseq) (ISEQ_COMPILE_DATA(iseq)->last_line)
static int static int
iseq_add_mark_object_compile_time(const rb_iseq_t *iseq, VALUE v) iseq_add_mark_object_compile_time(const rb_iseq_t *iseq, VALUE v)
{ {
@ -1393,7 +1395,8 @@ get_local_var_idx(const rb_iseq_t *iseq, ID id)
int idx = get_dyna_var_idx_at_raw(iseq->body->local_iseq, id); int idx = get_dyna_var_idx_at_raw(iseq->body->local_iseq, id);
if (idx < 0) { if (idx < 0) {
rb_bug("get_local_var_idx: %d", idx); COMPILE_ERROR(iseq, ISEQ_LAST_LINE(iseq),
"get_local_var_idx: %d", idx);
} }
return idx; return idx;
@ -1414,7 +1417,8 @@ get_dyna_var_idx(const rb_iseq_t *iseq, ID id, int *level, int *ls)
} }
if (idx < 0) { if (idx < 0) {
rb_bug("get_dyna_var_idx: -1"); COMPILE_ERROR(iseq, ISEQ_LAST_LINE(iseq),
"get_dyna_var_idx: -1");
} }
*level = lv; *level = lv;
@ -2154,7 +2158,10 @@ iseq_set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *const anchor)
unsigned int ic_index = FIX2UINT(operands[j]); unsigned int ic_index = FIX2UINT(operands[j]);
IC ic = (IC)&body->is_entries[ic_index]; IC ic = (IC)&body->is_entries[ic_index];
if (UNLIKELY(ic_index >= body->is_size)) { if (UNLIKELY(ic_index >= body->is_size)) {
rb_bug("iseq_set_sequence: ic_index overflow: index: %d, size: %d", ic_index, body->is_size); BADINSN_DUMP(anchor, &iobj->link, 0);
COMPILE_ERROR(iseq, iobj->insn_info.line_no,
"iseq_set_sequence: ic_index overflow: index: %d, size: %d",
ic_index, body->is_size);
} }
generated_iseq[code_index + 1 + j] = (VALUE)ic; generated_iseq[code_index + 1 + j] = (VALUE)ic;
break; break;