diff --git a/src/script_opt/Expr.cc b/src/script_opt/Expr.cc index 5a04a3bef1..90e5419a0d 100644 --- a/src/script_opt/Expr.cc +++ b/src/script_opt/Expr.cc @@ -2613,9 +2613,16 @@ ExprPtr InlineExpr::Reduce(Reducer* c, StmtPtr& red_stmt) { body = body->Reduce(c); c->PopInlineBlock(); - auto catch_ret = with_location_of(make_intrusive(sf, body, ret_val), this); + StmtPtr repl_stmt; - red_stmt = MergeStmts(red_stmt, catch_ret); + if ( body->Tag() == STMT_NULL ) + // The inlined body reduced down to nothing, expose that fact + // rather than masking it with an empty catch-return. + repl_stmt = make_intrusive(); + else + repl_stmt = make_intrusive(sf, body, ret_val); + + red_stmt = MergeStmts(red_stmt, with_location_of(repl_stmt, this)); return ret_val ? ret_val->Duplicate() : nullptr; } diff --git a/testing/btest/Baseline/opt.null-inline-branch/output b/testing/btest/Baseline/opt.null-inline-branch/output new file mode 100644 index 0000000000..acd35f11eb --- /dev/null +++ b/testing/btest/Baseline/opt.null-inline-branch/output @@ -0,0 +1,2 @@ +### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. +got through the conditional diff --git a/testing/btest/opt/null-inline-branch.zeek b/testing/btest/opt/null-inline-branch.zeek new file mode 100644 index 0000000000..942b8509ac --- /dev/null +++ b/testing/btest/opt/null-inline-branch.zeek @@ -0,0 +1,19 @@ +# @TEST-DOC: Regression test for past ZAM issues with inlining empty functions in conditionals +# +# @TEST-EXEC: zeek -b -O ZAM %INPUT >output +# @TEST-EXEC: btest-diff output + +function empty_func() {} + +# Use a global to avoid constant propagation optimizing out the conditional. +global bar = F; + +event zeek_init() + { + if ( bar ) + empty_func(); + else + empty_func(); + + print "got through the conditional"; + }