From 049d29921949f7458095ce7ba8a1016c32fc8b04 Mon Sep 17 00:00:00 2001 From: Ed J Date: Wed, 20 Nov 2024 15:04:32 +0000 Subject: [PATCH] use additional get_condition_dor when DOR op and next is NEXTSTATE --- Cover.xs | 31 +++++++++++++++++++----- test_output/cover/overload_bool.5.012000 | 11 ++++++--- tests/overload_bool | 1 + 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/Cover.xs b/Cover.xs index 09b12442..caacebad 100644 --- a/Cover.xs +++ b/Cover.xs @@ -703,11 +703,9 @@ static OP *find_skipped_conditional(pTHX_ OP *o) { } #endif -/* NOTE: caller must protect get_condition calls by locking DC_mutex */ - +/* NOTE: caller must protect get_condition* calls by locking DC_mutex */ static OP *get_condition(pTHX) { SV **pc = hv_fetch(Pending_conditionals, get_key(PL_op), KEY_SZ, 0); - if (pc && SvROK(*pc)) { dSP; int true_ish; @@ -724,10 +722,29 @@ static OP *get_condition(pTHX) { PL_op, (void *)PL_op->op_targ, pc, hex_key(get_key(PL_op)))); dump_conditions(aTHX); NDEB(svdump(Pending_conditionals)); - /* croak("urgh"); */ exit(1); } - + return PL_op; +} +static OP *get_condition_dor(pTHX) { + SV **pc = hv_fetch(Pending_conditionals, get_key(PL_op), KEY_SZ, 0); + if (pc && SvROK(*pc)) { + dSP; + int true_ish; + NDEB(D(L, "get_condition_dor from %p, %p: %p (%s)\n", + PL_op, (void *)PL_op->op_targ, pc, hex_key(get_key(PL_op)))); + /* dump_conditions(aTHX); */ + NDEB(svdump(Pending_conditionals)); + true_ish = SvOK(TOPs); + NDEB(D(L, " get_condition_dor true_ish=%d\n", true_ish)); + add_condition(aTHX_ *pc, true_ish ? 2 : 1); + } else { + PDEB(D(L, "All is lost, I know not where to go from %p, %p: %p (%s)\n", + PL_op, (void *)PL_op->op_targ, pc, hex_key(get_key(PL_op)))); + dump_conditions(aTHX); + NDEB(svdump(Pending_conditionals)); + exit(1); + } return PL_op; } @@ -919,7 +936,9 @@ static void cover_logop(pTHX) { NDEB(op_dump(PL_op)); NDEB(op_dump(next)); - next->op_ppaddr = get_condition; + next->op_ppaddr = (next->op_type == OP_NEXTSTATE && ( + PL_op->op_type == OP_DOR || PL_op->op_type == OP_DORASSIGN)) + ? get_condition_dor : get_condition; MUTEX_UNLOCK(&DC_mutex); } } else { diff --git a/test_output/cover/overload_bool.5.012000 b/test_output/cover/overload_bool.5.012000 index e37d5f4c..a1a6ae95 100644 --- a/test_output/cover/overload_bool.5.012000 +++ b/test_output/cover/overload_bool.5.012000 @@ -4,8 +4,8 @@ Reading database from ... ------------------- ------ ------ ------ ------ ------ File stmt bran cond sub total ------------------- ------ ------ ------ ------ ------ -tests/overload_bool 63.6 50.0 50.0 25.0 52.6 -Total 63.6 50.0 50.0 25.0 52.6 +tests/overload_bool 69.2 50.0 50.0 25.0 56.5 +Total 69.2 50.0 50.0 25.0 56.5 ------------------- ------ ------ ------ ------ ------ @@ -45,8 +45,10 @@ line err stmt bran cond sub code 21 22 1 my $boolobj = bless {}, 'Foo'; 23 *** 1 * 50 $boolobj //= 5; -24 -25 1; +24 *** 1 * 50 my $var; $var //= bless {}, "Foo"; + 1 +25 +26 1; Branches @@ -65,6 +67,7 @@ or 2 conditions line err % l !l expr ----- --- ------ ------ ------ ---- 23 *** 50 1 0 $boolobj //= 5 +24 *** 50 0 1 $var //= bless({}, "Foo") Covered Subroutines diff --git a/tests/overload_bool b/tests/overload_bool index 77dd496f..32d0c677 100644 --- a/tests/overload_bool +++ b/tests/overload_bool @@ -21,5 +21,6 @@ bless {}, 'Foo' if $foo; my $boolobj = bless {}, 'Foo'; $boolobj //= 5; +my $var; $var //= bless {}, "Foo"; 1;