mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
ZAM fix for inlining empty function bodies as the sole elements of an if-else
This commit is contained in:
parent
a3a0155825
commit
286c4dc776
3 changed files with 30 additions and 2 deletions
|
@ -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<CatchReturnStmt>(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<NullStmt>();
|
||||
else
|
||||
repl_stmt = make_intrusive<CatchReturnStmt>(sf, body, ret_val);
|
||||
|
||||
red_stmt = MergeStmts(red_stmt, with_location_of(repl_stmt, this));
|
||||
|
||||
return ret_val ? ret_val->Duplicate() : nullptr;
|
||||
}
|
||||
|
|
2
testing/btest/Baseline/opt.null-inline-branch/output
Normal file
2
testing/btest/Baseline/opt.null-inline-branch/output
Normal file
|
@ -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
|
19
testing/btest/opt/null-inline-branch.zeek
Normal file
19
testing/btest/opt/null-inline-branch.zeek
Normal file
|
@ -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";
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue