summaryrefslogtreecommitdiff
path: root/compile.c
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-01-14 06:34:02 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-01-14 06:34:02 +0000
commitaed655c0969baeb48f1f683ba4426ec7b7f466bb (patch)
tree937c7ce31662e9851188f3fb9088e8b045d72500 /compile.c
parentd3aa6514b455835220212298a4b189db28300c19 (diff)
merge revision(s) 66670,66676: [Backport #15476]
compile.c: support branch coverage for `a&.foo = 1` [Bug #15476] compile.c (iseq_set_sequence): fix branch coverage table Not only TRACE_ELEMENT but also INSN_ELEMENT may have events. The old pc2branchindex was created using only events of TRACE_ELEMENTs. This change uses events of INSN_ELEMENTs too for pc2branchindex table. [Bug #15476] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_6@66813 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/compile.c b/compile.c
index 0bca488614..a23e7867aa 100644
--- a/compile.c
+++ b/compile.c
@@ -2061,6 +2061,7 @@ iseq_set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *const anchor)
/* update sp */
sp = calc_sp_depth(sp, iobj);
insn_num++;
+ events = iobj->insn_info.events |= events;
if (ISEQ_COVERAGE(iseq)) {
if (ISEQ_LINE_COVERAGE(iseq) && (events & RUBY_EVENT_COVERAGE_LINE) &&
!(rb_get_coverage_mode() & COVERAGE_TARGET_ONESHOT_LINES)) {
@@ -2077,7 +2078,6 @@ iseq_set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *const anchor)
}
}
code_index += insn_data_length(iobj);
- iobj->insn_info.events |= events;
events = 0;
data = 0;
break;
@@ -7459,8 +7459,10 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, in
DECL_ANCHOR(args);
unsigned int flag = 0;
ID mid = node->nd_mid;
- LABEL *lskip = 0;
+ LABEL *else_label = 0;
+ LABEL *end_label = 0;
VALUE argc;
+ VALUE branches = 0;
/* optimization shortcut
* obj["literal"] = value -> opt_aset_with(obj, "literal", value)
@@ -7500,8 +7502,11 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, in
/* safe nav attr */
mid = rb_id_attrset(mid);
ADD_INSN(recv, line, dup);
- lskip = NEW_LABEL(line);
- ADD_INSNL(recv, line, branchnil, lskip);
+ else_label = NEW_LABEL(line);
+ end_label = NEW_LABEL(line);
+ DECL_BRANCH_BASE(branches, nd_first_lineno(node), nd_first_column(node), nd_last_lineno(node), nd_last_column(node), "&.");
+ ADD_INSNL(recv, line, branchnil, else_label);
+ ADD_TRACE_BRANCH_COVERAGE(recv, nd_first_lineno(node), nd_first_column(node), nd_last_lineno(node), nd_last_column(node), "then", branches);
}
if (!popped) {
ADD_INSN(ret, line, putnil);
@@ -7533,7 +7538,12 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, in
ADD_SEQ(ret, args);
}
ADD_SEND_WITH_FLAG(ret, line, mid, argc, INT2FIX(flag));
- if (lskip) ADD_LABEL(ret, lskip);
+ if (else_label && end_label) {
+ ADD_INSNL(ret, line, jump, end_label);
+ ADD_LABEL(ret, else_label);
+ ADD_TRACE_BRANCH_COVERAGE(ret, nd_first_lineno(node), nd_first_column(node), nd_last_lineno(node), nd_last_column(node), "else", branches);
+ ADD_LABEL(ret, end_label);
+ }
ADD_INSN(ret, line, pop);
break;