From 620b3d3a092dbc28458d699f6fa6b212f5a08902 Mon Sep 17 00:00:00 2001 From: tengtengh Date: Wed, 3 Sep 2025 15:54:42 +0800 Subject: [PATCH] Fix incorrect bytecode of double division -0 Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICW6L8 Signed-off-by: tengtengh --- ets2panda/compiler/core/ETSCompiler.cpp | 6 +++-- ets2panda/test/runtime/ets/div_neg_zero_0.ets | 22 +++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 ets2panda/test/runtime/ets/div_neg_zero_0.ets diff --git a/ets2panda/compiler/core/ETSCompiler.cpp b/ets2panda/compiler/core/ETSCompiler.cpp index 897b874816..1d294ec436 100644 --- a/ets2panda/compiler/core/ETSCompiler.cpp +++ b/ets2panda/compiler/core/ETSCompiler.cpp @@ -1159,9 +1159,11 @@ void ETSCompiler::Compile(const ir::NumberLiteral *expr) const } else if (expr->Number().IsLong()) { etsg->LoadAccumulatorWideInt(expr, expr->Number().GetLong()); } else if (expr->Number().IsFloat()) { - etsg->LoadAccumulatorFloat(expr, expr->Number().GetFloat()); + etsg->LoadAccumulatorFloat(expr, expr->Number().Str().Is("-0") ? static_cast(-0.0) + : expr->Number().GetFloat()); } else { - etsg->LoadAccumulatorDouble(expr, expr->Number().GetDouble()); + etsg->LoadAccumulatorDouble(expr, expr->Number().Str().Is("-0") ? static_cast(-0.0) + : expr->Number().GetDouble()); } ES2PANDA_ASSERT(etsg->Checker()->Relation()->IsIdenticalTo(etsg->GetAccumulatorType(), expr->TsType())); diff --git a/ets2panda/test/runtime/ets/div_neg_zero_0.ets b/ets2panda/test/runtime/ets/div_neg_zero_0.ets new file mode 100644 index 0000000000..92ba9f762d --- /dev/null +++ b/ets2panda/test/runtime/ets/div_neg_zero_0.ets @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2025 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. + */ + +function main() { + let x1 = -0; + let y1 = 1; + let z1 = y1 / x1; + arktest.assertEQ(z1.toString(), "-Infinity") +} + -- Gitee