diff --git a/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp b/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp index 57b3ae2698198bf3160c4d3369bf256939d3aa4e..13aafc786b9f38fbbbe724c3f585a3470ee68373 100644 --- a/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp +++ b/ets2panda/compiler/lowering/ets/constantExpressionLowering.cpp @@ -581,6 +581,10 @@ static TargetType PerformMultiplicativeOperation(TargetType leftNum, TargetType { auto isForbiddenZeroDivision = [&rightNum]() { return std::is_integral_v && rightNum == 0; }; auto isFloatZeroDevision = [&rightNum]() { return std::is_floating_point_v && rightNum == 0; }; + auto isIntegralDivideResOverflow = [&rightNum, &leftNum]() { + // Note: Handle corner cases + return std::is_integral_v && leftNum == std::numeric_limits::min() && rightNum == -1; + }; auto opType = expr->OperatorType(); switch (opType) { case lexer::TokenType::PUNCTUATOR_MULTIPLY: { @@ -597,7 +601,9 @@ static TargetType PerformMultiplicativeOperation(TargetType leftNum, TargetType } ES2PANDA_ASSERT(rightNum != 0); - // CC-OFFNXT(G.EXP.22-CPP) false positive + if (isIntegralDivideResOverflow()) { + return std::numeric_limits::min(); + } return leftNum / rightNum; } case lexer::TokenType::PUNCTUATOR_MOD: { diff --git a/ets2panda/parser/ETSparserAnnotations.cpp b/ets2panda/parser/ETSparserAnnotations.cpp index 25c6ec13c3afa43bcb08aafbe371f0a326fe044b..1f37cf46053fa86a9d59f233bf34ad0acc66b473 100644 --- a/ets2panda/parser/ETSparserAnnotations.cpp +++ b/ets2panda/parser/ETSparserAnnotations.cpp @@ -114,7 +114,8 @@ ArenaVector ETSParser::ParseAnnotationProperties(ir::ModifierFlag Lexer()->NextToken(lexer::NextTokenFlags::KEYWORD_TO_IDENT); ArenaVector properties(Allocator()->Adapter()); - while (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_RIGHT_BRACE) { + while (Lexer()->GetToken().Type() != lexer::TokenType::PUNCTUATOR_RIGHT_BRACE && + Lexer()->GetToken().Type() != lexer::TokenType::EOS) { if ((memberModifiers & ir::ModifierFlags::ANNOTATION_DECLARATION) != 0U && Lexer()->GetToken().Type() == lexer::TokenType::PUNCTUATOR_SEMI_COLON) { Lexer()->NextToken(); // eat ';' diff --git a/ets2panda/test/ast/compiler/ets/parser_annotation_n.ets b/ets2panda/test/ast/compiler/ets/parser_annotation_n.ets new file mode 100644 index 0000000000000000000000000000000000000000..32781a0e03ff9243f03759e7940168c57252ce1d --- /dev/null +++ b/ets2panda/test/ast/compiler/ets/parser_annotation_n.ets @@ -0,0 +1,19 @@ +/* + * 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. + */ + +@interface /* @@ label1 */� + +/* @@@ label1 Error SyntaxError: Unexpected token, expected an identifier. */ +/* @@? 20:1 Error SyntaxError: Expected '{', got 'end of stream'. */ diff --git a/ets2panda/test/runtime/ets/MaxBoundInt.ets b/ets2panda/test/runtime/ets/MaxBoundInt.ets new file mode 100644 index 0000000000000000000000000000000000000000..b03c7c465559dc536d5dd19a5b2b919d12355f02 --- /dev/null +++ b/ets2panda/test/runtime/ets/MaxBoundInt.ets @@ -0,0 +1,17 @@ +/* + * 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. + */ + +arktest.assertEQ(-2147483648 / -1, -2147483648) +arktest.assertEQ(-9223372036854775808 / -1, -9223372036854775808)