From 4dcfe2b1fe86555eb2f7341a8c5d7b3bbdb9ca68 Mon Sep 17 00:00:00 2001 From: shawn_hu_ls Date: Fri, 2 Sep 2022 09:42:52 +0800 Subject: [PATCH] Fix es2abc nobody function coredump in emitter Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/I5OF3J?from=project-issue Signed-off-by: shawn_hu_ls --- es2panda/binder/binder.cpp | 2 +- es2panda/compiler/core/pandagen.cpp | 4 ++++ es2panda/ir/base/classDefinition.cpp | 4 ++++ es2panda/parser/parserImpl.cpp | 6 +++--- es2panda/parser/parserImpl.h | 2 +- 5 files changed, 13 insertions(+), 5 deletions(-) diff --git a/es2panda/binder/binder.cpp b/es2panda/binder/binder.cpp index 63f359f987..aec814482d 100644 --- a/es2panda/binder/binder.cpp +++ b/es2panda/binder/binder.cpp @@ -461,7 +461,7 @@ void Binder::ResolveReference(const ir::AstNode *parent, ir::AstNode *childNode) ResolveReference(scriptFunc, scriptFunc->ReturnTypeAnnotation()); } - if (scriptFunc->IsOverload()) { + if (scriptFunc->IsOverload() || scriptFunc->Declare()) { break; } } diff --git a/es2panda/compiler/core/pandagen.cpp b/es2panda/compiler/core/pandagen.cpp index 6103be37a8..ac9b02f19b 100644 --- a/es2panda/compiler/core/pandagen.cpp +++ b/es2panda/compiler/core/pandagen.cpp @@ -1091,6 +1091,10 @@ void PandaGen::LoadHomeObject(const ir::AstNode *node) void PandaGen::DefineFunction(const ir::AstNode *node, const ir::ScriptFunction *realNode, const util::StringView &name) { + if (realNode->IsOverload() || realNode->Declare()) { + return; + } + auto formalParamCnt = realNode->FormalParamsLength(); if (realNode->IsMethod()) { ra_.Emit(node, name, static_cast(formalParamCnt), LexEnv()); diff --git a/es2panda/ir/base/classDefinition.cpp b/es2panda/ir/base/classDefinition.cpp index e947b8f01c..bda274c4ac 100644 --- a/es2panda/ir/base/classDefinition.cpp +++ b/es2panda/ir/base/classDefinition.cpp @@ -281,6 +281,10 @@ void ClassDefinition::CompileMissingProperties(compiler::PandaGen *pg, const uti void ClassDefinition::Compile(compiler::PandaGen *pg) const { + if (declare_) { + return; + } + compiler::RegScope rs(pg); compiler::VReg classReg = pg->AllocReg(); compiler::VReg lexenv = pg->LexEnv(); diff --git a/es2panda/parser/parserImpl.cpp b/es2panda/parser/parserImpl.cpp index d6bfecb3bf..b1bab02173 100644 --- a/es2panda/parser/parserImpl.cpp +++ b/es2panda/parser/parserImpl.cpp @@ -2398,7 +2398,7 @@ static bool IsConstructor(ir::Statement *stmt) return def->Kind() == ir::MethodDefinitionKind::CONSTRUCTOR; } -ir::MethodDefinition *ParserImpl::CreateImplicitConstructor(bool hasSuperClass) +ir::MethodDefinition *ParserImpl::CreateImplicitConstructor(bool hasSuperClass, bool isDeclare) { ArenaVector params(Allocator()->Adapter()); ArenaVector statements(Allocator()->Adapter()); @@ -2423,7 +2423,7 @@ ir::MethodDefinition *ParserImpl::CreateImplicitConstructor(bool hasSuperClass) auto *body = AllocNode(scope, std::move(statements)); auto *func = AllocNode(scope, std::move(params), nullptr, body, nullptr, - ir::ScriptFunctionFlags::CONSTRUCTOR, false); + ir::ScriptFunctionFlags::CONSTRUCTOR, isDeclare); scope->BindNode(func); paramScope->BindNode(func); scope->BindParamScope(paramScope); @@ -2657,7 +2657,7 @@ ir::ClassDefinition *ParserImpl::ParseClassDefinition(bool isDeclaration, bool i lexer::SourcePosition classBodyEndLoc = lexer_->GetToken().End(); if (ctor == nullptr) { - ctor = CreateImplicitConstructor(hasSuperClass); + ctor = CreateImplicitConstructor(hasSuperClass, isDeclare); ctor->SetRange({startLoc, classBodyEndLoc}); } lexer_->NextToken(); diff --git a/es2panda/parser/parserImpl.h b/es2panda/parser/parserImpl.h index 0a70e8e116..7c8297a726 100644 --- a/es2panda/parser/parserImpl.h +++ b/es2panda/parser/parserImpl.h @@ -286,7 +286,7 @@ private: ir::Statement *ParseClassElement(const ArenaVector &properties, ArenaVector *indexSignatures, bool hasSuperClass, bool isDeclare, bool isAbstractClass); - ir::MethodDefinition *CreateImplicitConstructor(bool hasSuperClass); + ir::MethodDefinition *CreateImplicitConstructor(bool hasSuperClass, bool isDeclare = false); ir::MethodDefinition *CheckClassMethodOverload(ir::Statement *property, ir::MethodDefinition **ctor, bool isDeclare, lexer::SourcePosition errorInfo, ir::MethodDefinition *lastOverload, bool implExists, bool isAbstract = false); -- Gitee