From ba0b7492a7ca0703e2bb395f3ec7db02d8eb2d4f Mon Sep 17 00:00:00 2001 From: Vern Paxson Date: Fri, 30 May 2025 09:38:42 -0700 Subject: [PATCH 1/2] Remove unused ZAM compiler method --- src/script_opt/ZAM/Low-Level.cc | 2 -- src/script_opt/ZAM/Low-Level.h | 3 --- 2 files changed, 5 deletions(-) diff --git a/src/script_opt/ZAM/Low-Level.cc b/src/script_opt/ZAM/Low-Level.cc index 87d3de2057..ad4415982e 100644 --- a/src/script_opt/ZAM/Low-Level.cc +++ b/src/script_opt/ZAM/Low-Level.cc @@ -183,6 +183,4 @@ const Stmt* ZAMCompiler::LastStmt(const Stmt* s) const { return s; } -ZAMStmt ZAMCompiler::PrevStmt(const ZAMStmt s) { return ZAMStmt(s.stmt_num - 1); } - } // namespace zeek::detail diff --git a/src/script_opt/ZAM/Low-Level.h b/src/script_opt/ZAM/Low-Level.h index d40802f981..12aa7476e0 100644 --- a/src/script_opt/ZAM/Low-Level.h +++ b/src/script_opt/ZAM/Low-Level.h @@ -31,9 +31,6 @@ int InternalAddVal(ZInstAux* zi, int i, Expr* e); // global/capture store for this instruction. const ZAMStmt AddInst(const ZInstI& inst, bool suppress_non_local = false); -// Returns the statement just before the given one. -ZAMStmt PrevStmt(const ZAMStmt s); - // Returns the last (interpreter) statement in the body. const Stmt* LastStmt(const Stmt* s) const; From dc68a62a1e4fca429ac4a8e6168bd29dc91df21d Mon Sep 17 00:00:00 2001 From: Vern Paxson Date: Fri, 30 May 2025 09:44:26 -0700 Subject: [PATCH 2/2] fix for crash when interpreting transformed ASTs that include multi-field record assignments/additions --- src/script_opt/Expr.cc | 3 ++ .../opt.regress-record-multi-assign/output | 3 ++ .../opt/regress-record-multi-assign.zeek | 31 +++++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 testing/btest/Baseline/opt.regress-record-multi-assign/output create mode 100644 testing/btest/opt/regress-record-multi-assign.zeek diff --git a/src/script_opt/Expr.cc b/src/script_opt/Expr.cc index 2f471d3ef5..159d0107e7 100644 --- a/src/script_opt/Expr.cc +++ b/src/script_opt/Expr.cc @@ -2951,6 +2951,8 @@ RecordFieldUpdatesExpr::RecordFieldUpdatesExpr(ExprTag t, const std::vector 0); stmt_pool.erase(s); } + + SetType(base_type(TYPE_VOID)); } RecordFieldUpdatesExpr::RecordFieldUpdatesExpr(ExprTag t, ExprPtr e1, ExprPtr e2, std::vector _lhs_map, @@ -2958,6 +2960,7 @@ RecordFieldUpdatesExpr::RecordFieldUpdatesExpr(ExprTag t, ExprPtr e1, ExprPtr e2 : BinaryExpr(t, std::move(e1), std::move(e2)) { lhs_map = std::move(_lhs_map); rhs_map = std::move(_rhs_map); + SetType(base_type(TYPE_VOID)); } ValPtr RecordFieldUpdatesExpr::Fold(Val* v1, Val* v2) const { diff --git a/testing/btest/Baseline/opt.regress-record-multi-assign/output b/testing/btest/Baseline/opt.regress-record-multi-assign/output new file mode 100644 index 0000000000..a977361cc9 --- /dev/null +++ b/testing/btest/Baseline/opt.regress-record-multi-assign/output @@ -0,0 +1,3 @@ +### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. +[a=37, b=47] +[a=4, b=3] diff --git a/testing/btest/opt/regress-record-multi-assign.zeek b/testing/btest/opt/regress-record-multi-assign.zeek new file mode 100644 index 0000000000..04363f9d8b --- /dev/null +++ b/testing/btest/opt/regress-record-multi-assign.zeek @@ -0,0 +1,31 @@ +# @TEST-DOC: Regression test for assigning multiple fields in a record +# @TEST-REQUIRES: test "${ZEEK_USE_CPP}" != "1" +# @TEST-EXEC: zeek -b -O xform %INPUT >output +# @TEST-EXEC: btest-diff output + +type R: record { + a: count; + b: count; +}; + +function multi_add(x: R, y: R): R + { + y$a += x$b; + y$b += x$a; + return y; + } + +function multi_assign(x: R, y: R): R + { + y$a = x$b; + y$b = x$a; + return y; + } + +event zeek_init() + { + local x = R($a=3, $b=4); + local y = R($a=33, $b=44); + print multi_add(x, y); + print multi_assign(x, y); + }