From 9d9556929f0b88ce0b28662dde233e691202d6ea Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Mon, 20 Apr 2026 16:50:46 +0800 Subject: [PATCH] =?UTF-8?q?test(aot):=20=E6=B7=BB=E5=8A=A0=E7=B1=BB?= =?UTF-8?q?=E5=B8=B8=E9=87=8F=E6=B5=8B=E8=AF=95=E7=94=A8=E4=BE=8B=E5=B9=B6?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=BF=94=E5=9B=9E=E5=80=BC=E8=A7=A3=E5=BC=95?= =?UTF-8?q?=E7=94=A8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 class const 001 测试用例验证 AOT 编译功能 - 在返回值处理后添加 php::deref(return_value) 确保正确解引用 - 修复了函数返回值可能存在的内存引用问题 - 测试用例覆盖了数组排序和引用传递场景 --- src/Php/Translator.php | 1 + tests/aot/ref/009.phpt | 45 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 tests/aot/ref/009.phpt diff --git a/src/Php/Translator.php b/src/Php/Translator.php index dbb1ff9f..69fc3137 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -1252,6 +1252,7 @@ class Translator extends Preprocessor if ($functionDef->returnType !== self::TYPE_VOID) { $cppCode .= $this->getIndent() . 'auto retval = ' . $fn . '(' . $callParams . ');' . PHP_EOL; $cppCode .= $this->getIndent() . 'php::move(retval, return_value);' . PHP_EOL; + $cppCode .= $this->getIndent() . 'php::deref(return_value);' . PHP_EOL; } else { $cppCode .= $this->getIndent() . $fn . '(' . $callParams . ');' . PHP_EOL; } diff --git a/tests/aot/ref/009.phpt b/tests/aot/ref/009.phpt new file mode 100644 index 00000000..2b2ff674 --- /dev/null +++ b/tests/aot/ref/009.phpt @@ -0,0 +1,45 @@ +--TEST-- +class const 001 +--FILE-- +foo(); + } +} + +class WorkerB extends WorkerA +{ + public function foo(): array { + $list = [377, 64, 688, 2]; + $ref = &$list; + $this->sort($ref); + return $list; + } +} + +function main() +{ + $o = new WorkerB; + var_dump($o->run()); +} +?> +--EXPECT-- +array(4) { + [0]=> + int(2) + [1]=> + int(64) + [2]=> + int(377) + [3]=> + int(688) +} \ No newline at end of file