From f594f1db77372840865fc5a1e96a12abaaf33a3d Mon Sep 17 00:00:00 2001 From: ekkoruse Date: Wed, 16 Jul 2025 10:38:02 +0800 Subject: [PATCH] fix forupdate clone fix forupdate clone segv Issue: https://gitee.com/openharmony/arkcompiler_ets_frontend/issues/ICMMDW?from=project-issue Signed-off-by: ekkoruse --- .../ir/statements/forUpdateStatement.cpp | 6 ++--- .../test/ast/parser/ets/forupdate_clone.ets | 25 +++++++++++++++++++ 2 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 ets2panda/test/ast/parser/ets/forupdate_clone.ets diff --git a/ets2panda/ir/statements/forUpdateStatement.cpp b/ets2panda/ir/statements/forUpdateStatement.cpp index 912dd11f40..123bb71a20 100644 --- a/ets2panda/ir/statements/forUpdateStatement.cpp +++ b/ets2panda/ir/statements/forUpdateStatement.cpp @@ -127,9 +127,9 @@ checker::VerifiedType ForUpdateStatement::Check(checker::ETSChecker *checker) ForUpdateStatement *ForUpdateStatement::Clone(ArenaAllocator *const allocator, AstNode *const parent) { - auto *const init = init_->Clone(allocator, nullptr); - auto *const test = test_->Clone(allocator, nullptr)->AsExpression(); - auto *const update = update_->Clone(allocator, nullptr)->AsExpression(); + auto *const init = init_ == nullptr ? nullptr : init_->Clone(allocator, nullptr); + auto *const test = test_ == nullptr ? nullptr : test_->Clone(allocator, nullptr)->AsExpression(); + auto *const update = update_ == nullptr ? nullptr : update_->Clone(allocator, nullptr)->AsExpression(); auto *const body = body_->Clone(allocator, nullptr)->AsStatement(); auto *const clone = util::NodeAllocator::ForceSetParent(allocator, init, test, update, body); diff --git a/ets2panda/test/ast/parser/ets/forupdate_clone.ets b/ets2panda/test/ast/parser/ets/forupdate_clone.ets new file mode 100644 index 0000000000..231d72c0e6 --- /dev/null +++ b/ets2panda/test/ast/parser/ets/forupdate_clone.ets @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2024-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. + */ + +let b = (() => { + return () => { + let a = 1 + for (let i = 0; i < 5;) { + a += 1 + i += 1 + } + return a; + }; +})(); -- Gitee