mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Merge remote-tracking branch 'origin/topic/vern/zam-coverity'
* origin/topic/vern/zam-coverity: still more nit-squashing avoiding using back() for an empty std::string additional tweaks to address some compiler warnings tweaks to address some compiler warnings tweaks to address concerns flagged by Coverity
This commit is contained in:
commit
619af69e42
20 changed files with 125 additions and 57 deletions
12
CHANGES
12
CHANGES
|
@ -1,3 +1,15 @@
|
||||||
|
4.2.0-dev.165 | 2021-09-14 18:39:34 -0700
|
||||||
|
|
||||||
|
* still more nit-squashing (Vern Paxson, Corelight)
|
||||||
|
|
||||||
|
* avoiding using back() for an empty std::string (Vern Paxson, Corelight)
|
||||||
|
|
||||||
|
* additional tweaks to address some compiler warnings (Vern Paxson, Corelight)
|
||||||
|
|
||||||
|
* tweaks to address some compiler warnings (Vern Paxson, Corelight)
|
||||||
|
|
||||||
|
* tweaks to address concerns flagged by Coverity (Vern Paxson, Corelight)
|
||||||
|
|
||||||
4.2.0-dev.159 | 2021-09-14 13:00:50 -0700
|
4.2.0-dev.159 | 2021-09-14 13:00:50 -0700
|
||||||
|
|
||||||
* ignore_checksums_nets: Add test for multiple subnets (Arne Welzel, Corelight)
|
* ignore_checksums_nets: Add test for multiple subnets (Arne Welzel, Corelight)
|
||||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
||||||
4.2.0-dev.159
|
4.2.0-dev.165
|
||||||
|
|
|
@ -450,7 +450,7 @@ void GenIDDefs::EndConfluenceBlock(bool no_orig)
|
||||||
|
|
||||||
confluence_blocks.pop_back();
|
confluence_blocks.pop_back();
|
||||||
|
|
||||||
int bb = barrier_blocks.back();
|
auto bb = barrier_blocks.back();
|
||||||
if ( bb > 0 && confluence_blocks.size() == bb )
|
if ( bb > 0 && confluence_blocks.size() == bb )
|
||||||
barrier_blocks.pop_back();
|
barrier_blocks.pop_back();
|
||||||
|
|
||||||
|
@ -520,7 +520,7 @@ void GenIDDefs::TrackID(const ID* id, const ExprPtr& e)
|
||||||
|
|
||||||
// Ensure we track this identifier across all relevant
|
// Ensure we track this identifier across all relevant
|
||||||
// confluence regions.
|
// confluence regions.
|
||||||
for ( int i = barrier_blocks.back(); i < confluence_blocks.size(); ++i )
|
for ( auto i = barrier_blocks.back(); i < confluence_blocks.size(); ++i )
|
||||||
// Add one because modified_IDs includes outer non-confluence
|
// Add one because modified_IDs includes outer non-confluence
|
||||||
// block.
|
// block.
|
||||||
modified_IDs[i+1].insert(id);
|
modified_IDs[i+1].insert(id);
|
||||||
|
|
|
@ -99,7 +99,7 @@ private:
|
||||||
// unseen confluence regions outer to those, and (2) they
|
// unseen confluence regions outer to those, and (2) they
|
||||||
// can get quite deep due when inlining, so there are savings
|
// can get quite deep due when inlining, so there are savings
|
||||||
// to avoid having to track outer to them.
|
// to avoid having to track outer to them.
|
||||||
std::vector<int> barrier_blocks;
|
std::vector<bro_uint_t> barrier_blocks;
|
||||||
|
|
||||||
// The following is parallel to confluence_blocks except
|
// The following is parallel to confluence_blocks except
|
||||||
// the front entry tracks identifiers at the outermost
|
// the front entry tracks identifiers at the outermost
|
||||||
|
|
|
@ -71,7 +71,7 @@ void IDOptInfo::Clear()
|
||||||
|
|
||||||
void IDOptInfo::DefinedAfter(const Stmt* s, const ExprPtr& e,
|
void IDOptInfo::DefinedAfter(const Stmt* s, const ExprPtr& e,
|
||||||
const std::vector<const Stmt*>& conf_blocks,
|
const std::vector<const Stmt*>& conf_blocks,
|
||||||
int conf_start)
|
bro_uint_t conf_start)
|
||||||
{
|
{
|
||||||
if ( tracing )
|
if ( tracing )
|
||||||
printf("ID %s defined at %d: %s\n", trace_ID, s ? s->GetOptInfo()->stmt_num : NO_DEF, s ? obj_desc(s).c_str() : "<entry>");
|
printf("ID %s defined at %d: %s\n", trace_ID, s ? s->GetOptInfo()->stmt_num : NO_DEF, s ? obj_desc(s).c_str() : "<entry>");
|
||||||
|
@ -174,7 +174,7 @@ void IDOptInfo::BranchBackTo(const Stmt* from, const Stmt* to, bool close_all)
|
||||||
auto from_reg = ActiveRegion();
|
auto from_reg = ActiveRegion();
|
||||||
auto f_oi = from->GetOptInfo();
|
auto f_oi = from->GetOptInfo();
|
||||||
auto t_oi = to->GetOptInfo();
|
auto t_oi = to->GetOptInfo();
|
||||||
auto t_r_ind = FindRegionBeforeIndex(t_oi->stmt_num);
|
bro_uint_t t_r_ind = FindRegionBeforeIndex(t_oi->stmt_num);
|
||||||
auto& t_r = usage_regions[t_r_ind];
|
auto& t_r = usage_regions[t_r_ind];
|
||||||
|
|
||||||
if ( from_reg && from_reg->DefinedAfter() != t_r.DefinedAfter() &&
|
if ( from_reg && from_reg->DefinedAfter() != t_r.DefinedAfter() &&
|
||||||
|
@ -327,7 +327,7 @@ void IDOptInfo::ConfluenceBlockEndsAfter(const Stmt* s, bool no_orig_flow)
|
||||||
|
|
||||||
int num_regions = 0;
|
int num_regions = 0;
|
||||||
|
|
||||||
for ( auto i = 0; i < usage_regions.size(); ++i )
|
for ( auto i = 0U; i < usage_regions.size(); ++i )
|
||||||
{
|
{
|
||||||
auto& ur = usage_regions[i];
|
auto& ur = usage_regions[i];
|
||||||
|
|
||||||
|
@ -480,7 +480,7 @@ void IDOptInfo::EndRegionsAfter(int stmt_num, int level)
|
||||||
int IDOptInfo::FindRegionBeforeIndex(int stmt_num)
|
int IDOptInfo::FindRegionBeforeIndex(int stmt_num)
|
||||||
{
|
{
|
||||||
int region_ind = NO_DEF;
|
int region_ind = NO_DEF;
|
||||||
for ( auto i = 0; i < usage_regions.size(); ++i )
|
for ( auto i = 0U; i < usage_regions.size(); ++i )
|
||||||
{
|
{
|
||||||
auto ur = usage_regions[i];
|
auto ur = usage_regions[i];
|
||||||
|
|
||||||
|
|
|
@ -142,7 +142,7 @@ public:
|
||||||
// conf_blocks may be empty).
|
// conf_blocks may be empty).
|
||||||
void DefinedAfter(const Stmt* s, const ExprPtr& e,
|
void DefinedAfter(const Stmt* s, const ExprPtr& e,
|
||||||
const std::vector<const Stmt*>& conf_blocks,
|
const std::vector<const Stmt*>& conf_blocks,
|
||||||
int conf_start);
|
bro_uint_t conf_start);
|
||||||
|
|
||||||
// Called upon encountering a "return" statement.
|
// Called upon encountering a "return" statement.
|
||||||
void ReturnAt(const Stmt* s);
|
void ReturnAt(const Stmt* s);
|
||||||
|
|
|
@ -484,7 +484,7 @@ void ZAMCompiler::ReMapFrame()
|
||||||
frame1_to_frame2.resize(frame_layout1.size(), -1);
|
frame1_to_frame2.resize(frame_layout1.size(), -1);
|
||||||
managed_slotsI.clear();
|
managed_slotsI.clear();
|
||||||
|
|
||||||
for ( unsigned int i = 0; i < insts1.size(); ++i )
|
for ( bro_uint_t i = 0; i < insts1.size(); ++i )
|
||||||
{
|
{
|
||||||
auto inst = insts1[i];
|
auto inst = insts1[i];
|
||||||
|
|
||||||
|
@ -659,7 +659,7 @@ void ZAMCompiler::ReMapInterpreterFrame()
|
||||||
remapped_intrp_frame_sizes[func] = next_interp_slot;
|
remapped_intrp_frame_sizes[func] = next_interp_slot;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZAMCompiler::ReMapVar(ID* id, int slot, int inst)
|
void ZAMCompiler::ReMapVar(ID* id, int slot, bro_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
|
||||||
|
@ -686,9 +686,10 @@ void ZAMCompiler::ReMapVar(ID* id, int slot, int inst)
|
||||||
// ZAM instructions are careful to allow operands and
|
// ZAM instructions are careful to allow operands and
|
||||||
// assignment destinations to refer to the same slot.
|
// assignment destinations to refer to the same slot.
|
||||||
|
|
||||||
if ( s.scope_end <= inst && s.is_managed == is_managed )
|
if ( s.scope_end <= static_cast<int>(inst) &&
|
||||||
|
s.is_managed == is_managed )
|
||||||
{ // It's compatible.
|
{ // It's compatible.
|
||||||
if ( s.scope_end == inst )
|
if ( s.scope_end == static_cast<int>(inst) )
|
||||||
{ // It ends right on the money.
|
{ // It ends right on the money.
|
||||||
apt_slot = i;
|
apt_slot = i;
|
||||||
break;
|
break;
|
||||||
|
@ -727,7 +728,8 @@ void ZAMCompiler::ReMapVar(ID* id, int slot, int inst)
|
||||||
|
|
||||||
void ZAMCompiler::CheckSlotAssignment(int slot, const ZInstI* inst)
|
void ZAMCompiler::CheckSlotAssignment(int slot, const ZInstI* inst)
|
||||||
{
|
{
|
||||||
ASSERT(slot >= 0 && slot < frame_denizens.size());
|
ASSERT(slot >= 0 &&
|
||||||
|
static_cast<bro_uint_t>(slot) < frame_denizens.size());
|
||||||
|
|
||||||
// We construct temporaries such that their values are never used
|
// We construct temporaries such that their values are never used
|
||||||
// earlier than their definitions in loop bodies. For other
|
// earlier than their definitions in loop bodies. For other
|
||||||
|
@ -766,7 +768,7 @@ void ZAMCompiler::CheckSlotUse(int slot, const ZInstI* inst)
|
||||||
if ( slot < 0 )
|
if ( slot < 0 )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ASSERT(slot < frame_denizens.size());
|
ASSERT(static_cast<bro_uint_t>(slot) < frame_denizens.size());
|
||||||
|
|
||||||
if ( denizen_beginning.count(slot) == 0 )
|
if ( denizen_beginning.count(slot) == 0 )
|
||||||
{
|
{
|
||||||
|
@ -952,9 +954,9 @@ ZInstI* ZAMCompiler::FirstLiveInst(ZInstI* i, bool follow_gotos)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ZAMCompiler::FirstLiveInst(int i, bool follow_gotos)
|
bro_uint_t ZAMCompiler::FirstLiveInst(bro_uint_t i, bool follow_gotos)
|
||||||
{
|
{
|
||||||
int num_inspected = 0;
|
bro_uint_t num_inspected = 0;
|
||||||
while ( i < insts1.size() )
|
while ( i < insts1.size() )
|
||||||
{
|
{
|
||||||
auto i0 = insts1[i];
|
auto i0 = insts1[i];
|
||||||
|
@ -982,7 +984,7 @@ int ZAMCompiler::FirstLiveInst(int i, bool follow_gotos)
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZAMCompiler::KillInst(int i)
|
void ZAMCompiler::KillInst(bro_uint_t i)
|
||||||
{
|
{
|
||||||
auto inst = insts1[i];
|
auto inst = insts1[i];
|
||||||
|
|
||||||
|
@ -1007,6 +1009,8 @@ void ZAMCompiler::KillInst(int i)
|
||||||
|
|
||||||
if ( inst->IsUnconditionalBranch() )
|
if ( inst->IsUnconditionalBranch() )
|
||||||
{
|
{
|
||||||
|
ASSERT(t);
|
||||||
|
|
||||||
// No direct flow after this point ... unless we're
|
// No direct flow after this point ... unless we're
|
||||||
// branching to the next immediate live instruction.
|
// branching to the next immediate live instruction.
|
||||||
auto after_inst = NextLiveInst(inst, true);
|
auto after_inst = NextLiveInst(inst, true);
|
||||||
|
@ -1035,7 +1039,7 @@ void ZAMCompiler::KillInst(int i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZAMCompiler::KillInsts(int i)
|
void ZAMCompiler::KillInsts(bro_uint_t i)
|
||||||
{
|
{
|
||||||
auto inst = insts1[i];
|
auto inst = insts1[i];
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ ZInstI* ZAMCompiler::FindLiveTarget(ZInstI* goto_target)
|
||||||
return goto_target;
|
return goto_target;
|
||||||
|
|
||||||
int idx = goto_target->inst_num;
|
int idx = goto_target->inst_num;
|
||||||
ASSERT(idx >= 0 && idx <= insts1.size());
|
ASSERT(idx >= 0 && idx <= int(insts1.size()));
|
||||||
|
|
||||||
while ( idx < int(insts1.size()) && ! insts1[idx]->live )
|
while ( idx < int(insts1.size()) && ! insts1[idx]->live )
|
||||||
++idx;
|
++idx;
|
||||||
|
|
|
@ -371,21 +371,25 @@ bool ZAMCompiler::BuiltIn_sub_bytes(const NameExpr* n, const ExprPList& args)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x4: // first argument a constant
|
case 0x4: // first argument a constant
|
||||||
|
ASSERT(c);
|
||||||
z = ZInstI(OP_SUB_BYTES_VVVC, nslot, v3, v4, c);
|
z = ZInstI(OP_SUB_BYTES_VVVC, nslot, v3, v4, c);
|
||||||
z.op_type = OP_VVVC;
|
z.op_type = OP_VVVC;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x5: // first and third constant
|
case 0x5: // first and third constant
|
||||||
|
ASSERT(c);
|
||||||
z = ZInstI(OP_SUB_BYTES_VViC, nslot, v3, v4, c);
|
z = ZInstI(OP_SUB_BYTES_VViC, nslot, v3, v4, c);
|
||||||
z.op_type = OP_VVVC_I3;
|
z.op_type = OP_VVVC_I3;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x6: // first and second constant - flip!
|
case 0x6: // first and second constant - flip!
|
||||||
|
ASSERT(c);
|
||||||
z = ZInstI(OP_SUB_BYTES_ViVC, nslot, v4, v3, c);
|
z = ZInstI(OP_SUB_BYTES_ViVC, nslot, v4, v3, c);
|
||||||
z.op_type = OP_VVVC_I3;
|
z.op_type = OP_VVVC_I3;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 0x7: // whole shebang
|
case 0x7: // whole shebang
|
||||||
|
ASSERT(c);
|
||||||
z = ZInstI(OP_SUB_BYTES_ViiC, nslot, v3, v4, c);
|
z = ZInstI(OP_SUB_BYTES_ViiC, nslot, v3, v4, c);
|
||||||
z.op_type = OP_VVVC_I2_I3;
|
z.op_type = OP_VVVC_I2_I3;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -183,7 +183,7 @@ private:
|
||||||
const ZAMStmt LoopOverVector(const ForStmt* f, const NameExpr* val);
|
const ZAMStmt LoopOverVector(const ForStmt* f, const NameExpr* val);
|
||||||
const ZAMStmt LoopOverString(const ForStmt* f, const Expr* e);
|
const ZAMStmt LoopOverString(const ForStmt* f, const Expr* e);
|
||||||
|
|
||||||
const ZAMStmt FinishLoop(const ZAMStmt iter_head, ZInstI iter_stmt,
|
const ZAMStmt FinishLoop(const ZAMStmt iter_head, ZInstI& iter_stmt,
|
||||||
const Stmt* body, int iter_slot,
|
const Stmt* body, int iter_slot,
|
||||||
bool is_table);
|
bool is_table);
|
||||||
|
|
||||||
|
@ -450,7 +450,7 @@ private:
|
||||||
|
|
||||||
// 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(ID* id, int slot, int inst);
|
void ReMapVar(ID* id, int slot, bro_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.
|
||||||
|
@ -494,12 +494,12 @@ private:
|
||||||
// First form returns nil if there's nothing live after i.
|
// First form returns nil if there's nothing live after i.
|
||||||
// Second form returns insts1.size() in that case.
|
// Second form returns insts1.size() in that case.
|
||||||
ZInstI* FirstLiveInst(ZInstI* i, bool follow_gotos = false);
|
ZInstI* FirstLiveInst(ZInstI* i, bool follow_gotos = false);
|
||||||
int FirstLiveInst(int i, bool follow_gotos = false);
|
bro_uint_t FirstLiveInst(bro_uint_t i, bool follow_gotos = false);
|
||||||
|
|
||||||
// Same, but not including i.
|
// Same, but not including i.
|
||||||
ZInstI* NextLiveInst(ZInstI* i, bool follow_gotos = false)
|
ZInstI* NextLiveInst(ZInstI* i, bool follow_gotos = false)
|
||||||
{
|
{
|
||||||
if ( i->inst_num == insts1.size() - 1 )
|
if ( i->inst_num == static_cast<int>(insts1.size()) - 1 )
|
||||||
return nullptr;
|
return nullptr;
|
||||||
return FirstLiveInst(insts1[i->inst_num + 1], follow_gotos);
|
return FirstLiveInst(insts1[i->inst_num + 1], follow_gotos);
|
||||||
}
|
}
|
||||||
|
@ -511,12 +511,12 @@ private:
|
||||||
// into insts1; any labels associated with it are transferred
|
// into insts1; any labels associated with it are transferred
|
||||||
// to its next live successor, if any.
|
// to its next live successor, if any.
|
||||||
void KillInst(ZInstI* i) { KillInst(i->inst_num); }
|
void KillInst(ZInstI* i) { KillInst(i->inst_num); }
|
||||||
void KillInst(int i);
|
void KillInst(bro_uint_t i);
|
||||||
|
|
||||||
// The same, but kills any successor instructions until finding
|
// The same, but kills any successor instructions until finding
|
||||||
// one that's labeled.
|
// one that's labeled.
|
||||||
void KillInsts(ZInstI* i) { KillInsts(i->inst_num); }
|
void KillInsts(ZInstI* i) { KillInsts(i->inst_num); }
|
||||||
void KillInsts(int i);
|
void KillInsts(bro_uint_t i);
|
||||||
|
|
||||||
// The first of these is used as we compile down to ZInstI's.
|
// The first of these is used as we compile down to ZInstI's.
|
||||||
// The second is the final intermediary code. They're separate
|
// The second is the final intermediary code. They're separate
|
||||||
|
|
|
@ -315,7 +315,7 @@ void ZAMCompiler::RemapFrameDenizens(const std::vector<int>& inst1_to_inst2)
|
||||||
// the form "slotX = slotX". In that
|
// the form "slotX = slotX". In that
|
||||||
// case, look forward for the next viable
|
// case, look forward for the next viable
|
||||||
// instruction.
|
// instruction.
|
||||||
while ( start < int(insts1.size()) &&
|
while ( start < insts1.size() &&
|
||||||
inst1_to_inst2[start] == -1 )
|
inst1_to_inst2[start] == -1 )
|
||||||
++start;
|
++start;
|
||||||
|
|
||||||
|
|
|
@ -105,6 +105,7 @@ const ZAMStmt ZAMCompiler::AppendToField(const NameExpr* n1, const NameExpr* n2,
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
ASSERT(c);
|
||||||
z = ZInstI(OP_APPENDTOFIELD_VCi, FrameSlot(n1), offset, c);
|
z = ZInstI(OP_APPENDTOFIELD_VCi, FrameSlot(n1), offset, c);
|
||||||
z.op_type = OP_VVC_I2;
|
z.op_type = OP_VVC_I2;
|
||||||
}
|
}
|
||||||
|
@ -547,6 +548,8 @@ const ZAMStmt ZAMCompiler::CompileInExpr(const NameExpr* n1, const ListExpr* l,
|
||||||
|
|
||||||
else if ( l_e0_n )
|
else if ( l_e0_n )
|
||||||
{
|
{
|
||||||
|
ASSERT(l_e1_c);
|
||||||
|
|
||||||
z = GenInst(OP_VAL2_IS_IN_TABLE_VVVC,
|
z = GenInst(OP_VAL2_IS_IN_TABLE_VVVC,
|
||||||
n1, l_e0_n, n2, l_e1_c);
|
n1, l_e0_n, n2, l_e1_c);
|
||||||
z.t2 = l_e0_n->GetType();
|
z.t2 = l_e0_n->GetType();
|
||||||
|
@ -554,6 +557,8 @@ const ZAMStmt ZAMCompiler::CompileInExpr(const NameExpr* n1, const ListExpr* l,
|
||||||
|
|
||||||
else if ( l_e1_n )
|
else if ( l_e1_n )
|
||||||
{
|
{
|
||||||
|
ASSERT(l_e0_c);
|
||||||
|
|
||||||
z = GenInst(OP_VAL2_IS_IN_TABLE_VVCV,
|
z = GenInst(OP_VAL2_IS_IN_TABLE_VVCV,
|
||||||
n1, l_e1_n, n2, l_e0_c);
|
n1, l_e1_n, n2, l_e0_c);
|
||||||
z.t2 = l_e1_n->GetType();
|
z.t2 = l_e1_n->GetType();
|
||||||
|
@ -563,6 +568,9 @@ const ZAMStmt ZAMCompiler::CompileInExpr(const NameExpr* n1, const ListExpr* l,
|
||||||
{
|
{
|
||||||
// Ugh, both are constants. Assign first to
|
// Ugh, both are constants. Assign first to
|
||||||
// a temporary.
|
// a temporary.
|
||||||
|
ASSERT(l_e0_c);
|
||||||
|
ASSERT(l_e1_c);
|
||||||
|
|
||||||
auto slot = TempForConst(l_e0_c);
|
auto slot = TempForConst(l_e0_c);
|
||||||
z = ZInstI(OP_VAL2_IS_IN_TABLE_VVVC, FrameSlot(n1),
|
z = ZInstI(OP_VAL2_IS_IN_TABLE_VVVC, FrameSlot(n1),
|
||||||
slot, FrameSlot(n2), l_e1_c);
|
slot, FrameSlot(n2), l_e1_c);
|
||||||
|
@ -687,6 +695,8 @@ const ZAMStmt ZAMCompiler::CompileIndex(const NameExpr* n1, int n2_slot,
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
ASSERT(c3);
|
||||||
|
|
||||||
auto zop = AssignmentFlavor(OP_TABLE_INDEX1_VVC,
|
auto zop = AssignmentFlavor(OP_TABLE_INDEX1_VVC,
|
||||||
n1->GetType()->Tag());
|
n1->GetType()->Tag());
|
||||||
z = ZInstI(zop, Frame1Slot(n1, zop),
|
z = ZInstI(zop, Frame1Slot(n1, zop),
|
||||||
|
@ -911,16 +921,22 @@ const ZAMStmt ZAMCompiler::DoCall(const CallExpr* c, const NameExpr* n)
|
||||||
z = ZInstI(AssignmentFlavor(OP_CALL1_VV, nt),
|
z = ZInstI(AssignmentFlavor(OP_CALL1_VV, nt),
|
||||||
n_slot, FrameSlot(n0));
|
n_slot, FrameSlot(n0));
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
ASSERT(c0);
|
||||||
z = ZInstI(AssignmentFlavor(OP_CALL1_VC, nt),
|
z = ZInstI(AssignmentFlavor(OP_CALL1_VC, nt),
|
||||||
n_slot, c0);
|
n_slot, c0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ( n0 )
|
if ( n0 )
|
||||||
z = ZInstI(OP_CALL1_V, FrameSlot(n0));
|
z = ZInstI(OP_CALL1_V, FrameSlot(n0));
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
ASSERT(c0);
|
||||||
z = ZInstI(OP_CALL1_C, c0);
|
z = ZInstI(OP_CALL1_C, c0);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
z.t = arg0->GetType();
|
z.t = arg0->GetType();
|
||||||
}
|
}
|
||||||
|
@ -1170,7 +1186,7 @@ const ZAMStmt ZAMCompiler::RecordCoerce(const NameExpr* n, const Expr* e)
|
||||||
z.aux = new ZInstAux(map_size);
|
z.aux = new ZInstAux(map_size);
|
||||||
z.aux->map = map;
|
z.aux->map = map;
|
||||||
|
|
||||||
for ( auto i = 0; i < map_size; ++i )
|
for ( auto i = 0U; i < map_size; ++i )
|
||||||
z.aux->Add(i, map[i], nullptr);
|
z.aux->Add(i, map[i], nullptr);
|
||||||
|
|
||||||
// Mark the integer entries in z.aux as not being frame slots as usual.
|
// Mark the integer entries in z.aux as not being frame slots as usual.
|
||||||
|
|
|
@ -923,7 +923,7 @@ void ZAM_ExprOpTemplate::Parse(const string& attr, const string& line,
|
||||||
if ( words.size() == 1 )
|
if ( words.size() == 1 )
|
||||||
g->Gripe("op-type needs arguments", line);
|
g->Gripe("op-type needs arguments", line);
|
||||||
|
|
||||||
for ( auto i = 1; i < words.size(); ++i )
|
for ( auto i = 1U; i < words.size(); ++i )
|
||||||
{
|
{
|
||||||
auto& w_i = words[i];
|
auto& w_i = words[i];
|
||||||
if ( w_i.size() != 1 )
|
if ( w_i.size() != 1 )
|
||||||
|
@ -1023,7 +1023,7 @@ void ZAM_ExprOpTemplate::Instantiate()
|
||||||
InstantiateC3(op_types);
|
InstantiateC3(op_types);
|
||||||
|
|
||||||
bool all_var = true;
|
bool all_var = true;
|
||||||
for ( auto i = 1; i < op_types.size(); ++i )
|
for ( auto i = 1U; i < op_types.size(); ++i )
|
||||||
if ( op_types[i] != ZAM_OT_VAR )
|
if ( op_types[i] != ZAM_OT_VAR )
|
||||||
all_var = false;
|
all_var = false;
|
||||||
|
|
||||||
|
@ -2101,7 +2101,7 @@ void ZAMGen::Emit(EmitTarget et, const string& s)
|
||||||
|
|
||||||
fputs(s.c_str(), f);
|
fputs(s.c_str(), f);
|
||||||
|
|
||||||
if ( s.back() != '\n' && ! no_NL )
|
if ( ! no_NL && (s.empty() || s.back() != '\n') )
|
||||||
fputs("\n", f);
|
fputs("\n", f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2272,6 +2272,15 @@ bool ZAMGen::ParseTemplate()
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
ZAMGen(argc, argv);
|
try
|
||||||
|
{
|
||||||
|
ZAMGen zg(argc, argv);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
catch ( const std::regex_error& e )
|
||||||
|
{
|
||||||
|
fprintf(stderr, "%s: regular expression error - %s\n",
|
||||||
|
argv[0], e.what());
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -90,7 +90,7 @@ private:
|
||||||
const TableVal* tv = nullptr;
|
const TableVal* tv = nullptr;
|
||||||
|
|
||||||
// Associated auxiliary information.
|
// Associated auxiliary information.
|
||||||
ZInstAux* aux;
|
ZInstAux* aux = nullptr;
|
||||||
|
|
||||||
std::optional<DictIterator> tbl_iter;
|
std::optional<DictIterator> tbl_iter;
|
||||||
std::optional<DictIterator> tbl_end;
|
std::optional<DictIterator> tbl_end;
|
||||||
|
|
|
@ -791,13 +791,13 @@ internal-op Val-Is-In-Vector
|
||||||
type VVV
|
type VVV
|
||||||
eval auto& vec = frame[z.v3].vector_val;
|
eval auto& vec = frame[z.v3].vector_val;
|
||||||
auto ind = frame[z.v2].int_val;
|
auto ind = frame[z.v2].int_val;
|
||||||
frame[z.v1].int_val = ind >= 0 && ind < vec->Size();
|
frame[z.v1].int_val = ind >= 0 && static_cast<bro_uint_t>(ind) < vec->Size();
|
||||||
|
|
||||||
internal-op Const-Is-In-Vector
|
internal-op Const-Is-In-Vector
|
||||||
type VCV
|
type VCV
|
||||||
eval auto& vec = frame[z.v2].vector_val;
|
eval auto& vec = frame[z.v2].vector_val;
|
||||||
auto ind = z.c.int_val;
|
auto ind = z.c.int_val;
|
||||||
frame[z.v1].int_val = ind >= 0 && ind < vec->Size();
|
frame[z.v1].int_val = ind >= 0 && static_cast<bro_uint_t>(ind) < vec->Size();
|
||||||
|
|
||||||
expr-op Cond
|
expr-op Cond
|
||||||
type VVVV
|
type VVVV
|
||||||
|
@ -902,7 +902,7 @@ eval EvalIndexVec(frame[z.v3].uint_val)
|
||||||
macro EvalIndexVec(index)
|
macro EvalIndexVec(index)
|
||||||
auto vv = frame[z.v2].vector_val->RawVec();
|
auto vv = frame[z.v2].vector_val->RawVec();
|
||||||
const auto& vec = *vv;
|
const auto& vec = *vv;
|
||||||
auto ind = index;
|
bro_uint_t ind = index;
|
||||||
if ( ind >= vv->size() )
|
if ( ind >= vv->size() )
|
||||||
ZAM_run_time_error(z.loc, "no such index");
|
ZAM_run_time_error(z.loc, "no such index");
|
||||||
AssignV1(CopyVal(*vec[ind]))
|
AssignV1(CopyVal(*vec[ind]))
|
||||||
|
@ -917,7 +917,7 @@ eval EvalIndexAnyVec(frame[z.v3].uint_val)
|
||||||
|
|
||||||
macro EvalIndexAnyVec(index)
|
macro EvalIndexAnyVec(index)
|
||||||
auto vv = frame[z.v2].vector_val;
|
auto vv = frame[z.v2].vector_val;
|
||||||
auto ind = index;
|
bro_uint_t ind = index;
|
||||||
if ( ind >= vv->Size() )
|
if ( ind >= vv->Size() )
|
||||||
ZAM_run_time_error(z.loc, "no such index");
|
ZAM_run_time_error(z.loc, "no such index");
|
||||||
AssignV1(ZVal(vv->ValAt(ind).release()))
|
AssignV1(ZVal(vv->ValAt(ind).release()))
|
||||||
|
@ -1749,7 +1749,7 @@ op CheckAnyLen
|
||||||
op1-read
|
op1-read
|
||||||
type Vi
|
type Vi
|
||||||
eval auto v = frame[z.v1].list_val;
|
eval auto v = frame[z.v1].list_val;
|
||||||
if ( v->Vals().size() != z.v2 )
|
if ( v->Vals().size() != static_cast<bro_uint_t>(z.v2) )
|
||||||
ZAM_run_time_error(z.loc, "mismatch in list lengths");
|
ZAM_run_time_error(z.loc, "mismatch in list lengths");
|
||||||
|
|
||||||
op Print
|
op Print
|
||||||
|
|
|
@ -530,6 +530,7 @@ const ZAMStmt ZAMCompiler::ValueSwitch(const SwitchStmt* sw, const NameExpr* v,
|
||||||
auto sv = cv->AsString()->Render();
|
auto sv = cv->AsString()->Render();
|
||||||
std::string s(sv);
|
std::string s(sv);
|
||||||
new_str_cases[s] = case_body_start;
|
new_str_cases[s] = case_body_start;
|
||||||
|
delete[] sv;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -806,7 +807,7 @@ const ZAMStmt ZAMCompiler::LoopOverTable(const ForStmt* f, const NameExpr* val)
|
||||||
|
|
||||||
auto aux = new ZInstAux(0);
|
auto aux = new ZInstAux(0);
|
||||||
|
|
||||||
for ( int i = 0; i < loop_vars->length(); ++i )
|
for ( auto i = 0; i < loop_vars->length(); ++i )
|
||||||
{
|
{
|
||||||
auto id = (*loop_vars)[i];
|
auto id = (*loop_vars)[i];
|
||||||
|
|
||||||
|
@ -897,6 +898,7 @@ const ZAMStmt ZAMCompiler::LoopOverString(const ForStmt* f, const Expr* e)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
ASSERT(c);
|
||||||
z = ZInstI(OP_INIT_STRING_LOOP_VC, iter_slot, c);
|
z = ZInstI(OP_INIT_STRING_LOOP_VC, iter_slot, c);
|
||||||
z.op_type = OP_VC_I1;
|
z.op_type = OP_VC_I1;
|
||||||
}
|
}
|
||||||
|
@ -926,9 +928,9 @@ const ZAMStmt ZAMCompiler::Loop(const Stmt* body)
|
||||||
return tail;
|
return tail;
|
||||||
}
|
}
|
||||||
|
|
||||||
const ZAMStmt ZAMCompiler::FinishLoop(const ZAMStmt iter_head, ZInstI iter_stmt,
|
const ZAMStmt ZAMCompiler::FinishLoop(const ZAMStmt iter_head,
|
||||||
const Stmt* body, int iter_slot,
|
ZInstI& iter_stmt, const Stmt* body,
|
||||||
bool is_table)
|
int iter_slot, bool is_table)
|
||||||
{
|
{
|
||||||
auto loop_iter = AddInst(iter_stmt);
|
auto loop_iter = AddInst(iter_stmt);
|
||||||
auto body_end = CompileStmt(body);
|
auto body_end = CompileStmt(body);
|
||||||
|
|
|
@ -49,7 +49,8 @@ void report_ZOP_profile()
|
||||||
// assigned value was missing (which we can only tell for managed types),
|
// assigned value was missing (which we can only tell for managed types),
|
||||||
// true otherwise.
|
// true otherwise.
|
||||||
|
|
||||||
static bool copy_vec_elem(VectorVal* vv, int ind, ZVal zv, const TypePtr& t)
|
static bool copy_vec_elem(VectorVal* vv, bro_uint_t ind, ZVal zv,
|
||||||
|
const TypePtr& t)
|
||||||
{
|
{
|
||||||
if ( vv->Size() <= ind )
|
if ( vv->Size() <= ind )
|
||||||
vv->Resize(ind + 1);
|
vv->Resize(ind + 1);
|
||||||
|
@ -263,7 +264,7 @@ ValPtr ZBody::DoExec(Frame* f, int start_pc, StmtFlowType& flow)
|
||||||
const int end_pc = ninst;
|
const int end_pc = ninst;
|
||||||
|
|
||||||
// Return value, or nil if none.
|
// Return value, or nil if none.
|
||||||
const ZVal* ret_u;
|
const ZVal* ret_u = nullptr;
|
||||||
|
|
||||||
// Type of the return value. If nil, then we don't have a value.
|
// Type of the return value. If nil, then we don't have a value.
|
||||||
TypePtr ret_type;
|
TypePtr ret_type;
|
||||||
|
|
|
@ -9,7 +9,7 @@ using std::string;
|
||||||
|
|
||||||
namespace zeek::detail {
|
namespace zeek::detail {
|
||||||
|
|
||||||
void ZInst::Dump(int inst_num, const FrameReMap* mappings) const
|
void ZInst::Dump(bro_uint_t inst_num, const FrameReMap* mappings) const
|
||||||
{
|
{
|
||||||
// printf("v%d ", n);
|
// printf("v%d ", n);
|
||||||
|
|
||||||
|
@ -170,6 +170,8 @@ int ZInst::NumFrameSlots() const
|
||||||
case OP_VVVV:
|
case OP_VVVV:
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ZInst::NumSlots() const
|
int ZInst::NumSlots() const
|
||||||
|
@ -208,9 +210,11 @@ int ZInst::NumSlots() const
|
||||||
case OP_VVVV_I2_I3_I4:
|
case OP_VVVV_I2_I3_I4:
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
string ZInst::VName(int n, int inst_num, const FrameReMap* mappings) const
|
string ZInst::VName(int n, bro_uint_t inst_num, const FrameReMap* mappings) const
|
||||||
{
|
{
|
||||||
if ( n > NumFrameSlots() )
|
if ( n > NumFrameSlots() )
|
||||||
return "";
|
return "";
|
||||||
|
@ -221,7 +225,7 @@ string ZInst::VName(int n, int inst_num, const FrameReMap* mappings) const
|
||||||
return "<special>";
|
return "<special>";
|
||||||
|
|
||||||
// Find which identifier manifests at this instruction.
|
// Find which identifier manifests at this instruction.
|
||||||
ASSERT(slot >= 0 && slot < mappings->size());
|
ASSERT(slot >= 0 && static_cast<bro_uint_t>(slot) < mappings->size());
|
||||||
|
|
||||||
auto& map = (*mappings)[slot];
|
auto& map = (*mappings)[slot];
|
||||||
|
|
||||||
|
@ -278,6 +282,8 @@ ValPtr ZInst::ConstVal() const
|
||||||
case OP_VVVV_I2_I3_I4:
|
case OP_VVVV_I2_I3_I4:
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
string ZInst::ConstDump() const
|
string ZInst::ConstDump() const
|
||||||
|
@ -321,16 +327,18 @@ string ZInstI::VName(int n, const FrameMap* frame_ids,
|
||||||
|
|
||||||
if ( remappings && live )
|
if ( remappings && live )
|
||||||
{ // Find which identifier manifests at this instruction.
|
{ // Find which identifier manifests at this instruction.
|
||||||
ASSERT(slot >= 0 && slot < remappings->size());
|
ASSERT(slot >= 0 &&
|
||||||
|
static_cast<bro_uint_t>(slot) < remappings->size());
|
||||||
|
|
||||||
auto& map = (*remappings)[slot];
|
auto& map = (*remappings)[slot];
|
||||||
|
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
auto inst_num_u = static_cast<bro_uint_t>(inst_num);
|
||||||
for ( i = 0; i < map.id_start.size(); ++i )
|
for ( i = 0; i < map.id_start.size(); ++i )
|
||||||
{
|
{
|
||||||
// See discussion for ZInst::VName.
|
// See discussion for ZInst::VName.
|
||||||
if ( (n == 1 && map.id_start[i] > inst_num) ||
|
if ( (n == 1 && map.id_start[i] > inst_num_u) ||
|
||||||
(n > 1 && map.id_start[i] >= inst_num) )
|
(n > 1 && map.id_start[i] >= inst_num_u) )
|
||||||
// Went too far.
|
// Went too far.
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -431,6 +439,8 @@ bool ZInstI::AssignsToSlot1() const
|
||||||
auto fl = op1_flavor[op];
|
auto fl = op1_flavor[op];
|
||||||
return fl == OP1_WRITE || fl == OP1_READ_WRITE;
|
return fl == OP1_WRITE || fl == OP1_READ_WRITE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZInstI::UsesSlot(int slot) const
|
bool ZInstI::UsesSlot(int slot) const
|
||||||
|
@ -473,6 +483,8 @@ bool ZInstI::UsesSlot(int slot) const
|
||||||
case OP_VVVV:
|
case OP_VVVV:
|
||||||
return v1_match || v2 == slot || v3 == slot || v4 == slot;
|
return v1_match || v2 == slot || v3 == slot || v4 == slot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ZInstI::UsesSlots(int& s1, int& s2, int& s3, int& s4) const
|
bool ZInstI::UsesSlots(int& s1, int& s2, int& s3, int& s4) const
|
||||||
|
@ -538,6 +550,8 @@ bool ZInstI::UsesSlots(int& s1, int& s2, int& s3, int& s4) const
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZInstI::UpdateSlots(std::vector<int>& slot_mapping)
|
void ZInstI::UpdateSlots(std::vector<int>& slot_mapping)
|
||||||
|
|
|
@ -35,14 +35,14 @@ public:
|
||||||
|
|
||||||
// The ZAM instruction number where a given identifier starts its
|
// The ZAM instruction number where a given identifier starts its
|
||||||
// scope, parallel to "ids".
|
// scope, parallel to "ids".
|
||||||
std::vector<int> id_start;
|
std::vector<bro_uint_t> id_start;
|
||||||
|
|
||||||
// The current end of the frame slot's scope. Gets updated as
|
// The current end of the frame slot's scope. Gets updated as
|
||||||
// new IDs are added to share the slot.
|
// new IDs are added to share the slot.
|
||||||
int scope_end;
|
int scope_end = -1;
|
||||||
|
|
||||||
// Whether this is a managed slot.
|
// Whether this is a managed slot.
|
||||||
bool is_managed;
|
bool is_managed = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
using FrameReMap = std::vector<FrameSharingInfo>;
|
using FrameReMap = std::vector<FrameSharingInfo>;
|
||||||
|
@ -66,7 +66,7 @@ public:
|
||||||
virtual ~ZInst() { }
|
virtual ~ZInst() { }
|
||||||
|
|
||||||
// Methods for printing out the instruction for debugging/maintenance.
|
// Methods for printing out the instruction for debugging/maintenance.
|
||||||
void Dump(int inst_num, const FrameReMap* mappings) const;
|
void Dump(bro_uint_t inst_num, const FrameReMap* mappings) const;
|
||||||
void Dump(const std::string& id1, const std::string& id2,
|
void Dump(const std::string& id1, const std::string& id2,
|
||||||
const std::string& id3, const std::string& id4) const;
|
const std::string& id3, const std::string& id4) const;
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ public:
|
||||||
// by its number within a larger set. "mappings" provides the
|
// by its number within a larger set. "mappings" provides the
|
||||||
// mappings used to translate raw slots to the corresponding
|
// mappings used to translate raw slots to the corresponding
|
||||||
// script variable(s).
|
// script variable(s).
|
||||||
std::string VName(int n, int inst_num,
|
std::string VName(int n, bro_uint_t inst_num,
|
||||||
const FrameReMap* mappings) const;
|
const FrameReMap* mappings) const;
|
||||||
|
|
||||||
// Number of slots that refer to a frame element. These always
|
// Number of slots that refer to a frame element. These always
|
||||||
|
@ -98,7 +98,9 @@ public:
|
||||||
// When an instruction has both frame slots and integer constants,
|
// When an instruction has both frame slots and integer constants,
|
||||||
// the former always come first, even if conceptually in the operation
|
// the former always come first, even if conceptually in the operation
|
||||||
// the constant is an "earlier" operand.
|
// the constant is an "earlier" operand.
|
||||||
int v1, v2, v3, v4;
|
//
|
||||||
|
// Initialized here to keep Coverity happy.
|
||||||
|
int v1 = -1, v2 = -1, v3 = -1, v4 = -1;
|
||||||
|
|
||||||
ZVal c; // constant associated with instruction, if any
|
ZVal c; // constant associated with instruction, if any
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,8 @@ const char* ZOP_name(ZOp op)
|
||||||
#include "zeek/ZAM-OpsNamesDefs.h"
|
#include "zeek/ZAM-OpsNamesDefs.h"
|
||||||
case OP_NOP: return "nop";
|
case OP_NOP: return "nop";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return "<error>";
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char* op_type_name(ZAMOpType ot)
|
static const char* op_type_name(ZAMOpType ot)
|
||||||
|
@ -41,6 +43,8 @@ static const char* op_type_name(ZAMOpType ot)
|
||||||
case OP_VVVV_I3_I4: return "VVVV_I3_I4";
|
case OP_VVVV_I3_I4: return "VVVV_I3_I4";
|
||||||
case OP_VVVV_I2_I3_I4: return "VVVV_I2_I3_I4";
|
case OP_VVVV_I2_I3_I4: return "VVVV_I2_I3_I4";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return "<error>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue