登录
注册
开源
企业版
高校版
搜索
帮助中心
使用条款
关于我们
开源
企业版
高校版
私有云
模力方舟
AI 队友
登录
注册
轻量养虾,开箱即用!低 Token + 稳定算力,Gitee & 模力方舟联合出品的 PocketClaw 正式开售!点击了解详情~
代码拉取完成,页面将自动刷新
仓库状态说明
捐赠
捐赠前请先登录
取消
前往登录
扫描微信二维码支付
取消
支付完成
支付提示
将跳转至支付宝完成支付
确定
取消
Watch
不关注
关注所有动态
仅关注版本发行动态
关注但不提醒动态
53
Star
23
Fork
153
OpenHarmony-SIG
/
arkcompiler_ets_frontend
关闭
代码
Issues
23
Pull Requests
81
Wiki
统计
流水线
服务
JavaDoc
PHPDoc
质量分析
Jenkins for Gitee
腾讯云托管
腾讯云 Serverless
悬镜安全
阿里云 SAE
Codeblitz
SBOM
开发画像分析
我知道了,不再自动展开
更新失败,请稍后重试!
移除标识
内容风险标识
本任务被
标识为内容中包含有代码安全 Bug 、隐私泄露等敏感信息,仓库外成员不可访问
[es2panda] char variable exceeds the limit
已完成
#I87CWW
任务
semenovaleksandr
创建于
2023-10-12 04:30
The following ArkTS program iterate char beyond the boundary defined in [ArkTS spec](https://gitee.com/openharmony-sig/arkcompiler_runtime_core/releases/download/sts-spec-release-2023-06-16/sts-spec-2023-06-16-77e6a6fa.pdf). Syntactically the program is correct (similar java program iterates endlessly as the value never reaches the threshold). Issue is that the cycle variable in fact is integer, not char, and the char value reaches the value of 100000. ```java function main(): void { let count: int = 0; for (let ch: char = 0; ch < 100000; ch++) { count++; console.println(count + "\t" + ch); // the program prints 100000 lines and stops. } } ``` output: ``` $ build-host/bin/es2panda test3.ets $ build-host/bin/ark_aot --load-runtimes=ets --boot-panda-files build-host/plugins/ets/etsstdlib.abc --compiler-disasm-dump --paoc-panda-files test3.abc $ build-host/bin/ark --boot-panda-files build-host/plugins/ets/etsstdlib.abc --load-runtimes=ets test3.abc ETSGLOBAL::main 1 �� 2 3 4 ... 99998 蚝 99999 蚞 100000 蚟 ``` Here is the disassembly of ets panda binary. Obviously it misses `andi 0xffff` instruction after the increment: ``` .function void ETSGLOBAL.main() <static, access.function=public> { ldai 0x0 sta v0 ldai 0x0 sta v1 jump_label_1: lda v1 sta v2 ldai 0x186a0 jle v2, jump_label_0 lda v0 sta v2 addi 0x1 sta v0 lda v2 ldstatic.obj std.core.ETSGLOBAL.console sta.obj v2 initobj.short std.core.StringBuilder._ctor_:(std.core.StringBuilder) sta.obj v4 lda v0 sta v5 call.short std.core.StringBuilder.append:(std.core.StringBuilder,i32), v4, v5 lda.str "\t" sta.obj v5 call.short std.core.StringBuilder.append:(std.core.StringBuilder,std.core.String), v4, v5 lda v1 sta v5 call.short std.core.StringBuilder.append:(std.core.StringBuilder,u16), v4, v5 call.short std.core.StringBuilder.toString:(std.core.StringBuilder), v4 sta.obj v3 call.virt.short std.core.Console.println:(std.core.Console,std.core.String), v2, v3 lda v1 sta v2 addi 0x1 sta v1 lda v2 jmp jump_label_1 jump_label_0: return.void } ``` For the reference, the similar java program with disassembly listing: ```java class Test3 { public static void main(String a[]) { int count = 0; for (char ch = 0; ch < 100_000; ch++) { count++; System.out.println(count + " " + ch); } } } .function void Test3.main(java.lang.String[] a0) <static, access.function=public> { movi v0, 0x186a0 movi v1, 0x0 mov v2, v1 jump_label_1: lda v2 jge v0, jump_label_0 inci v1, 0x1 ldstatic.obj java.lang.System.out sta.obj v3 initobj.short java.lang.StringBuilder._ctor_:(java.lang.StringBuilder) call.virt.acc.short java.lang.StringBuilder.append:(java.lang.StringBuilder,i32), v1, 0x0 sta.obj v4 lda.str " " call.virt.acc.short java.lang.StringBuilder.append:(java.lang.StringBuilder,java.lang.String), v4, 0x1 call.virt.acc.short java.lang.StringBuilder.append:(java.lang.StringBuilder,u16), v2, 0x0 call.virt.acc.short java.lang.StringBuilder.toString:(java.lang.StringBuilder), v0, 0x0 call.virt.acc.short java.io.PrintStream.println:(java.io.PrintStream,java.lang.String), v3, 0x1 lda v2 addi 0x1 andi 0xffff sta v2 jmp jump_label_1 jump_label_0: return.void } ``` For `char` there are separate bytecodes to save to different containers, which cut off extra bits. There is some arithmetic with 32-bit values and there are comparison operations for which uncleared high bits are critical. So, before comparison we need to do truncation of small types (less than 32-bit). Either via `andi` or via `i32toi16`.
The following ArkTS program iterate char beyond the boundary defined in [ArkTS spec](https://gitee.com/openharmony-sig/arkcompiler_runtime_core/releases/download/sts-spec-release-2023-06-16/sts-spec-2023-06-16-77e6a6fa.pdf). Syntactically the program is correct (similar java program iterates endlessly as the value never reaches the threshold). Issue is that the cycle variable in fact is integer, not char, and the char value reaches the value of 100000. ```java function main(): void { let count: int = 0; for (let ch: char = 0; ch < 100000; ch++) { count++; console.println(count + "\t" + ch); // the program prints 100000 lines and stops. } } ``` output: ``` $ build-host/bin/es2panda test3.ets $ build-host/bin/ark_aot --load-runtimes=ets --boot-panda-files build-host/plugins/ets/etsstdlib.abc --compiler-disasm-dump --paoc-panda-files test3.abc $ build-host/bin/ark --boot-panda-files build-host/plugins/ets/etsstdlib.abc --load-runtimes=ets test3.abc ETSGLOBAL::main 1 �� 2 3 4 ... 99998 蚝 99999 蚞 100000 蚟 ``` Here is the disassembly of ets panda binary. Obviously it misses `andi 0xffff` instruction after the increment: ``` .function void ETSGLOBAL.main() <static, access.function=public> { ldai 0x0 sta v0 ldai 0x0 sta v1 jump_label_1: lda v1 sta v2 ldai 0x186a0 jle v2, jump_label_0 lda v0 sta v2 addi 0x1 sta v0 lda v2 ldstatic.obj std.core.ETSGLOBAL.console sta.obj v2 initobj.short std.core.StringBuilder._ctor_:(std.core.StringBuilder) sta.obj v4 lda v0 sta v5 call.short std.core.StringBuilder.append:(std.core.StringBuilder,i32), v4, v5 lda.str "\t" sta.obj v5 call.short std.core.StringBuilder.append:(std.core.StringBuilder,std.core.String), v4, v5 lda v1 sta v5 call.short std.core.StringBuilder.append:(std.core.StringBuilder,u16), v4, v5 call.short std.core.StringBuilder.toString:(std.core.StringBuilder), v4 sta.obj v3 call.virt.short std.core.Console.println:(std.core.Console,std.core.String), v2, v3 lda v1 sta v2 addi 0x1 sta v1 lda v2 jmp jump_label_1 jump_label_0: return.void } ``` For the reference, the similar java program with disassembly listing: ```java class Test3 { public static void main(String a[]) { int count = 0; for (char ch = 0; ch < 100_000; ch++) { count++; System.out.println(count + " " + ch); } } } .function void Test3.main(java.lang.String[] a0) <static, access.function=public> { movi v0, 0x186a0 movi v1, 0x0 mov v2, v1 jump_label_1: lda v2 jge v0, jump_label_0 inci v1, 0x1 ldstatic.obj java.lang.System.out sta.obj v3 initobj.short java.lang.StringBuilder._ctor_:(java.lang.StringBuilder) call.virt.acc.short java.lang.StringBuilder.append:(java.lang.StringBuilder,i32), v1, 0x0 sta.obj v4 lda.str " " call.virt.acc.short java.lang.StringBuilder.append:(java.lang.StringBuilder,java.lang.String), v4, 0x1 call.virt.acc.short java.lang.StringBuilder.append:(java.lang.StringBuilder,u16), v2, 0x0 call.virt.acc.short java.lang.StringBuilder.toString:(java.lang.StringBuilder), v0, 0x0 call.virt.acc.short java.io.PrintStream.println:(java.io.PrintStream,java.lang.String), v3, 0x1 lda v2 addi 0x1 andi 0xffff sta v2 jmp jump_label_1 jump_label_0: return.void } ``` For `char` there are separate bytecodes to save to different containers, which cut off extra bits. There is some arithmetic with 32-bit values and there are comparison operations for which uncleared high bits are critical. So, before comparison we need to do truncation of small types (less than 32-bit). Either via `andi` or via `i32toi16`.
评论 (
2
)
登录
后才可以发表评论
状态
已完成
待办的
进行中
已完成
已拒绝
负责人
未设置
标签
未设置
项目
未立项任务
未立项任务
里程碑
未关联里程碑
未关联里程碑
Pull Requests
未关联
未关联
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
未关联
分支 (
-
)
标签 (
-
)
开始日期   -   截止日期
-
置顶选项
不置顶
置顶等级:高
置顶等级:中
置顶等级:低
优先级
不指定
严重
主要
次要
不重要
预计工期
(小时)
参与者(2)
1
https://gitee.com/openharmony-sig/arkcompiler_ets_frontend.git
git@gitee.com:openharmony-sig/arkcompiler_ets_frontend.git
openharmony-sig
arkcompiler_ets_frontend
arkcompiler_ets_frontend
点此查找更多帮助
搜索帮助
Git 命令在线学习
如何在 Gitee 导入 GitHub 仓库
Git 仓库基础操作
企业版和社区版功能对比
SSH 公钥设置
如何处理代码冲突
仓库体积过大,如何减小?
如何找回被删除的仓库数据
Gitee 产品配额说明
GitHub仓库快速导入Gitee及同步更新
什么是 Release(发行版)
将 PHP 项目自动发布到 packagist.org
评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册