From f627b8799c53d66c1b7b1598bb52dce9bd95a273 Mon Sep 17 00:00:00 2001 From: Csaba Osztrogonac Date: Mon, 8 May 2023 03:36:09 +0200 Subject: [PATCH] [ets] Fix compiling conditions There were a typo in Condition::Compile() which caused that boxing/unboxing conversions on the left operand weren't applied. Change-Id: I745ba6025ffb0af5e3512448da8071f3c4cf3b22 Signed-off-by: Csaba Osztrogonac --- compiler/base/condition.cpp | 2 +- test/runtime/ets/if-unbox.ets | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 test/runtime/ets/if-unbox.ets diff --git a/compiler/base/condition.cpp b/compiler/base/condition.cpp index be2ff503d..8a452c057 100644 --- a/compiler/base/condition.cpp +++ b/compiler/base/condition.cpp @@ -120,7 +120,7 @@ void Condition::Compile(ETSGen *etsg, const ir::Expression *expr, Label *false_l VReg lhs = etsg->AllocReg(); bin_expr->Left()->Compile(etsg); - etsg->ApplyConversionAndStoreAccumulator(bin_expr, lhs, bin_expr->OperationType()); + etsg->ApplyConversionAndStoreAccumulator(bin_expr->Left(), lhs, bin_expr->OperationType()); bin_expr->Right()->Compile(etsg); etsg->ApplyConversion(bin_expr->Right(), bin_expr->OperationType()); etsg->Condition(bin_expr, bin_expr->OperatorType(), lhs, false_label); diff --git a/test/runtime/ets/if-unbox.ets b/test/runtime/ets/if-unbox.ets new file mode 100644 index 000000000..5ce73ce03 --- /dev/null +++ b/test/runtime/ets/if-unbox.ets @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2023 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 cond1(): int { + let a = 1 as Int; + if(a != 5) return 1; + return 0; +} + +function cond2(): int { + if((1 as Int) != 5) return 1; + return 0; +} + +function main(): void { + assert cond1() == 1; + assert cond2() == 1; +} -- Gitee