Merge remote-tracking branch 'origin/topic/vern/CPP-maint.Mar25'

* origin/topic/vern/CPP-maint.Mar25:
  minor baseline updates for -O gen-C++
  -O gen-C++ support for pattern-to-pattern comparison
  -O gen-C++ support for pattern vector comparisons
  -O gen-C++ support for type expressions
This commit is contained in:
Tim Wojtulewicz 2025-03-19 12:46:41 -07:00
commit 38484b6dc6
23 changed files with 172 additions and 7 deletions

View file

@ -1,3 +1,11 @@
7.2.0-dev.400 | 2025-03-19 12:46:41 -0700
* -O gen-C++ support for pattern-to-pattern comparison (Vern Paxson, Corelight)
* -O gen-C++ support for pattern vector comparisons (Vern Paxson, Corelight)
* -O gen-C++ support for type expressions (Vern Paxson, Corelight)
7.2.0-dev.395 | 2025-03-19 11:58:41 -0700 7.2.0-dev.395 | 2025-03-19 11:58:41 -0700
* CI: Run btests on macOS under sudo (Tim Wojtulewicz, Corelight) * CI: Run btests on macOS under sudo (Tim Wojtulewicz, Corelight)

View file

@ -1 +1 @@
7.2.0-dev.395 7.2.0-dev.400

View file

@ -103,6 +103,8 @@ shared_ptr<CPP_InitInfo> CPPCompile::RegisterConstant(const ValPtr& vp, int& con
case TYPE_FUNC: gi = make_shared<FuncConstInfo>(this, vp); break; case TYPE_FUNC: gi = make_shared<FuncConstInfo>(this, vp); break;
case TYPE_TYPE: gi = make_shared<TypeConstInfo>(this, vp); break;
default: reporter->InternalError("bad constant type in CPPCompile::AddConstant"); break; default: reporter->InternalError("bad constant type in CPPCompile::AddConstant"); break;
} }

View file

