From 643134f76da21c8ead58e827ec9a539d75145785 Mon Sep 17 00:00:00 2001 From: MuSilk Date: Thu, 17 Jul 2025 17:26:29 +0800 Subject: [PATCH] Fix INT_MIN % -1 bug Issue:[Bug]: INT_MIN % -1 crashed https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICN1A6 Signed-off-by: MuSilk --- .../ets/constantExpressionLowering.cpp | 3 +++ .../test/runtime/ets/intmin_mod_minus_1.ets | 20 +++++++++++++++++++ .../test/runtime/ets/large_number_parse.ets | 18 +++++++++++++++++ .../ets-runtime/ets-runtime-ignored.txt | 3 +++ 4 files changed, 44 insertions(+) create mode 100644 ets2panda/test/runtime/ets/intmin_mod_minus_1.ets create mode 100644 ets2panda/test/runtime/ets/large_number_parse.ets diff --git a/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp b/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp index 6a08c07932..505e6eaa95 100644 --- a/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp +++ b/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp @@ -616,6 +616,9 @@ static TargetType PerformMultiplicativeOperation(TargetType leftNum, TargetType return std::numeric_limits::max(); } if constexpr (std::is_integral_v) { + if (isIntegralDivideResOverflow()) { + return 0; + } return leftNum % rightNum; } else { return std::fmod(leftNum, rightNum); diff --git a/ets2panda/test/runtime/ets/intmin_mod_minus_1.ets b/ets2panda/test/runtime/ets/intmin_mod_minus_1.ets new file mode 100644 index 0000000000..0070beeee9 --- /dev/null +++ b/ets2panda/test/runtime/ets/intmin_mod_minus_1.ets @@ -0,0 +1,20 @@ +/* + * 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() { + const INT_MIN:int = -2147483648; + let a = INT_MIN % -1; + arktest.assertEQ(a, 0); +} \ No newline at end of file diff --git a/ets2panda/test/runtime/ets/large_number_parse.ets b/ets2panda/test/runtime/ets/large_number_parse.ets new file mode 100644 index 0000000000..a2d8d03389 --- /dev/null +++ b/ets2panda/test/runtime/ets/large_number_parse.ets @@ -0,0 +1,18 @@ +/* + * 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. + */ + +const INT_MIN = 0x800000013; +let a = INT_MIN % 10; +arktest.assertEQ(a,7); \ No newline at end of file diff --git a/ets2panda/test/test-lists/ets-runtime/ets-runtime-ignored.txt b/ets2panda/test/test-lists/ets-runtime/ets-runtime-ignored.txt index e06e50c35d..92528c5c18 100644 --- a/ets2panda/test/test-lists/ets-runtime/ets-runtime-ignored.txt +++ b/ets2panda/test/test-lists/ets-runtime/ets-runtime-ignored.txt @@ -124,3 +124,6 @@ RecursiveTypeAlias10.ets first_match/namespace.ets first_match/namespace2.ets first_match/namespace3.ets + +# Issue #28214 +large_number_parse.ets \ No newline at end of file -- Gitee