Merge remote-tracking branch 'origin/topic/vern/emphasize-IDPtrs'

* origin/topic/vern/emphasize-IDPtrs:
  fixup! fixup! shift much of the internal use of ID* identifier pointers over to IDPtr objects
  fixup! shift much of the internal use of ID* identifier pointers over to IDPtr objects
  fixup! shift much of the internal use of ID* identifier pointers over to IDPtr objects
  fixup! shift much of the internal use of ID* identifier pointers over to IDPtr objects
  annotate a number of BTests as unsuited for -O gen-C++ testing due to multiple Zeek runs
  BTest baseline updates for -O gen-C++ - all minor tweaks
  BTest updates for script optimization tracking of BiFs
  regression test for former ASAN issue with script optimization of lambdas
  shift much of the internal use of ID* identifier pointers over to IDPtr objects
  maintenance update for script optimization's knowledge of BiFs
  logger fix for interoperability with -O gen-C++ code
This commit is contained in:
Tim Wojtulewicz 2025-09-03 15:02:41 -07:00
commit e3b22cd21f
85 changed files with 488 additions and 417 deletions

24
CHANGES
View file

@ -1,3 +1,27 @@
8.1.0-dev.508 | 2025-09-03 15:02:41 -0700
* fixup! fixup! shift much of the internal use of ID* identifier pointers over to IDPtr objects (Vern Paxson, Corelight)
* fixup! shift much of the internal use of ID* identifier pointers over to IDPtr objects (Vern Paxson, Corelight)
* fixup! shift much of the internal use of ID* identifier pointers over to IDPtr objects (Vern Paxson, Corelight)
* fixup! shift much of the internal use of ID* identifier pointers over to IDPtr objects (Vern Paxson, Corelight)
* annotate a number of BTests as unsuited for -O gen-C++ testing due to multiple Zeek runs (Vern Paxson, Corelight)
* BTest baseline updates for -O gen-C++ - all minor tweaks (Vern Paxson, Corelight)
* BTest updates for script optimization tracking of BiFs (Vern Paxson, Corelight)
* regression test for former ASAN issue with script optimization of lambdas (Vern Paxson, Corelight)
* shift much of the internal use of ID* identifier pointers over to IDPtr objects (Vern Paxson, Corelight)
* maintenance update for script optimization's knowledge of BiFs (Vern Paxson, Corelight)
* logger fix for interoperability with -O gen-C++ code (Vern Paxson, Corelight)
8.1.0-dev.496 | 2025-09-03 16:17:23 -0400 8.1.0-dev.496 | 2025-09-03 16:17:23 -0400
* tightened up parsing of $field=X record constructor expressions (Vern Paxson, Corelight) * tightened up parsing of $field=X record constructor expressions (Vern Paxson, Corelight)

View file

@ -1 +1 @@
8.1.0-dev.496 8.1.0-dev.508

View file

