summaryrefslogtreecommitdiff
path: root/compile.c
diff options
context:
space:
mode:
authormame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-01-01 01:41:23 +0000
committermame <mame@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-01-01 01:41:23 +0000
commit67a257cac091e44cd49a5c1a8c00cee59e284cff (patch)
tree4e32b06bbedfd464b05cb1b669e947bd718d3e23 /compile.c
parent8423533c25db3d5e427accfa8e66895777c36df6 (diff)
compile.c: support branch coverage for `a&.foo = 1`
[Bug #15476] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66670 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/compile.c b/compile.c
index 233edf21c2..5ae2c48153 100644
--- a/compile.c
+++ b/compile.c
@@ -7462,8 +7462,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)
@@ -7503,8 +7505,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);
@@ -7536,7 +7541,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;