@ -294,6 +294,7 @@ void CPPCompile::GenProlog() {
const_info[TYPE_TABLE] = CreateCompoundInitInfo("Table", "ValPtr"); const_info[TYPE_TABLE] = CreateCompoundInitInfo("Table", "ValPtr");
const_info[TYPE_FUNC] = CreateCompoundInitInfo("Func", "ValPtr"); const_info[TYPE_FUNC] = CreateCompoundInitInfo("Func", "ValPtr");
const_info[TYPE_FILE] = CreateCompoundInitInfo("File", "ValPtr"); const_info[TYPE_FILE] = CreateCompoundInitInfo("File", "ValPtr");
const_info[TYPE_TYPE] = CreateCompoundInitInfo("TypeVal", "Ptr");
type_info = CreateCompoundInitInfo("Type", "Ptr"); type_info = CreateCompoundInitInfo("Type", "Ptr");
attr_info = CreateCompoundInitInfo("Attr", "Ptr"); attr_info = CreateCompoundInitInfo("Attr", "Ptr");

View file

@ -998,10 +998,23 @@ string CPPCompile::GenEQ(const Expr* e, GenType gt, const char* op, const char*
auto tag = op1->GetType()->Tag(); auto tag = op1->GetType()->Tag();
string negated(e->Tag() == EXPR_EQ ? "" : "! "); string negated(e->Tag() == EXPR_EQ ? "" : "! ");
if ( tag == TYPE_PATTERN ) if ( tag == TYPE_PATTERN ) {
return NativeToGT(negated + GenExpr(op1, GEN_DONT_CARE) + "->MatchExactly(" + GenExpr(op2, GEN_DONT_CARE) + auto gen1 = GenExpr(op1, GEN_DONT_CARE);
"->AsString())", auto gen2 = GenExpr(op2, GEN_DONT_CARE);
e->GetType(), gt); string gen;
if ( op2->GetType()->Tag() == TYPE_PATTERN ) {
gen1 += "->AsPattern()->PatternText()";
gen2 += "->AsPattern()->PatternText()";
gen = "(strcmp(" + gen1 + ", " + gen2 + ") == 0)";
}
else
gen = gen1 + "->MatchExactly(" + gen2 + "->AsString())";
return NativeToGT(negated + gen, e->GetType(), gt);
}
if ( tag == TYPE_FUNC ) { if ( tag == TYPE_FUNC ) {
auto gen_f1 = GenExpr(op1, GEN_DONT_CARE); auto gen_f1 = GenExpr(op1, GEN_DONT_CARE);
@ -1156,8 +1169,12 @@ string CPPCompile::GenVectorOp(const Expr* e, string op1, string op2, const char
auto invoke = string(vec_op) + "__CPP(" + op1 + ", " + op2 + ")"; auto invoke = string(vec_op) + "__CPP(" + op1 + ", " + op2 + ")";
if ( op2_t->Yield()->Tag() == TYPE_STRING ) auto tag2 = op2_t->Yield()->Tag();
if ( tag2 == TYPE_STRING )
return string("str_vec_op_") + invoke; return string("str_vec_op_") + invoke;
if ( tag2 == TYPE_PATTERN )
return string("pat_vec_op_") + invoke;
auto gen = string("vec_op_") + invoke; auto gen = string("vec_op_") + invoke;

View file

@ -299,6 +299,11 @@ void FuncConstInfo::InitializerVals(std::vector<std::string>& ivs) const {
} }
} }
void TypeConstInfo::InitializerVals(std::vector<std::string>& ivs) const {
auto& t = tv->GetType()->AsTypeType()->GetType();
ivs.emplace_back(Fmt(t->Tag()));
}
AttrInfo::AttrInfo(CPPCompile* _c, const AttrPtr& attr) : CompoundItemInfo(_c) { AttrInfo::AttrInfo(CPPCompile* _c, const AttrPtr& attr) : CompoundItemInfo(_c) {
vals.emplace_back(Fmt(static_cast<int>(attr->Tag()))); vals.emplace_back(Fmt(static_cast<int>(attr->Tag())));
auto a_e = attr->GetExpr(); auto a_e = attr->GetExpr();

View file

@ -467,6 +467,16 @@ private:
FuncVal* fv; FuncVal* fv;
}; };
class TypeConstInfo : public CompoundItemInfo {
public:
TypeConstInfo(CPPCompile* _c, ValPtr v) : CompoundItemInfo(_c, v), tv(v->AsTypeVal()) {}
void InitializerVals(std::vector<std::string>& ivs) const override;
private:
TypeVal* tv;
};
// Initialization information for single attributes and sets of attributes. // Initialization information for single attributes and sets of attributes.
class AttrInfo : public CompoundItemInfo { class AttrInfo : public CompoundItemInfo {
public: public:

View file

@ -149,6 +149,14 @@ void CPP_IndexedInits<T>::Generate(InitsManager* im, std::vector<FuncValPtr>& iv
ivec[offset] = lookup_func__CPP(fn, num_bodies, hashes, im->Types(t)); ivec[offset] = lookup_func__CPP(fn, num_bodies, hashes, im->Types(t));
} }
template<class T>
void CPP_IndexedInits<T>::Generate(InitsManager* im, std::vector<TypeValPtr>& ivec, int offset,
ValElemVec& init_vals) const {
auto bt = base_type(static_cast<TypeTag>(init_vals[0]));
auto t = make_intrusive<TypeType>(bt);
ivec[offset] = make_intrusive<TypeVal>(t);
}
template<class T> template<class T>
void CPP_IndexedInits<T>::Generate(InitsManager* im, std::vector<AttrPtr>& ivec, int offset, void CPP_IndexedInits<T>::Generate(InitsManager* im, std::vector<AttrPtr>& ivec, int offset,
ValElemVec& init_vals) const { ValElemVec& init_vals) const {
@ -216,6 +224,7 @@ template class CPP_IndexedInits<RecordValPtr>;
template class CPP_IndexedInits<TableValPtr>; template class CPP_IndexedInits<TableValPtr>;
template class CPP_IndexedInits<FileValPtr>; template class CPP_IndexedInits<FileValPtr>;
template class CPP_IndexedInits<FuncValPtr>; template class CPP_IndexedInits<FuncValPtr>;
template class CPP_IndexedInits<TypeValPtr>;
template class CPP_IndexedInits<AttrPtr>; template class CPP_IndexedInits<AttrPtr>;
template class CPP_IndexedInits<AttributesPtr>; template class CPP_IndexedInits<AttributesPtr>;
template class CPP_IndexedInits<TypePtr>; template class CPP_IndexedInits<TypePtr>;

View file

@ -16,6 +16,7 @@ namespace zeek::detail {
using FileValPtr = IntrusivePtr<FileVal>; using FileValPtr = IntrusivePtr<FileVal>;
using FuncValPtr = IntrusivePtr<FuncVal>; using FuncValPtr = IntrusivePtr<FuncVal>;
using TypeValPtr = IntrusivePtr<TypeVal>;
class InitsManager; class InitsManager;
@ -274,6 +275,7 @@ protected:
void Generate(InitsManager* im, std::vector<TableValPtr>& ivec, int offset, ValElemVec& init_vals) const; void Generate(InitsManager* im, std::vector<TableValPtr>& ivec, int offset, ValElemVec& init_vals) const;
void Generate(InitsManager* im, std::vector<FileValPtr>& ivec, int offset, ValElemVec& init_vals) const; void Generate(InitsManager* im, std::vector<FileValPtr>& ivec, int offset, ValElemVec& init_vals) const;
void Generate(InitsManager* im, std::vector<FuncValPtr>& ivec, int offset, ValElemVec& init_vals) const; void Generate(InitsManager* im, std::vector<FuncValPtr>& ivec, int offset, ValElemVec& init_vals) const;
void Generate(InitsManager* im, std::vector<TypeValPtr>& ivec, int offset, ValElemVec& init_vals) const;
void Generate(InitsManager* im, std::vector<AttrPtr>& ivec, int offset, ValElemVec& init_vals) const; void Generate(InitsManager* im, std::vector<AttrPtr>& ivec, int offset, ValElemVec& init_vals) const;
void Generate(InitsManager* im, std::vector<AttributesPtr>& ivec, int offset, ValElemVec& init_vals) const; void Generate(InitsManager* im, std::vector<AttributesPtr>& ivec, int offset, ValElemVec& init_vals) const;

View file

@ -3,6 +3,7 @@
#include "zeek/script_opt/CPP/RuntimeVec.h" #include "zeek/script_opt/CPP/RuntimeVec.h"
#include "zeek/Overflow.h" #include "zeek/Overflow.h"
#include "zeek/RE.h"
#include "zeek/ZeekString.h" #include "zeek/ZeekString.h"
namespace zeek::detail { namespace zeek::detail {
@ -320,6 +321,29 @@ static VectorValPtr str_vec_op_kernel__CPP(const VectorValPtr& v1, const VectorV
return v_result; return v_result;
} }
// Kernel for element-by-element pattern relationals. "is_eq" governs
// whether the operation is equality (true) or inequality (false).
static VectorValPtr pat_vec_op_kernel__CPP(const VectorValPtr& v1, const VectorValPtr& v2, bool is_eq) {
auto res_type = make_intrusive<VectorType>(base_type(TYPE_BOOL));
auto v_result = make_intrusive<VectorVal>(res_type);
auto n = v1->Size();
for ( unsigned int i = 0; i < n; ++i ) {
auto v1_i = v1->ValAt(i);
auto v2_i = v2->ValAt(i);
if ( ! v1_i || ! v2_i )
continue;
auto p1 = v1_i->AsPattern();
auto p2 = v2_i->AsPattern();
bool elem_eq = strcmp(p1->PatternText(), p2->PatternText()) == 0;
v_result->Assign(i, val_mgr->Bool(elem_eq == is_eq));
}
return v_result;
}
VectorValPtr str_vec_op_lt__CPP(const VectorValPtr& v1, const VectorValPtr& v2) { VectorValPtr str_vec_op_lt__CPP(const VectorValPtr& v1, const VectorValPtr& v2) {
return str_vec_op_kernel__CPP(v1, v2, -1, -1); return str_vec_op_kernel__CPP(v1, v2, -1, -1);
} }
@ -339,6 +363,13 @@ VectorValPtr str_vec_op_ge__CPP(const VectorValPtr& v1, const VectorValPtr& v2)
return str_vec_op_kernel__CPP(v1, v2, 0, 1); return str_vec_op_kernel__CPP(v1, v2, 0, 1);
} }
VectorValPtr pat_vec_op_eq__CPP(const VectorValPtr& v1, const VectorValPtr& v2) {
return pat_vec_op_kernel__CPP(v1, v2, true);
}
VectorValPtr pat_vec_op_ne__CPP(const VectorValPtr& v1, const VectorValPtr& v2) {
return pat_vec_op_kernel__CPP(v1, v2, false);
}
VectorValPtr vector_select__CPP(const VectorValPtr& v1, VectorValPtr v2, VectorValPtr v3) { VectorValPtr vector_select__CPP(const VectorValPtr& v1, VectorValPtr v2, VectorValPtr v3) {
auto vt = v2->GetType<VectorType>(); auto vt = v2->GetType<VectorType>();
auto v_result = make_intrusive<VectorVal>(vt); auto v_result = make_intrusive<VectorVal>(vt);

View file

@ -72,6 +72,10 @@ extern VectorValPtr str_vec_op_ne__CPP(const VectorValPtr& v1, const VectorValPt
extern VectorValPtr str_vec_op_gt__CPP(const VectorValPtr& v1, const VectorValPtr& v2); extern VectorValPtr str_vec_op_gt__CPP(const VectorValPtr& v1, const VectorValPtr& v2);
extern VectorValPtr str_vec_op_ge__CPP(const VectorValPtr& v1, const VectorValPtr& v2); extern VectorValPtr str_vec_op_ge__CPP(const VectorValPtr& v1, const VectorValPtr& v2);
// Pattern vector relationals.
extern VectorValPtr pat_vec_op_eq__CPP(const VectorValPtr& v1, const VectorValPtr& v2);
extern VectorValPtr pat_vec_op_ne__CPP(const VectorValPtr& v1, const VectorValPtr& v2);
// Support for vector conditional ('?:') expressions. Using the boolean // Support for vector conditional ('?:') expressions. Using the boolean
// vector v1 as a selector, returns a new vector populated with the // vector v1 as a selector, returns a new vector populated with the
// elements selected out of v2 and v3. // elements selected out of v2 and v3.

View file

@ -0,0 +1,3 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
error in <...>/is_event_handled.zeek (C++), line 9: is_event_handled: 'myfunc1' is not an event (<___>testing_btest__tmp_bifs_is_event_handled_is_event_handled_zeek__global_stmts__zf: function() : void())
error in <...>/is_event_handled.zeek (C++), line 9: is_event_handled: 'conn_id' is not an event (<___>testing_btest__tmp_bifs_is_event_handled_is_event_handled_zeek__global_stmts__zf: function() : void())

View file

@ -0,0 +1,5 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
T
F
F
F

View file

@ -0,0 +1,7 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
1362692526.869344 error in <...>/lookup_connection.zeek (C++), line 6: invalid connection ID record encountered: the proto field has the "unknown" 65535 value. Did you forget to set it? (<___>testing_btest__tmp_bifs_lookup_connection_lookup_connection_zeek__new_connection__0__zf: function() : void())
1362692526.869344 error in <...>/lookup_connection.zeek (C++), line 6: connection ID not a known connection (<___>testing_btest__tmp_bifs_lookup_connection_lookup_connection_zeek__new_connection__0__zf: function() : void() and [orig_h=141.142.228.5, orig_p=59856/tcp, resp_h=192.150.187.43, resp_p=80/tcp, proto=65535])
1362692526.869344 error in <...>/lookup_connection.zeek (C++), line 29: invalid connection ID record encountered: the proto field has the "unknown" 65535 value. Did you forget to set it? (<___>testing_btest__tmp_bifs_lookup_connection_lookup_connection_zeek__new_connection__1__zf: function() : void())
1362692526.869344 error in <...>/lookup_connection.zeek (C++), line 47: invalid connection ID record encountered (<___>testing_btest__tmp_bifs_lookup_connection_lookup_connection_zeek__new_connection__2__zf: function() : void())
1362692526.869344 error in <...>/lookup_connection.zeek (C++), line 47: connection ID not a known connection (<___>testing_btest__tmp_bifs_lookup_connection_lookup_connection_zeek__new_connection__2__zf: function() : void() and [orig_h=<uninitialized>, orig_p=<uninitialized>, resp_h=<uninitialized>, resp_p=<uninitialized>, proto=65535])
1362692526.869344 error in <...>/lookup_connection.zeek (C++), line 47: invalid connection ID record encountered (<___>testing_btest__tmp_bifs_lookup_connection_lookup_connection_zeek__new_connection__2__zf: function() : void())

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.
error in <...>/to_count.zeek (C++), line 5: bad conversion to count (<___>testing_btest__tmp_bifs_to_count_to_count_zeek__zeek_init__36__zf: function() : void() and -2)
error in <...>/to_count.zeek (C++), line 5: bad conversion to count (<___>testing_btest__tmp_bifs_to_count_to_count_zeek__zeek_init__36__zf: function() : void() and )
error in <...>/to_count.zeek (C++), line 5: bad conversion to count (<___>testing_btest__tmp_bifs_to_count_to_count_zeek__zeek_init__36__zf: function() : void() and not a count)

View file

@ -0,0 +1,17 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
0
2
3
4
7
0
18446744073709551611
205
206
172
35
195
195
0
123
9223372036854775808 and 9223372036854775808 are the same

View 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.
error in <...>/to_int.zeek (C++), line 5: bad conversion to integer (<___>testing_btest__tmp_bifs_to_int_to_int_zeek__zeek_init__36__zf: function() : void() and not an int)

View file

@ -0,0 +1,15 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
1
-1
188
39
243
243
4294967296
0
205
206
3
4
-3
-4

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.
error in <...>/cluster-publish-errors.zeek (C++), line 55: Publish of unknown record type 'Cluster::MyEvent' (<___>testing_btest__tmp_cluster_generic_cluster_publish_errors_cluster_publish_errors_zeek__zeek_init__40__zf: function() : void())
error in <...>/cluster-publish-errors.zeek (C++), line 62: Publish of unknown record type 'Cluster::MyEvent' (<___>testing_btest__tmp_cluster_generic_cluster_publish_errors_cluster_publish_errors_zeek__zeek_init__41__zf: function() : void())
error in <...>/cluster-publish-errors.zeek (C++), line 69: Publish of unknown record type 'Cluster::MyEvent' (<___>testing_btest__tmp_cluster_generic_cluster_publish_errors_cluster_publish_errors_zeek__zeek_init__42__zf: function() : void())

View file

@ -0,0 +1,13 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
Broker::make_event with Cluster::publish()
r=, T
Broker::make_event with Cluster::publish_hrw()
r=, T
Broker::make_event with Cluster::publish_rr()
r=, T
Cluster::publish() with wrong event
r=, F
Cluster::publish_hrw() with wrong event
r=, F
Cluster::publish_rr() with wrong event
r=, F

View file

@ -1,7 +1,7 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63. ### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
f, lambda_<10820400278317158366>: function() : void f, lambda_<10820400278317158366>: function() : void
compiled-C++ compiled-C++
g, lambda_<9730512750166342063>: function() : void g, lambda_<16208386833253569415>: function() : void
compiled-C++ compiled-C++
test_function, test_function: function() : void test_function, test_function: function() : void
compiled-C++ compiled-C++

View file

@ -0,0 +1,3 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
ts uid history service
XXXXXXXXXX.XXXXXX CHhAvVGS1DHFjwGM9 Dd quic,ssl

View file

@ -0,0 +1,3 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
analyzer_confirmation, 1692198386.837988, CHhAvVGS1DHFjwGM9, AllAnalyzers::ANALYZER_ANALYZER_QUIC
analyzer_confirmation, 1692198386.837988, CHhAvVGS1DHFjwGM9, AllAnalyzers::ANALYZER_ANALYZER_SSL