diff --git a/src/script_opt/ZAM/AM-Opt.cc b/src/script_opt/ZAM/AM-Opt.cc index 25b795d0e5..0cf8169eaf 100644 --- a/src/script_opt/ZAM/AM-Opt.cc +++ b/src/script_opt/ZAM/AM-Opt.cc @@ -1007,6 +1007,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); diff --git a/src/script_opt/ZAM/BuiltIn.cc b/src/script_opt/ZAM/BuiltIn.cc index 7ee89f40e6..1ee2f230fb 100644 --- a/src/script_opt/ZAM/BuiltIn.cc +++ b/src/script_opt/ZAM/BuiltIn.cc @@ -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; diff --git a/src/script_opt/ZAM/Compile.h b/src/script_opt/ZAM/Compile.h index 7678797a63..2ffad07277 100644 --- a/src/script_opt/ZAM/Compile.h +++ b/src/script_opt/ZAM/Compile.h @@ -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); diff --git a/src/script_opt/ZAM/Expr.cc b/src/script_opt/ZAM/Expr.cc index 90a08a46c5..3829fb4ddf 100644 --- a/src/script_opt/ZAM/Expr.cc +++ b/src/script_opt/ZAM/Expr.cc @@ -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(); diff --git a/src/script_opt/ZAM/Gen-ZAM.cc b/src/script_opt/ZAM/Gen-ZAM.cc index 851d39c811..9fd863e0b1 100644 --- a/src/script_opt/ZAM/Gen-ZAM.cc +++ b/src/script_opt/ZAM/Gen-ZAM.cc @@ -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); + } } diff --git a/src/script_opt/ZAM/IterInfo.h b/src/script_opt/ZAM/IterInfo.h index 2af43dbc8a..33eac3e4ff 100644 --- a/src/script_opt/ZAM/IterInfo.h +++ b/src/script_opt/ZAM/IterInfo.h @@ -90,7 +90,7 @@ private: const TableVal* tv = nullptr; // Associated auxiliary information. - ZInstAux* aux; + ZInstAux* aux = nullptr; std::optional tbl_iter; std::optional tbl_end; diff --git a/src/script_opt/ZAM/Stmt.cc b/src/script_opt/ZAM/Stmt.cc index 21f670d2e6..538352f5af 100644 --- a/src/script_opt/ZAM/Stmt.cc +++ b/src/script_opt/ZAM/Stmt.cc @@ -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; } @@ -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); diff --git a/src/script_opt/ZAM/ZInst.h b/src/script_opt/ZAM/ZInst.h index ccdb5deddd..3ec17848b6 100644 --- a/src/script_opt/ZAM/ZInst.h +++ b/src/script_opt/ZAM/ZInst.h @@ -39,10 +39,10 @@ public: // 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; @@ -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