@ -4226,7 +4226,7 @@ LambdaExpr::LambdaExpr(FunctionIngredientsPtr arg_ing, IDPList arg_outer_ids, st
if ( captures ) { if ( captures ) {
outer_ids.clear(); outer_ids.clear();
for ( auto& c : *captures ) for ( auto& c : *captures )
outer_ids.append(c.Id().get()); outer_ids.emplace_back(c.Id());
} }
// Install a primary version of the function globally. This is used // Install a primary version of the function globally. This is used
@ -4271,7 +4271,7 @@ LambdaExpr::LambdaExpr(LambdaExpr* orig) : Expr(EXPR_LAMBDA) {
// We need to have our own copies of the outer IDs and captures so // We need to have our own copies of the outer IDs and captures so
// we can rename them when inlined. // we can rename them when inlined.
for ( auto i : orig->outer_ids ) for ( auto i : orig->outer_ids )
outer_ids.append(i); outer_ids.emplace_back(i);
if ( orig->captures ) { if ( orig->captures ) {
captures = std::vector<FuncType::Capture>{}; captures = std::vector<FuncType::Capture>{};
@ -4295,11 +4295,11 @@ bool LambdaExpr::CheckCaptures(StmtPtr when_parent) {
return true; return true;
} }
std::set<const ID*> outer_is_matched; std::unordered_set<IDPtr> outer_is_matched;
std::set<const ID*> capture_is_matched; std::unordered_set<IDPtr> capture_is_matched;
for ( const auto& c : *captures ) { for ( const auto& c : *captures ) {
auto cid = c.Id().get(); auto cid = c.Id();
if ( ! cid ) if ( ! cid )
// This happens for undefined/inappropriate // This happens for undefined/inappropriate
@ -4317,7 +4317,7 @@ bool LambdaExpr::CheckCaptures(StmtPtr when_parent) {
return false; return false;
} }
for ( auto id : outer_ids ) for ( const auto& id : outer_ids )
if ( cid == id ) { if ( cid == id ) {
outer_is_matched.insert(id); outer_is_matched.insert(id);
capture_is_matched.insert(cid); capture_is_matched.insert(cid);
@ -4337,7 +4337,7 @@ bool LambdaExpr::CheckCaptures(StmtPtr when_parent) {
} }
for ( const auto& c : *captures ) { for ( const auto& c : *captures ) {
auto cid = c.Id().get(); const auto& cid = c.Id();
if ( cid && ! capture_is_matched.contains(cid) ) { if ( cid && ! capture_is_matched.contains(cid) ) {
auto msg = util::fmt("%s is captured but not used inside %s", cid->Name(), desc); auto msg = util::fmt("%s is captured but not used inside %s", cid->Name(), desc);
if ( when_parent ) if ( when_parent )

View file

@ -49,7 +49,8 @@ enum IDScope : uint8_t { SCOPE_FUNCTION, SCOPE_MODULE, SCOPE_GLOBAL };
class ID; class ID;
using IDPtr = IntrusivePtr<ID>; using IDPtr = IntrusivePtr<ID>;
using IDSet = std::unordered_set<const ID*>; using IDPList = std::vector<IDPtr>;
using IDSet = std::unordered_set<IDPtr>;
class IDOptInfo; class IDOptInfo;

View file

@ -536,14 +536,7 @@ Case::Case(ListExprPtr arg_expr_cases, IDPList* arg_type_cases, StmtPtr arg_s)
} }
} }
Case::~Case() { Case::~Case() { delete type_cases; }
if ( type_cases ) {
for ( const auto& id : *type_cases )
Unref(id);
delete type_cases;
}
}
void Case::Describe(ODesc* d) const { void Case::Describe(ODesc* d) const {
if ( ! (expr_cases || type_cases) ) { if ( ! (expr_cases || type_cases) ) {
@ -580,9 +573,10 @@ void Case::Describe(ODesc* d) const {
if ( type_cases ) { if ( type_cases ) {
const IDPList& t = *type_cases; const IDPList& t = *type_cases;
d->AddCount(t.length()); auto n = t.size();
d->AddCount(n);
loop_over_list(t, i) { for ( auto i = 0U; i < n; ++i ) {
if ( i > 0 && d->IsReadable() ) if ( i > 0 && d->IsReadable() )
d->Add(","); d->Add(",");
@ -763,21 +757,21 @@ bool SwitchStmt::AddCaseLabelValueMapping(const Val* v, int idx) {
return true; return true;
} }
bool SwitchStmt::AddCaseLabelTypeMapping(ID* t, int idx) { bool SwitchStmt::AddCaseLabelTypeMapping(IDPtr t, int idx) {
for ( const auto& i : case_label_type_list ) { for ( const auto& i : case_label_type_list ) {
if ( same_type(i.first->GetType(), t->GetType()) ) if ( same_type(i.first->GetType(), t->GetType()) )
return false; return false;
} }
auto e = std::make_pair(t, idx); auto e = std::make_pair(std::move(t), idx);
case_label_type_list.push_back(e); case_label_type_list.push_back(e);
return true; return true;
} }
std::pair<int, ID*> SwitchStmt::FindCaseLabelMatch(const Val* v) const { std::pair<int, IDPtr> SwitchStmt::FindCaseLabelMatch(const Val* v) const {
int label_idx = -1; int label_idx = -1;
ID* label_id = nullptr; IDPtr label_id;
// Find matching expression cases. // Find matching expression cases.
if ( case_label_hash_map.Length() ) { if ( case_label_hash_map.Length() ) {
@ -817,7 +811,7 @@ ValPtr SwitchStmt::DoExec(Frame* f, Val* v, StmtFlowType& flow) {
auto m = FindCaseLabelMatch(v); auto m = FindCaseLabelMatch(v);
int matching_label_idx = m.first; int matching_label_idx = m.first;
ID* matching_id = m.second; auto matching_id = m.second;
if ( matching_label_idx == -1 ) if ( matching_label_idx == -1 )
return nullptr; return nullptr;
@ -1015,7 +1009,7 @@ ForStmt::ForStmt(IDPList* arg_loop_vars, ExprPtr loop_expr) : ExprStmt(STMT_FOR,
if ( e->GetType()->Tag() == TYPE_TABLE ) { if ( e->GetType()->Tag() == TYPE_TABLE ) {
const auto& indices = e->GetType()->AsTableType()->GetIndexTypes(); const auto& indices = e->GetType()->AsTableType()->GetIndexTypes();
if ( loop_vars->length() == 1 && (*loop_vars)[0]->IsBlank() ) { if ( loop_vars->size() == 1 && (*loop_vars)[0]->IsBlank() ) {
// Special case support for looping with a single loop_var // Special case support for looping with a single loop_var
// ignoring the full index of a table. // ignoring the full index of a table.
// //
@ -1024,12 +1018,12 @@ ForStmt::ForStmt(IDPList* arg_loop_vars, ExprPtr loop_expr) : ExprStmt(STMT_FOR,
// //
return; return;
} }
else if ( static_cast<int>(indices.size()) != loop_vars->length() ) { else if ( indices.size() != loop_vars->size() ) {
e->Error("wrong index size"); e->Error("wrong index size");
return; return;
} }
for ( auto i = 0u; i < indices.size(); i++ ) { for ( size_t i = 0; i < indices.size(); i++ ) {
const auto& ind_type = indices[i]; const auto& ind_type = indices[i];
const auto& lv = (*loop_vars)[i]; const auto& lv = (*loop_vars)[i];
const auto& lvt = lv->GetType(); const auto& lvt = lv->GetType();
@ -1042,14 +1036,13 @@ ForStmt::ForStmt(IDPList* arg_loop_vars, ExprPtr loop_expr) : ExprStmt(STMT_FOR,
e->Error("type clash in iteration", lvt.get()); e->Error("type clash in iteration", lvt.get());
} }
else { else
add_local({NewRef{}, lv}, ind_type, INIT_SKIP, nullptr, nullptr, VAR_REGULAR); add_local(lv, ind_type, INIT_SKIP, nullptr, nullptr, VAR_REGULAR);
}
} }
} }
else if ( e->GetType()->Tag() == TYPE_VECTOR ) { else if ( e->GetType()->Tag() == TYPE_VECTOR ) {
if ( loop_vars->length() != 1 ) { if ( loop_vars->size() != 1 ) {
e->Error("iterating over a vector requires only a single index type"); e->Error("iterating over a vector requires only a single index type");
return; return;
} }
@ -1061,7 +1054,7 @@ ForStmt::ForStmt(IDPList* arg_loop_vars, ExprPtr loop_expr) : ExprStmt(STMT_FOR,
// nop // nop
} }
else if ( ! t ) else if ( ! t )
add_local({NewRef{}, lv}, base_type(TYPE_COUNT), INIT_SKIP, nullptr, nullptr, VAR_REGULAR); add_local(lv, base_type(TYPE_COUNT), INIT_SKIP, nullptr, nullptr, VAR_REGULAR);
else if ( ! IsIntegral(t->Tag()) ) { else if ( ! IsIntegral(t->Tag()) ) {
e->Error("vector index in \"for\" loop must be integral"); e->Error("vector index in \"for\" loop must be integral");
@ -1070,7 +1063,7 @@ ForStmt::ForStmt(IDPList* arg_loop_vars, ExprPtr loop_expr) : ExprStmt(STMT_FOR,
} }
else if ( e->GetType()->Tag() == TYPE_STRING ) { else if ( e->GetType()->Tag() == TYPE_STRING ) {
if ( loop_vars->length() != 1 ) { if ( loop_vars->size() != 1 ) {
e->Error("iterating over a string requires only a single index type"); e->Error("iterating over a string requires only a single index type");
return; return;
} }
@ -1082,7 +1075,7 @@ ForStmt::ForStmt(IDPList* arg_loop_vars, ExprPtr loop_expr) : ExprStmt(STMT_FOR,
// nop // nop
} }
else if ( ! t ) else if ( ! t )
add_local({NewRef{}, (*loop_vars)[0]}, base_type(TYPE_STRING), INIT_SKIP, nullptr, nullptr, VAR_REGULAR); add_local((*loop_vars)[0], base_type(TYPE_STRING), INIT_SKIP, nullptr, nullptr, VAR_REGULAR);
else if ( t->Tag() != TYPE_STRING ) { else if ( t->Tag() != TYPE_STRING ) {
e->Error("string index in \"for\" loop must be string"); e->Error("string index in \"for\" loop must be string");
@ -1123,11 +1116,7 @@ ForStmt::ForStmt(IDPList* arg_loop_vars, ExprPtr loop_expr, IDPtr val_var)
add_local(value_var, yield_type, INIT_SKIP, nullptr, nullptr, VAR_REGULAR); add_local(value_var, yield_type, INIT_SKIP, nullptr, nullptr, VAR_REGULAR);
} }
ForStmt::~ForStmt() { ForStmt::~ForStmt() { delete loop_vars; }
for ( const auto& var : *loop_vars )
Unref(var);
delete loop_vars;
}
ValPtr ForStmt::DoExec(Frame* f, Val* v, StmtFlowType& flow) { ValPtr ForStmt::DoExec(Frame* f, Val* v, StmtFlowType& flow) {
ValPtr ret; ValPtr ret;
@ -1142,7 +1131,7 @@ ValPtr ForStmt::DoExec(Frame* f, Val* v, StmtFlowType& flow) {
// If there are only blank loop_vars (iterating over just the values), // If there are only blank loop_vars (iterating over just the values),
// we can avoid the RecreateIndex() overhead. // we can avoid the RecreateIndex() overhead.
bool all_loop_vars_blank = true; bool all_loop_vars_blank = true;
for ( const auto* lv : *loop_vars ) for ( const auto& lv : *loop_vars )
all_loop_vars_blank &= lv->IsBlank(); all_loop_vars_blank &= lv->IsBlank();
for ( const auto& lve : *loop_vals ) { for ( const auto& lve : *loop_vals ) {
@ -1155,7 +1144,7 @@ ValPtr ForStmt::DoExec(Frame* f, Val* v, StmtFlowType& flow) {
if ( ! all_loop_vars_blank ) { if ( ! all_loop_vars_blank ) {
auto ind_lv = tv->RecreateIndex(*k); auto ind_lv = tv->RecreateIndex(*k);
for ( int i = 0; i < ind_lv->Length(); i++ ) { for ( int i = 0; i < ind_lv->Length(); i++ ) {
const auto* lv = (*loop_vars)[i]; const auto& lv = (*loop_vars)[i];
if ( ! lv->IsBlank() ) if ( ! lv->IsBlank() )
f->SetElement(lv, ind_lv->Idx(i)); f->SetElement(lv, ind_lv->Idx(i));
} }
@ -1173,7 +1162,7 @@ ValPtr ForStmt::DoExec(Frame* f, Val* v, StmtFlowType& flow) {
VectorVal* vv = v->AsVectorVal(); VectorVal* vv = v->AsVectorVal();
const auto& raw_vv = vv->RawVec(); const auto& raw_vv = vv->RawVec();
for ( auto i = 0u; i < vv->Size(); ++i ) { for ( size_t i = 0; i < vv->Size(); ++i ) {
if ( ! raw_vv[i] ) if ( ! raw_vv[i] )
continue; continue;
@ -1182,7 +1171,7 @@ ValPtr ForStmt::DoExec(Frame* f, Val* v, StmtFlowType& flow) {
if ( value_var ) if ( value_var )
f->SetElement(value_var, vv->ValAt(i)); f->SetElement(value_var, vv->ValAt(i));
const auto* lv = (*loop_vars)[0]; const auto& lv = (*loop_vars)[0];
if ( ! lv->IsBlank() ) if ( ! lv->IsBlank() )
f->SetElement(lv, val_mgr->Count(i)); f->SetElement(lv, val_mgr->Count(i));
@ -1227,16 +1216,16 @@ void ForStmt::StmtDescribe(ODesc* d) const {
if ( d->IsReadable() ) if ( d->IsReadable() )
d->Add("("); d->Add("(");
if ( loop_vars->length() ) if ( ! loop_vars->empty() )
d->Add("["); d->Add("[");
loop_over_list(*loop_vars, i) { for ( size_t i = 0; i < loop_vars->size(); ++i ) {
(*loop_vars)[i]->Describe(d); (*loop_vars)[i]->Describe(d);
if ( i > 0 ) if ( i > 0 )
d->Add(","); d->Add(",");
} }
if ( loop_vars->length() ) if ( ! loop_vars->empty() )
d->Add("]"); d->Add("]");
if ( value_var ) { if ( value_var ) {
@ -1775,22 +1764,16 @@ void WhenInfo::BuildProfile() {
break; break;
} }
if ( ! is_present ) { if ( ! is_present )
IDPtr wl_ptr = {NewRef{}, const_cast<ID*>(wl)}; cl->emplace_back(wl, false);
cl->emplace_back(std::move(wl_ptr), false);
}
// In addition, don't treat them as external locals that // In addition, don't treat them as external locals that
// existed at the onset. // existed at the onset.
when_expr_locals_set.erase(wl); when_expr_locals_set.erase(wl);
} }
for ( auto& w : when_expr_locals_set ) { for ( auto& w : when_expr_locals_set )
// We need IDPtr versions of the locals so we can manipulate when_expr_locals.emplace_back(w);
// them during script optimization.
auto non_const_w = const_cast<ID*>(w);
when_expr_locals.emplace_back(NewRef{}, non_const_w);
}
} }
void WhenInfo::Build(StmtPtr ws) { void WhenInfo::Build(StmtPtr ws) {

View file

@ -194,7 +194,7 @@ protected:
int DefaultCaseIndex() const { return default_case_idx; } int DefaultCaseIndex() const { return default_case_idx; }
const auto& ValueMap() const { return case_label_value_map; } const auto& ValueMap() const { return case_label_value_map; }
const std::vector<std::pair<ID*, int>>* TypeMap() const { return &case_label_type_list; } const std::vector<std::pair<IDPtr, int>>* TypeMap() const { return &case_label_type_list; }
const CompositeHash* CompHash() const { return comp_hash; } const CompositeHash* CompHash() const { return comp_hash; }
ValPtr DoExec(Frame* f, Val* v, StmtFlowType& flow) override; ValPtr DoExec(Frame* f, Val* v, StmtFlowType& flow) override;
@ -212,20 +212,20 @@ protected:
// Adds an entry in case_label_type_map for the given type (w/ ID) to // Adds an entry in case_label_type_map for the given type (w/ ID) to
// associate it with the given index in the cases list. If an entry // associate it with the given index in the cases list. If an entry
// for the type already exists, returns false; else returns true. // for the type already exists, returns false; else returns true.
bool AddCaseLabelTypeMapping(ID* t, int idx); bool AddCaseLabelTypeMapping(IDPtr t, int idx);
// Returns index of a case label that matches the value, or // Returns index of a case label that matches the value, or
// default_case_idx if no case label matches (which may be -1 if // default_case_idx if no case label matches (which may be -1 if
// there's no default label). The second tuple element is the ID of // there's no default label). The second tuple element is the ID of
// the matching type-based case if it defines one. // the matching type-based case if it defines one.
std::pair<int, ID*> FindCaseLabelMatch(const Val* v) const; std::pair<int, IDPtr> FindCaseLabelMatch(const Val* v) const;
case_list* cases = nullptr; case_list* cases = nullptr;
int default_case_idx = -1; int default_case_idx = -1;
CompositeHash* comp_hash = nullptr; CompositeHash* comp_hash = nullptr;
std::unordered_map<const Val*, int> case_label_value_map; std::unordered_map<const Val*, int> case_label_value_map;
PDict<int> case_label_hash_map; PDict<int> case_label_hash_map;
std::vector<std::pair<ID*, int>> case_label_type_list; std::vector<std::pair<IDPtr, int>> case_label_type_list;
}; };
class EventStmt final : public ExprStmt { class EventStmt final : public ExprStmt {

View file

@ -44,7 +44,7 @@ TraversalCode trigger::TriggerTraversalCallback::PreExpr(const Expr* expr) {
switch ( expr->Tag() ) { switch ( expr->Tag() ) {
case EXPR_NAME: { case EXPR_NAME: {
const auto* e = static_cast<const NameExpr*>(expr); const auto* e = static_cast<const NameExpr*>(expr);
auto id = e->Id(); auto id = e->IdPtr();
if ( id->IsGlobal() ) if ( id->IsGlobal() )
globals.insert(id); globals.insert(id);
@ -184,7 +184,7 @@ void Trigger::ReInit(std::vector<ValPtr> index_expr_results) {
} }
for ( auto g : globals ) { for ( auto g : globals ) {
Register(g); Register(g.get());
auto& v = g->GetVal(); auto& v = g->GetVal();
if ( v && v->Modifiable() ) if ( v && v->Modifiable() )

View file

@ -667,7 +667,7 @@ public:
TraversalCode PostExpr(const Expr*) override; TraversalCode PostExpr(const Expr*) override;
std::vector<ScopePtr> scopes; std::vector<ScopePtr> scopes;
std::unordered_set<ID*> outer_id_references; std::unordered_set<IDPtr> outer_id_references;
}; };
TraversalCode OuterIDBindingFinder::PreExpr(const Expr* expr) { TraversalCode OuterIDBindingFinder::PreExpr(const Expr* expr) {
@ -681,7 +681,7 @@ TraversalCode OuterIDBindingFinder::PreExpr(const Expr* expr) {
return TC_CONTINUE; return TC_CONTINUE;
auto e = static_cast<const NameExpr*>(expr); auto e = static_cast<const NameExpr*>(expr);
auto id = e->Id(); auto id = e->IdPtr();
if ( id->IsGlobal() ) if ( id->IsGlobal() )
return TC_CONTINUE; return TC_CONTINUE;
@ -760,8 +760,8 @@ IDPList gather_outer_ids(ScopePtr scope, StmtPtr body) {
IDPList idl; IDPList idl;
for ( auto id : cb.outer_id_references ) for ( auto& id : cb.outer_id_references )
idl.append(id); idl.emplace_back(std::move(id));
return idl; return idl;
} }

View file

@ -20,7 +20,6 @@ class Type;
using ValPList = PList<Val>; using ValPList = PList<Val>;
using ExprPList = PList<detail::Expr>; using ExprPList = PList<detail::Expr>;
using IDPList = PList<detail::ID>;
using TypePList = PList<Type>; using TypePList = PList<Type>;
using AttrPList = PList<detail::Attr>; using AttrPList = PList<detail::Attr>;
using TimerPList = PList<detail::Timer, ListOrder::UNORDERED>; using TimerPList = PList<detail::Timer, ListOrder::UNORDERED>;

View file

@ -48,12 +48,12 @@ struct WriteContext {
WriteIdx idx = 0; // Ever increasing counter. WriteIdx idx = 0; // Ever increasing counter.
bool operator<(const WriteContext& o) const { bool operator<(const WriteContext& o) const {
assert(id == o.id); assert(id->Get() == o.id->Get());
return idx < o.idx; return idx < o.idx;
} }
bool operator==(const WriteContext& o) const { bool operator==(const WriteContext& o) const {
assert(id == o.id); assert(id->Get() == o.id->Get());
return idx == o.idx; return idx == o.idx;
} }
}; };

View file

@ -331,7 +331,7 @@ static void refine_location(zeek::detail::ID* id) {
bool b; bool b;
char* str; char* str;
zeek::detail::ID* id; zeek::detail::ID* id;
zeek::IDPList* id_l; zeek::detail::IDPList* id_l;
zeek::detail::InitClass ic; zeek::detail::InitClass ic;
zeek::Val* val; zeek::Val* val;
zeek::RE_Matcher* re; zeek::RE_Matcher* re;
@ -2017,12 +2017,12 @@ case:
case_type_list: case_type_list:
case_type_list ',' case_type case_type_list ',' case_type
{ $1->push_back($3); } { $1->push_back({AdoptRef{}, $3}); }
| |
case_type case_type
{ {
$$ = new IDPList; $$ = new IDPList;
$$->push_back($1); $$->push_back({AdoptRef{}, $1});
} }
; ;
@ -2066,7 +2066,7 @@ for_head:
} }
auto* loop_vars = new IDPList; auto* loop_vars = new IDPList;
loop_vars->push_back(loop_var.release()); loop_vars->push_back(loop_var);
$$ = new ForStmt(loop_vars, {AdoptRef{}, $5}); $$ = new ForStmt(loop_vars, {AdoptRef{}, $5});
} }
@ -2098,7 +2098,7 @@ for_head:
val_var = install_ID($5, module, false, false); val_var = install_ID($5, module, false, false);
auto* loop_vars = new IDPList; auto* loop_vars = new IDPList;
loop_vars->push_back(key_var.release()); loop_vars->push_back(key_var);
$$ = new ForStmt(loop_vars, {AdoptRef{}, $7}, std::move(val_var)); $$ = new ForStmt(loop_vars, {AdoptRef{}, $7}, std::move(val_var));
} }
@ -2122,11 +2122,11 @@ for_head:
local_id_list: local_id_list:
local_id_list ',' local_id local_id_list ',' local_id
{ $1->push_back($3); } { $1->push_back({AdoptRef{}, $3}); }
| local_id | local_id
{ {
$$ = new IDPList; $$ = new IDPList;
$$->push_back($1); $$->push_back({AdoptRef{}, $1});
} }
; ;

View file

@ -154,7 +154,7 @@ void CPPCompile::DeclareSubclass(const FuncTypePtr& ft, const ProfileFunc* pf, c
// An additional constructor just used to generate place-holder // An additional constructor just used to generate place-holder
// instances, due to the misdesign that lambdas are identified // instances, due to the misdesign that lambdas are identified
// by their Func objects rather than their FuncVal objects. // by their Func objects rather than their FuncVal objects.
if ( lambda_ids && lambda_ids->length() > 0 ) if ( lambda_ids && ! lambda_ids->empty() )
Emit("%s_cl(const char* name) : CPPStmt(name, %s) { }", fname, loc_info); Emit("%s_cl(const char* name) : CPPStmt(name, %s) { }", fname, loc_info);
Emit("ValPtr Exec(Frame* f, StmtFlowType& flow) override"); Emit("ValPtr Exec(Frame* f, StmtFlowType& flow) override");
@ -216,7 +216,7 @@ void CPPCompile::BuildLambda(const FuncTypePtr& ft, const ProfileFunc* pf, const
// Generate initialization to create and register the lambda. // Generate initialization to create and register the lambda.
auto h = pf->HashVal(); auto h = pf->HashVal();
auto nl = lambda_ids->length(); auto nl = lambda_ids->size();
bool has_captures = nl > 0; bool has_captures = nl > 0;
auto gi = make_shared<LambdaRegistrationInfo>(this, l->Name(), ft, fname + "_cl", h, has_captures); auto gi = make_shared<LambdaRegistrationInfo>(this, l->Name(), ft, fname + "_cl", h, has_captures);
@ -226,10 +226,10 @@ void CPPCompile::BuildLambda(const FuncTypePtr& ft, const ProfileFunc* pf, const
// Frame object. // Frame object.
Emit("void SetLambdaCaptures(Frame* f) override"); Emit("void SetLambdaCaptures(Frame* f) override");
StartBlock(); StartBlock();
for ( int i = 0; i < nl; ++i ) { for ( size_t i = 0; i < nl; ++i ) {
auto l_i = (*lambda_ids)[i]; auto l_i = (*lambda_ids)[i];
const auto& t_i = l_i->GetType(); const auto& t_i = l_i->GetType();
auto cap_i = string("f->GetElement(") + Fmt(i) + ")"; auto cap_i = string("f->GetElement(") + Fmt(static_cast<int>(i)) + ")";
Emit("%s = %s;", lambda_names[l_i], GenericValPtrToGT(cap_i, t_i, GEN_NATIVE)); Emit("%s = %s;", lambda_names[l_i], GenericValPtrToGT(cap_i, t_i, GEN_NATIVE));
} }
EndBlock(); EndBlock();
@ -238,7 +238,7 @@ void CPPCompile::BuildLambda(const FuncTypePtr& ft, const ProfileFunc* pf, const
Emit("std::vector<ValPtr> SerializeLambdaCaptures() const override"); Emit("std::vector<ValPtr> SerializeLambdaCaptures() const override");
StartBlock(); StartBlock();
Emit("std::vector<ValPtr> vals;"); Emit("std::vector<ValPtr> vals;");
for ( int i = 0; i < nl; ++i ) { for ( size_t i = 0; i < nl; ++i ) {
auto l_i = (*lambda_ids)[i]; auto l_i = (*lambda_ids)[i];
const auto& t_i = l_i->GetType(); const auto& t_i = l_i->GetType();
Emit("vals.emplace_back(%s);", NativeToGT(lambda_names[l_i], t_i, GEN_VAL_PTR)); Emit("vals.emplace_back(%s);", NativeToGT(lambda_names[l_i], t_i, GEN_VAL_PTR));
@ -364,7 +364,7 @@ void CPPCompile::GatherParamNames(vector<string>& p_names, const FuncTypePtr& ft
p_names.emplace_back(lambda_names[id]); p_names.emplace_back(lambda_names[id]);
} }
const ID* CPPCompile::FindParam(int i, const ProfileFunc* pf) { IDPtr CPPCompile::FindParam(int i, const ProfileFunc* pf) {
const auto& params = pf->Params(); const auto& params = pf->Params();
for ( const auto& p : params ) for ( const auto& p : params )

View file

@ -68,7 +68,7 @@ void GatherParamNames(std::vector<std::string>& p_names, const FuncTypePtr& ft,
// Inspects the given profile to find the i'th parameter (starting at 0). // Inspects the given profile to find the i'th parameter (starting at 0).
// Returns nil if the profile indicates that the parameter is not used by the // Returns nil if the profile indicates that the parameter is not used by the
// function. // function.
const ID* FindParam(int i, const ProfileFunc* pf); IDPtr FindParam(int i, const ProfileFunc* pf);
// Information associated with a CPPDynStmt dynamic dispatch. // Information associated with a CPPDynStmt dynamic dispatch.
struct DispatchInfo { struct DispatchInfo {
@ -92,7 +92,7 @@ std::unordered_map<std::string, std::string> func_index;
// Names for lambda capture ID's. These require a separate space that // Names for lambda capture ID's. These require a separate space that
// incorporates the lambda's name, to deal with nested lambda's that refer // incorporates the lambda's name, to deal with nested lambda's that refer
// to the identifiers with the same name. // to the identifiers with the same name.
std::unordered_map<const ID*, std::string> lambda_names; std::unordered_map<IDPtr, std::string> lambda_names;
// The function's parameters. Tracked so we don't re-declare them. // The function's parameters. Tracked so we don't re-declare them.
IDSet params; IDSet params;

View file

@ -63,8 +63,8 @@ void CPPCompile::Compile(bool report_uncompilable) {
(void)pfs->HashType(t); (void)pfs->HashType(t);
rep_types.insert(TypeRep(t)); rep_types.insert(TypeRep(t));
all_accessed_globals.insert(g.get()); all_accessed_globals.insert(g);
accessed_globals.insert(g.get()); accessed_globals.insert(g);
for ( const auto& i_e : g->GetOptInfo()->GetInitExprs() ) { for ( const auto& i_e : g->GetOptInfo()->GetInitExprs() ) {
auto pf = std::make_shared<ProfileFunc>(i_e.get()); auto pf = std::make_shared<ProfileFunc>(i_e.get());

View file

@ -147,7 +147,7 @@ string CPPCompile::GenExpr(const Expr* e, GenType gt, bool top_level) {
string CPPCompile::GenNameExpr(const NameExpr* ne, GenType gt) { string CPPCompile::GenNameExpr(const NameExpr* ne, GenType gt) {
const auto& t = ne->GetType(); const auto& t = ne->GetType();
auto n = ne->Id(); const auto& n = ne->IdPtr();
bool is_global_var = global_vars.contains(n); bool is_global_var = global_vars.contains(n);
if ( t->Tag() == TYPE_FUNC && ! is_global_var ) { if ( t->Tag() == TYPE_FUNC && ! is_global_var ) {
@ -272,7 +272,7 @@ string CPPCompile::GenCallExpr(const CallExpr* c, GenType gt, bool top_level) {
auto gen = GenExpr(f, GEN_DONT_CARE); auto gen = GenExpr(f, GEN_DONT_CARE);
if ( f->Tag() == EXPR_NAME ) { if ( f->Tag() == EXPR_NAME ) {
auto f_id = f->AsNameExpr()->Id(); const auto& f_id = f->AsNameExpr()->IdPtr();
const auto& params = f_id->GetType()->AsFuncType()->Params(); const auto& params = f_id->GetType()->AsFuncType()->Params();
auto id_name = f_id->Name(); auto id_name = f_id->Name();
auto nargs = args_l->Exprs().length(); auto nargs = args_l->Exprs().length();
@ -1046,7 +1046,7 @@ string CPPCompile::GenAssign(const ExprPtr& lhs, const ExprPtr& rhs, const strin
string CPPCompile::GenDirectAssign(const ExprPtr& lhs, const string& rhs_native, const string& rhs_val_ptr, GenType gt, string CPPCompile::GenDirectAssign(const ExprPtr& lhs, const string& rhs_native, const string& rhs_val_ptr, GenType gt,
bool top_level) { bool top_level) {
auto n = lhs->AsNameExpr()->Id(); const auto& n = lhs->AsNameExpr()->IdPtr();
if ( n->IsBlank() ) if ( n->IsBlank() )
return rhs_native; return rhs_native;
@ -1134,7 +1134,7 @@ string CPPCompile::GenListAssign(const ExprPtr& lhs, const ExprPtr& rhs) {
auto rhs_i = GenericValPtrToGT(rhs_i_base, t_i, GEN_NATIVE); auto rhs_i = GenericValPtrToGT(rhs_i_base, t_i, GEN_NATIVE);
gen += IDNameStr(var->Id()) + " = " + rhs_i; gen += IDNameStr(var->IdPtr()) + " = " + rhs_i;
if ( i < n - 1 ) if ( i < n - 1 )
gen += ", "; gen += ", ";

View file

@ -195,7 +195,7 @@ void CPPCompile::InitializeGlobals() {
auto& ofiles = analysis_options.only_files; auto& ofiles = analysis_options.only_files;
for ( const auto& ginit : IDOptInfo::GetGlobalInitExprs() ) { for ( const auto& ginit : IDOptInfo::GetGlobalInitExprs() ) {
auto g = ginit.Id(); IDPtr g{NewRef{}, const_cast<ID*>(ginit.Id())};
if ( ! ofiles.empty() && ! obj_matches_opt_files(g) ) if ( ! ofiles.empty() && ! obj_matches_opt_files(g) )
continue; continue;

View file

@ -331,7 +331,7 @@ AttrInfo::AttrInfo(CPPCompile* _c, const AttrPtr& attr) : CompoundItemInfo(_c) {
} }
else if ( a_e->Tag() == EXPR_NAME ) { else if ( a_e->Tag() == EXPR_NAME ) {
auto g = a_e->AsNameExpr()->Id(); auto g = a_e->AsNameExpr()->IdPtr();
gi = c->RegisterGlobal(g); gi = c->RegisterGlobal(g);
init_cohort = max(init_cohort, gi->InitCohort() + 1); init_cohort = max(init_cohort, gi->InitCohort() + 1);
@ -363,7 +363,7 @@ AttrsInfo::AttrsInfo(CPPCompile* _c, const AttributesPtr& _attrs) : CompoundItem
} }
} }
GlobalLookupInitInfo::GlobalLookupInitInfo(CPPCompile* c, const ID* g, string _CPP_name, bool do_init) GlobalLookupInitInfo::GlobalLookupInitInfo(CPPCompile* c, IDPtr g, string _CPP_name, bool do_init)
: CPP_InitInfo(g), CPP_name(std::move(_CPP_name)) { : CPP_InitInfo(g), CPP_name(std::move(_CPP_name)) {
Zeek_name = g->Name(); Zeek_name = g->Name();
val = ValElem(c, do_init ? g->GetVal() : nullptr); val = ValElem(c, do_init ? g->GetVal() : nullptr);
@ -375,7 +375,7 @@ void GlobalLookupInitInfo::InitializerVals(std::vector<std::string>& ivs) const
ivs.push_back(val); ivs.push_back(val);
} }
GlobalInitInfo::GlobalInitInfo(CPPCompile* c, const ID* g, string _CPP_name) GlobalInitInfo::GlobalInitInfo(CPPCompile* c, IDPtr g, string _CPP_name)
: GlobalLookupInitInfo(c, g, std::move(_CPP_name)) { : GlobalLookupInitInfo(c, g, std::move(_CPP_name)) {
auto& gt = g->GetType(); auto& gt = g->GetType();
auto gi = c->RegisterType(gt); auto gi = c->RegisterType(gt);

View file

@ -488,7 +488,7 @@ public:
// then the global will be (re-)initialized to its value during compilation. // then the global will be (re-)initialized to its value during compilation.
class GlobalLookupInitInfo : public CPP_InitInfo { class GlobalLookupInitInfo : public CPP_InitInfo {
public: public:
GlobalLookupInitInfo(CPPCompile* c, const ID* g, std::string CPP_name, bool do_init = false); GlobalLookupInitInfo(CPPCompile* c, IDPtr g, std::string CPP_name, bool do_init = false);
std::string InitializerType() const override { return "CPP_GlobalLookupInit"; } std::string InitializerType() const override { return "CPP_GlobalLookupInit"; }
void InitializerVals(std::vector<std::string>& ivs) const override; void InitializerVals(std::vector<std::string>& ivs) const override;
@ -502,7 +502,7 @@ protected:
// Information for initializing a Zeek global. // Information for initializing a Zeek global.
class GlobalInitInfo : public GlobalLookupInitInfo { class GlobalInitInfo : public GlobalLookupInitInfo {
public: public:
GlobalInitInfo(CPPCompile* c, const ID* g, std::string CPP_name); GlobalInitInfo(CPPCompile* c, IDPtr g, std::string CPP_name);
std::string InitializerType() const override { return "CPP_GlobalInit"; } std::string InitializerType() const override { return "CPP_GlobalInit"; }
void InitializerVals(std::vector<std::string>& ivs) const override; void InitializerVals(std::vector<std::string>& ivs) const override;

View file

@ -11,7 +11,7 @@ using namespace std;
void CPPCompile::GenStmt(const Stmt* s) { void CPPCompile::GenStmt(const Stmt* s) {
auto loc = s->GetLocationInfo(); auto loc = s->GetLocationInfo();
if ( loc != &detail::no_location && s->Tag() != STMT_LIST ) if ( loc != &detail::no_location && s->Tag() != STMT_LIST )
Emit("// %s:%d", loc->FileName(), loc->FirstLine()); Emit("// %s:%s", loc->FileName(), to_string(loc->FirstLine()));
switch ( s->Tag() ) { switch ( s->Tag() ) {
case STMT_INIT: GenInitStmt(s->AsInitStmt()); break; case STMT_INIT: GenInitStmt(s->AsInitStmt()); break;
@ -82,7 +82,7 @@ void CPPCompile::GenInitStmt(const InitStmt* init) {
auto type_type = TypeType(t); auto type_type = TypeType(t);
auto type_ind = GenTypeName(t); auto type_ind = GenTypeName(t);
if ( ! locals.contains(aggr.get()) ) { if ( ! locals.contains(aggr) ) {
// fprintf(stderr, "aggregate %s unused\n", obj_desc(aggr.get()).c_str()); // fprintf(stderr, "aggregate %s unused\n", obj_desc(aggr.get()).c_str());
continue; continue;
} }
@ -223,7 +223,7 @@ void CPPCompile::GenTypeSwitchStmt(const Expr* e, const case_list* cases) {
Emit("}"); // end the scoping block Emit("}"); // end the scoping block
} }
void CPPCompile::GenTypeSwitchCase(const ID* id, int case_offset, bool is_multi) { void CPPCompile::GenTypeSwitchCase(const IDPtr id, int case_offset, bool is_multi) {
Emit("case %s:", Fmt(case_offset)); Emit("case %s:", Fmt(case_offset));
if ( ! id->Name() ) if ( ! id->Name() )
@ -310,13 +310,13 @@ void CPPCompile::GenWhenStmt(const WhenStmt* w) {
for ( auto& l : wi->WhenExprLocals() ) for ( auto& l : wi->WhenExprLocals() )
if ( IsAggr(l->GetType()) ) if ( IsAggr(l->GetType()) )
local_aggrs.push_back(IDNameStr(l.get())); local_aggrs.push_back(IDNameStr(l));
auto when_lambda = GenExpr(wi->Lambda(), GEN_NATIVE); auto when_lambda = GenExpr(wi->Lambda(), GEN_NATIVE);
GenWhenStmt(wi.get(), when_lambda, w->GetLocationInfo(), std::move(local_aggrs)); GenWhenStmt(wi.get(), when_lambda, w->GetLocationInfo(), std::move(local_aggrs));
} }
void CPPCompile::GenWhenStmt(const WhenInfo* wi, const std::string& when_lambda, const Location* loc, void CPPCompile::GenWhenStmt(const WhenInfo* wi, const string& when_lambda, const Location* loc,
vector<string> local_aggrs) { vector<string> local_aggrs) {
auto is_return = wi->IsReturn() ? "true" : "false"; auto is_return = wi->IsReturn() ? "true" : "false";
auto timeout = wi->TimeoutExpr(); auto timeout = wi->TimeoutExpr();
@ -333,7 +333,7 @@ void CPPCompile::GenWhenStmt(const WhenInfo* wi, const std::string& when_lambda,
StartBlock(); StartBlock();
Emit("CPP__wi = std::make_shared<WhenInfo>(%s);", is_return); Emit("CPP__wi = std::make_shared<WhenInfo>(%s);", is_return);
for ( auto& wg : wi->WhenExprGlobals() ) for ( auto& wg : wi->WhenExprGlobals() )
Emit("CPP__w_globals.insert(find_global__CPP(\"%s\").get());", wg->Name()); Emit("CPP__w_globals.insert(find_global__CPP(\"%s\"));", wg->Name());
EndBlock(); EndBlock();
NL(); NL();
@ -430,7 +430,8 @@ void CPPCompile::GenForOverTable(const ExprPtr& tbl, const IDPtr& value_var, con
Emit("%s = %s;", IDName(value_var), Emit("%s = %s;", IDName(value_var),
GenericValPtrToGT("current_tev__CPP->GetVal()", value_var->GetType(), GEN_NATIVE)); GenericValPtrToGT("current_tev__CPP->GetVal()", value_var->GetType(), GEN_NATIVE));
for ( int i = 0; i < loop_vars->length(); ++i ) { int n = static_cast<int>(loop_vars->size());
for ( int i = 0; i < n; ++i ) {
auto var = (*loop_vars)[i]; auto var = (*loop_vars)[i];
if ( var->IsBlank() ) if ( var->IsBlank() )
continue; continue;
@ -498,8 +499,8 @@ void CPPCompile::GenAssertStmt(const AssertStmt* a) {
Emit("auto msg_val = zeek::val_mgr->EmptyString();"); Emit("auto msg_val = zeek::val_mgr->EmptyString();");
auto loc = a->GetLocationInfo(); auto loc = a->GetLocationInfo();
Emit("static Location loc(\"%s\", %s, %s);", loc->FileName(), std::to_string(loc->FirstLine()), Emit("static Location loc(\"%s\", %s, %s);", loc->FileName(), to_string(loc->FirstLine()),
std::to_string(loc->LastLine())); to_string(loc->LastLine()));
Emit("report_assert(assert_result, \"%s\", msg_val, &loc);", CPPEscape(a->CondDesc().c_str()).c_str()); Emit("report_assert(assert_result, \"%s\", msg_val, &loc);", CPPEscape(a->CondDesc().c_str()).c_str());
EndBlock(); EndBlock();

View file

@ -16,7 +16,7 @@ void GenEventStmt(const EventStmt* ev);
void GenSwitchStmt(const SwitchStmt* sw); void GenSwitchStmt(const SwitchStmt* sw);
void GenTypeSwitchStmt(const Expr* e, const case_list* cases); void GenTypeSwitchStmt(const Expr* e, const case_list* cases);
void GenTypeSwitchCase(const ID* id, int case_offset, bool is_multi); void GenTypeSwitchCase(const IDPtr id, int case_offset, bool is_multi);
void GenValueSwitchStmt(const Expr* e, const case_list* cases); void GenValueSwitchStmt(const Expr* e, const case_list* cases);
void GenWhenStmt(const WhenStmt* w); void GenWhenStmt(const WhenStmt* w);

View file

@ -7,7 +7,7 @@ namespace zeek::detail {
using namespace std; using namespace std;
void CPPCompile::CreateGlobal(const ID* g) { void CPPCompile::CreateGlobal(IDPtr g) {
auto gn = string(g->Name()); auto gn = string(g->Name());
bool is_bif = pfs->BiFGlobals().contains(g); bool is_bif = pfs->BiFGlobals().contains(g);
@ -45,7 +45,7 @@ void CPPCompile::CreateGlobal(const ID* g) {
global_vars.emplace(g); global_vars.emplace(g);
} }
std::shared_ptr<CPP_InitInfo> CPPCompile::RegisterGlobal(const ID* g) { std::shared_ptr<CPP_InitInfo> CPPCompile::RegisterGlobal(IDPtr g) {
auto gg = global_gis.find(g); auto gg = global_gis.find(g);
if ( gg != global_gis.end() ) if ( gg != global_gis.end() )
@ -71,7 +71,7 @@ std::shared_ptr<CPP_InitInfo> CPPCompile::RegisterGlobal(const ID* g) {
return gi; return gi;
} }
std::shared_ptr<CPP_InitInfo> CPPCompile::GenerateGlobalInit(const ID* g) { std::shared_ptr<CPP_InitInfo> CPPCompile::GenerateGlobalInit(IDPtr g) {
auto gn = string(g->Name()); auto gn = string(g->Name());
if ( ! standalone ) if ( ! standalone )
return make_shared<GlobalLookupInitInfo>(this, g, globals[gn]); return make_shared<GlobalLookupInitInfo>(this, g, globals[gn]);
@ -94,7 +94,7 @@ std::shared_ptr<CPP_InitInfo> CPPCompile::GenerateGlobalInit(const ID* g) {
return make_shared<GlobalLookupInitInfo>(this, g, globals[gn], needs_redef); return make_shared<GlobalLookupInitInfo>(this, g, globals[gn], needs_redef);
} }
void CPPCompile::AddBiF(const ID* b, bool is_var) { void CPPCompile::AddBiF(IDPtr b, bool is_var) {
auto bn = b->Name(); auto bn = b->Name();
auto n = string(bn); auto n = string(bn);
if ( is_var ) if ( is_var )
@ -117,7 +117,7 @@ bool CPPCompile::AddGlobal(const string& g, const char* suffix) {
void CPPCompile::RegisterEvent(string ev_name) { body_events[body_name].emplace_back(std::move(ev_name)); } void CPPCompile::RegisterEvent(string ev_name) { body_events[body_name].emplace_back(std::move(ev_name)); }
const string& CPPCompile::IDNameStr(const ID* id) { const string& CPPCompile::IDNameStr(const IDPtr& id) {
if ( id->IsGlobal() ) { if ( id->IsGlobal() ) {
auto g = string(id->Name()); auto g = string(id->Name());
if ( ! globals.contains(g) ) if ( ! globals.contains(g) )
@ -130,7 +130,7 @@ const string& CPPCompile::IDNameStr(const ID* id) {
return l->second; return l->second;
} }
static string trim_name(const ID* id) { static string trim_name(const IDPtr& id) {
auto n = id->Name(); auto n = id->Name();
auto without_module = strstr(n, "::"); auto without_module = strstr(n, "::");
@ -152,9 +152,9 @@ static string trim_name(const ID* id) {
return ns; return ns;
} }
string CPPCompile::LocalName(const ID* l) const { return Canonicalize(trim_name(l)); } string CPPCompile::LocalName(const IDPtr& l) const { return Canonicalize(trim_name(l)); }
string CPPCompile::CaptureName(const ID* c) const { string CPPCompile::CaptureName(const IDPtr& c) const {
// We want to strip both the module and any inlining appendage. // We want to strip both the module and any inlining appendage.
auto tn = trim_name(c); auto tn = trim_name(c);

View file

@ -7,20 +7,20 @@
public: public:
// Tracks a global to generate the necessary initialization. // Tracks a global to generate the necessary initialization.
// Returns the associated initialization info. // Returns the associated initialization info.
std::shared_ptr<CPP_InitInfo> RegisterGlobal(const ID* g); std::shared_ptr<CPP_InitInfo> RegisterGlobal(IDPtr g);
private: private:
// Generate declarations associated with the given global, and, if it's used // Generate declarations associated with the given global, and, if it's used
// as a variable (not just as a function being called), track it as such. // as a variable (not just as a function being called), track it as such.
void CreateGlobal(const ID* g); void CreateGlobal(IDPtr g);
// Low-level function for generating an initializer for a global. Takes // Low-level function for generating an initializer for a global. Takes
// into account differences for standalone-compilation. // into account differences for standalone-compilation.
std::shared_ptr<CPP_InitInfo> GenerateGlobalInit(const ID* g); std::shared_ptr<CPP_InitInfo> GenerateGlobalInit(IDPtr g);
// Register the given identifier as a BiF. If is_var is true then the BiF // Register the given identifier as a BiF. If is_var is true then the BiF
// is also used in a non-call context. // is also used in a non-call context.
void AddBiF(const ID* b, bool is_var); void AddBiF(IDPtr b, bool is_var);
// Register the given global name. "suffix" distinguishes particular types // Register the given global name. "suffix" distinguishes particular types
// of globals, such as the names of bifs, global (non-function) variables, // of globals, such as the names of bifs, global (non-function) variables,
@ -32,9 +32,8 @@ void RegisterEvent(std::string ev_name);
// The following match various forms of identifiers to the name used for // The following match various forms of identifiers to the name used for
// their C++ equivalent. // their C++ equivalent.
const char* IDName(const IDPtr& id) { return IDName(id.get()); } const char* IDName(const IDPtr& id) { return IDNameStr(id).c_str(); }
const char* IDName(const ID* id) { return IDNameStr(id).c_str(); } const std::string& IDNameStr(const IDPtr& id);
const std::string& IDNameStr(const ID* id);
// Returns a canonicalized version of a variant of a global made distinct by // Returns a canonicalized version of a variant of a global made distinct by
// the given suffix. // the given suffix.
@ -42,12 +41,10 @@ std::string GlobalName(const std::string& g, const char* suffix) { return Canoni
// Returns a canonicalized form of a local identifier's name, expanding its // Returns a canonicalized form of a local identifier's name, expanding its
// module prefix if needed. // module prefix if needed.
std::string LocalName(const ID* l) const; std::string LocalName(const IDPtr& l) const;
std::string LocalName(const IDPtr& l) const { return LocalName(l.get()); }
// The same, but for a capture. // The same, but for a capture.
std::string CaptureName(const ID* l) const; std::string CaptureName(const IDPtr& l) const;
std::string CaptureName(const IDPtr& l) const { return CaptureName(l.get()); }
// Returns a canonicalized name, with various non-alphanumeric characters // Returns a canonicalized name, with various non-alphanumeric characters
// stripped or transformed, and guaranteed not to conflict with C++ keywords. // stripped or transformed, and guaranteed not to conflict with C++ keywords.
@ -59,10 +56,10 @@ std::string GlobalName(const ExprPtr& e) { return globals[e->AsNameExpr()->Id()-
// Globals that are used (appear in the profiles) of the bodies we're // Globals that are used (appear in the profiles) of the bodies we're
// compiling. Includes globals just used as functions to call. // compiling. Includes globals just used as functions to call.
std::unordered_set<const ID*> all_accessed_globals; std::unordered_set<IDPtr> all_accessed_globals;
// Same, but just the globals used in contexts beyond function calls. // Same, but just the globals used in contexts beyond function calls.
std::unordered_set<const ID*> accessed_globals; std::unordered_set<IDPtr> accessed_globals;
// Lambdas that are accessed. // Lambdas that are accessed.
std::unordered_set<const LambdaExpr*> accessed_lambdas; std::unordered_set<const LambdaExpr*> accessed_lambdas;
@ -74,10 +71,10 @@ std::unordered_set<std::string> accessed_events;
std::unordered_map<std::string, std::string> globals; std::unordered_map<std::string, std::string> globals;
// Similar for locals, for the function currently being compiled. // Similar for locals, for the function currently being compiled.
std::unordered_map<const ID*, std::string> locals; std::unordered_map<IDPtr, std::string> locals;
// Retrieves the initialization information associated with the given global. // Retrieves the initialization information associated with the given global.
std::unordered_map<const ID*, std::shared_ptr<CPP_InitInfo>> global_gis; std::unordered_map<IDPtr, std::shared_ptr<CPP_InitInfo>> global_gis;
// Maps event names to the names we use for them. // Maps event names to the names we use for them.
std::unordered_map<std::string, std::string> events; std::unordered_map<std::string, std::string> events;

View file

@ -6,7 +6,7 @@
namespace zeek::detail { namespace zeek::detail {
CSE_ValidityChecker::CSE_ValidityChecker(std::shared_ptr<ProfileFuncs> _pfs, const std::vector<const ID*>& _ids, CSE_ValidityChecker::CSE_ValidityChecker(std::shared_ptr<ProfileFuncs> _pfs, const std::vector<IDPtr>& _ids,
const Expr* _start_e, const Expr* _end_e) const Expr* _start_e, const Expr* _end_e)
: pfs(std::move(_pfs)), ids(_ids) { : pfs(std::move(_pfs)), ids(_ids) {
start_e = _start_e; start_e = _start_e;
@ -111,7 +111,7 @@ TraversalCode CSE_ValidityChecker::PreExpr(const Expr* e) {
auto lhs_ref = e->GetOp1()->AsRefExprPtr(); auto lhs_ref = e->GetOp1()->AsRefExprPtr();
auto lhs = lhs_ref->GetOp1()->AsNameExpr(); auto lhs = lhs_ref->GetOp1()->AsNameExpr();
if ( CheckID(lhs->Id(), false) ) if ( CheckID(lhs->IdPtr(), false) )
return TC_ABORTALL; return TC_ABORTALL;
// Note, we don't use CheckAggrMod() because this is a plain // Note, we don't use CheckAggrMod() because this is a plain
@ -127,7 +127,7 @@ TraversalCode CSE_ValidityChecker::PreExpr(const Expr* e) {
case EXPR_INDEX_ASSIGN: { case EXPR_INDEX_ASSIGN: {
auto lhs_aggr = e->GetOp1(); auto lhs_aggr = e->GetOp1();
auto lhs_aggr_id = lhs_aggr->AsNameExpr()->Id(); const auto& lhs_aggr_id = lhs_aggr->AsNameExpr()->IdPtr();
if ( CheckID(lhs_aggr_id, true) || CheckTableMod(lhs_aggr->GetType()) ) if ( CheckID(lhs_aggr_id, true) || CheckTableMod(lhs_aggr->GetType()) )
return TC_ABORTALL; return TC_ABORTALL;
@ -135,7 +135,7 @@ TraversalCode CSE_ValidityChecker::PreExpr(const Expr* e) {
case EXPR_FIELD_LHS_ASSIGN: { case EXPR_FIELD_LHS_ASSIGN: {
auto lhs = e->GetOp1(); auto lhs = e->GetOp1();
auto lhs_aggr_id = lhs->AsNameExpr()->Id(); const auto& lhs_aggr_id = lhs->AsNameExpr()->IdPtr();
auto lhs_field = static_cast<const FieldLHSAssignExpr*>(e)->Field(); auto lhs_field = static_cast<const FieldLHSAssignExpr*>(e)->Field();
if ( CheckID(lhs_aggr_id, true) ) if ( CheckID(lhs_aggr_id, true) )
@ -186,7 +186,7 @@ TraversalCode CSE_ValidityChecker::PreExpr(const Expr* e) {
auto aggr_t = aggr->GetType(); auto aggr_t = aggr->GetType();
if ( in_aggr_mod_expr > 0 ) { if ( in_aggr_mod_expr > 0 ) {
auto aggr_id = aggr->AsNameExpr()->Id(); const auto& aggr_id = aggr->AsNameExpr()->IdPtr();
if ( CheckID(aggr_id, true) || CheckAggrMod(aggr_t) ) if ( CheckID(aggr_id, true) || CheckAggrMod(aggr_t) )
return TC_ABORTALL; return TC_ABORTALL;
@ -211,7 +211,7 @@ TraversalCode CSE_ValidityChecker::PostExpr(const Expr* e) {
return TC_CONTINUE; return TC_CONTINUE;
} }
bool CSE_ValidityChecker::CheckID(const ID* id, bool ignore_orig) { bool CSE_ValidityChecker::CheckID(const IDPtr& id, bool ignore_orig) {
for ( auto i : ids ) { for ( auto i : ids ) {
if ( ignore_orig && i == ids.front() ) if ( ignore_orig && i == ids.front() )
continue; continue;

View file

@ -17,7 +17,7 @@ class TempVar;
class CSE_ValidityChecker : public TraversalCallback { class CSE_ValidityChecker : public TraversalCallback {
public: public:
CSE_ValidityChecker(std::shared_ptr<ProfileFuncs> pfs, const std::vector<const ID*>& ids, const Expr* start_e, CSE_ValidityChecker(std::shared_ptr<ProfileFuncs> pfs, const std::vector<IDPtr>& ids, const Expr* start_e,
const Expr* end_e); const Expr* end_e);
TraversalCode PreStmt(const Stmt*) override; TraversalCode PreStmt(const Stmt*) override;
@ -45,7 +45,7 @@ public:
protected: protected:
// Returns true if an assignment involving the given identifier on // Returns true if an assignment involving the given identifier on
// the LHS is in conflict with the identifiers we're tracking. // the LHS is in conflict with the identifiers we're tracking.
bool CheckID(const ID* id, bool ignore_orig); bool CheckID(const IDPtr& id, bool ignore_orig);
// Returns true if a modification to an aggregate of the given type // Returns true if a modification to an aggregate of the given type
// potentially aliases with one of the identifiers we're tracking. // potentially aliases with one of the identifiers we're tracking.
@ -83,7 +83,7 @@ protected:
// The list of identifiers for which an assignment to one of them // The list of identifiers for which an assignment to one of them
// renders the CSE unsafe. // renders the CSE unsafe.
const std::vector<const ID*>& ids; const std::vector<IDPtr>& ids;
// Where in the AST to start our analysis. This is the initial // Where in the AST to start our analysis. This is the initial
// assignment expression. // assignment expression.

View file

@ -2396,7 +2396,7 @@ bool LambdaExpr::IsReduced(Reducer* c) const {
for ( auto& cp : *captures ) { for ( auto& cp : *captures ) {
auto& cid = cp.Id(); auto& cid = cp.Id();
if ( ! private_captures.contains(cid.get()) && ! c->ID_IsReduced(cid) ) if ( ! private_captures.contains(cid) && ! c->ID_IsReduced(cid) )
return NonReduced(this); return NonReduced(this);
} }
@ -2424,7 +2424,7 @@ void LambdaExpr::UpdateCaptures(Reducer* c) {
for ( auto& cp : *captures ) { for ( auto& cp : *captures ) {
auto& cid = cp.Id(); auto& cid = cp.Id();
if ( ! private_captures.contains(cid.get()) ) if ( ! private_captures.contains(cid) )
cp.SetID(c->UpdateID(cid)); cp.SetID(c->UpdateID(cid));
} }

View file

@ -414,7 +414,6 @@ static std::unordered_map<std::string, unsigned int> func_attrs = {
{"reading_live_traffic", ATTR_IDEMPOTENT}, {"reading_live_traffic", ATTR_IDEMPOTENT},
{"reading_traces", ATTR_IDEMPOTENT}, {"reading_traces", ATTR_IDEMPOTENT},
{"record_fields", ATTR_FOLDABLE}, {"record_fields", ATTR_FOLDABLE},
{"record_type_to_vector", ATTR_FOLDABLE},
{"remask_addr", ATTR_FOLDABLE}, {"remask_addr", ATTR_FOLDABLE},
{"remove_prefix", ATTR_FOLDABLE}, {"remove_prefix", ATTR_FOLDABLE},
{"remove_suffix", ATTR_FOLDABLE}, {"remove_suffix", ATTR_FOLDABLE},

View file

@ -112,7 +112,7 @@ TraversalCode GenIDDefs::PreStmt(const Stmt* s) {
auto retvar = cr->RetVar(); auto retvar = cr->RetVar();
if ( retvar ) if ( retvar )
TrackID(retvar->Id()); TrackID(retvar->IdPtr());
return TC_ABORTSTMT; return TC_ABORTSTMT;
} }
@ -278,7 +278,7 @@ TraversalCode GenIDDefs::PreExpr(const Expr* e) {
e->GetOptInfo()->stmt_num = stmt_num; e->GetOptInfo()->stmt_num = stmt_num;
switch ( e->Tag() ) { switch ( e->Tag() ) {
case EXPR_NAME: CheckVarUsage(e, e->AsNameExpr()->Id()); break; case EXPR_NAME: CheckVarUsage(e, e->AsNameExpr()->IdPtr()); break;
case EXPR_ASSIGN: { case EXPR_ASSIGN: {
auto lhs = e->GetOp1(); auto lhs = e->GetOp1();
@ -358,7 +358,7 @@ bool GenIDDefs::CheckLHS(const ExprPtr& lhs, const ExprPtr& rhs) {
case EXPR_NAME: { case EXPR_NAME: {
auto n = lhs->AsNameExpr(); auto n = lhs->AsNameExpr();
TrackID(n->Id(), rhs); TrackID(n->IdPtr(), rhs);
return true; return true;
} }
@ -371,7 +371,7 @@ bool GenIDDefs::CheckLHS(const ExprPtr& lhs, const ExprPtr& rhs) {
return false; return false;
auto n = expr->AsNameExpr(); auto n = expr->AsNameExpr();
TrackID(n->Id()); TrackID(n->IdPtr());
} }
return true; return true;
@ -400,7 +400,7 @@ bool GenIDDefs::IsAggr(const Expr* e) const {
return zeek::IsAggr(tag); return zeek::IsAggr(tag);
} }
void GenIDDefs::CheckVarUsage(const Expr* e, const ID* id) { void GenIDDefs::CheckVarUsage(const Expr* e, const IDPtr& id) {
if ( analysis_options.usage_issues != 1 || id->IsGlobal() || suppress_usage > 0 ) if ( analysis_options.usage_issues != 1 || id->IsGlobal() || suppress_usage > 0 )
return; return;
@ -483,7 +483,7 @@ void GenIDDefs::ReturnAt(const Stmt* s) {
id->GetOptInfo()->ReturnAt(s); id->GetOptInfo()->ReturnAt(s);
} }
void GenIDDefs::TrackID(const ID* id, const ExprPtr& e) { void GenIDDefs::TrackID(const IDPtr& id, const ExprPtr& e) {
auto oi = id->GetOptInfo(); auto oi = id->GetOptInfo();
// The 4th argument here is hardwired to 0, meaning "assess across all // The 4th argument here is hardwired to 0, meaning "assess across all

View file

@ -39,7 +39,7 @@ private:
// If -u is active, checks for whether the given identifier present // If -u is active, checks for whether the given identifier present
// in the given expression is undefined at that point. // in the given expression is undefined at that point.
void CheckVarUsage(const Expr* e, const ID* id); void CheckVarUsage(const Expr* e, const IDPtr& id);
// Begin a new confluence block with the given statement. // Begin a new confluence block with the given statement.
void StartConfluenceBlock(const Stmt* s); void StartConfluenceBlock(const Stmt* s);
@ -70,8 +70,7 @@ private:
// statement in the current confluence block. 'e' is the // statement in the current confluence block. 'e' is the
// expression used to define the identifier, for simple direct // expression used to define the identifier, for simple direct
// assignments. // assignments.
void TrackID(const IDPtr& id, const ExprPtr& e = nullptr) { TrackID(id.get(), e); } void TrackID(const IDPtr& id, const ExprPtr& e = nullptr);
void TrackID(const ID* id, const ExprPtr& e = nullptr);
// Profile for the function. Currently, all we actually need from // Profile for the function. Currently, all we actually need from
// this is the list of globals and locals. // this is the list of globals and locals.

View file

@ -420,7 +420,7 @@ ExprPtr Inliner::DoInline(ScriptFuncPtr sf, StmtPtr body, ListExprPtr args, Scop
for ( int i = 0; i < nparam; ++i ) { for ( int i = 0; i < nparam; ++i ) {
auto& vi = vars[i]; auto& vi = vars[i];
params.emplace_back(vi); params.emplace_back(vi);
param_is_modified.emplace_back((pf->Assignees().contains(vi.get()))); param_is_modified.emplace_back((pf->Assignees().contains(vi)));
} }
// Recursively inline the body. This is safe to do because we've // Recursively inline the body. This is safe to do because we've

View file

@ -35,7 +35,7 @@ ProfileFunc::ProfileFunc(const Func* func, const StmtPtr& body, bool _abs_rec_fi
int offset = 0; int offset = 0;
for ( auto& c : *fcaps ) { for ( auto& c : *fcaps ) {
auto cid = c.Id().get(); auto cid = c.Id();
captures.insert(cid); captures.insert(cid);
captures_offsets[cid] = offset++; captures_offsets[cid] = offset++;
} }
@ -88,7 +88,7 @@ ProfileFunc::ProfileFunc(const Expr* e, bool _abs_rec_fields) {
auto& ov = profiled_scope->OrderedVars(); auto& ov = profiled_scope->OrderedVars();
for ( int i = 0; i < num_params; ++i ) for ( int i = 0; i < num_params; ++i )
params.insert(ov[i].get()); params.insert(ov[i]);
TrackType(ft); TrackType(ft);
body->Traverse(this); body->Traverse(this);
@ -106,7 +106,7 @@ TraversalCode ProfileFunc::PreStmt(const Stmt* s) {
switch ( s->Tag() ) { switch ( s->Tag() ) {
case STMT_INIT: case STMT_INIT:
for ( const auto& id : s->AsInitStmt()->Inits() ) { for ( const auto& id : s->AsInitStmt()->Inits() ) {
inits.insert(id.get()); inits.insert(id);
auto& t = id->GetType(); auto& t = id->GetType();
TrackType(t); TrackType(t);
@ -143,7 +143,7 @@ TraversalCode ProfileFunc::PreStmt(const Stmt* s) {
locals.insert(id); locals.insert(id);
if ( value_var ) if ( value_var )
locals.insert(value_var.get()); locals.insert(value_var);
} break; } break;
case STMT_SWITCH: { case STMT_SWITCH: {
@ -194,7 +194,7 @@ TraversalCode ProfileFunc::PreExpr(const Expr* e) {
case EXPR_NAME: { case EXPR_NAME: {
auto n = e->AsNameExpr(); auto n = e->AsNameExpr();
auto id = n->Id(); auto id = n->IdPtr();
// Turns out that NameExpr's can be constructed using a // Turns out that NameExpr's can be constructed using a
// different Type* than that of the identifier itself, // different Type* than that of the identifier itself,
@ -202,7 +202,7 @@ TraversalCode ProfileFunc::PreExpr(const Expr* e) {
TrackType(id->GetType()); TrackType(id->GetType());
if ( id->IsGlobal() ) { if ( id->IsGlobal() ) {
PreID(id); PreID(id.get());
break; break;
} }
@ -256,7 +256,7 @@ TraversalCode ProfileFunc::PreExpr(const Expr* e) {
auto& rhs_id = rhs->AsNameExpr()->IdPtr(); auto& rhs_id = rhs->AsNameExpr()->IdPtr();
const auto& t = rhs_id->GetType(); const auto& t = rhs_id->GetType();
if ( t->Tag() == TYPE_FUNC && t->AsFuncType()->Flavor() == FUNC_FLAVOR_FUNCTION ) if ( t->Tag() == TYPE_FUNC && t->AsFuncType()->Flavor() == FUNC_FLAVOR_FUNCTION )
indirect_funcs.insert(rhs_id.get()); indirect_funcs.insert(rhs_id);
} }
} }
@ -272,7 +272,7 @@ TraversalCode ProfileFunc::PreExpr(const Expr* e) {
switch ( lhs->Tag() ) { switch ( lhs->Tag() ) {
case EXPR_NAME: { case EXPR_NAME: {
auto id = lhs->AsNameExpr()->Id(); auto id = lhs->AsNameExpr()->IdPtr();
TrackAssignment(id); TrackAssignment(id);
if ( is_assign ) { if ( is_assign ) {
@ -346,11 +346,11 @@ TraversalCode ProfileFunc::PreExpr(const Expr* e) {
auto f = c->Func(); auto f = c->Func();
const NameExpr* n = nullptr; const NameExpr* n = nullptr;
const ID* func = nullptr; IDPtr func;
if ( f->Tag() == EXPR_NAME ) { if ( f->Tag() == EXPR_NAME ) {
n = f->AsNameExpr(); n = f->AsNameExpr();
func = n->Id(); func = n->IdPtr();
if ( ! func->IsGlobal() ) if ( ! func->IsGlobal() )
does_indirect_calls = true; does_indirect_calls = true;
@ -367,7 +367,7 @@ TraversalCode ProfileFunc::PreExpr(const Expr* e) {
auto& arg_id = arg->AsNameExpr()->IdPtr(); auto& arg_id = arg->AsNameExpr()->IdPtr();
const auto& t = arg_id->GetType(); const auto& t = arg_id->GetType();
if ( t->Tag() == TYPE_FUNC && t->AsFuncType()->Flavor() == FUNC_FLAVOR_FUNCTION ) if ( t->Tag() == TYPE_FUNC && t->AsFuncType()->Flavor() == FUNC_FLAVOR_FUNCTION )
indirect_funcs.insert(arg_id.get()); indirect_funcs.insert(arg_id);
} }
} }
@ -482,8 +482,8 @@ TraversalCode ProfileFunc::PreExpr(const Expr* e) {
return TC_CONTINUE; return TC_CONTINUE;
} }
TraversalCode ProfileFunc::PreID(const ID* id) { TraversalCode ProfileFunc::PreID(const ID* id_raw) {
TrackID(id); IDPtr id{NewRef{}, const_cast<ID*>(id_raw)};
if ( id->IsGlobal() ) { if ( id->IsGlobal() ) {
globals.insert(id); globals.insert(id);
@ -521,7 +521,7 @@ void ProfileFunc::TrackType(const Type* t) {
ordered_types.push_back(t); ordered_types.push_back(t);
} }
void ProfileFunc::TrackID(const ID* id) { void ProfileFunc::TrackID(const IDPtr id) {
if ( ! id ) if ( ! id )
return; return;
@ -540,8 +540,8 @@ void ProfileFunc::TrackID(const ID* id) {
ordered_ids.push_back(id); ordered_ids.push_back(id);
} }
void ProfileFunc::TrackAssignment(const ID* id) { void ProfileFunc::TrackAssignment(const IDPtr id) {
if ( assignees.contains(id) ) if ( assignees.count(id) > 0 )
++assignees[id]; ++assignees[id];
else else
assignees[id] = 1; assignees[id] = 1;

View file

@ -98,7 +98,7 @@ public:
const auto& CapturesOffsets() const { return captures_offsets; } const auto& CapturesOffsets() const { return captures_offsets; }
const IDSet& WhenLocals() const { return when_locals; } const IDSet& WhenLocals() const { return when_locals; }
const IDSet& Params() const { return params; } const IDSet& Params() const { return params; }
const std::unordered_map<const ID*, int>& Assignees() const { return assignees; } const std::unordered_map<IDPtr, int>& Assignees() const { return assignees; }
const IDSet& NonLocalAssignees() const { return non_local_assignees; } const IDSet& NonLocalAssignees() const { return non_local_assignees; }
const auto& TableRefs() const { return tbl_refs; } const auto& TableRefs() const { return tbl_refs; }
const auto& AggrMods() const { return aggr_mods; } const auto& AggrMods() const { return aggr_mods; }
@ -108,7 +108,7 @@ public:
const std::vector<const LambdaExpr*>& Lambdas() const { return lambdas; } const std::vector<const LambdaExpr*>& Lambdas() const { return lambdas; }
const std::vector<const ConstExpr*>& Constants() const { return constants; } const std::vector<const ConstExpr*>& Constants() const { return constants; }
const IDSet& UnorderedIdentifiers() const { return ids; } const IDSet& UnorderedIdentifiers() const { return ids; }
const std::vector<const ID*>& OrderedIdentifiers() const { return ordered_ids; } const std::vector<IDPtr>& OrderedIdentifiers() const { return ordered_ids; }
const TypeSet& UnorderedTypes() const { return types; } const TypeSet& UnorderedTypes() const { return types; }
const std::vector<const Type*>& OrderedTypes() const { return ordered_types; } const std::vector<const Type*>& OrderedTypes() const { return ordered_types; }
const auto& TypeAliases() const { return type_aliases; } const auto& TypeAliases() const { return type_aliases; }
@ -153,10 +153,10 @@ protected:
void TrackType(const TypePtr& t) { TrackType(t.get()); } void TrackType(const TypePtr& t) { TrackType(t.get()); }
// Take note of the presence of an identifier. // Take note of the presence of an identifier.
void TrackID(const ID* id); void TrackID(IDPtr id);
// Take note of an assignment to an identifier. // Take note of an assignment to an identifier.
void TrackAssignment(const ID* id); void TrackAssignment(IDPtr id);
// Extracts attributes of a record type used in a constructor (or implicit // Extracts attributes of a record type used in a constructor (or implicit
// initialization, or coercion, which does an implicit construction). // initialization, or coercion, which does an implicit construction).
@ -198,7 +198,7 @@ protected:
// they are assigned to (no entry if never). Does not include // they are assigned to (no entry if never). Does not include
// implicit assignments due to initializations, which are instead // implicit assignments due to initializations, which are instead
// captured in "inits". // captured in "inits".
std::unordered_map<const ID*, int> assignees; std::unordered_map<IDPtr, int> assignees;
// A subset of assignees reflecting those that are globals or captures. // A subset of assignees reflecting those that are globals or captures.
IDSet non_local_assignees; IDSet non_local_assignees;
@ -230,7 +230,7 @@ protected:
IDSet captures; IDSet captures;
// This maps capture identifiers to their offsets. // This maps capture identifiers to their offsets.
std::map<const ID*, int> captures_offsets; std::unordered_map<IDPtr, int> captures_offsets;
// Constants seen in the function. // Constants seen in the function.
std::vector<const ConstExpr*> constants; std::vector<const ConstExpr*> constants;
@ -239,7 +239,7 @@ protected:
IDSet ids; IDSet ids;
// The same, but in a deterministic order. // The same, but in a deterministic order.
std::vector<const ID*> ordered_ids; std::vector<IDPtr> ordered_ids;
// Types seen in the function. A set rather than a vector because // Types seen in the function. A set rather than a vector because
// the same type can be seen numerous times. // the same type can be seen numerous times.

View file

@ -239,12 +239,12 @@ Reducer::Reducer(const ScriptFuncPtr& func, std::shared_ptr<ProfileFunc> _pf, st
auto& scope_vars = current_scope()->OrderedVars(); auto& scope_vars = current_scope()->OrderedVars();
for ( auto i = 0; i < num_params; ++i ) for ( auto i = 0; i < num_params; ++i )
tracked_ids.insert(scope_vars[i].get()); tracked_ids.insert(scope_vars[i]);
// Now include any captures. // Now include any captures.
if ( ft->GetCaptures() ) if ( ft->GetCaptures() )
for ( auto& c : *ft->GetCaptures() ) for ( auto& c : *ft->GetCaptures() )
tracked_ids.insert(c.Id().get()); tracked_ids.insert(c.Id());
} }
StmtPtr Reducer::Reduce(StmtPtr s) { StmtPtr Reducer::Reduce(StmtPtr s) {
@ -275,17 +275,12 @@ NameExprPtr Reducer::UpdateName(NameExprPtr n) {
return ne; return ne;
} }
bool Reducer::NameIsReduced(const NameExpr* n) { return ID_IsReducedOrTopLevel(n->Id()); } bool Reducer::NameIsReduced(const NameExpr* n) { return ID_IsReducedOrTopLevel(n->IdPtr()); }
void Reducer::UpdateIDs(IDPList* ids) { void Reducer::UpdateIDs(IDPList* ids) {
loop_over_list(*ids, i) { for ( auto& id : *ids )
IDPtr id = {NewRef{}, (*ids)[i]}; if ( ! ID_IsReducedOrTopLevel(id) )
id = UpdateID(id);
if ( ! ID_IsReducedOrTopLevel(id) ) {
Unref((*ids)[i]);
(*ids)[i] = UpdateID(id).release();
}
}
} }
void Reducer::UpdateIDs(std::vector<IDPtr>& ids) { void Reducer::UpdateIDs(std::vector<IDPtr>& ids) {
@ -317,7 +312,7 @@ IDPtr Reducer::UpdateID(IDPtr id) {
return FindNewLocal(id); return FindNewLocal(id);
} }
bool Reducer::ID_IsReducedOrTopLevel(const ID* id) { bool Reducer::ID_IsReducedOrTopLevel(const IDPtr& id) {
if ( inline_block_level == 0 ) { if ( inline_block_level == 0 ) {
tracked_ids.insert(id); tracked_ids.insert(id);
return true; return true;
@ -326,8 +321,8 @@ bool Reducer::ID_IsReducedOrTopLevel(const ID* id) {
return ID_IsReduced(id); return ID_IsReduced(id);
} }
bool Reducer::ID_IsReduced(const ID* id) const { bool Reducer::ID_IsReduced(const IDPtr& id) const {
return inline_block_level == 0 || tracked_ids.contains(id) || id->IsGlobal() || IsTemporary(id); return inline_block_level == 0 || tracked_ids.count(id) > 0 || id->IsGlobal() || IsTemporary(id);
} }
StmtPtr Reducer::GenParam(const IDPtr& id, ExprPtr rhs, bool is_modified) { StmtPtr Reducer::GenParam(const IDPtr& id, ExprPtr rhs, bool is_modified) {
@ -335,7 +330,7 @@ StmtPtr Reducer::GenParam(const IDPtr& id, ExprPtr rhs, bool is_modified) {
param->SetLocationInfo(rhs->GetLocationInfo()); param->SetLocationInfo(rhs->GetLocationInfo());
auto rhs_id = rhs->Tag() == EXPR_NAME ? rhs->AsNameExpr()->IdPtr() : nullptr; auto rhs_id = rhs->Tag() == EXPR_NAME ? rhs->AsNameExpr()->IdPtr() : nullptr;
if ( rhs_id && ! pf->Locals().contains(rhs_id.get()) && ! rhs_id->IsConst() ) if ( rhs_id && ! pf->Locals().contains(rhs_id) && ! rhs_id->IsConst() )
// It's hard to guarantee the RHS won't change during // It's hard to guarantee the RHS won't change during
// the inline block's execution. // the inline block's execution.
is_modified = true; is_modified = true;
@ -352,14 +347,14 @@ StmtPtr Reducer::GenParam(const IDPtr& id, ExprPtr rhs, bool is_modified) {
// Can use a temporary variable, which then supports // Can use a temporary variable, which then supports
// optimization via alias propagation. // optimization via alias propagation.
auto param_id = GenTemporary(id->GetType(), rhs, param->IdPtr()); auto param_id = GenTemporary(id->GetType(), rhs, param->IdPtr());
auto& tv = ids_to_temps[param_id.get()]; auto& tv = ids_to_temps[param_id];
if ( rhs_id ) if ( rhs_id )
tv->SetAlias(rhs_id); tv->SetAlias(rhs_id);
else if ( rhs->Tag() == EXPR_CONST ) else if ( rhs->Tag() == EXPR_CONST )
tv->SetConst(rhs->AsConstExpr()); tv->SetConst(rhs->AsConstExpr());
param_temps.insert(param_id.get()); param_temps.insert(param_id);
param = make_intrusive<NameExpr>(param_id); param = make_intrusive<NameExpr>(param_id);
param->SetLocationInfo(rhs->GetLocationInfo()); param->SetLocationInfo(rhs->GetLocationInfo());
} }
@ -402,7 +397,7 @@ NameExprPtr Reducer::GetRetVar(TypePtr type) {
ret_id->SetType(std::move(type)); ret_id->SetType(std::move(type));
ret_id->GetOptInfo()->SetTemp(); ret_id->GetOptInfo()->SetTemp();
ret_vars.insert(ret_id.get()); ret_vars.insert(ret_id);
// Track this as a new local *if* we're in the outermost inlining // Track this as a new local *if* we're in the outermost inlining
// block. If we're recursively deeper into inlining, then this // block. If we're recursively deeper into inlining, then this
@ -442,7 +437,7 @@ IDPtr Reducer::FindExprTmp(const Expr* rhs, const Expr* a, const std::shared_ptr
if ( same_expr(rhs, et_i_expr, true) ) { if ( same_expr(rhs, et_i_expr, true) ) {
// We have an apt candidate. Make sure its value // We have an apt candidate. Make sure its value
// always makes it here. // always makes it here.
auto id = et_i->Id().get(); const auto& id = et_i->Id();
auto stmt_num = a->GetOptInfo()->stmt_num; auto stmt_num = a->GetOptInfo()->stmt_num;
auto def = id->GetOptInfo()->DefinitionBefore(stmt_num); auto def = id->GetOptInfo()->DefinitionBefore(stmt_num);
@ -464,7 +459,7 @@ IDPtr Reducer::FindExprTmp(const Expr* rhs, const Expr* a, const std::shared_ptr
return nullptr; return nullptr;
} }
bool Reducer::ExprValid(const ID* id, const Expr* e1, const Expr* e2) const { bool Reducer::ExprValid(const IDPtr& id, const Expr* e1, const Expr* e2) const {
// First check for whether e1 is already known to itself have side effects. // First check for whether e1 is already known to itself have side effects.
// If so, then it's never safe to reuse its associated identifier in lieu // If so, then it's never safe to reuse its associated identifier in lieu
// of e2. // of e2.
@ -522,17 +517,17 @@ bool Reducer::ExprValid(const ID* id, const Expr* e1, const Expr* e2) const {
// of script functions. // of script functions.
// Tracks which ID's are germane for our analysis. // Tracks which ID's are germane for our analysis.
std::vector<const ID*> ids; std::vector<IDPtr> ids;
ids.push_back(id); ids.push_back(std::move(id));
// Identify variables involved in the expression. // Identify variables involved in the expression.
CheckIDs(e1->GetOp1().get(), ids); CheckIDs(e1->GetOp1(), ids);
CheckIDs(e1->GetOp2().get(), ids); CheckIDs(e1->GetOp2(), ids);
CheckIDs(e1->GetOp3().get(), ids); CheckIDs(e1->GetOp3(), ids);
if ( e1->Tag() == EXPR_NAME ) if ( e1->Tag() == EXPR_NAME )
ids.push_back(e1->AsNameExpr()->Id()); ids.push_back(e1->AsNameExpr()->IdPtr());
CSE_ValidityChecker vc(pfs, ids, e1, e2); CSE_ValidityChecker vc(pfs, ids, e1, e2);
reduction_root->Traverse(&vc); reduction_root->Traverse(&vc);
@ -540,22 +535,22 @@ bool Reducer::ExprValid(const ID* id, const Expr* e1, const Expr* e2) const {
return vc.IsValid(); return vc.IsValid();
} }
void Reducer::CheckIDs(const Expr* e, std::vector<const ID*>& ids) const { void Reducer::CheckIDs(const ExprPtr& e, std::vector<IDPtr>& ids) const {
if ( ! e ) if ( ! e )
return; return;
if ( e->Tag() == EXPR_LIST ) { if ( e->Tag() == EXPR_LIST ) {
const auto& e_l = e->AsListExpr()->Exprs(); const auto& e_l = e->AsListExpr()->Exprs();
for ( auto i = 0; i < e_l.length(); ++i ) for ( auto i = 0; i < e_l.length(); ++i )
CheckIDs(e_l[i], ids); CheckIDs({NewRef{}, e_l[i]}, ids);
} }
else if ( e->Tag() == EXPR_NAME ) else if ( e->Tag() == EXPR_NAME )
ids.push_back(e->AsNameExpr()->Id()); ids.push_back(e->AsNameExpr()->IdPtr());
} }
bool Reducer::IsCSE(const AssignExpr* a, const NameExpr* lhs, const Expr* rhs) { bool Reducer::IsCSE(const AssignExpr* a, const NameExpr* lhs, const Expr* rhs) {
auto lhs_id = lhs->Id(); auto lhs_id = lhs->IdPtr();
auto lhs_tmp = FindTemporary(lhs_id); // nil if LHS not a temporary auto lhs_tmp = FindTemporary(lhs_id); // nil if LHS not a temporary
auto rhs_tmp = FindExprTmp(rhs, a, lhs_tmp); auto rhs_tmp = FindExprTmp(rhs, a, lhs_tmp);
@ -572,8 +567,8 @@ bool Reducer::IsCSE(const AssignExpr* a, const NameExpr* lhs, const Expr* rhs) {
} }
if ( rhs->Tag() == EXPR_NAME ) { if ( rhs->Tag() == EXPR_NAME ) {
auto rhs_id = rhs->AsNameExpr()->IdPtr(); const auto& rhs_id = rhs->AsNameExpr()->IdPtr();
auto rhs_tmp_var = FindTemporary(rhs_id.get()); auto rhs_tmp_var = FindTemporary(rhs_id);
if ( rhs_tmp_var ) { if ( rhs_tmp_var ) {
if ( rhs_tmp_var->Const() ) if ( rhs_tmp_var->Const() )
@ -659,16 +654,15 @@ ExprPtr Reducer::UpdateExpr(ExprPtr e) {
return OptExpr(e); return OptExpr(e);
auto n = e->AsNameExpr(); auto n = e->AsNameExpr();
auto id = n->Id(); const auto& id = n->IdPtr();
if ( id->IsGlobal() ) if ( id->IsGlobal() )
return e; return e;
auto tmp_var = FindTemporary(id); auto tmp_var = FindTemporary(id);
if ( ! tmp_var ) { if ( ! tmp_var ) {
IDPtr id_ptr = {NewRef{}, id};
auto stmt_num = e->GetOptInfo()->stmt_num; auto stmt_num = e->GetOptInfo()->stmt_num;
auto is_const = CheckForConst(id_ptr, stmt_num); auto is_const = CheckForConst(id, stmt_num);
if ( is_const ) { if ( is_const ) {
// Remember this variable as one whose value // Remember this variable as one whose value
@ -690,12 +684,12 @@ ExprPtr Reducer::UpdateExpr(ExprPtr e) {
if ( alias ) { if ( alias ) {
// Make sure that the definitions for the alias here are // Make sure that the definitions for the alias here are
// the same as when the alias was created. // the same as when the alias was created.
auto alias_tmp = FindTemporary(alias.get()); auto alias_tmp = FindTemporary(alias);
// Resolve any alias chains. // Resolve any alias chains.
while ( alias_tmp && alias_tmp->Alias() ) { while ( alias_tmp && alias_tmp->Alias() ) {
alias = alias_tmp->Alias(); alias = alias_tmp->Alias();
alias_tmp = FindTemporary(alias.get()); alias_tmp = FindTemporary(alias);
} }
return NewVarUsage(alias, e.get()); return NewVarUsage(alias, e.get());
@ -711,7 +705,7 @@ ExprPtr Reducer::UpdateExpr(ExprPtr e) {
StmtPtr Reducer::MergeStmts(const NameExpr* lhs, ExprPtr rhs, const StmtPtr& succ_stmt) { StmtPtr Reducer::MergeStmts(const NameExpr* lhs, ExprPtr rhs, const StmtPtr& succ_stmt) {
// First check for tmp=rhs. // First check for tmp=rhs.
auto lhs_id = lhs->Id(); auto lhs_id = lhs->IdPtr();
auto lhs_tmp = FindTemporary(lhs_id); auto lhs_tmp = FindTemporary(lhs_id);
if ( ! lhs_tmp ) if ( ! lhs_tmp )
@ -738,8 +732,8 @@ StmtPtr Reducer::MergeStmts(const NameExpr* lhs, ExprPtr rhs, const StmtPtr& suc
// Complex 2nd-statement assignment. // Complex 2nd-statement assignment.
return nullptr; return nullptr;
auto a_lhs_var = a_lhs_deref->AsNameExpr()->Id(); const auto& a_lhs_var = a_lhs_deref->AsNameExpr()->IdPtr();
auto a_rhs_var = a_rhs->AsNameExpr()->Id(); const auto& a_rhs_var = a_rhs->AsNameExpr()->IdPtr();
if ( a_rhs_var != lhs_id ) if ( a_rhs_var != lhs_id )
// 2nd statement is var=something else. // 2nd statement is var=something else.
@ -794,13 +788,13 @@ IDPtr Reducer::GenTemporary(TypePtr t, ExprPtr rhs, IDPtr id) {
temps.push_back(temp); temps.push_back(temp);
om.AddObj(temp_id.get()); om.AddObj(temp_id.get());
ids_to_temps[temp_id.get()] = temp; ids_to_temps[temp_id] = temp;
return temp_id; return temp_id;
} }
IDPtr Reducer::FindNewLocal(const IDPtr& id) { IDPtr Reducer::FindNewLocal(const IDPtr& id) {
auto mapping = orig_to_new_locals.find(id.get()); auto mapping = orig_to_new_locals.find(id);
if ( mapping != orig_to_new_locals.end() ) if ( mapping != orig_to_new_locals.end() )
return mapping->second; return mapping->second;
@ -809,8 +803,8 @@ IDPtr Reducer::FindNewLocal(const IDPtr& id) {
} }
void Reducer::AddNewLocal(const IDPtr& l) { void Reducer::AddNewLocal(const IDPtr& l) {
new_locals.insert(l.get()); new_locals.insert(l);
tracked_ids.insert(l.get()); tracked_ids.insert(l);
} }
IDPtr Reducer::GenLocal(const IDPtr& orig) { IDPtr Reducer::GenLocal(const IDPtr& orig) {
@ -838,25 +832,22 @@ IDPtr Reducer::GenLocal(const IDPtr& orig) {
local_id->GetOptInfo()->SetTemp(); local_id->GetOptInfo()->SetTemp();
IDPtr prev; IDPtr prev;
if ( orig_to_new_locals.contains(orig.get()) ) if ( orig_to_new_locals.contains(orig) )
prev = orig_to_new_locals[orig.get()]; prev = orig_to_new_locals[orig];
AddNewLocal(local_id); AddNewLocal(local_id);
om.AddObj(orig.get()); om.AddObj(orig.get());
orig_to_new_locals[orig.get()] = local_id; orig_to_new_locals[orig] = local_id;
if ( ! block_locals.empty() && ! ret_vars.contains(orig.get()) ) if ( ! block_locals.empty() && ! ret_vars.contains(orig) )
block_locals.back()[orig.get()] = prev; block_locals.back()[orig] = prev;
return local_id; return local_id;
} }
bool Reducer::IsNewLocal(const ID* id) const { bool Reducer::IsNewLocal(const IDPtr& id) const { return new_locals.contains(id); }
ID* non_const_ID = (ID*)id; // I don't get why C++ requires this
return new_locals.contains(non_const_ID);
}
std::shared_ptr<TempVar> Reducer::FindTemporary(const ID* id) const { std::shared_ptr<TempVar> Reducer::FindTemporary(const IDPtr& id) const {
auto tmp = ids_to_temps.find(id); auto tmp = ids_to_temps.find(id);
if ( tmp == ids_to_temps.end() ) if ( tmp == ids_to_temps.end() )
return nullptr; return nullptr;

View file

@ -34,12 +34,10 @@ public:
bool IDsAreReduced(const std::vector<IDPtr>& ids) const; bool IDsAreReduced(const std::vector<IDPtr>& ids) const;
IDPtr UpdateID(IDPtr id); IDPtr UpdateID(IDPtr id);
bool ID_IsReduced(const IDPtr& id) const { return ID_IsReduced(id.get()); } bool ID_IsReduced(const IDPtr& id) const;
bool ID_IsReduced(const ID* id) const;
// A version of ID_IsReduced() that tracks top-level variables, too. // A version of ID_IsReduced() that tracks top-level variables, too.
bool ID_IsReducedOrTopLevel(const IDPtr& id) { return ID_IsReducedOrTopLevel(id.get()); } bool ID_IsReducedOrTopLevel(const IDPtr& id);
bool ID_IsReducedOrTopLevel(const ID* id);
// This is called *prior* to pushing a new inline block, in order // This is called *prior* to pushing a new inline block, in order
// to generate the equivalent of function parameters. "rhs" is // to generate the equivalent of function parameters. "rhs" is
@ -79,13 +77,13 @@ public:
int NumTemps() const { return temps.size(); } int NumTemps() const { return temps.size(); }
// True if this name already reflects the replacement. // True if this name already reflects the replacement.
bool IsNewLocal(const NameExpr* n) const { return IsNewLocal(n->Id()); } bool IsNewLocal(const NameExpr* n) const { return IsNewLocal(n->IdPtr()); }
bool IsNewLocal(const ID* id) const; bool IsNewLocal(const IDPtr& id) const;
bool IsTemporary(const ID* id) const { return FindTemporary(id) != nullptr; } bool IsTemporary(const IDPtr& id) const { return FindTemporary(id) != nullptr; }
bool IsParamTemp(const ID* id) const { return param_temps.contains(id); } bool IsParamTemp(const IDPtr& id) const { return param_temps.contains(id); }
bool IsConstantVar(const ID* id) const { return constant_vars.contains(id); } bool IsConstantVar(const IDPtr& id) const { return constant_vars.find(id) != constant_vars.end(); }
// True if the Reducer is being used in the context of a second // True if the Reducer is being used in the context of a second
// pass over for AST optimization. // pass over for AST optimization.
@ -183,16 +181,16 @@ protected:
// Tests whether an expression computed at e1 (and assigned to "id") // Tests whether an expression computed at e1 (and assigned to "id")
// remains valid for substitution at e2. // remains valid for substitution at e2.
bool ExprValid(const ID* id, const Expr* e1, const Expr* e2) const; bool ExprValid(const IDPtr& id, const Expr* e1, const Expr* e2) const;
// Inspects the given expression for identifiers, adding any // Inspects the given expression for identifiers, adding any
// observed to the given vector. Assumes reduced form, so only // observed to the given vector. Assumes reduced form, so only
// NameExpr's and ListExpr's are of interest - does not traverse // NameExpr's and ListExpr's are of interest - does not traverse
// into compound expressions. // into compound expressions.
void CheckIDs(const Expr* e, std::vector<const ID*>& ids) const; void CheckIDs(const ExprPtr& e, std::vector<IDPtr>& ids) const;
IDPtr GenTemporary(TypePtr t, ExprPtr rhs, IDPtr id = nullptr); IDPtr GenTemporary(TypePtr t, ExprPtr rhs, IDPtr id = nullptr);
std::shared_ptr<TempVar> FindTemporary(const ID* id) const; std::shared_ptr<TempVar> FindTemporary(const IDPtr& id) const;
// Retrieve the identifier corresponding to the new local for // Retrieve the identifier corresponding to the new local for
// the given expression. Creates the local if necessary. // the given expression. Creates the local if necessary.
@ -228,7 +226,7 @@ protected:
// Lets us go from an identifier to an associated temporary // Lets us go from an identifier to an associated temporary
// variable, if it corresponds to one. // variable, if it corresponds to one.
std::unordered_map<const ID*, std::shared_ptr<TempVar>> ids_to_temps; std::unordered_map<IDPtr, std::shared_ptr<TempVar>> ids_to_temps;
// Identifiers that we're tracking (and don't want to replace). // Identifiers that we're tracking (and don't want to replace).
IDSet tracked_ids; IDSet tracked_ids;
@ -242,7 +240,7 @@ protected:
// Mapping of original identifiers to new locals. Used to // Mapping of original identifiers to new locals. Used to
// rename local variables when inlining. // rename local variables when inlining.
std::unordered_map<const ID*, IDPtr> orig_to_new_locals; std::unordered_map<IDPtr, IDPtr> orig_to_new_locals;
// Tracks expressions we've folded, so that we can recognize them // Tracks expressions we've folded, so that we can recognize them
// for constant propagation. // for constant propagation.
@ -269,7 +267,7 @@ protected:
// Tracks locals introduced in the current block, remembering // Tracks locals introduced in the current block, remembering
// their previous replacement value (per "orig_to_new_locals"), // their previous replacement value (per "orig_to_new_locals"),
// if any. When we pop the block, we restore the previous mapping. // if any. When we pop the block, we restore the previous mapping.
std::vector<std::unordered_map<const ID*, IDPtr>> block_locals; std::vector<std::unordered_map<IDPtr, IDPtr>> block_locals;
// Memory management for AST elements that might change during // Memory management for AST elements that might change during
// the reduction/optimization processes. // the reduction/optimization processes.

View file

@ -371,10 +371,8 @@ IntrusivePtr<Case> Case::Duplicate() {
if ( type_cases ) { if ( type_cases ) {
new_type_cases = new IDPList(); new_type_cases = new IDPList();
for ( auto tc : *type_cases ) { for ( auto tc : *type_cases )
zeek::Ref(tc); new_type_cases->emplace_back(std::move(tc));
new_type_cases->append(tc);
}
} }
return make_intrusive<Case>(nullptr, new_type_cases, s->Duplicate()); return make_intrusive<Case>(nullptr, new_type_cases, s->Duplicate());
@ -439,9 +437,9 @@ StmtPtr SwitchStmt::DoReduce(Reducer* rc) {
// Update type cases. // Update type cases.
for ( auto& i : case_label_type_list ) { for ( auto& i : case_label_type_list ) {
IDPtr idp = {NewRef{}, i.first}; auto& id = i.first;
if ( idp->Name() ) if ( id->Name() )
i.first = rc->UpdateID(idp).release(); id = rc->UpdateID(id);
} }
for ( const auto& c : *cases ) { for ( const auto& c : *cases ) {
@ -458,7 +456,7 @@ StmtPtr SwitchStmt::DoReduce(Reducer* rc) {
if ( c_t ) { if ( c_t ) {
for ( auto& c_t_i : *c_t ) for ( auto& c_t_i : *c_t )
if ( c_t_i->Name() ) if ( c_t_i->Name() )
c_t_i = rc->UpdateID({NewRef{}, c_t_i}).release(); c_t_i = rc->UpdateID(c_t_i);
} }
c->UpdateBody(c->Body()->Reduce(rc)); c->UpdateBody(c->Body()->Reduce(rc));
@ -479,7 +477,7 @@ bool SwitchStmt::NoFlowAfter(bool ignore_break) const {
return false; return false;
if ( (! c->ExprCases() || c->ExprCases()->Exprs().length() == 0) && if ( (! c->ExprCases() || c->ExprCases()->Exprs().length() == 0) &&
(! c->TypeCases() || c->TypeCases()->length() == 0) ) (! c->TypeCases() || c->TypeCases()->empty()) )
// We saw the default, and the test before this // We saw the default, and the test before this
// one established that it has no flow after it. // one established that it has no flow after it.
default_seen_with_no_flow_after = true; default_seen_with_no_flow_after = true;
@ -570,12 +568,9 @@ bool WhileStmt::CouldReturn(bool ignore_break) const { return body->CouldReturn(
StmtPtr ForStmt::Duplicate() { StmtPtr ForStmt::Duplicate() {
auto expr_copy = e->Duplicate(); auto expr_copy = e->Duplicate();
auto new_loop_vars = new zeek::IDPList; auto new_loop_vars = new IDPList;
loop_over_list(*loop_vars, i) { for ( auto id : *loop_vars )
auto id = (*loop_vars)[i]; new_loop_vars->emplace_back(std::move(id));
zeek::Ref(id);
new_loop_vars->append(id);
}
ForStmt* f; ForStmt* f;
if ( value_var ) if ( value_var )
@ -798,7 +793,7 @@ static unsigned int find_rec_assignment_chain(const std::vector<StmtPtr>& stmts,
return i; return i;
} }
using OpChain = std::map<const ID*, std::vector<const Stmt*>>; using OpChain = std::unordered_map<IDPtr, std::vector<const Stmt*>>;
static void update_assignment_chains(const StmtPtr& s, OpChain& assign_chains, OpChain& add_chains) { static void update_assignment_chains(const StmtPtr& s, OpChain& assign_chains, OpChain& add_chains) {
auto se = s->AsExprStmt()->StmtExpr(); auto se = s->AsExprStmt()->StmtExpr();
@ -854,7 +849,7 @@ static void update_assignment_chains(const StmtPtr& s, OpChain& assign_chains, O
return; return;
// If we get here, it's a keeper, record the associated statement. // If we get here, it's a keeper, record the associated statement.
auto id = f_rec->AsNameExpr()->Id(); auto id = f_rec->AsNameExpr()->IdPtr();
(*c)[id].push_back(s.get()); (*c)[id].push_back(s.get());
} }
@ -1000,7 +995,7 @@ bool StmtList::ReduceStmt(unsigned int& s_i, std::vector<StmtPtr>& f_stmts, Redu
} }
} }
if ( c->IsTemporary(var->Id()) && ! c->IsParamTemp(var->Id()) && c->IsCSE(a, var, rhs.get()) ) { if ( c->IsTemporary(var->IdPtr()) && ! c->IsParamTemp(var->IdPtr()) && c->IsCSE(a, var, rhs.get()) ) {
// printf("discarding %s as unnecessary\n", var->Id()->Name()); // printf("discarding %s as unnecessary\n", var->Id()->Name());
// Skip this now unnecessary statement. // Skip this now unnecessary statement.
return true; return true;
@ -1106,7 +1101,7 @@ bool WhenInfo::HasUnreducedIDs(Reducer* c) const {
for ( auto& cp : *cl ) { for ( auto& cp : *cl ) {
const auto& cid = cp.Id(); const auto& cid = cp.Id();
if ( ! when_new_locals.contains(cid.get()) && ! c->ID_IsReduced(cp.Id()) ) if ( ! when_new_locals.contains(cid) && ! c->ID_IsReduced(cp.Id()) )
return true; return true;
} }
@ -1120,7 +1115,7 @@ bool WhenInfo::HasUnreducedIDs(Reducer* c) const {
void WhenInfo::UpdateIDs(Reducer* c) { void WhenInfo::UpdateIDs(Reducer* c) {
for ( auto& cp : *cl ) { for ( auto& cp : *cl ) {
auto& cid = cp.Id(); auto& cid = cp.Id();
if ( ! when_new_locals.contains(cid.get()) ) if ( ! when_new_locals.contains(cid) )
cp.SetID(c->UpdateID(cid)); cp.SetID(c->UpdateID(cid));
} }

View file

@ -40,7 +40,7 @@ UsageAnalyzer::UsageAnalyzer(std::vector<FuncInfo>& funcs) {
auto& globals = global_scope()->Vars(); auto& globals = global_scope()->Vars();
for ( auto& gpair : globals ) { for ( auto& gpair : globals ) {
auto id = gpair.second.get(); auto& id = gpair.second;
auto& t = id->GetType(); auto& t = id->GetType();
if ( t->Tag() != TYPE_FUNC ) if ( t->Tag() != TYPE_FUNC )
@ -69,7 +69,7 @@ UsageAnalyzer::UsageAnalyzer(std::vector<FuncInfo>& funcs) {
for ( auto& gpair : globals ) { for ( auto& gpair : globals ) {
auto& id = gpair.second; auto& id = gpair.second;
if ( reachables.contains(id.get()) ) if ( reachables.count(id) > 0 )
continue; continue;
auto f = GetFuncIfAny(id); auto f = GetFuncIfAny(id);
@ -116,8 +116,10 @@ public:
return TC_CONTINUE; return TC_CONTINUE;
} }
TraversalCode PreID(const ID* id) override { TraversalCode PreID(const ID* raw_id) override {
if ( ids.contains(id) ) IDPtr id{NewRef{}, const_cast<ID*>(raw_id)};
if ( ids.count(id) > 0 )
return TC_ABORTSTMT; return TC_ABORTSTMT;
if ( attr_depth > 0 ) if ( attr_depth > 0 )
@ -132,7 +134,7 @@ public:
} }
int attr_depth = 0; // Are we in an attribute? int attr_depth = 0; // Are we in an attribute?
std::set<const detail::ID*> ids; // List of IDs found in attributes. std::unordered_set<IDPtr> ids; // List of IDs found in attributes.
std::set<const Type*> analyzed_types; // Endless recursion avoidance. std::set<const Type*> analyzed_types; // Endless recursion avoidance.
}; };
@ -142,15 +144,15 @@ void UsageAnalyzer::FindSeeds(IDSet& seeds) const {
auto& id = gpair.second; auto& id = gpair.second;
if ( id->GetAttr(ATTR_IS_USED) || id->GetAttr(ATTR_DEPRECATED) ) { if ( id->GetAttr(ATTR_IS_USED) || id->GetAttr(ATTR_DEPRECATED) ) {
seeds.insert(id.get()); seeds.insert(id);
continue; continue;
} }
auto f = GetFuncIfAny(id); auto f = GetFuncIfAny(id);
if ( f && id->GetType<FuncType>()->Flavor() == FUNC_FLAVOR_EVENT ) { if ( f && id->GetType<FuncType>()->Flavor() == FUNC_FLAVOR_EVENT ) {
if ( ! script_events.contains(f->GetName()) ) if ( script_events.count(f->GetName()) == 0 )
seeds.insert(id.get()); seeds.insert(id);
continue; continue;
} }
@ -159,7 +161,7 @@ void UsageAnalyzer::FindSeeds(IDSet& seeds) const {
// it's meant to be used, even if the current scripts don't // it's meant to be used, even if the current scripts don't
// use it. // use it.
if ( id->IsExport() || id->ModuleName() == "GLOBAL" ) if ( id->IsExport() || id->ModuleName() == "GLOBAL" )
seeds.insert(id.get()); seeds.insert(id);
else else
// ...otherwise, find all IDs referenced from attribute expressions // ...otherwise, find all IDs referenced from attribute expressions
// found through this identifier. // found through this identifier.
@ -169,7 +171,7 @@ void UsageAnalyzer::FindSeeds(IDSet& seeds) const {
seeds.insert(attr_ids_collector.ids.begin(), attr_ids_collector.ids.end()); seeds.insert(attr_ids_collector.ids.begin(), attr_ids_collector.ids.end());
} }
const Func* UsageAnalyzer::GetFuncIfAny(const ID* id) const { const Func* UsageAnalyzer::GetFuncIfAny(const IDPtr& id) const {
auto& t = id->GetType(); auto& t = id->GetType();
if ( t->Tag() != TYPE_FUNC ) if ( t->Tag() != TYPE_FUNC )
return nullptr; return nullptr;
@ -205,7 +207,7 @@ bool UsageAnalyzer::ExpandReachables(const IDSet& curr_r) {
return ! new_reachables.empty(); return ! new_reachables.empty();
} }
void UsageAnalyzer::Expand(const ID* id) { void UsageAnalyzer::Expand(const IDPtr& id) {
// A subtle problem arises for exported globals that refer to functions // A subtle problem arises for exported globals that refer to functions
// that themselves generate events. Because for identifiers we don't // that themselves generate events. Because for identifiers we don't
// traverse their values (since there's no Traverse infrastructure for // traverse their values (since there's no Traverse infrastructure for
@ -224,8 +226,10 @@ void UsageAnalyzer::Expand(const ID* id) {
id->Traverse(this); id->Traverse(this);
} }
TraversalCode UsageAnalyzer::PreID(const ID* id) { TraversalCode UsageAnalyzer::PreID(const ID* raw_id) {
if ( analyzed_IDs.contains(id) ) IDPtr id{NewRef{}, const_cast<ID*>(raw_id)};
if ( analyzed_IDs.count(id) > 0 )
// No need to repeat the analysis. // No need to repeat the analysis.
return TC_ABORTSTMT; return TC_ABORTSTMT;

View file

@ -28,8 +28,7 @@ private:
// Given an identifier, return its corresponding script function, // Given an identifier, return its corresponding script function,
// or nil if that's not applicable. // or nil if that's not applicable.
const Func* GetFuncIfAny(const ID* id) const; const Func* GetFuncIfAny(const IDPtr& id) const;
const Func* GetFuncIfAny(const IDPtr& id) const { return GetFuncIfAny(id.get()); }
// Iteratively follows reachability across the set of reachable // Iteratively follows reachability across the set of reachable
// identifiers (starting with the seeds) until there's no more to reap. // identifiers (starting with the seeds) until there's no more to reap.
@ -41,7 +40,7 @@ private:
// For a given identifier, populates new_reachables with new // For a given identifier, populates new_reachables with new
// identifiers directly reachable from it. // identifiers directly reachable from it.
void Expand(const ID* f); void Expand(const IDPtr& f);
// Hooks into AST traversal to find reachable functions/hooks/events. // Hooks into AST traversal to find reachable functions/hooks/events.
TraversalCode PreID(const ID* id) override; TraversalCode PreID(const ID* id) override;

View file

@ -74,7 +74,7 @@ bool UseDefs::RemoveUnused(int iter) {
std::vector<IDPtr> used_ids; std::vector<IDPtr> used_ids;
for ( const auto& id : inits ) for ( const auto& id : inits )
if ( is_atomic_type(id->GetType()) || ! CheckIfUnused(s, id.get(), false) ) if ( is_atomic_type(id->GetType()) || ! CheckIfUnused(s, id, false) )
used_ids.emplace_back(id); used_ids.emplace_back(id);
if ( used_ids.empty() ) { // There aren't any ID's to keep. if ( used_ids.empty() ) { // There aren't any ID's to keep.
@ -118,7 +118,7 @@ bool UseDefs::RemoveUnused(int iter) {
if ( n->Tag() != EXPR_NAME ) if ( n->Tag() != EXPR_NAME )
reporter->InternalError("lhs name inconsistency in UseDefs::RemoveUnused"); reporter->InternalError("lhs name inconsistency in UseDefs::RemoveUnused");
auto id = n->AsNameExpr()->Id(); const auto& id = n->AsNameExpr()->IdPtr();
auto rhs = a->GetOp2(); auto rhs = a->GetOp2();
auto rt = rhs->Tag(); auto rt = rhs->Tag();
@ -146,7 +146,7 @@ bool UseDefs::RemoveUnused(int iter) {
return did_omission; return did_omission;
} }
bool UseDefs::CheckIfUnused(const Stmt* s, const ID* id, bool report) { bool UseDefs::CheckIfUnused(const Stmt* s, const IDPtr& id, bool report) {
if ( id->IsGlobal() ) if ( id->IsGlobal() )
return false; return false;
@ -247,7 +247,7 @@ UDs UseDefs::PropagateUDs(const Stmt* s, UDs succ_UDs, const Stmt* succ_stmt, bo
reporter->InternalError("lhs inconsistency in UseDefs::ExprUDs"); reporter->InternalError("lhs inconsistency in UseDefs::ExprUDs");
auto lhs_var = lhs_ref->GetOp1(); auto lhs_var = lhs_ref->GetOp1();
auto lhs_id = lhs_var->AsNameExpr()->Id(); auto lhs_id = lhs_var->AsNameExpr()->IdPtr();
auto lhs_UDs = RemoveID(lhs_id, succ_UDs); auto lhs_UDs = RemoveID(lhs_id, succ_UDs);
auto rhs_UDs = ExprUDs(a->GetOp2().get()); auto rhs_UDs = ExprUDs(a->GetOp2().get());
auto uds = UD_Union(lhs_UDs, rhs_UDs); auto uds = UD_Union(lhs_UDs, rhs_UDs);
@ -361,7 +361,7 @@ UDs UseDefs::PropagateUDs(const Stmt* s, UDs succ_UDs, const Stmt* succ_stmt, bo
auto val_var = f->ValueVar(); auto val_var = f->ValueVar();
if ( val_var ) if ( val_var )
RemoveUDFrom(f_UDs, val_var.get()); RemoveUDFrom(f_UDs, val_var);
// The loop might not execute at all. // The loop might not execute at all.
FoldInUDs(f_UDs, succ_UDs); FoldInUDs(f_UDs, succ_UDs);
@ -540,7 +540,7 @@ void UseDefs::AddInExprUDs(UDs uds, const Expr* e) {
switch ( e->Tag() ) { switch ( e->Tag() ) {
case EXPR_REF: AddInExprUDs(uds, e->GetOp1().get()); break; case EXPR_REF: AddInExprUDs(uds, e->GetOp1().get()); break;
case EXPR_NAME: AddID(uds, e->AsNameExpr()->Id()); break; case EXPR_NAME: AddID(uds, e->AsNameExpr()->IdPtr()); break;
case EXPR_LIST: { case EXPR_LIST: {
auto l = e->AsListExpr(); auto l = e->AsListExpr();
@ -582,9 +582,9 @@ void UseDefs::AddInExprUDs(UDs uds, const Expr* e) {
} }
} }
void UseDefs::AddID(UDs uds, const ID* id) const { uds->Add(id); } void UseDefs::AddID(UDs uds, IDPtr id) const { uds->Add(std::move(id)); }
UDs UseDefs::RemoveID(const ID* id, const UDs& uds) { UDs UseDefs::RemoveID(const IDPtr& id, const UDs& uds) {
if ( ! uds ) if ( ! uds )
return nullptr; return nullptr;
@ -596,7 +596,7 @@ UDs UseDefs::RemoveID(const ID* id, const UDs& uds) {
return new_uds; return new_uds;
} }
void UseDefs::RemoveUDFrom(UDs uds, const ID* id) { void UseDefs::RemoveUDFrom(UDs uds, const IDPtr& id) {
if ( uds ) if ( uds )
uds->Remove(id); uds->Remove(id);
} }

View file

@ -27,10 +27,10 @@ public:
void Replicate(const UDs& from) { use_defs = from->use_defs; } void Replicate(const UDs& from) { use_defs = from->use_defs; }
bool HasID(const ID* id) { return use_defs.contains(id); } bool HasID(const IDPtr& id) { return use_defs.find(id) != use_defs.end(); }
void Add(const ID* id) { use_defs.insert(id); } void Add(IDPtr id) { use_defs.insert(std::move(id)); }
void Remove(const ID* id) { use_defs.erase(id); } void Remove(const IDPtr& id) { use_defs.erase(id); }
const IDSet& IterateOver() const { return use_defs; } const IDSet& IterateOver() const { return use_defs; }
@ -83,7 +83,7 @@ private:
// For a given identifier defined at a given statement, returns // For a given identifier defined at a given statement, returns
// whether it is unused. If "report" is true, also reports // whether it is unused. If "report" is true, also reports
// this fact. // this fact.
bool CheckIfUnused(const Stmt* s, const ID* id, bool report); bool CheckIfUnused(const Stmt* s, const IDPtr& id, bool report);
// Propagates use-defs (backwards) across statement s, // Propagates use-defs (backwards) across statement s,
// given its successor's UDs. // given its successor's UDs.
@ -112,14 +112,14 @@ private:
void AddInExprUDs(UDs uds, const Expr* e); void AddInExprUDs(UDs uds, const Expr* e);
// Add an ID into an existing set of UDs. // Add an ID into an existing set of UDs.
void AddID(UDs uds, const ID* id) const; void AddID(UDs uds, IDPtr id) const;
// Returns a new use-def corresponding to the given one, but // Returns a new use-def corresponding to the given one, but
// with the definition of "id" removed. // with the definition of "id" removed.
UDs RemoveID(const ID* id, const UDs& uds); UDs RemoveID(const IDPtr& id, const UDs& uds);
// Similar, but updates the UDs in place. // Similar, but updates the UDs in place.
void RemoveUDFrom(UDs uds, const ID* id); void RemoveUDFrom(UDs uds, const IDPtr& id);
// Adds in the additional UDs to the main UDs. Always creates // Adds in the additional UDs to the main UDs. Always creates
// a new use_def and updates main_UDs to point to it. // a new use_def and updates main_UDs to point to it.

View file

@ -431,7 +431,7 @@ void ZAMCompiler::ComputeFrameLifetimes() {
case OP_STORE_GLOBAL_g: { case OP_STORE_GLOBAL_g: {
// Use of the global goes to here. // Use of the global goes to here.
auto slot = frame_layout1[globalsI[inst->v1].id.get()]; const auto& slot = frame_layout1[globalsI[inst->v1].id];
ExtendLifetime(slot, EndOfLoop(inst, 1)); ExtendLifetime(slot, EndOfLoop(inst, 1));
break; break;
} }
@ -671,7 +671,7 @@ void ZAMCompiler::ReMapInterpreterFrame() {
remapped_intrp_frame_sizes[f] = next_interp_slot; remapped_intrp_frame_sizes[f] = next_interp_slot;
} }
void ZAMCompiler::ReMapVar(const ID* id, int slot, zeek_uint_t inst) { void ZAMCompiler::ReMapVar(const IDPtr& id, int slot, zeek_uint_t inst) {
// A greedy algorithm for this is to simply find the first suitable // A greedy algorithm for this is to simply find the first suitable
// frame slot. We do that with one twist: we also look for a // frame slot. We do that with one twist: we also look for a
// compatible slot for which its current end-of-scope is exactly // compatible slot for which its current end-of-scope is exactly

View file

@ -38,7 +38,7 @@ void ReMapInterpreterFrame();
// Computes the remapping for a variable currently in the given slot, // Computes the remapping for a variable currently in the given slot,
// whose scope begins at the given instruction. // whose scope begins at the given instruction.
void ReMapVar(const ID* id, int slot, zeek_uint_t inst); void ReMapVar(const IDPtr& id, int slot, zeek_uint_t inst);
// Look to initialize the beginning of local lifetime based on slot // Look to initialize the beginning of local lifetime based on slot
// assignment at instruction inst. // assignment at instruction inst.

View file

@ -156,7 +156,7 @@ private:
std::shared_ptr<Reducer> reducer; std::shared_ptr<Reducer> reducer;
// Maps identifiers to their (unique) frame location. // Maps identifiers to their (unique) frame location.
std::unordered_map<const ID*, int> frame_layout1; std::unordered_map<IDPtr, int> frame_layout1;
// Inverse mapping, used for tracking frame usage (and for dumping // Inverse mapping, used for tracking frame usage (and for dumping
// statements). // statements).
@ -201,7 +201,7 @@ private:
// values that get finalized when constructing the corresponding // values that get finalized when constructing the corresponding
// ZBody. // ZBody.
std::vector<GlobalInfo> globalsI; std::vector<GlobalInfo> globalsI;
std::unordered_map<const ID*, int> global_id_to_info; // inverse std::unordered_map<IDPtr, int> global_id_to_info; // inverse
// Intermediary switch tables (branching to ZInst's rather // Intermediary switch tables (branching to ZInst's rather
// than concrete instruction offsets). // than concrete instruction offsets).

View file

@ -47,13 +47,9 @@ void ZAMCompiler::Init() {
} }
void ZAMCompiler::InitGlobals() { void ZAMCompiler::InitGlobals() {
for ( auto g : pf->Globals() ) { for ( auto& g : pf->Globals() ) {
auto non_const_g = const_cast<ID*>(g); GlobalInfo info{.id = g, .slot = AddToFrame(g)};
global_id_to_info[g] = globalsI.size();
GlobalInfo info;
info.id = {NewRef{}, non_const_g};
info.slot = AddToFrame(non_const_g);
global_id_to_info[non_const_g] = globalsI.size();
globalsI.push_back(info); globalsI.push_back(info);
} }
} }
@ -70,9 +66,8 @@ void ZAMCompiler::InitArgs() {
if ( --nparam < 0 ) if ( --nparam < 0 )
break; break;
auto arg_id = a.get(); if ( uds && uds->HasID(a) )
if ( uds && uds->HasID(arg_id) ) LoadParam(a);
LoadParam(arg_id);
else { else {
// printf("param %s unused\n", obj_desc(arg_id.get())); // printf("param %s unused\n", obj_desc(arg_id.get()));
} }
@ -88,22 +83,20 @@ void ZAMCompiler::InitCaptures() {
void ZAMCompiler::InitLocals() { void ZAMCompiler::InitLocals() {
// Assign slots for locals (which includes temporaries). // Assign slots for locals (which includes temporaries).
for ( auto l : pf->Locals() ) { for ( auto& l : pf->Locals() ) {
if ( IsCapture(l) ) if ( IsCapture(l) )
continue; continue;
if ( pf->WhenLocals().contains(l) ) if ( pf->WhenLocals().contains(l) )
continue; continue;
auto non_const_l = const_cast<ID*>(l);
// Don't add locals that were already added because they're // Don't add locals that were already added because they're
// parameters. // parameters.
// //
// Don't worry about unused variables, those will get // Don't worry about unused variables, those will get
// removed during low-level ZAM optimization. // removed during low-level ZAM optimization.
if ( ! HasFrameSlot(non_const_l) ) if ( ! HasFrameSlot(l) )
(void)AddToFrame(non_const_l); (void)AddToFrame(l);
} }
} }

View file

@ -951,7 +951,7 @@ const ZAMStmt ZAMCompiler::BuildLambda(int n_slot, ExprPtr e) {
for ( int i = 0; i < ncaptures; ++i ) { for ( int i = 0; i < ncaptures; ++i ) {
auto& id_i = (*captures)[i].Id(); auto& id_i = (*captures)[i].Id();
if ( pf->WhenLocals().contains(id_i.get()) ) if ( pf->WhenLocals().contains(id_i) )
aux->Add(i, nullptr); aux->Add(i, nullptr);
else else
aux->Add(i, FrameSlot(id_i), id_i->GetType()); aux->Add(i, FrameSlot(id_i), id_i->GetType());

View file

@ -16,7 +16,7 @@ using AttributesPtr = IntrusivePtr<Attributes>;
// Maps ZAM frame slots to associated identifiers. These are the simplest // Maps ZAM frame slots to associated identifiers. These are the simplest
// types of frames, where each identifier has its own slot. // types of frames, where each identifier has its own slot.
using FrameMap = std::vector<const ID*>; using FrameMap = std::vector<IDPtr>;
// Maps ZAM frame slots to information for sharing the slot across // Maps ZAM frame slots to information for sharing the slot across
// multiple script variables. // multiple script variables.
@ -25,7 +25,7 @@ public:
// The variables sharing the slot. ID's need to be non-const so we // The variables sharing the slot. ID's need to be non-const so we
// can manipulate them, for example by changing their interpreter // can manipulate them, for example by changing their interpreter
// frame offset. // frame offset.
std::vector<const ID*> ids; std::vector<IDPtr> ids;
// A parallel vector, only used for fully compiled code, which // A parallel vector, only used for fully compiled code, which
// gives the names of the identifiers. When in use, the above // gives the names of the identifiers. When in use, the above

View file

@ -163,7 +163,7 @@ const ZAMStmt ZAMCompiler::AddInst(const ZInstI& inst, bool suppress_non_local)
else else
op = OP_STORE_CAPTURE_Vi; op = OP_STORE_CAPTURE_Vi;
auto store_inst = ZInstI(op, RawSlot(c_id.get()), cs); auto store_inst = ZInstI(op, RawSlot(c_id), cs);
store_inst.op_type = OP_VV_I2; store_inst.op_type = OP_VV_I2;
return AddInst(store_inst); return AddInst(store_inst);

View file

@ -702,13 +702,11 @@ const ZAMStmt ZAMCompiler::LoopOverTable(const ForStmt* f, const NameExpr* val)
// variables are actually used in the body. Now that we have '_' // variables are actually used in the body. Now that we have '_'
// loop placeholder variables, this is no longer worth trying to // loop placeholder variables, this is no longer worth trying to
// optimize for, though we still optimize for those placeholders. // optimize for, though we still optimize for those placeholders.
int num_unused = 0; size_t num_unused = 0;
auto aux = new ZInstAux(0); auto aux = new ZInstAux(0);
for ( auto i = 0; i < loop_vars->length(); ++i ) { for ( const auto& id : *loop_vars ) {
auto id = (*loop_vars)[i];
if ( id->IsBlank() ) if ( id->IsBlank() )
++num_unused; ++num_unused;
@ -719,7 +717,7 @@ const ZAMStmt ZAMCompiler::LoopOverTable(const ForStmt* f, const NameExpr* val)
aux->is_managed.push_back(ZVal::IsManagedType(t)); aux->is_managed.push_back(ZVal::IsManagedType(t));
} }
bool no_loop_vars = (num_unused == loop_vars->length()); bool no_loop_vars = (num_unused == loop_vars->size());
if ( value_var ) if ( value_var )
aux->value_var_type = value_var->GetType(); aux->value_var_type = value_var->GetType();

View file

@ -17,21 +17,21 @@ bool ZAMCompiler::IsUnused(const IDPtr& id, const Stmt* where) const {
// "usage" can be nil if due to constant propagation we've prune // "usage" can be nil if due to constant propagation we've prune
// all of the uses of the given identifier. // all of the uses of the given identifier.
return ! usage || ! usage->HasID(id.get()); return ! usage || ! usage->HasID(id);
} }
bool ZAMCompiler::IsCapture(const ID* id) const { bool ZAMCompiler::IsCapture(const IDPtr& id) const {
const auto& c = pf->CapturesOffsets(); const auto& c = pf->CapturesOffsets();
return c.contains(id); return c.contains(id);
} }
int ZAMCompiler::CaptureOffset(const ID* id) const { int ZAMCompiler::CaptureOffset(const IDPtr& id) const {
auto id_offset = pf->CapturesOffsets().find(id); auto id_offset = pf->CapturesOffsets().find(id);
ASSERT(id_offset != pf->CapturesOffsets().end()); ASSERT(id_offset != pf->CapturesOffsets().end());
return id_offset->second; return id_offset->second;
} }
void ZAMCompiler::LoadParam(const ID* id) { void ZAMCompiler::LoadParam(const IDPtr& id) {
if ( id->IsType() ) if ( id->IsType() )
reporter->InternalError("don't know how to compile local variable that's a type not a value"); reporter->InternalError("don't know how to compile local variable that's a type not a value");
@ -50,7 +50,7 @@ void ZAMCompiler::LoadParam(const ID* id) {
(void)AddInst(z); (void)AddInst(z);
} }
const ZAMStmt ZAMCompiler::LoadGlobal(const ID* id) { const ZAMStmt ZAMCompiler::LoadGlobal(const IDPtr& id) {
ZOp op; ZOp op;
if ( id->IsType() ) if ( id->IsType() )
@ -68,12 +68,12 @@ const ZAMStmt ZAMCompiler::LoadGlobal(const ID* id) {
// We use the id_val for reporting used-but-not-set errors. // We use the id_val for reporting used-but-not-set errors.
z.aux = new ZInstAux(0); z.aux = new ZInstAux(0);
z.aux->id_val = {NewRef{}, const_cast<ID*>(id)}; z.aux->id_val = std::move(id);
return AddInst(z, true); return AddInst(z, true);
} }
const ZAMStmt ZAMCompiler::LoadCapture(const ID* id) { const ZAMStmt ZAMCompiler::LoadCapture(const IDPtr& id) {
ZOp op; ZOp op;
if ( ZVal::IsManagedType(id->GetType()) ) if ( ZVal::IsManagedType(id->GetType()) )
@ -90,13 +90,13 @@ const ZAMStmt ZAMCompiler::LoadCapture(const ID* id) {
return AddInst(z, true); return AddInst(z, true);
} }
int ZAMCompiler::AddToFrame(const ID* id) { int ZAMCompiler::AddToFrame(const IDPtr& id) {
frame_layout1[id] = frame_sizeI; frame_layout1[id] = frame_sizeI;
frame_denizens.push_back(id); frame_denizens.push_back(id);
return frame_sizeI++; return frame_sizeI++;
} }
int ZAMCompiler::FrameSlot(const ID* id) { int ZAMCompiler::FrameSlot(const IDPtr& id) {
auto slot = RawSlot(id); auto slot = RawSlot(id);
if ( id->IsGlobal() ) if ( id->IsGlobal() )
@ -108,7 +108,7 @@ int ZAMCompiler::FrameSlot(const ID* id) {
return slot; return slot;
} }
int ZAMCompiler::Frame1Slot(const ID* id, ZAMOp1Flavor fl) { int ZAMCompiler::Frame1Slot(const IDPtr& id, ZAMOp1Flavor fl) {
if ( fl == OP1_READ ) if ( fl == OP1_READ )
return FrameSlot(id); return FrameSlot(id);
@ -134,7 +134,7 @@ int ZAMCompiler::Frame1Slot(const ID* id, ZAMOp1Flavor fl) {
return slot; return slot;
} }
int ZAMCompiler::RawSlot(const ID* id) { int ZAMCompiler::RawSlot(const IDPtr& id) {
auto id_slot = frame_layout1.find(id); auto id_slot = frame_layout1.find(id);
if ( id_slot == frame_layout1.end() ) if ( id_slot == frame_layout1.end() )
@ -143,7 +143,7 @@ int ZAMCompiler::RawSlot(const ID* id) {
return id_slot->second; return id_slot->second;
} }
bool ZAMCompiler::HasFrameSlot(const ID* id) const { return frame_layout1.contains(id); } bool ZAMCompiler::HasFrameSlot(const IDPtr& id) const { return frame_layout1.contains(id); }
int ZAMCompiler::NewSlot(bool is_managed) { int ZAMCompiler::NewSlot(bool is_managed) {
char buf[8192]; char buf[8192];
@ -154,7 +154,7 @@ int ZAMCompiler::NewSlot(bool is_managed) {
auto tag = is_managed ? TYPE_TABLE : TYPE_VOID; auto tag = is_managed ? TYPE_TABLE : TYPE_VOID;
auto internal_reg = new ID(buf, SCOPE_FUNCTION, false); auto internal_reg = make_intrusive<ID>(buf, SCOPE_FUNCTION, false);
internal_reg->SetType(base_type(tag)); internal_reg->SetType(base_type(tag));
return AddToFrame(internal_reg); return AddToFrame(internal_reg);

View file

@ -6,37 +6,33 @@
bool IsUnused(const IDPtr& id, const Stmt* where) const; bool IsUnused(const IDPtr& id, const Stmt* where) const;
bool IsCapture(const IDPtr& id) const { return IsCapture(id.get()); } bool IsCapture(const IDPtr& id) const;
bool IsCapture(const ID* id) const; int CaptureOffset(const IDPtr& id) const;
int CaptureOffset(const IDPtr& id) const { return IsCapture(id.get()); } void LoadParam(const IDPtr& id);
int CaptureOffset(const ID* id) const; const ZAMStmt LoadGlobal(const IDPtr& id);
const ZAMStmt LoadCapture(const IDPtr& id);
void LoadParam(const ID* id); int AddToFrame(const IDPtr&);
const ZAMStmt LoadGlobal(const ID* id);
const ZAMStmt LoadCapture(const ID* id);
int AddToFrame(const ID*); int FrameSlot(const IDPtr& id);
int FrameSlot(const IDPtr& id) { return FrameSlot(id.get()); }
int FrameSlot(const ID* id);
int FrameSlotIfName(const Expr* e) { int FrameSlotIfName(const Expr* e) {
auto n = e->Tag() == EXPR_NAME ? e->AsNameExpr() : nullptr; auto n = e->Tag() == EXPR_NAME ? e->AsNameExpr() : nullptr;
return n ? FrameSlot(n->Id()) : -1; return n ? FrameSlot(n->IdPtr()) : -1;
} }
int FrameSlot(const NameExpr* n) { return FrameSlot(n->Id()); } int FrameSlot(const NameExpr* n) { return FrameSlot(n->IdPtr()); }
int Frame1Slot(const NameExpr* n, ZOp op) { return Frame1Slot(n->Id(), op); } int Frame1Slot(const NameExpr* n, ZOp op) { return Frame1Slot(n->IdPtr(), op); }
int Frame1Slot(const ID* id, ZOp op) { return Frame1Slot(id, op1_flavor[op]); } int Frame1Slot(const IDPtr& id, ZOp op) { return Frame1Slot(id, op1_flavor[op]); }
int Frame1Slot(const NameExpr* n, ZAMOp1Flavor fl) { return Frame1Slot(n->Id(), fl); } int Frame1Slot(const NameExpr* n, ZAMOp1Flavor fl) { return Frame1Slot(n->IdPtr(), fl); }
int Frame1Slot(const ID* id, ZAMOp1Flavor fl); int Frame1Slot(const IDPtr& id, ZAMOp1Flavor fl);
// The slot without doing any global-related checking. // The slot without doing any global-related checking.
int RawSlot(const NameExpr* n) { return RawSlot(n->Id()); } int RawSlot(const NameExpr* n) { return RawSlot(n->IdPtr()); }
int RawSlot(const ID* id); int RawSlot(const IDPtr& id);
bool HasFrameSlot(const ID* id) const; bool HasFrameSlot(const IDPtr& id) const;
int NewSlot(const TypePtr& t) { return NewSlot(ZVal::IsManagedType(t)); } int NewSlot(const TypePtr& t) { return NewSlot(ZVal::IsManagedType(t)); }
int NewSlot(bool is_managed); int NewSlot(bool is_managed);

View file

@ -398,7 +398,7 @@ string ZInstI::VName(int n, const FrameMap* frame_ids, const FrameReMap* remappi
if ( slot < 0 ) if ( slot < 0 )
return "<special>"; return "<special>";
const ID* id; IDPtr id;
if ( remappings && live ) { // Find which identifier manifests at this instruction. if ( remappings && live ) { // Find which identifier manifests at this instruction.
ASSERT(slot >= 0 && static_cast<zeek_uint_t>(slot) < remappings->size()); ASSERT(slot >= 0 && static_cast<zeek_uint_t>(slot) < remappings->size());

View file

@ -3,5 +3,5 @@ proto confirm, AllAnalyzers::ANALYZER_ANALYZER_HTTP
T T
http_request, GET, /style/enhanced.css http_request, GET, /style/enhanced.css
total http messages, { total http messages, {
[[orig_h=192.168.1.104, orig_p=1673/tcp, resp_h=63.245.209.11, resp_p=80/tcp, proto=6]] = 1 [[orig_h=192.168.1.104, orig_p=1673/tcp, resp_h=63.245.209.11, resp_p=80/tcp, proto=6, ctx=[]]] = 1
} }

View file

@ -1,16 +1,16 @@
### 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.
proto confirm, AllAnalyzers::ANALYZER_ANALYZER_HTTP proto confirm, AllAnalyzers::ANALYZER_ANALYZER_HTTP
http_request, GET, /style/enhanced.css http_request, GET, /style/enhanced.css
preventing disable_analyzer, [orig_h=192.168.1.104, orig_p=1673/tcp, resp_h=63.245.209.11, resp_p=80/tcp, proto=6], AllAnalyzers::ANALYZER_ANALYZER_HTTP, 3, 1 preventing disable_analyzer, [orig_h=192.168.1.104, orig_p=1673/tcp, resp_h=63.245.209.11, resp_p=80/tcp, proto=6, ctx=[]], AllAnalyzers::ANALYZER_ANALYZER_HTTP, 3, 1
F F
http_reply, 200 http_reply, 200
http_request, GET, /script/urchin.js http_request, GET, /script/urchin.js
preventing disable_analyzer, [orig_h=192.168.1.104, orig_p=1673/tcp, resp_h=63.245.209.11, resp_p=80/tcp, proto=6], AllAnalyzers::ANALYZER_ANALYZER_HTTP, 3, 3 preventing disable_analyzer, [orig_h=192.168.1.104, orig_p=1673/tcp, resp_h=63.245.209.11, resp_p=80/tcp, proto=6, ctx=[]], AllAnalyzers::ANALYZER_ANALYZER_HTTP, 3, 3
F F
http_reply, 200 http_reply, 200
http_request, GET, /images/template/screen/bullet_utility.png http_request, GET, /images/template/screen/bullet_utility.png
allowing disable_analyzer, [orig_h=192.168.1.104, orig_p=1673/tcp, resp_h=63.245.209.11, resp_p=80/tcp, proto=6], AllAnalyzers::ANALYZER_ANALYZER_HTTP, 3, 5 allowing disable_analyzer, [orig_h=192.168.1.104, orig_p=1673/tcp, resp_h=63.245.209.11, resp_p=80/tcp, proto=6, ctx=[]], AllAnalyzers::ANALYZER_ANALYZER_HTTP, 3, 5
T T
total http messages, { total http messages, {
[[orig_h=192.168.1.104, orig_p=1673/tcp, resp_h=63.245.209.11, resp_p=80/tcp, proto=6]] = 5 [[orig_h=192.168.1.104, orig_p=1673/tcp, resp_h=63.245.209.11, resp_p=80/tcp, proto=6, ctx=[]]] = 5
} }

View file

@ -3,5 +3,5 @@ proto confirm, AllAnalyzers::ANALYZER_ANALYZER_HTTP
http_request, GET, /style/enhanced.css http_request, GET, /style/enhanced.css
T T
total http messages, { total http messages, {
[[orig_h=192.168.1.104, orig_p=1673/tcp, resp_h=63.245.209.11, resp_p=80/tcp, proto=6]] = 1 [[orig_h=192.168.1.104, orig_p=1673/tcp, resp_h=63.245.209.11, resp_p=80/tcp, proto=6, ctx=[]]] = 1
} }

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.
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: 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 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, ctx=[]])
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 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: 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: 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, ctx=[]])
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: invalid connection ID record encountered (<___>testing_btest__tmp_bifs_lookup_connection_lookup_connection_zeek__new_connection__2__zf: function() : void())

View file

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

View file

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

View file

@ -1,6 +1,6 @@
### 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.
error in <...>/create-failure.zeek (C++), line 61: Failed to attach master store backend_failure: (<___>testing_btest__tmp_broker_store_create_failure_create_failure_zeek__zeek_init__36__zf: function() : void()) error in <...>/create-failure.zeek (C++), line 61: Failed to attach master store backend_failure: (<___>testing_btest__tmp_broker_store_create_failure_create_failure_zeek__zeek_init__35__zf: function() : void())
error in <...>/create-failure.zeek (C++), line 61: Could not create Broker master store '../fail' (<___>testing_btest__tmp_broker_store_create_failure_create_failure_zeek__zeek_init__36__zf: function() : void()) error in <...>/create-failure.zeek (C++), line 61: Could not create Broker master store '../fail' (<___>testing_btest__tmp_broker_store_create_failure_create_failure_zeek__zeek_init__35__zf: function() : void())
error in <...>/create-failure.zeek, line 49: invalid Broker store handle (lambda_9763286939515018196__lb_cl: function() : void() and broker::store::{}) error in <...>/create-failure.zeek, line 49: invalid Broker store handle (lambda_9763286939515018196__lb_cl: function() : void() and broker::store::{})
error in <...>/create-failure.zeek, line 49: invalid Broker store handle (lambda_9763286939515018196__lb_cl: function() : void() and broker::store::{}) error in <...>/create-failure.zeek, line 49: invalid Broker store handle (lambda_9763286939515018196__lb_cl: function() : void() and broker::store::{})
error in <...>/create-failure.zeek, line 49: invalid Broker store handle (lambda_9763286939515018196__lb_cl: function() : void() and broker::store::{}) error in <...>/create-failure.zeek, line 49: invalid Broker store handle (lambda_9763286939515018196__lb_cl: function() : void() and broker::store::{})

View file

@ -1,4 +1,4 @@
### 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.
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 55: Publish of unknown record type 'Cluster::MyEvent' (<___>testing_btest__tmp_cluster_generic_cluster_publish_errors_cluster_publish_errors_zeek__zeek_init__39__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 62: 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 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()) 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__41__zf: function() : void())

View file

@ -1,6 +1,6 @@
### 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.
error in <...>/errors.zeek (C++), line 16: no event arguments given (<___>testing_btest__tmp_cluster_generic_errors_errors_zeek__zeek_init__36__zf: function() : void()) error in <...>/errors.zeek (C++), line 16: no event arguments given (<___>testing_btest__tmp_cluster_generic_errors_errors_zeek__zeek_init__35__zf: function() : void())
error in <...>/errors.zeek (C++), line 16: not enough arguments (<___>testing_btest__tmp_cluster_generic_errors_errors_zeek__zeek_init__36__zf: function() : void()) error in <...>/errors.zeek (C++), line 16: not enough arguments (<___>testing_btest__tmp_cluster_generic_errors_errors_zeek__zeek_init__35__zf: function() : void())
error in <...>/errors.zeek (C++), line 16: bad number of arguments for ping1: got 0, expect 2 error in <...>/errors.zeek (C++), line 16: bad number of arguments for ping1: got 0, expect 2
error in <...>/errors.zeek (C++), line 16: bad number of arguments for ping1: got 0, expect 2 error in <...>/errors.zeek (C++), line 16: bad number of arguments for ping1: got 0, expect 2
error in <...>/errors.zeek (C++), line 16: bad number of arguments for ping1: got 1, expect 2 error in <...>/errors.zeek (C++), line 16: bad number of arguments for ping1: got 1, expect 2
@ -11,5 +11,5 @@ error in <...>/errors.zeek (C++), line 37: event parameter #2 type mismatch, got
error in <...>/errors.zeek (C++), line 37: event parameter #2 type mismatch, got count, expecting string error in <...>/errors.zeek (C++), line 37: event parameter #2 type mismatch, got count, expecting string
error in <...>/errors.zeek (C++), line 37: unexpected function type for hook1: hook error in <...>/errors.zeek (C++), line 37: unexpected function type for hook1: hook
error in <...>/errors.zeek (C++), line 37: unexpected function type for hook1: hook error in <...>/errors.zeek (C++), line 37: unexpected function type for hook1: hook
error in <...>/errors.zeek (C++), line 37: expected function or record as first argument, got count (<___>testing_btest__tmp_cluster_generic_errors_errors_zeek__zeek_init__37__zf: function() : void()) error in <...>/errors.zeek (C++), line 37: expected function or record as first argument, got count (<___>testing_btest__tmp_cluster_generic_errors_errors_zeek__zeek_init__36__zf: function() : void())
error in <...>/errors.zeek (C++), line 37: got non-event type 'count' (<___>testing_btest__tmp_cluster_generic_errors_errors_zeek__zeek_init__37__zf: function() : void()) error in <...>/errors.zeek (C++), line 37: got non-event type 'count' (<___>testing_btest__tmp_cluster_generic_errors_errors_zeek__zeek_init__36__zf: function() : void())

View file

@ -1,6 +1,6 @@
### 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.
error in <...>/make_event.zeek (C++), line 30: not enough arguments (<___>testing_btest__tmp_cluster_generic_make_event_make_event_zeek__zeek_init__39__zf: function() : void()) error in <...>/make_event.zeek (C++), line 30: not enough arguments (<___>testing_btest__tmp_cluster_generic_make_event_make_event_zeek__zeek_init__38__zf: function() : void())
error in <...>/make_event.zeek (C++), line 35: got non-event type 'string' (<___>testing_btest__tmp_cluster_generic_make_event_make_event_zeek__zeek_init__40__zf: function() : void()) error in <...>/make_event.zeek (C++), line 35: got non-event type 'string' (<___>testing_btest__tmp_cluster_generic_make_event_make_event_zeek__zeek_init__39__zf: function() : void())
error in <...>/make_event.zeek (C++), line 40: unexpected function type for test_fun: function error in <...>/make_event.zeek (C++), line 40: unexpected function type for test_fun: function
error in <...>/make_event.zeek (C++), line 45: unexpected function type for test_hook: hook error in <...>/make_event.zeek (C++), line 45: unexpected function type for test_hook: hook
error in <...>/make_event.zeek (C++), line 50: bad number of arguments for test_event2: got 0, expect 1 error in <...>/make_event.zeek (C++), line 50: bad number of arguments for test_event2: got 0, expect 1

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.
event(), []
event(s:string), [abc]

View file

@ -1,5 +1,5 @@
### 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.
error in <...>/listen-idempotent.zeek (C++), line 9: Already listening on 127.0.0.1:<port> (<___>testing_btest__tmp_cluster_websocket_listen_idempotent_listen_idempotent_zeek__zeek_init__36__zf: function() : void()) error in <...>/listen-idempotent.zeek (C++), line 9: Already listening on 127.0.0.1:<port> (<___>testing_btest__tmp_cluster_websocket_listen_idempotent_listen_idempotent_zeek__zeek_init__35__zf: function() : void())
error in <...>/listen-idempotent.zeek (C++), line 9: Already listening on 127.0.0.1:<port> (<___>testing_btest__tmp_cluster_websocket_listen_idempotent_listen_idempotent_zeek__zeek_init__36__zf: function() : void()) error in <...>/listen-idempotent.zeek (C++), line 9: Already listening on 127.0.0.1:<port> (<___>testing_btest__tmp_cluster_websocket_listen_idempotent_listen_idempotent_zeek__zeek_init__35__zf: function() : void())
error in <...>/listen-idempotent.zeek (C++), line 9: Already listening on 127.0.0.1:<port> (<___>testing_btest__tmp_cluster_websocket_listen_idempotent_listen_idempotent_zeek__zeek_init__36__zf: function() : void()) error in <...>/listen-idempotent.zeek (C++), line 9: Already listening on 127.0.0.1:<port> (<___>testing_btest__tmp_cluster_websocket_listen_idempotent_listen_idempotent_zeek__zeek_init__35__zf: function() : void())
received termination signal received termination signal

View file

@ -1,3 +1,3 @@
### 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.
error in <...>/tls-usage-error.zeek (C++), line 7: Invalid tls_options: No key_file field (<___>testing_btest__tmp_cluster_websocket_tls_usage_error_tls_usage_error_zeek__zeek_init__36__zf: function() : void()) error in <...>/tls-usage-error.zeek (C++), line 7: Invalid tls_options: No key_file field (<___>testing_btest__tmp_cluster_websocket_tls_usage_error_tls_usage_error_zeek__zeek_init__35__zf: function() : void())
error in <...>/tls-usage-error.zeek (C++), line 7: Invalid tls_options: No cert_file field (<___>testing_btest__tmp_cluster_websocket_tls_usage_error_tls_usage_error_zeek__zeek_init__36__zf: function() : void()) error in <...>/tls-usage-error.zeek (C++), line 7: Invalid tls_options: No cert_file field (<___>testing_btest__tmp_cluster_websocket_tls_usage_error_tls_usage_error_zeek__zeek_init__35__zf: function() : void())

View file

@ -1,3 +1,3 @@
### 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.
analyzer_confirmation_info, AllAnalyzers::ANALYZER_ANALYZER_FTP, [orig_h=2001:470:1f05:17a6:d69a:20ff:fefd:6b88, orig_p=24316/tcp, resp_h=2001:6a8:a40::21, resp_p=21/tcp, proto=6], 3 analyzer_confirmation_info, AllAnalyzers::ANALYZER_ANALYZER_FTP, [orig_h=2001:470:1f05:17a6:d69a:20ff:fefd:6b88, orig_p=24316/tcp, resp_h=2001:6a8:a40::21, resp_p=21/tcp, proto=6, ctx=[]], 3
analyzer_violation_info, AllAnalyzers::ANALYZER_ANALYZER_FTP, non-numeric reply code, [orig_h=2001:470:1f05:17a6:d69a:20ff:fefd:6b88, orig_p=24316/tcp, resp_h=2001:6a8:a40::21, resp_p=21/tcp, proto=6], 3, SSH-2.0-mod_sftp/0.9.7 analyzer_violation_info, AllAnalyzers::ANALYZER_ANALYZER_FTP, non-numeric reply code, [orig_h=2001:470:1f05:17a6:d69a:20ff:fefd:6b88, orig_p=24316/tcp, resp_h=2001:6a8:a40::21, resp_p=21/tcp, proto=6, ctx=[]], 3, SSH-2.0-mod_sftp/0.9.7

View file

@ -1,3 +1,3 @@
### 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.
analyzer_confirmation_info, AllAnalyzers::ANALYZER_ANALYZER_SSL, [orig_h=1.1.1.1, orig_p=20394/tcp, resp_h=2.2.2.2, resp_p=443/tcp, proto=6], 3 analyzer_confirmation_info, AllAnalyzers::ANALYZER_ANALYZER_SSL, [orig_h=192.168.4.149, orig_p=53525/tcp, resp_h=74.125.239.37, resp_p=443/tcp, proto=6, ctx=[]], 3
analyzer_violation_info, AllAnalyzers::ANALYZER_ANALYZER_SSL, Invalid version late in TLS connection. Packet reported version: 0, [orig_h=1.1.1.1, orig_p=20394/tcp, resp_h=2.2.2.2, resp_p=443/tcp, proto=6], 3 analyzer_violation_info, AllAnalyzers::ANALYZER_ANALYZER_SSL, Invalid version late in TLS connection. Packet reported version: 0, [orig_h=192.168.4.149, orig_p=53525/tcp, resp_h=74.125.239.37, resp_p=443/tcp, proto=6, ctx=[]], 3

View file

@ -1,19 +1,19 @@
### 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.
ftp field missing ftp field missing
[orig_h=141.142.220.118, orig_p=48649/tcp, resp_h=208.80.152.118, resp_p=80/tcp, proto=6] [orig_h=141.142.220.118, orig_p=48649/tcp, resp_h=208.80.152.118, resp_p=80/tcp, proto=6, ctx=[]]
ftp field missing ftp field missing
[orig_h=141.142.220.118, orig_p=49997/tcp, resp_h=208.80.152.3, resp_p=80/tcp, proto=6] [orig_h=141.142.220.118, orig_p=49997/tcp, resp_h=208.80.152.3, resp_p=80/tcp, proto=6, ctx=[]]
ftp field missing ftp field missing
[orig_h=141.142.220.118, orig_p=49996/tcp, resp_h=208.80.152.3, resp_p=80/tcp, proto=6] [orig_h=141.142.220.118, orig_p=49996/tcp, resp_h=208.80.152.3, resp_p=80/tcp, proto=6, ctx=[]]
ftp field missing ftp field missing
[orig_h=141.142.220.118, orig_p=49998/tcp, resp_h=208.80.152.3, resp_p=80/tcp, proto=6] [orig_h=141.142.220.118, orig_p=49998/tcp, resp_h=208.80.152.3, resp_p=80/tcp, proto=6, ctx=[]]
ftp field missing ftp field missing
[orig_h=141.142.220.118, orig_p=50000/tcp, resp_h=208.80.152.3, resp_p=80/tcp, proto=6] [orig_h=141.142.220.118, orig_p=50000/tcp, resp_h=208.80.152.3, resp_p=80/tcp, proto=6, ctx=[]]
ftp field missing ftp field missing
[orig_h=141.142.220.118, orig_p=49999/tcp, resp_h=208.80.152.3, resp_p=80/tcp, proto=6] [orig_h=141.142.220.118, orig_p=49999/tcp, resp_h=208.80.152.3, resp_p=80/tcp, proto=6, ctx=[]]
ftp field missing ftp field missing
[orig_h=141.142.220.118, orig_p=50001/tcp, resp_h=208.80.152.3, resp_p=80/tcp, proto=6] [orig_h=141.142.220.118, orig_p=50001/tcp, resp_h=208.80.152.3, resp_p=80/tcp, proto=6, ctx=[]]
ftp field missing ftp field missing
[orig_h=141.142.220.118, orig_p=35642/tcp, resp_h=208.80.152.2, resp_p=80/tcp, proto=6] [orig_h=141.142.220.118, orig_p=35642/tcp, resp_h=208.80.152.2, resp_p=80/tcp, proto=6, ctx=[]]
ftp field missing ftp field missing
[orig_h=141.142.220.235, orig_p=6705/tcp, resp_h=173.192.163.128, resp_p=80/tcp, proto=6] [orig_h=141.142.220.235, orig_p=6705/tcp, resp_h=173.192.163.128, resp_p=80/tcp, proto=6, ctx=[]]

View file

@ -1,5 +1,5 @@
### 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.
error in <...>/publish-hrw-type-check.zeek (C++), line 13: expected type Cluster::Pool for pool (<___>testing_btest__tmp_scripts_base_frameworks_cluster_publish_hrw_type_check_publish_hrw_type_check_zeek__zeek_init__36__zf: function() : void()) error in <...>/publish-hrw-type-check.zeek (C++), line 13: expected type Cluster::Pool for pool (<___>testing_btest__tmp_scripts_base_frameworks_cluster_publish_hrw_type_check_publish_hrw_type_check_zeek__zeek_init__35__zf: function() : void())
error in <...>/publish-hrw-type-check.zeek (C++), line 13: expected type Cluster::Pool for pool (<___>testing_btest__tmp_scripts_base_frameworks_cluster_publish_hrw_type_check_publish_hrw_type_check_zeek__zeek_init__36__zf: function() : void()) error in <...>/publish-hrw-type-check.zeek (C++), line 13: expected type Cluster::Pool for pool (<___>testing_btest__tmp_scripts_base_frameworks_cluster_publish_hrw_type_check_publish_hrw_type_check_zeek__zeek_init__35__zf: function() : void())
error in <...>/publish-hrw-type-check.zeek (C++), line 13: expected type Cluster::Pool for pool (<___>testing_btest__tmp_scripts_base_frameworks_cluster_publish_hrw_type_check_publish_hrw_type_check_zeek__zeek_init__36__zf: function() : void()) error in <...>/publish-hrw-type-check.zeek (C++), line 13: expected type Cluster::Pool for pool (<___>testing_btest__tmp_scripts_base_frameworks_cluster_publish_hrw_type_check_publish_hrw_type_check_zeek__zeek_init__35__zf: function() : void())
error in <...>/publish-hrw-type-check.zeek (C++), line 13: expected type string for key, got port (<___>testing_btest__tmp_scripts_base_frameworks_cluster_publish_hrw_type_check_publish_hrw_type_check_zeek__zeek_init__36__zf: function() : void()) error in <...>/publish-hrw-type-check.zeek (C++), line 13: expected type string for key, got port (<___>testing_btest__tmp_scripts_base_frameworks_cluster_publish_hrw_type_check_publish_hrw_type_check_zeek__zeek_init__35__zf: function() : void())

View file

@ -1,11 +1,11 @@
### 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.
analyzer_confirmation, [orig_h=10.0.0.80, orig_p=56637/tcp, resp_h=68.233.76.12, resp_p=443/tcp, proto=6], AllAnalyzers::ANALYZER_ANALYZER_SSL, 3 analyzer_confirmation, [orig_h=10.0.0.80, orig_p=56637/tcp, resp_h=68.233.76.12, resp_p=443/tcp, proto=6, ctx=[]], AllAnalyzers::ANALYZER_ANALYZER_SSL, 3
encrypted_data, [orig_h=10.0.0.80, orig_p=56637/tcp, resp_h=68.233.76.12, resp_p=443/tcp, proto=6], T, 22, 32, 1 encrypted_data, [orig_h=10.0.0.80, orig_p=56637/tcp, resp_h=68.233.76.12, resp_p=443/tcp, proto=6, ctx=[]], T, 22, 32, 1
established, [orig_h=10.0.0.80, orig_p=56637/tcp, resp_h=68.233.76.12, resp_p=443/tcp, proto=6] established, [orig_h=10.0.0.80, orig_p=56637/tcp, resp_h=68.233.76.12, resp_p=443/tcp, proto=6, ctx=[]]
disabling_analyzer, [orig_h=10.0.0.80, orig_p=56637/tcp, resp_h=68.233.76.12, resp_p=443/tcp, proto=6], AllAnalyzers::ANALYZER_ANALYZER_SSL, 3 disabling_analyzer, [orig_h=10.0.0.80, orig_p=56637/tcp, resp_h=68.233.76.12, resp_p=443/tcp, proto=6, ctx=[]], AllAnalyzers::ANALYZER_ANALYZER_SSL, 3
preventing disabling_analyzer, [orig_h=10.0.0.80, orig_p=56637/tcp, resp_h=68.233.76.12, resp_p=443/tcp, proto=6], AllAnalyzers::ANALYZER_ANALYZER_SSL, 3 preventing disabling_analyzer, [orig_h=10.0.0.80, orig_p=56637/tcp, resp_h=68.233.76.12, resp_p=443/tcp, proto=6, ctx=[]], AllAnalyzers::ANALYZER_ANALYZER_SSL, 3
encrypted_data, [orig_h=10.0.0.80, orig_p=56637/tcp, resp_h=68.233.76.12, resp_p=443/tcp, proto=6], F, 22, 32, 2 encrypted_data, [orig_h=10.0.0.80, orig_p=56637/tcp, resp_h=68.233.76.12, resp_p=443/tcp, proto=6, ctx=[]], F, 22, 32, 2
encrypted_data, [orig_h=10.0.0.80, orig_p=56637/tcp, resp_h=68.233.76.12, resp_p=443/tcp, proto=6], T, 23, 31, 3 encrypted_data, [orig_h=10.0.0.80, orig_p=56637/tcp, resp_h=68.233.76.12, resp_p=443/tcp, proto=6, ctx=[]], T, 23, 31, 3
encrypted_data, [orig_h=10.0.0.80, orig_p=56637/tcp, resp_h=68.233.76.12, resp_p=443/tcp, proto=6], T, 23, 17, 4 encrypted_data, [orig_h=10.0.0.80, orig_p=56637/tcp, resp_h=68.233.76.12, resp_p=443/tcp, proto=6, ctx=[]], T, 23, 17, 4
disabling_analyzer, [orig_h=10.0.0.80, orig_p=56637/tcp, resp_h=68.233.76.12, resp_p=443/tcp, proto=6], AllAnalyzers::ANALYZER_ANALYZER_SSL, 3 disabling_analyzer, [orig_h=10.0.0.80, orig_p=56637/tcp, resp_h=68.233.76.12, resp_p=443/tcp, proto=6, ctx=[]], AllAnalyzers::ANALYZER_ANALYZER_SSL, 3
allowing disabling_analyzer, [orig_h=10.0.0.80, orig_p=56637/tcp, resp_h=68.233.76.12, resp_p=443/tcp, proto=6], AllAnalyzers::ANALYZER_ANALYZER_SSL, 3 allowing disabling_analyzer, [orig_h=10.0.0.80, orig_p=56637/tcp, resp_h=68.233.76.12, resp_p=443/tcp, proto=6, ctx=[]], AllAnalyzers::ANALYZER_ANALYZER_SSL, 3

View file

@ -1,2 +1,2 @@
### 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.
566 seen BiFs, 0 unseen BiFs (), 0 new BiFs () 563 seen BiFs, 0 unseen BiFs (), 0 new BiFs ()

View file

@ -1,6 +1,10 @@
# This tests whether the script-layer can correctly query if a given Broker # This tests whether the script-layer can correctly query if a given Broker
# peering originated from the local node or from another node that peered with it. # peering originated from the local node or from another node that peered with it.
# #
# Can't use this test for -O gen-C++ because of multiple simultaneous
# Zeek runs.
# @TEST-REQUIRES: test "${ZEEK_USE_CPP}" != "1"
#
# @TEST-GROUP: broker # @TEST-GROUP: broker
# @TEST-PORT: BROKER_PORT # @TEST-PORT: BROKER_PORT
# #

View file

@ -1,5 +1,9 @@
# @TEST-DOC: Test that calling Broker::publish() with a Cluster::Event instance fails. Regression test for #4571. # @TEST-DOC: Test that calling Broker::publish() with a Cluster::Event instance fails. Regression test for #4571.
# #
# Can't use this test for -O gen-C++ because of multiple simultaneous
# Zeek runs.
# @TEST-REQUIRES: test "${ZEEK_USE_CPP}" != "1"
#
# @TEST-GROUP: broker # @TEST-GROUP: broker
# #
# @TEST-PORT: BROKER_PORT # @TEST-PORT: BROKER_PORT

View file

@ -1,3 +1,7 @@
# Can't use this test for -O gen-C++ because of multiple simultaneous
# Zeek runs.
# @TEST-REQUIRES: test "${ZEEK_USE_CPP}" != "1"
#
# @TEST-GROUP: broker # @TEST-GROUP: broker
# #
# @TEST-PORT: BROKER_PORT # @TEST-PORT: BROKER_PORT

View file

@ -1,3 +1,7 @@
# Can't use this test for -O gen-C++ because of multiple simultaneous
# Zeek runs.
# @TEST-REQUIRES: test "${ZEEK_USE_CPP}" != "1"
#
# @TEST-GROUP: broker # @TEST-GROUP: broker
# #
# @TEST-PORT: BROKER_PORT # @TEST-PORT: BROKER_PORT

View file

@ -1,3 +1,6 @@
# Can't use this test for -O gen-C++ because of multiple differing Zeek runs.
# @TEST-REQUIRES: test "${ZEEK_USE_CPP}" != "1"
# @TEST-EXEC: zeek -b -C -r $TRACES/wikipedia.trace discarder-ip.zeek >output # @TEST-EXEC: zeek -b -C -r $TRACES/wikipedia.trace discarder-ip.zeek >output
# @TEST-EXEC: zeek -b -C -r $TRACES/wikipedia.trace discarder-tcp.zeek >>output # @TEST-EXEC: zeek -b -C -r $TRACES/wikipedia.trace discarder-tcp.zeek >>output
# @TEST-EXEC: zeek -b -C -r $TRACES/wikipedia.trace discarder-udp.zeek >>output # @TEST-EXEC: zeek -b -C -r $TRACES/wikipedia.trace discarder-udp.zeek >>output

View file

@ -1,5 +1,10 @@
# A test of prefix-based @load'ing # A test of prefix-based @load'ing
# Can't use this test for -O gen-C++ because none of the scripts has
# testing/btest in its path when loaded, so don't get recognized for
# compilation.
# @TEST-REQUIRES: test "${ZEEK_USE_CPP}" != "1"
# @TEST-EXEC: zeek -b base/utils/site base/protocols/http addprefixes >output # @TEST-EXEC: zeek -b base/utils/site base/protocols/http addprefixes >output
# @TEST-EXEC: btest-diff output # @TEST-EXEC: btest-diff output

View file

@ -1,4 +1,8 @@
# @TEST-REQUIRES: test "${ZEEK_ZAM}" != "1" # @TEST-REQUIRES: test "${ZEEK_ZAM}" != "1"
# Can't use this test for -O gen-C++ because none of the scripts has
# testing/btest in its path when loaded, so don't get recognized for
# compilation.
# @TEST-REQUIRES: test "${ZEEK_USE_CPP}" != "1"
# #
# @TEST-EXEC: ZEEK_PROFILER_FILE=cov.txt zeek -b -r $TRACES/http/get.trace profiling-test1.zeek # @TEST-EXEC: ZEEK_PROFILER_FILE=cov.txt zeek -b -r $TRACES/http/get.trace profiling-test1.zeek
# @TEST-EXEC: grep profiling-test1.zeek cov.txt > step1.out # @TEST-EXEC: grep profiling-test1.zeek cov.txt > step1.out

View file

@ -1,3 +1,7 @@
# Can't use this test for -O gen-C++ because the additional script doesn't
# have testing/btest in its path when loaded, so isn't recognized for
# compilation.
# @TEST-REQUIRES: test "${ZEEK_USE_CPP}" != "1"
# @TEST-EXEC: zeek -b %INPUT >out # @TEST-EXEC: zeek -b %INPUT >out
# @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out # @TEST-EXEC: TEST_DIFF_CANONIFIER=$SCRIPTS/diff-remove-abspath btest-diff out
# @TEST-EXEC: zeek -b ./pathtest.zeek >out2 # @TEST-EXEC: zeek -b ./pathtest.zeek >out2

View file

@ -21,8 +21,6 @@ global known_BiFs = set(
"Analyzer::__schedule_analyzer", "Analyzer::__schedule_analyzer",
"Analyzer::__tag", "Analyzer::__tag",
"Broker::__append", "Broker::__append",
"Broker::__auto_publish",
"Broker::__auto_unpublish",
"Broker::__clear", "Broker::__clear",
"Broker::__close", "Broker::__close",
"Broker::__create_clone", "Broker::__create_clone",
@ -452,7 +450,6 @@ global known_BiFs = set(
"reading_live_traffic", "reading_live_traffic",
"reading_traces", "reading_traces",
"record_fields", "record_fields",
"record_type_to_vector",
"remask_addr", "remask_addr",
"remove_prefix", "remove_prefix",
"remove_suffix", "remove_suffix",

View file

@ -0,0 +1,35 @@
# @TEST-DOC: Regression test for lambda construction that used to violate memory safety
# @TEST-REQUIRES: test "${ZEEK_USE_CPP}" != "1"
#
# It just needs to run without crashing. It generates a bunch of warnings but
# those aren't of interest here.
# @TEST-EXEC: zeek -b -O ZAM %INPUT
function g()
{
}
function gen0(f: function())
{
function[f]()
{
print f;
};
}
function genN(c: count)
{
switch c
{
case 0: gen0(g); break;
case 1: gen0(g); break;
case 2: gen0(g); break;
case 3: gen0(g); break;
case 4: gen0(g); break;
}
}
event zeek_init()
{
genN(3);
}

View file

@ -1,5 +1,8 @@
# Test that certificate event caching works as expected. # Test that certificate event caching works as expected.
# Can't use this test for -O gen-C++ because of multiple different Zeek runs.
# @TEST-REQUIRES: test "${ZEEK_USE_CPP}" != "1"
# @TEST-EXEC: zeek -b -r $TRACES/tls/google-duplicate.trace common.zeek google-duplicate.zeek # @TEST-EXEC: zeek -b -r $TRACES/tls/google-duplicate.trace common.zeek google-duplicate.zeek
# @TEST-EXEC: cat $TRACES/tls/tls-fragmented-handshake.pcap.gz | gunzip | zeek -b -r - common.zeek fragmented.zeek # @TEST-EXEC: cat $TRACES/tls/tls-fragmented-handshake.pcap.gz | gunzip | zeek -b -r - common.zeek fragmented.zeek
# @TEST-EXEC: zeek -b -r $TRACES/rdp/rdp-to-ssl.pcap common.zeek rdp.zeek # @TEST-EXEC: zeek -b -r $TRACES/rdp/rdp-to-ssl.pcap common.zeek rdp.zeek

View file

@ -1,3 +1,7 @@
# Can't use this test for -O gen-C++ because of multiple simultaneous
# Zeek runs.
# @TEST-REQUIRES: test "${ZEEK_USE_CPP}" != "1"
#
# @TEST-PORT: BROKER_MANAGER_PORT # @TEST-PORT: BROKER_MANAGER_PORT
# @TEST-PORT: BROKER_PROXY1_PORT # @TEST-PORT: BROKER_PROXY1_PORT
# @TEST-PORT: BROKER_PROXY2_PORT # @TEST-PORT: BROKER_PROXY2_PORT

View file

@ -1,3 +1,7 @@
# Can't use this test for -O gen-C++ because of multiple simultaneous
# Zeek runs.
# @TEST-REQUIRES: test "${ZEEK_USE_CPP}" != "1"
# @TEST-PORT: BROKER_PORT # @TEST-PORT: BROKER_PORT
# #
# @TEST-EXEC: btest-bg-run controllee ZEEKPATH=$ZEEKPATH:.. zeek -b %INPUT only-for-controllee frameworks/control/controllee Broker::default_port=$BROKER_PORT # @TEST-EXEC: btest-bg-run controllee ZEEKPATH=$ZEEKPATH:.. zeek -b %INPUT only-for-controllee frameworks/control/controllee Broker::default_port=$BROKER_PORT

View file

@ -1,3 +1,7 @@
# Can't use this test for -O gen-C++ because of multiple simultaneous
# Zeek runs.
# @TEST-REQUIRES: test "${ZEEK_USE_CPP}" != "1"
#
# @TEST-PORT: BROKER_PORT # @TEST-PORT: BROKER_PORT
# @TEST-EXEC: btest-bg-run recv "zeek -b ../recv.zeek >recv.out" # @TEST-EXEC: btest-bg-run recv "zeek -b ../recv.zeek >recv.out"
# @TEST-EXEC: btest-bg-run send "zeek -b -r $TRACES/tls/ecdhe.pcap --pseudo-realtime ../send.zeek >send.out" # @TEST-EXEC: btest-bg-run send "zeek -b -r $TRACES/tls/ecdhe.pcap --pseudo-realtime ../send.zeek >send.out"

View file

@ -1,3 +1,7 @@
# Can't use this test for -O gen-C++ because of multiple simultaneous
# Zeek runs.
# @TEST-REQUIRES: test "${ZEEK_USE_CPP}" != "1"
#
# @TEST-PORT: BROKER_PORT # @TEST-PORT: BROKER_PORT
# @TEST-EXEC: btest-bg-run recv "zeek -b ../recv.zeek >recv.out" # @TEST-EXEC: btest-bg-run recv "zeek -b ../recv.zeek >recv.out"
# @TEST-EXEC: btest-bg-run send "zeek -b -r $TRACES/tls/ecdhe.pcap --pseudo-realtime ../send.zeek >send.out" # @TEST-EXEC: btest-bg-run send "zeek -b -r $TRACES/tls/ecdhe.pcap --pseudo-realtime ../send.zeek >send.out"

View file

@ -1,3 +1,7 @@
# Can't use this test for -O gen-C++ because of multiple simultaneous
# Zeek runs.
# @TEST-REQUIRES: test "${ZEEK_USE_CPP}" != "1"
#
# @TEST-PORT: BROKER_PORT # @TEST-PORT: BROKER_PORT
# @TEST-EXEC: btest-bg-run recv "zeek -b ../recv.zeek >recv.out" # @TEST-EXEC: btest-bg-run recv "zeek -b ../recv.zeek >recv.out"
# @TEST-EXEC: btest-bg-run send "zeek -b -r $TRACES/smtp.trace --pseudo-realtime ../send.zeek >send.out" # @TEST-EXEC: btest-bg-run send "zeek -b -r $TRACES/smtp.trace --pseudo-realtime ../send.zeek >send.out"

View file

@ -1,3 +1,7 @@
# Can't use this test for -O gen-C++ because of multiple simultaneous
# Zeek runs.
# @TEST-REQUIRES: test "${ZEEK_USE_CPP}" != "1"
#
# @TEST-PORT: BROKER_PORT # @TEST-PORT: BROKER_PORT
# @TEST-EXEC: btest-bg-run recv "zeek -b ../recv.zeek >recv.out" # @TEST-EXEC: btest-bg-run recv "zeek -b ../recv.zeek >recv.out"
# @TEST-EXEC: btest-bg-run send "zeek -b -r $TRACES/smtp.trace --pseudo-realtime ../send.zeek >send.out" # @TEST-EXEC: btest-bg-run send "zeek -b -r $TRACES/smtp.trace --pseudo-realtime ../send.zeek >send.out"