diff --git a/ets2panda/ast_verifier/ASTVerifier.cpp b/ets2panda/ast_verifier/ASTVerifier.cpp index 9854161341dad190e547fec914f090536c2a9f5e..e55eaac5bb4bfcf16edb00c06b1de418aba183b4 100644 --- a/ets2panda/ast_verifier/ASTVerifier.cpp +++ b/ets2panda/ast_verifier/ASTVerifier.cpp @@ -80,7 +80,7 @@ static auto ExtractAst(const parser::Program &program, bool checkFullProgram) return astToCheck; } -void ASTVerifier::Verify(std::string_view phaseName) +void ASTVerifier::Verify(std::string_view phaseName) noexcept { if (context_.diagnosticEngine->IsAnyError()) { // NOTE(dkofanov): As for now, the policy is that ASTVerifier doesn't interrupt pipeline if there were errors diff --git a/ets2panda/ast_verifier/ASTVerifier.h b/ets2panda/ast_verifier/ASTVerifier.h index 1bd190ef7657372f5f3b05fa905c94602a9fbac7..82c05434b9eb9123e957f3f1e471eef55cc4fa3b 100644 --- a/ets2panda/ast_verifier/ASTVerifier.h +++ b/ets2panda/ast_verifier/ASTVerifier.h @@ -108,7 +108,7 @@ public: } } - void Verify(std::string_view phaseName); + void Verify(std::string_view phaseName) noexcept; void IntroduceNewInvariants(std::string_view occurredPhaseName) { diff --git a/ets2panda/compiler/base/lreference.cpp b/ets2panda/compiler/base/lreference.cpp index 1ae778a945176e180d5322d98fa8776da71b1814..852eb72ba2fbe9f75eaa01bd76326b106a6a5c3c 100644 --- a/ets2panda/compiler/base/lreference.cpp +++ b/ets2panda/compiler/base/lreference.cpp @@ -320,10 +320,10 @@ void ETSLReference::SetValueGetterSetter(const ir::MemberExpression *memberExpr) { ES2PANDA_ASSERT(memberExpr->PropVar() != nullptr); const auto *sig = memberExpr->PropVar()->TsType()->AsETSFunctionType()->FindSetter(); + ES2PANDA_ASSERT(sig->Function() != nullptr); auto argReg = etsg_->AllocReg(); etsg_->StoreAccumulator(Node(), argReg); - ES2PANDA_ASSERT(sig->Function() != nullptr); if (sig->Function()->IsStatic()) { etsg_->CallExact(Node(), sig->InternalName(), argReg); } else if (memberExpr->Object()->IsSuperExpression()) { diff --git a/ets2panda/compiler/core/CFG.cpp b/ets2panda/compiler/core/CFG.cpp index d1e62215e0ce57411bba4c82e0486d888ec68346..701a766ef76d6906c28549e7b1959abe55aa113f 100644 --- a/ets2panda/compiler/core/CFG.cpp +++ b/ets2panda/compiler/core/CFG.cpp @@ -201,6 +201,7 @@ CFG::BasicBlock *CFG::Build(ir::ScriptFunction *scriptFunctionNode) } BasicBlock *entryBB = CreateNewBB({}); + ES2PANDA_ASSERT(entryBB != nullptr); entryBB->SetFlag(BasicBlockFlags::ENTRY); functionNodeBBMap_[scriptFunctionNode] = entryBB; if (scriptFunctionNode->Id() != nullptr) { @@ -507,6 +508,7 @@ CFG::BasicBlock *CFG::Build(ir::WhileStatement *whileStatementNode, BasicBlock * { ++inLoop_; auto testBB = CreateNewBB({bb}); + ES2PANDA_ASSERT(testBB != nullptr); testBB->SetFlag(BasicBlockFlags::CONDITION); --inLoop_; auto falseBB = CreateNewBB({testBB}, {&falseLabel_}); @@ -515,6 +517,7 @@ CFG::BasicBlock *CFG::Build(ir::WhileStatement *whileStatementNode, BasicBlock * bb = Build(whileStatementNode->Test(), testBB); auto trueBB = CreateNewBB({bb}, {&trueLabel_}); trueBB = Build(whileStatementNode->Body(), trueBB); + ES2PANDA_ASSERT(trueBB != nullptr); trueBB->AddSuccessor(testBB); --inLoop_; return falseBB; @@ -525,12 +528,14 @@ CFG::BasicBlock *CFG::Build(ir::DoWhileStatement *doWhileStatementNode, BasicBlo ++inLoop_; auto bodyBB = CreateNewBB({bb}); auto testBB = CreateNewBB({}); + ES2PANDA_ASSERT(testBB != nullptr); testBB->SetFlag(BasicBlockFlags::CONDITION); --inLoop_; auto falseBB = CreateNewBB({testBB}, {&falseLabel_}); ++inLoop_; loopStmtJumpTargetMap_[doWhileStatementNode] = std::make_pair(testBB, falseBB); bb = Build(doWhileStatementNode->Body(), bodyBB); + ES2PANDA_ASSERT(bb != nullptr); testBB = Build(doWhileStatementNode->Test(), testBB); bb->AddSuccessor(testBB); AddBBEdge(testBB, bodyBB, &trueLabel_); @@ -636,6 +641,7 @@ CFG::BasicBlock *CFG::Build(ir::ForOfStatement *forOfStatementNode, BasicBlock * loopStmtJumpTargetMap_[forOfStatementNode] = std::make_pair(bb, nextBB); bb = Build(forOfStatementNode->Body(), bb); --inLoop_; + ES2PANDA_ASSERT(bb != nullptr); bb->AddSuccessor(loopBB); bb->AddSuccessor(nextBB); return nextBB; @@ -656,6 +662,7 @@ CFG::BasicBlock *CFG::Build(ir::ForUpdateStatement *forUpdateStatementNode, Basi testBB = Build(forUpdateStatementNode->Test(), testBB); auto bodyBB = Build(forUpdateStatementNode->Body(), trueBB); bodyBB = Build(forUpdateStatementNode->Update(), bodyBB); + ES2PANDA_ASSERT(bodyBB != nullptr); bodyBB->AddSuccessor(testBB); --inLoop_; return falseBB; @@ -667,6 +674,7 @@ CFG::BasicBlock *CFG::Build(ir::ForUpdateStatement *forUpdateStatementNode, Basi loopStmtJumpTargetMap_[forUpdateStatementNode] = std::make_pair(bodyStartBB, nextBB); auto bodyBB = Build(forUpdateStatementNode->Body(), bodyStartBB); bodyBB = Build(forUpdateStatementNode->Update(), bodyBB); + ES2PANDA_ASSERT(bodyBB != nullptr); bodyBB->AddSuccessor(bodyStartBB); --inLoop_; return nextBB; diff --git a/ets2panda/compiler/core/ETSCompiler.cpp b/ets2panda/compiler/core/ETSCompiler.cpp index 75fd7d3de505e7bba5f6d34adae7e5d6b9110aeb..675c8d449dcc1600dcfe65ce5f2557a450b9f0f7 100644 --- a/ets2panda/compiler/core/ETSCompiler.cpp +++ b/ets2panda/compiler/core/ETSCompiler.cpp @@ -649,6 +649,7 @@ static void ConvertRestArguments(checker::ETSChecker *const checker, const ir::C elements.emplace_back(expr->Arguments()[i]); } auto *arrayExpression = checker->AllocNode(std::move(elements), checker->Allocator()); + ES2PANDA_ASSERT(arrayExpression != nullptr); arrayExpression->SetParent(const_cast(expr)); auto restType = signature->RestVar()->TsType()->AsETSArrayType(); arrayExpression->SetTsType(restType); diff --git a/ets2panda/compiler/lowering/ets/asyncMethodLowering.cpp b/ets2panda/compiler/lowering/ets/asyncMethodLowering.cpp index 1affd68bbf51fb98621f4f1edf87c6ea977fb033..be15ae71a728ab845bcecc16c3347c18d2a49559 100644 --- a/ets2panda/compiler/lowering/ets/asyncMethodLowering.cpp +++ b/ets2panda/compiler/lowering/ets/asyncMethodLowering.cpp @@ -128,12 +128,13 @@ ir::MethodDefinition *CreateAsyncProxy(checker::ETSChecker *checker, ir::MethodD ir::ClassDefinition *classDef) { ir::ScriptFunction *asyncFunc = asyncMethod->Function(); + ES2PANDA_ASSERT(asyncFunc != nullptr); if (!asyncFunc->IsExternal()) { checker->VarBinder()->AsETSBinder()->GetRecordTable()->EmplaceSignatures(asyncFunc->Scope(), asyncFunc); } ir::MethodDefinition *implMethod = CreateAsyncImplMethod(checker, asyncMethod, classDef); - ES2PANDA_ASSERT(implMethod->Function() != nullptr); + ES2PANDA_ASSERT(implMethod != nullptr && implMethod->Function() != nullptr && implMethod->Id() != nullptr); varbinder::FunctionScope *implFuncScope = implMethod->Function()->Scope(); for (auto *decl : asyncFunc->Scope()->Decls()) { auto res = asyncFunc->Scope()->Bindings().find(decl->Name()); @@ -163,14 +164,17 @@ ir::MethodDefinition *CreateAsyncProxy(checker::ETSChecker *checker, ir::MethodD void ComposeAsyncImplMethod(checker::ETSChecker *checker, ir::MethodDefinition *node) { + ES2PANDA_ASSERT(checker->FindAncestorGivenByType(node, ir::AstNodeType::CLASS_DEFINITION)); auto *classDef = checker->FindAncestorGivenByType(node, ir::AstNodeType::CLASS_DEFINITION)->AsClassDefinition(); ir::MethodDefinition *implMethod = CreateAsyncProxy(checker, node, classDef); implMethod->Check(checker); node->SetAsyncPairMethod(implMethod); + ES2PANDA_ASSERT(node->Function() != nullptr); if (node->Function()->IsOverload()) { auto *baseOverloadImplMethod = node->BaseOverloadMethod()->AsyncPairMethod(); + ES2PANDA_ASSERT(implMethod->Function() != nullptr && baseOverloadImplMethod->Function() != nullptr); implMethod->Function()->Id()->SetVariable(baseOverloadImplMethod->Function()->Id()->Variable()); baseOverloadImplMethod->AddOverload(implMethod); implMethod->SetParent(baseOverloadImplMethod); diff --git a/ets2panda/compiler/lowering/ets/boxingForLocals.cpp b/ets2panda/compiler/lowering/ets/boxingForLocals.cpp index 0277b45394722568b48f7dc7b3856321096f8d79..3c5f9f78520201beb779196e7c42151909f0d76e 100644 --- a/ets2panda/compiler/lowering/ets/boxingForLocals.cpp +++ b/ets2panda/compiler/lowering/ets/boxingForLocals.cpp @@ -155,6 +155,7 @@ static void HandleFunctionParam(public_lib::Context *ctx, ir::ETSParameterExpres auto *newDecl = allocator->New(newVarName.View(), newDeclarator); auto *newVar = allocator->New(newDecl, oldVar->Flags()); + ES2PANDA_ASSERT(newVar != nullptr); newVar->SetTsType(boxedType); newDeclarator->Id()->AsIdentifier()->SetVariable(newVar); @@ -165,6 +166,7 @@ static void HandleFunctionParam(public_lib::Context *ctx, ir::ETSParameterExpres auto *newDeclaration = util::NodeAllocator::ForceSetParent( allocator, ir::VariableDeclaration::VariableDeclarationKind::CONST, allocator, std::move(declVec)); + ES2PANDA_ASSERT(newDeclaration != nullptr); newDeclaration->SetParent(body); newDeclaration->SetRange(param->Range()); bodyStmts.insert(bodyStmts.begin(), newDeclaration); diff --git a/ets2panda/ir/base/scriptFunction.cpp b/ets2panda/ir/base/scriptFunction.cpp index ce9683e82c892bc220fbfd130e77dd9af6141cf3..b57a1dd3e4d3d14207bfd322645d28639bb3bb3d 100644 --- a/ets2panda/ir/base/scriptFunction.cpp +++ b/ets2panda/ir/base/scriptFunction.cpp @@ -185,8 +185,11 @@ ScriptFunction *ScriptFunction::Clone(ArenaAllocator *allocator, AstNode *parent for (auto *param : Params()) { params.push_back(param->Clone(allocator, nullptr)->AsExpression()); } + AnnotationUsage *clonedAnnotationUsage; for (auto *annotationUsage : Annotations()) { - annotationUsages.push_back(annotationUsage->Clone(allocator, nullptr)->AsAnnotationUsage()); + clonedAnnotationUsage = annotationUsage->Clone(allocator, nullptr); + ES2PANDA_ASSERT(clonedAnnotationUsage != nullptr); + annotationUsages.push_back(clonedAnnotationUsage->AsAnnotationUsage()); } auto *res = util::NodeAllocator::ForceSetParent( allocator, allocator, diff --git a/ets2panda/ir/ts/tsArrayType.cpp b/ets2panda/ir/ts/tsArrayType.cpp index b5f988027e21799a7d763ce06a906d074e36f689..93a56fa2084f5ec91d28187c9bf354526845e15e 100644 --- a/ets2panda/ir/ts/tsArrayType.cpp +++ b/ets2panda/ir/ts/tsArrayType.cpp @@ -115,8 +115,10 @@ TSArrayType *TSArrayType::Clone(ArenaAllocator *const allocator, AstNode *const if (!Annotations().empty()) { ArenaVector annotationUsages {allocator->Adapter()}; + AnnotationUsage *clonedAnnotationUsage; for (auto *annotationUsage : Annotations()) { - annotationUsages.push_back(annotationUsage->Clone(allocator, clone)->AsAnnotationUsage()); + clonedAnnotationUsage = annotationUsage->Clone(allocator, clone); + annotationUsages.push_back(clonedAnnotationUsage->AsAnnotationUsage()); } clone->SetAnnotations(std::move(annotationUsages)); } diff --git a/ets2panda/ir/ts/tsThisType.cpp b/ets2panda/ir/ts/tsThisType.cpp index 03bcb6e6a2bf55dc9b49eb9485aca842b8f0a30f..1b49be750598aaeeaa48516938fc0b61b1dff07e 100644 --- a/ets2panda/ir/ts/tsThisType.cpp +++ b/ets2panda/ir/ts/tsThisType.cpp @@ -76,7 +76,7 @@ checker::Type *TSThisType::GetType([[maybe_unused]] checker::ETSChecker *checker TSThisType *TSThisType::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const clone = allocator->New(allocator); - + ES2PANDA_ASSERT(clone != nullptr); if (parent != nullptr) { clone->SetParent(parent); } @@ -84,8 +84,9 @@ TSThisType *TSThisType::Clone(ArenaAllocator *const allocator, AstNode *const pa if (!Annotations().empty()) { ArenaVector annotationUsages {allocator->Adapter()}; for (auto *annotationUsage : Annotations()) { - ES2PANDA_ASSERT(annotationUsage->Clone(allocator, clone) != nullptr); - annotationUsages.push_back(annotationUsage->Clone(allocator, clone)->AsAnnotationUsage()); + auto *clonedAnnotationUsage = annotationUsage->Clone(allocator, clone); + ES2PANDA_ASSERT(clonedAnnotationUsage != nullptr); + annotationUsages.push_back(clonedAnnotationUsage->AsAnnotationUsage()); } clone->SetAnnotations(std::move(annotationUsages)); } diff --git a/ets2panda/ir/ts/tsTupleType.cpp b/ets2panda/ir/ts/tsTupleType.cpp index 25f14ade82f72d5931bfe9502f0959f89638d253..2a568c57e3b624b0e9a445235c3ce38d1f0efc77 100644 --- a/ets2panda/ir/ts/tsTupleType.cpp +++ b/ets2panda/ir/ts/tsTupleType.cpp @@ -112,7 +112,7 @@ checker::Type *TSTupleType::GetType(checker::TSChecker *checker) auto *memberVar = varbinder::Scope::CreateVar(checker->Allocator(), memberIndex, varbinder::VariableFlags::PROPERTY, it); - + ES2PANDA_ASSERT(memberVar != nullptr); checker::ElementFlags memberFlag; if (it->IsTSNamedTupleMember()) { auto *namedMember = it->AsTSNamedTupleMember();