mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +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
|
||||
|
||||
* 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();
|
||||
|
||||
int bb = barrier_blocks.back();
|
||||
auto bb = barrier_blocks.back();
|
||||
if ( bb > 0 && confluence_blocks.size() == bb )
|
||||
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
|
||||
// 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
|
||||
// block.
|
||||
modified_IDs[i+1].insert(id);
|
||||
|
|
|
@ -99,7 +99,7 @@ private:
|
|||
// unseen confluence regions outer to those, and (2) they
|
||||
// can get quite deep due when inlining, so there are savings
|
||||
// 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 front entry tracks identifiers at the outermost
|
||||
|
|
|
@ -71,7 +71,7 @@ void IDOptInfo::Clear()
|
|||
|
||||
void IDOptInfo::DefinedAfter(const Stmt* s, const ExprPtr& e,
|
||||
const std::vector<const Stmt*>& conf_blocks,
|
||||
int conf_start)
|
||||
bro_uint_t conf_start)
|
||||
{
|
||||
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>");
|
||||
|
@ -174,7 +174,7 @@ void IDOptInfo::BranchBackTo(const Stmt* from, const Stmt* to, bool close_all)
|
|||
auto from_reg = ActiveRegion();
|
||||
auto f_oi = from->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];
|
||||
|
||||
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;
|
||||
|
||||
for ( auto i = 0; i < usage_regions.size(); ++i )
|
||||
for ( auto i = 0U; i < usage_regions.size(); ++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 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];
|
||||
|
||||
|
|
|
@ -142,7 +142,7 @@ public:
|
|||
// conf_blocks may be empty).
|
||||
void DefinedAfter(const Stmt* s, const ExprPtr& e,
|
||||
const std::vector<const Stmt*>& conf_blocks,
|
||||
int conf_start);
|
||||
bro_uint_t conf_start);
|
||||
|
||||
// Called upon encountering a "return" statement.
|
||||
void ReturnAt(const Stmt* s);
|
||||
|
|
|
@ -484,7 +484,7 @@ void ZAMCompiler::ReMapFrame()
|
|||
frame1_to_frame2.resize(frame_layout1.size(), -1);
|
||||
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];
|
||||
|
||||
|
@ -659,7 +659,7 @@ void ZAMCompiler::ReMapInterpreterFrame()
|
|||
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
|
||||
// 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
|
||||
// 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.
|
||||
if ( s.scope_end == inst )
|
||||
if ( s.scope_end == static_cast<int>(inst) )
|
||||
{ // It ends right on the money.
|
||||
apt_slot = i;
|
||||
break;
|
||||
|
@ -727,7 +728,8 @@ void ZAMCompiler::ReMapVar(ID* id, int slot, int 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
|
||||
// earlier than their definitions in loop bodies. For other
|
||||
|
@ -766,7 +768,7 @@ void ZAMCompiler::CheckSlotUse(int slot, const ZInstI* inst)
|
|||
if ( slot < 0 )
|
||||
return;
|
||||
|
||||
ASSERT(slot < frame_denizens.size());
|
||||
ASSERT(static_cast<bro_uint_t>(slot) < frame_denizens.size());
|
||||
|
||||
if ( denizen_beginning.count(slot) == 0 )
|
||||
{
|
||||
|
@ -952,9 +954,9 @@ ZInstI* ZAMCompiler::FirstLiveInst(ZInstI* i, bool follow_gotos)
|
|||
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() )
|
||||
{
|
||||
auto i0 = insts1[i];
|
||||
|
@ -982,7 +984,7 @@ int ZAMCompiler::FirstLiveInst(int i, bool follow_gotos)
|
|||
return i;
|
||||
}
|
||||
|
||||
void ZAMCompiler::KillInst(int i)
|
||||
void ZAMCompiler::KillInst(bro_uint_t i)
|
||||
{
|
||||
auto inst = insts1[i];
|
||||
|
||||
|
@ -1007,6 +1009,8 @@ void ZAMCompiler::KillInst(int i)
|
|||
|
||||
if ( inst->IsUnconditionalBranch() )
|
||||
{
|
||||
ASSERT(t);
|
||||
|
||||
// No direct flow after this point ... unless we're
|
||||
// branching to the next immediate live instruction.
|
||||
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];
|
||||
|
||||
|
|
|
@ -78,7 +78,7 @@ ZInstI* ZAMCompiler::FindLiveTarget(ZInstI* goto_target)
|
|||
return goto_target;
|
||||
|
||||
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 )
|
||||
++idx;
|
||||
|
|
|
@ -371,21 +371,25 @@ bool ZAMCompiler::BuiltIn_sub_bytes(const NameExpr* n, const ExprPList& args)
|
|||
break;
|
||||
|
||||
case 0x4: // first argument a constant
|
||||
ASSERT(c);
|
||||
z = ZInstI(OP_SUB_BYTES_VVVC, nslot, v3, v4, c);
|
||||
z.op_type = OP_VVVC;
|
||||
break;
|
||||
|
||||
case 0x5: // first and third constant
|
||||
ASSERT(c);
|
||||
z = ZInstI(OP_SUB_BYTES_VViC, nslot, v3, v4, c);
|
||||
z.op_type = OP_VVVC_I3;
|
||||
break;
|
||||
|
||||
case 0x6: // first and second constant - flip!
|
||||
ASSERT(c);
|
||||
z = ZInstI(OP_SUB_BYTES_ViVC, nslot, v4, v3, c);
|
||||
z.op_type = OP_VVVC_I3;
|
||||
break;
|
||||
|
||||
case 0x7: // whole shebang
|
||||
ASSERT(c);
|
||||
z = ZInstI(OP_SUB_BYTES_ViiC, nslot, v3, v4, c);
|
||||
z.op_type = OP_VVVC_I2_I3;
|
||||
break;
|
||||
|
|
|
@ -183,7 +183,7 @@ private:
|
|||
const ZAMStmt LoopOverVector(const ForStmt* f, const NameExpr* val);
|
||||
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,
|
||||
bool is_table);
|
||||
|
||||
|
@ -450,7 +450,7 @@ private:
|
|||
|
||||
// Computes the remapping for a variable currently in the given slot,
|
||||
// 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
|
||||
// assignment at instruction inst.
|
||||
|
@ -494,12 +494,12 @@ private:
|
|||
// First form returns nil if there's nothing live after i.
|
||||
// Second form returns insts1.size() in that case.
|
||||
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.
|
||||
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 FirstLiveInst(insts1[i->inst_num + 1], follow_gotos);
|
||||
}
|
||||
|
@ -511,12 +511,12 @@ private:
|
|||
// into insts1; any labels associated with it are transferred
|
||||
// to its next live successor, if any.
|
||||
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
|
||||
// one that's labeled.
|
||||
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 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
|
||||
// case, look forward for the next viable
|
||||
// instruction.
|
||||
while ( start < int(insts1.size()) &&
|
||||
while ( start < insts1.size() &&
|
||||
inst1_to_inst2[start] == -1 )
|
||||
++start;
|
||||
|
||||
|
|
|
@ -105,6 +105,7 @@ const ZAMStmt ZAMCompiler::AppendToField(const NameExpr* n1, const NameExpr* n2,
|
|||
}
|
||||
else
|
||||
{
|
||||
ASSERT(c);
|
||||
z = ZInstI(OP_APPENDTOFIELD_VCi, FrameSlot(n1), offset, c);
|
||||
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 )
|
||||
{
|
||||
ASSERT(l_e1_c);
|
||||
|
||||
z = GenInst(OP_VAL2_IS_IN_TABLE_VVVC,
|
||||
n1, l_e0_n, n2, l_e1_c);
|
||||
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 )
|
||||
{
|
||||
ASSERT(l_e0_c);
|
||||
|
||||
z = GenInst(OP_VAL2_IS_IN_TABLE_VVCV,
|
||||
n1, l_e1_n, n2, l_e0_c);
|
||||
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
|
||||
// a temporary.
|
||||
ASSERT(l_e0_c);
|
||||
ASSERT(l_e1_c);
|
||||
|
||||
auto slot = TempForConst(l_e0_c);
|
||||
z = ZInstI(OP_VAL2_IS_IN_TABLE_VVVC, FrameSlot(n1),
|
||||
slot, FrameSlot(n2), l_e1_c);
|
||||
|
@ -687,6 +695,8 @@ const ZAMStmt ZAMCompiler::CompileIndex(const NameExpr* n1, int n2_slot,
|
|||
|
||||
else
|
||||
{
|
||||
ASSERT(c3);
|
||||
|
||||
auto zop = AssignmentFlavor(OP_TABLE_INDEX1_VVC,
|
||||
n1->GetType()->Tag());
|
||||
z = ZInstI(zop, Frame1Slot(n1, zop),
|
||||
|
@ -911,15 +921,21 @@ const ZAMStmt ZAMCompiler::DoCall(const CallExpr* c, const NameExpr* n)
|
|||
z = ZInstI(AssignmentFlavor(OP_CALL1_VV, nt),
|
||||
n_slot, FrameSlot(n0));
|
||||
else
|
||||
{
|
||||
ASSERT(c0);
|
||||
z = ZInstI(AssignmentFlavor(OP_CALL1_VC, nt),
|
||||
n_slot, c0);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( n0 )
|
||||
z = ZInstI(OP_CALL1_V, FrameSlot(n0));
|
||||
else
|
||||
{
|
||||
ASSERT(c0);
|
||||
z = ZInstI(OP_CALL1_C, c0);
|
||||
}
|
||||
}
|
||||
|
||||
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->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);
|
||||
|
||||
// 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 )
|
||||
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];
|
||||
if ( w_i.size() != 1 )
|
||||
|
@ -1023,7 +1023,7 @@ void ZAM_ExprOpTemplate::Instantiate()
|
|||
InstantiateC3(op_types);
|
||||
|
||||
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 )
|
||||
all_var = false;
|
||||
|
||||
|
@ -2101,7 +2101,7 @@ void ZAMGen::Emit(EmitTarget et, const string& s)
|
|||
|
||||
fputs(s.c_str(), f);
|
||||
|
||||
if ( s.back() != '\n' && ! no_NL )
|
||||
if ( ! no_NL && (s.empty() || s.back() != '\n') )
|
||||
fputs("\n", f);
|
||||
}
|
||||
|
||||
|
@ -2272,6 +2272,15 @@ bool ZAMGen::ParseTemplate()
|
|||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
ZAMGen(argc, argv);
|
||||
exit(0);
|
||||
try
|
||||
{
|
||||
ZAMGen zg(argc, argv);
|
||||
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;
|
||||
|
||||
// Associated auxiliary information.
|
||||
ZInstAux* aux;
|
||||
ZInstAux* aux = nullptr;
|
||||
|
||||
std::optional<DictIterator> tbl_iter;
|
||||
std::optional<DictIterator> tbl_end;
|
||||
|
|
|
@ -791,13 +791,13 @@ internal-op Val-Is-In-Vector
|
|||
type VVV
|
||||
eval auto& vec = frame[z.v3].vector_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
|
||||
type VCV
|
||||
eval auto& vec = frame[z.v2].vector_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
|
||||
type VVVV
|
||||
|
@ -902,7 +902,7 @@ eval EvalIndexVec(frame[z.v3].uint_val)
|
|||
macro EvalIndexVec(index)
|
||||
auto vv = frame[z.v2].vector_val->RawVec();
|
||||
const auto& vec = *vv;
|
||||
auto ind = index;
|
||||
bro_uint_t ind = index;
|
||||
if ( ind >= vv->size() )
|
||||
ZAM_run_time_error(z.loc, "no such index");
|
||||
AssignV1(CopyVal(*vec[ind]))
|
||||
|
@ -917,7 +917,7 @@ eval EvalIndexAnyVec(frame[z.v3].uint_val)
|
|||
|
||||
macro EvalIndexAnyVec(index)
|
||||
auto vv = frame[z.v2].vector_val;
|
||||
auto ind = index;
|
||||
bro_uint_t ind = index;
|
||||
if ( ind >= vv->Size() )
|
||||
ZAM_run_time_error(z.loc, "no such index");
|
||||
AssignV1(ZVal(vv->ValAt(ind).release()))
|
||||
|
@ -1749,7 +1749,7 @@ op CheckAnyLen
|
|||
op1-read
|
||||
type Vi
|
||||
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");
|
||||
|
||||
op Print
|
||||
|
|
|
@ -530,6 +530,7 @@ const ZAMStmt ZAMCompiler::ValueSwitch(const SwitchStmt* sw, const NameExpr* v,
|
|||
auto sv = cv->AsString()->Render();
|
||||
std::string s(sv);
|
||||
new_str_cases[s] = case_body_start;
|
||||
delete[] sv;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -806,7 +807,7 @@ const ZAMStmt ZAMCompiler::LoopOverTable(const ForStmt* f, const NameExpr* val)
|
|||
|
||||
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];
|
||||
|
||||
|
@ -897,6 +898,7 @@ const ZAMStmt ZAMCompiler::LoopOverString(const ForStmt* f, const Expr* e)
|
|||
}
|
||||
else
|
||||
{
|
||||
ASSERT(c);
|
||||
z = ZInstI(OP_INIT_STRING_LOOP_VC, iter_slot, c);
|
||||
z.op_type = OP_VC_I1;
|
||||
}
|
||||
|
@ -926,9 +928,9 @@ const ZAMStmt ZAMCompiler::Loop(const Stmt* body)
|
|||
return tail;
|
||||
}
|
||||
|
||||
const ZAMStmt ZAMCompiler::FinishLoop(const ZAMStmt iter_head, ZInstI iter_stmt,
|
||||
const Stmt* body, int iter_slot,
|
||||
bool is_table)
|
||||
const ZAMStmt ZAMCompiler::FinishLoop(const ZAMStmt iter_head,
|
||||
ZInstI& iter_stmt, const Stmt* body,
|
||||
int iter_slot, bool is_table)
|
||||
{
|
||||
auto loop_iter = AddInst(iter_stmt);
|
||||
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),
|
||||
// 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 )
|
||||
vv->Resize(ind + 1);
|
||||
|
@ -263,7 +264,7 @@ ValPtr ZBody::DoExec(Frame* f, int start_pc, StmtFlowType& flow)
|
|||
const int end_pc = ninst;
|
||||
|
||||
// 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.
|
||||
TypePtr ret_type;
|
||||
|
|
|
@ -9,7 +9,7 @@ using std::string;
|
|||
|
||||
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);
|
||||
|
||||
|
@ -170,6 +170,8 @@ int ZInst::NumFrameSlots() const
|
|||
case OP_VVVV:
|
||||
return 4;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ZInst::NumSlots() const
|
||||
|
@ -208,9 +210,11 @@ int ZInst::NumSlots() const
|
|||
case OP_VVVV_I2_I3_I4:
|
||||
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() )
|
||||
return "";
|
||||
|
@ -221,7 +225,7 @@ string ZInst::VName(int n, int inst_num, const FrameReMap* mappings) const
|
|||
return "<special>";
|
||||
|
||||
// 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];
|
||||
|
||||
|
@ -278,6 +282,8 @@ ValPtr ZInst::ConstVal() const
|
|||
case OP_VVVV_I2_I3_I4:
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
string ZInst::ConstDump() const
|
||||
|
@ -321,16 +327,18 @@ string ZInstI::VName(int n, const FrameMap* frame_ids,
|
|||
|
||||
if ( remappings && live )
|
||||
{ // 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];
|
||||
|
||||
unsigned int i;
|
||||
auto inst_num_u = static_cast<bro_uint_t>(inst_num);
|
||||
for ( i = 0; i < map.id_start.size(); ++i )
|
||||
{
|
||||
// See discussion for ZInst::VName.
|
||||
if ( (n == 1 && map.id_start[i] > inst_num) ||
|
||||
(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_u) )
|
||||
// Went too far.
|
||||
break;
|
||||
}
|
||||
|
@ -431,6 +439,8 @@ bool ZInstI::AssignsToSlot1() const
|
|||
auto fl = op1_flavor[op];
|
||||
return fl == OP1_WRITE || fl == OP1_READ_WRITE;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ZInstI::UsesSlot(int slot) const
|
||||
|
@ -473,6 +483,8 @@ bool ZInstI::UsesSlot(int slot) const
|
|||
case OP_VVVV:
|
||||
return v1_match || v2 == slot || v3 == slot || v4 == slot;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
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 false;
|
||||
}
|
||||
|
||||
void ZInstI::UpdateSlots(std::vector<int>& slot_mapping)
|
||||
|
|
|
@ -35,14 +35,14 @@ public:
|
|||
|
||||
// The ZAM instruction number where a given identifier starts its
|
||||
// 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
|
||||
// new IDs are added to share the slot.
|
||||
int scope_end;
|
||||
int scope_end = -1;
|
||||
|
||||
// Whether this is a managed slot.
|
||||
bool is_managed;
|
||||
bool is_managed = false;
|
||||
};
|
||||
|
||||
using FrameReMap = std::vector<FrameSharingInfo>;
|
||||
|
@ -66,7 +66,7 @@ public:
|
|||
virtual ~ZInst() { }
|
||||
|
||||
// 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,
|
||||
const std::string& id3, const std::string& id4) const;
|
||||
|
||||
|
@ -75,7 +75,7 @@ public:
|
|||
// by its number within a larger set. "mappings" provides the
|
||||
// mappings used to translate raw slots to the corresponding
|
||||
// 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;
|
||||
|
||||
// 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,
|
||||
// the former always come first, even if conceptually in the operation
|
||||
// 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
|
||||
|
||||
|
|
|
@ -12,6 +12,8 @@ const char* ZOP_name(ZOp op)
|
|||
#include "zeek/ZAM-OpsNamesDefs.h"
|
||||
case OP_NOP: return "nop";
|
||||
}
|
||||
|
||||
return "<error>";
|
||||
}
|
||||
|
||||
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_I2_I3_I4: return "VVVV_I2_I3_I4";
|
||||
}
|
||||
|
||||
return "<error>";
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue