Fix for ZAM optimization of '?' conditional with vector-valued result

This commit is contained in:
Vern Paxson 2022-07-07 13:08:28 -07:00
parent ee88aa3acb
commit 0706e8869d
3 changed files with 11 additions and 1 deletions

View file

@ -227,7 +227,7 @@ const ZAMStmt ZAMCompiler::CompileAssignExpr(const AssignExpr* e)
return CondC2VVC(lhs, n1, c3); return CondC2VVC(lhs, n1, c3);
} }
if ( r1 && r2 ) if ( r1 && r2 && ! r3 )
{ {
auto v1 = IsVector(r1->GetType()->Tag()); auto v1 = IsVector(r1->GetType()->Tag());
auto v2 = IsVector(r2->GetType()->Tag()); auto v2 = IsVector(r2->GetType()->Tag());

View file

@ -13,3 +13,4 @@ associativity (PASS)
0, vector of string 0, vector of string
0, vector of string 0, vector of string
[1, 5, 3], vector of count [1, 5, 3], vector of count
[4, 5, 6], vector of count

View file

@ -20,6 +20,11 @@ function f2(): bool
return F; return F;
} }
# The following needs to be a global to test for a ZAM regression where
# the ZAM optimizer will optimize away the problematic condition if the
# value is constant.
global false = F;
event zeek_init() event zeek_init()
{ {
local a: count; local a: count;
@ -86,4 +91,8 @@ event zeek_init()
local tvc = vector(T, F, T); local tvc = vector(T, F, T);
local tvr = tvc ? vector(1, 2, 3) : vector(4, 5, 6); local tvr = tvc ? vector(1, 2, 3) : vector(4, 5, 6);
print tvr, type_name(tvr); print tvr, type_name(tvr);
# Test for ternary results
local tvr2 = false ? vector(1, 2, 3) : vector(4, 5, 6);
print tvr2, type_name(tvr2);
} }