From 81671ee7d8bc369f6fb05352049ff8817f4f2785 Mon Sep 17 00:00:00 2001 From: tsatsulya Date: Tue, 15 Jul 2025 16:30:57 +0300 Subject: [PATCH] fix codecheck Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICMK90?from=project-issue Signed-off-by: tsatsulya --- ets2panda/ast_verifier/ASTVerifier.cpp | 2 +- ets2panda/ast_verifier/ASTVerifier.h | 2 +- ets2panda/compiler/base/lreference.cpp | 2 +- ets2panda/compiler/core/CFG.cpp | 8 ++++++++ ets2panda/compiler/core/ETSCompiler.cpp | 1 + ets2panda/compiler/lowering/ets/asyncMethodLowering.cpp | 6 +++++- ets2panda/compiler/lowering/ets/boxingForLocals.cpp | 2 ++ ets2panda/ir/base/scriptFunction.cpp | 5 ++++- ets2panda/ir/ts/tsArrayType.cpp | 4 +++- ets2panda/ir/ts/tsThisType.cpp | 7 ++++--- ets2panda/ir/ts/tsTupleType.cpp | 2 +- 11 files changed, 31 insertions(+), 10 deletions(-) diff --git a/ets2panda/ast_verifier/ASTVerifier.cpp b/ets2panda/ast_verifier/ASTVerifier.cpp index 9854161341..e55eaac5bb 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 1bd190ef76..82c05434b9 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 1ae778a945..852eb72ba2 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 d1e62215e0..701a766ef7 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 75fd7d3de5..675c8d449d 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 1affd68bbf..be15ae71a7 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 0277b45394..3c5f9f7852 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 ce9683e82c..b57a1dd3e4 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 b5f988027e..93a56fa208 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 03bcb6e6a2..1b49be7505 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 25f14ade82..2a568c57e3 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(); -- Gitee