ZAM optimizer fix for += / -= set operations

This commit is contained in:
Vern Paxson 2025-07-08 18:18:27 -07:00 committed by Tim Wojtulewicz
parent 92868804b1
commit 1d43760862
3 changed files with 30 additions and 0 deletions

View file

@ -767,6 +767,9 @@ bool AddToExpr::IsReduced(Reducer* c) const {
}
ExprPtr AddToExpr::Reduce(Reducer* c, StmtPtr& red_stmt) {
if ( c->Optimizing() )
op2 = c->UpdateExpr(op2);
auto tag = op1->GetType()->Tag();
switch ( tag ) {
@ -869,6 +872,9 @@ bool RemoveFromExpr::IsReduced(Reducer* c) const {
}
ExprPtr RemoveFromExpr::Reduce(Reducer* c, StmtPtr& red_stmt) {
if ( c->Optimizing() )
op2 = c->UpdateExpr(op2);
if ( op1->GetType()->Tag() == TYPE_TABLE ) {
StmtPtr red_stmt1;
StmtPtr red_stmt2;

View file

@ -0,0 +1,4 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
[my_set={
}]

View file

@ -0,0 +1,20 @@
# @TEST-DOC: Regression test for ZAM optimizer mis-transforming set +=/-= ops
# @TEST-REQUIRES: test "${ZEEK_USE_CPP}" != "1"
# @TEST-EXEC: zeek -b -O ZAM %INPUT >output
# @TEST-EXEC: btest-diff output
type R: record {
my_set: set[string];
};
event zeek_init()
{
local r1 = R();
local r2 = R();
if ( |r1$my_set| > 0 )
print T;
r2$my_set += r1$my_set;
print r2;
}