diff options
author | Nobuyoshi Nakada <[email protected]> | 2023-09-06 00:44:35 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2023-09-13 08:30:37 +0900 |
commit | 6e64d4370456190541705ec4c6cf3af6bf4ac647 (patch) | |
tree | 22fc51ae963a4a6059222c1ede9d0ad6b67836ea /compile.c | |
parent | 19346c2336053b351673da030b00c704138252d8 (diff) |
[Bug #19862] Skip compiled result of never reachable expression
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/8381
Diffstat (limited to 'compile.c')
-rw-r--r-- | compile.c | 28 |
1 files changed, 20 insertions, 8 deletions
@@ -4154,9 +4154,10 @@ compile_flip_flop(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const nod } static int -compile_branch_condition(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *cond, +compile_branch_condition(rb_iseq_t *iseq, LINK_ANCHOR *ret, const NODE *cond, LABEL *then_label, LABEL *else_label); +#define COMPILE_SINGLE 2 static int compile_logical(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *cond, LABEL *then_label, LABEL *else_label) @@ -4175,28 +4176,39 @@ compile_logical(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *cond, return COMPILE_OK; } if (!label->refcnt) { - ADD_INSN(seq, cond, putnil); - } - else { - ADD_LABEL(seq, label); + return COMPILE_SINGLE; } + ADD_LABEL(seq, label); ADD_SEQ(ret, seq); return COMPILE_OK; } static int -compile_branch_condition(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *cond, +compile_branch_condition(rb_iseq_t *iseq, LINK_ANCHOR *ret, const NODE *cond, LABEL *then_label, LABEL *else_label) { + int ok; + DECL_ANCHOR(ignore); + again: switch (nd_type(cond)) { case NODE_AND: - CHECK(compile_logical(iseq, ret, cond->nd_1st, NULL, else_label)); + CHECK(ok = compile_logical(iseq, ret, cond->nd_1st, NULL, else_label)); cond = cond->nd_2nd; + if (ok == COMPILE_SINGLE) { + INIT_ANCHOR(ignore); + ret = ignore; + then_label = NEW_LABEL(nd_line(cond)); + } goto again; case NODE_OR: - CHECK(compile_logical(iseq, ret, cond->nd_1st, then_label, NULL)); + CHECK(ok = compile_logical(iseq, ret, cond->nd_1st, then_label, NULL)); cond = cond->nd_2nd; + if (ok == COMPILE_SINGLE) { + INIT_ANCHOR(ignore); + ret = ignore; + else_label = NEW_LABEL(nd_line(cond)); + } goto again; case NODE_LIT: /* NODE_LIT is always true */ case NODE_TRUE: |