mirror of
https://gitee.com/openharmony/arkcompiler_ets_runtime
synced 2024-10-06 23:54:03 +00:00
Fix bug that crash when circuit has no return
Issue: https://gitee.com/openharmony/arkcompiler_ets_runtime/issues/I9HVQ1 Description: Fix bug that crash when circuit has no return Signed-off-by: yycc <yuyicen1@huawei.com> Change-Id: Ief7e81e2359c8b6e69c58bb821555de86e882d77
This commit is contained in:
parent
21dd6c25b1
commit
bc481d15ba
@ -160,6 +160,7 @@ libark_jsoptimizer_sources = [
|
||||
"operations_stub_builder.cpp",
|
||||
"pass_manager.cpp",
|
||||
"post_schedule.cpp",
|
||||
"precompile_checker.cpp",
|
||||
"profiler_stub_builder.cpp",
|
||||
"range_analysis.cpp",
|
||||
"range_guard.cpp",
|
||||
|
@ -41,6 +41,7 @@
|
||||
#include "ecmascript/compiler/ntype_hcr_lowering.h"
|
||||
#include "ecmascript/compiler/number_speculative_runner.h"
|
||||
#include "ecmascript/compiler/post_schedule.h"
|
||||
#include "ecmascript/compiler/precompile_checker.h"
|
||||
#include "ecmascript/compiler/scheduler.h"
|
||||
#include "ecmascript/compiler/string_builder_optimizer.h"
|
||||
#include "ecmascript/compiler/slowpath_lowering.h"
|
||||
@ -276,6 +277,21 @@ private:
|
||||
T1* data_;
|
||||
};
|
||||
|
||||
class PreCompileCheckPass {
|
||||
public:
|
||||
bool Run(PassData* data)
|
||||
{
|
||||
TimeScope timescope("PreCompileCheckPass", data->GetMethodName(), data->GetMethodOffset(), data->GetLog());
|
||||
bool enableLog = data->GetLog()->GetEnableMethodLog() && data->GetLog()->OutputType();
|
||||
PreCompileChecker preCompileChecker(data, data->GetCircuit(), data->GetMethodName(), enableLog);
|
||||
if (!preCompileChecker.Run()) {
|
||||
data->AbortCompilation();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
class PGOTypeInferPass {
|
||||
public:
|
||||
bool Run(PassData* data)
|
||||
|
@ -282,8 +282,7 @@ bool PassManager::Compile(JSPandaFile *jsPandaFile, const std::string &fileName,
|
||||
compilationEnv_->GetNativeAreaAllocator(), decoder, passOptions_,
|
||||
optBCRange_);
|
||||
PassRunner<PassData> pipeline(&data);
|
||||
if (data.GetMethodLiteral()->HasDebuggerStmt()) {
|
||||
data.AbortCompilation();
|
||||
if (!pipeline.RunPass<PreCompileCheckPass>()) {
|
||||
return;
|
||||
}
|
||||
pipeline.RunPass<RunFlowCyclesVerifierPass>();
|
||||
|
53
ecmascript/compiler/precompile_checker.cpp
Normal file
53
ecmascript/compiler/precompile_checker.cpp
Normal file
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "ecmascript/compiler/pass.h"
|
||||
#include "ecmascript/compiler/precompile_checker.h"
|
||||
|
||||
namespace panda::ecmascript::kungfu {
|
||||
|
||||
bool PreCompileChecker::Run()
|
||||
{
|
||||
if (!HasReturnCheck()) {
|
||||
PrintAbortInfo("HasReturnCheck");
|
||||
return false;
|
||||
}
|
||||
if (HasDebuggerStmt()) {
|
||||
PrintAbortInfo("HasDebuggerStmt");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PreCompileChecker::HasReturnCheck() const
|
||||
{
|
||||
std::vector<GateRef> returnList;
|
||||
acc_.GetReturnOuts(returnList);
|
||||
return returnList.size() != 0;
|
||||
}
|
||||
|
||||
bool PreCompileChecker::HasDebuggerStmt() const
|
||||
{
|
||||
return data_->GetMethodLiteral()->HasDebuggerStmt();
|
||||
}
|
||||
|
||||
void PreCompileChecker::PrintAbortInfo(const std::string& checkName) const
|
||||
{
|
||||
if (enableLog_) {
|
||||
LOG_COMPILER(INFO) << checkName << " check failed! Abort compiling method "
|
||||
<< methodName_;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace panda::ecmascript::kungfu
|
41
ecmascript/compiler/precompile_checker.h
Normal file
41
ecmascript/compiler/precompile_checker.h
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef ECMASCRIPT_COMPILER_PRECOMPILE_CHECKER_H
|
||||
#define ECMASCRIPT_COMPILER_PRECOMPILE_CHECKER_H
|
||||
|
||||
#include "ecmascript/compiler/gate_accessor.h"
|
||||
|
||||
namespace panda::ecmascript::kungfu {
|
||||
class PassData;
|
||||
class PreCompileChecker {
|
||||
public:
|
||||
PreCompileChecker(PassData* data, Circuit* circuit, const std::string& methodName, bool enableLog)
|
||||
: data_(data), acc_(circuit), methodName_(methodName), enableLog_(enableLog) {}
|
||||
|
||||
bool Run();
|
||||
|
||||
private:
|
||||
bool HasReturnCheck() const;
|
||||
bool HasDebuggerStmt() const;
|
||||
void PrintAbortInfo(const std::string& checkName) const;
|
||||
PassData* data_;
|
||||
GateAccessor acc_;
|
||||
const std::string methodName_;
|
||||
bool enableLog_;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue
Block a user