From 198abd42e2e3efcb8219b34e1469a0afd57b876d Mon Sep 17 00:00:00 2001 From: Zhelyapov Aleksey Date: Mon, 7 Jul 2025 15:40:00 +0300 Subject: [PATCH] Fix codecheck Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICKLNU Signed-off-by: Zhelyapov Aleksey --- ets2panda/aot/main.cpp | 18 +++++++++++++---- ets2panda/checker/ts/destructuringContext.cpp | 1 + ets2panda/compiler/core/compilerImpl.cpp | 20 +++++++++++++++---- .../compiler/lowering/ets/enumLowering.cpp | 2 ++ .../ets/interfacePropertyDeclarations.cpp | 3 +++ ets2panda/declgen_ets2ts/declgenEts2Ts.cpp | 1 + ets2panda/ir/brokenTypeNode.cpp | 1 + ets2panda/ir/ts/tsTupleType.cpp | 1 + 8 files changed, 39 insertions(+), 8 deletions(-) diff --git a/ets2panda/aot/main.cpp b/ets2panda/aot/main.cpp index b8f59a420f..2782245c60 100644 --- a/ets2panda/aot/main.cpp +++ b/ets2panda/aot/main.cpp @@ -100,6 +100,15 @@ static int CompileMultipleFiles(es2panda::Compiler &compiler, std::vector &parserInputs, unsigned int returnCode) +{ + for (auto *input : parserInputs) { + delete input; + } + parserInputs.clear(); + return returnCode; +} + static unsigned int CompileFromConfig(es2panda::Compiler &compiler, util::Options *options, util::DiagnosticEngine &diagnosticEngine) { @@ -110,6 +119,7 @@ static unsigned int CompileFromConfig(es2panda::Compiler &compiler, util::Option } std::vector inputs {}; + std::vector parserInputs; unsigned int overallRes = 0; for (auto &[src, dst] : compilationList) { std::ifstream inputStream(src); @@ -119,14 +129,14 @@ static unsigned int CompileFromConfig(es2panda::Compiler &compiler, util::Option } std::stringstream ss; ss << inputStream.rdbuf(); - auto *parserInput = new std::string(ss.str()); + parserInputs.push_back(new std::string(ss.str())); inputStream.close(); - es2panda::SourceFile input(src, *parserInput, options->IsModule(), std::string_view(dst)); + es2panda::SourceFile input(src, *parserInputs.back(), options->IsModule(), std::string_view(dst)); inputs.push_back(input); } if (options->IsPermArena() && (options->GetExtension() == util::gen::extension::ETS)) { - return CompileMultipleFiles(compiler, inputs, options, diagnosticEngine); + return ReleaseInputsAndReturn(parserInputs, CompileMultipleFiles(compiler, inputs, options, diagnosticEngine)); } for (auto &input : inputs) { @@ -140,7 +150,7 @@ static unsigned int CompileFromConfig(es2panda::Compiler &compiler, util::Option overallRes |= static_cast(res); } } - return overallRes; + return ReleaseInputsAndReturn(parserInputs, overallRes); } static std::optional> InitializePlugins(std::vector const &names, diff --git a/ets2panda/checker/ts/destructuringContext.cpp b/ets2panda/checker/ts/destructuringContext.cpp index 62212a8fca..3a0994723c 100644 --- a/ets2panda/checker/ts/destructuringContext.cpp +++ b/ets2panda/checker/ts/destructuringContext.cpp @@ -157,6 +157,7 @@ void DestructuringContext::HandleAssignmentPattern(ir::AssignmentExpression *ass ES2PANDA_ASSERT(defaultType != nullptr); if (validateDefault && assignmentPattern->Right()->IsObjectExpression() && assignmentPattern->Left()->IsObjectPattern()) { + ES2PANDA_ASSERT(defaultType != nullptr); ValidateObjectLiteralType(defaultType->AsObjectType(), assignmentPattern->Left()->AsObjectPattern()); } diff --git a/ets2panda/compiler/core/compilerImpl.cpp b/ets2panda/compiler/core/compilerImpl.cpp index 0f206c0f0d..5a0a5ce4e1 100644 --- a/ets2panda/compiler/core/compilerImpl.cpp +++ b/ets2panda/compiler/core/compilerImpl.cpp @@ -427,10 +427,22 @@ static bool ExecuteParsingAndCompiling(const CompilationUnit &unit, public_lib:: return !context->diagnosticEngine->IsAnyError(); } +static pandasm::Program *ClearContextAndReturnProgam(public_lib::Context *context, pandasm::Program *program) +{ + context->config = nullptr; + context->parser = nullptr; + context->checker->SetAnalyzer(nullptr); + context->checker = nullptr; + context->analyzer = nullptr; + context->phaseManager = nullptr; + context->parserProgram = nullptr; + context->emitter = nullptr; + return program; +} + template -static pandasm::Program *Compile(const CompilationUnit &unit, CompilerImpl *compilerImpl, - [[maybe_unused]] public_lib::Context *context) +static pandasm::Program *Compile(const CompilationUnit &unit, CompilerImpl *compilerImpl, public_lib::Context *context) { auto config = public_lib::ConfigImpl {}; context->config = &config; @@ -475,9 +487,9 @@ static pandasm::Program *Compile(const CompilationUnit &unit, CompilerImpl *comp context->checker->Initialize(varbinder); if (!ExecuteParsingAndCompiling(unit, context)) { - return nullptr; + return ClearContextAndReturnProgam(context, nullptr); } - return EmitProgram(compilerImpl, context, unit); + return ClearContextAndReturnProgam(context, EmitProgram(compilerImpl, context, unit)); } pandasm::Program *CompilerImpl::Compile(const CompilationUnit &unit, public_lib::Context *context) diff --git a/ets2panda/compiler/lowering/ets/enumLowering.cpp b/ets2panda/compiler/lowering/ets/enumLowering.cpp index 5212c1dc3a..115baffb4b 100644 --- a/ets2panda/compiler/lowering/ets/enumLowering.cpp +++ b/ets2panda/compiler/lowering/ets/enumLowering.cpp @@ -152,6 +152,7 @@ template auto *const arrayClassProp = AllocNode( arrayIdent, arrayExpr, typeAnnotation, ir::ModifierFlags::STATIC | ir::ModifierFlags::PRIVATE | ir::ModifierFlags::READONLY, Allocator(), false); + ES2PANDA_ASSERT(arrayClassProp != nullptr); arrayClassProp->SetParent(enumClass); enumClass->Body().push_back(arrayClassProp); @@ -316,6 +317,7 @@ void EnumLoweringPhase::CreateCCtorForEnumClass(ir::ClassDefinition *const enumC auto *const methodDef = AllocNode(ir::MethodDefinitionKind::METHOD, identClone, funcExpr, ir::ModifierFlags::PRIVATE | ir::ModifierFlags::STATIC, Allocator(), false); + ES2PANDA_ASSERT(methodDef != nullptr); methodDef->SetParent(enumClass); enumClass->Body().push_back(methodDef); } diff --git a/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp b/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp index f9832dc3c3..14ab736122 100644 --- a/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp +++ b/ets2panda/compiler/lowering/ets/interfacePropertyDeclarations.cpp @@ -85,6 +85,7 @@ ir::FunctionSignature InterfacePropertyDeclarationsPhase::GenerateGetterOrSetter InitScopesPhaseETS::RunExternalNode(paramIdent, varbinder); auto *const paramExpression = ctx->AllocNode(paramIdent, false, ctx->Allocator()); + ES2PANDA_ASSERT(paramExpression != nullptr); paramExpression->SetRange(paramIdent->Range()); auto [paramVar, node] = paramScope->AddParamDecl(ctx->Allocator(), varbinder, paramExpression); if (node != nullptr) { @@ -108,6 +109,7 @@ ir::MethodDefinition *InterfacePropertyDeclarationsPhase::GenerateGetterOrSetter auto classScope = NearestScope(field); auto *paramScope = ctx->Allocator()->New(ctx->Allocator(), classScope); auto *functionScope = ctx->Allocator()->New(ctx->Allocator(), paramScope); + ES2PANDA_ASSERT(functionScope != nullptr); functionScope->BindParamScope(paramScope); paramScope->BindFunctionScope(functionScope); @@ -253,6 +255,7 @@ ir::Expression *InterfacePropertyDeclarationsPhase::UpdateInterfaceProperties(pu } auto newInterface = ctx->AllocNode(std::move(newPropertyList)); + ES2PANDA_ASSERT(newInterface != nullptr); newInterface->SetRange(interface->Range()); newInterface->SetParent(interface->Parent()); diff --git a/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp b/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp index d14977f265..51ef162a7c 100644 --- a/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp +++ b/ets2panda/declgen_ets2ts/declgenEts2Ts.cpp @@ -618,6 +618,7 @@ void TSDeclGen::GenFunctionType(const checker::ETSFunctionType *etsFunctionType, const bool isSetter = methodDef != nullptr ? methodDef->Kind() == ir::MethodDefinitionKind::SET : false; // CC-OFFNXT(G.FMT.14-CPP) project code style const auto *sig = GetFuncSignature(etsFunctionType, methodDef); + ES2PANDA_ASSERT(sig != nullptr); if (sig->HasFunction()) { GenTypeParameters(sig->Function()->TypeParams()); const auto *funcBody = sig->Function()->Body(); diff --git a/ets2panda/ir/brokenTypeNode.cpp b/ets2panda/ir/brokenTypeNode.cpp index 110222066d..05ef63679f 100644 --- a/ets2panda/ir/brokenTypeNode.cpp +++ b/ets2panda/ir/brokenTypeNode.cpp @@ -72,6 +72,7 @@ checker::VerifiedType BrokenTypeNode::Check([[maybe_unused]] checker::ETSChecker BrokenTypeNode *BrokenTypeNode::Clone(ArenaAllocator *const allocator, AstNode *const parent) { auto *const clone = allocator->New(allocator); + ES2PANDA_ASSERT(clone != nullptr); if (parent != nullptr) { clone->SetParent(parent); } diff --git a/ets2panda/ir/ts/tsTupleType.cpp b/ets2panda/ir/ts/tsTupleType.cpp index c6f8052957..45d7df04c4 100644 --- a/ets2panda/ir/ts/tsTupleType.cpp +++ b/ets2panda/ir/ts/tsTupleType.cpp @@ -93,6 +93,7 @@ checker::Type *GetNumberIndexType(ArenaVector numberIndexTypes, static void SetMemberVarType(checker::Type *memberType, varbinder::LocalVariable *memberVar) { + ES2PANDA_ASSERT(memberType != nullptr); memberType->SetVariable(memberVar); memberVar->SetTsType(memberType); } -- Gitee