From 242a541d9fe91e95748558a3351097d4b6841c55 Mon Sep 17 00:00:00 2001 From: PurHur Date: Sat, 6 Jun 2026 14:31:07 +0000 Subject: [PATCH] php-in-php: strnatcmp LLVM bodies for AOT standalone (#5517) Emit strnatcmp/strnatcasecmp LLVM in standalone load type (no phpc_strnatcmp*.c), add JIT compliance + standalone unit test, and AOT fixture. Co-authored-by: Cursor --- lib/JIT/Builtin/StringNaturalCompareJit.php | 11 ++----- test/compliance/StrnatcmpJITTest.php | 29 +++++++++++++++++ .../cases/stdlib/strnatcmp_jit.phpt | 14 +++++++++ test/fixtures/aot/cases/strnatcmp.phpt | 11 +++++++ .../StringNaturalCompareStandaloneTest.php | 31 +++++++++++++++++++ 5 files changed, 88 insertions(+), 8 deletions(-) create mode 100644 test/compliance/StrnatcmpJITTest.php create mode 100644 test/compliance/cases/stdlib/strnatcmp_jit.phpt create mode 100644 test/fixtures/aot/cases/strnatcmp.phpt create mode 100644 test/unit/JIT/StringNaturalCompareStandaloneTest.php diff --git a/lib/JIT/Builtin/StringNaturalCompareJit.php b/lib/JIT/Builtin/StringNaturalCompareJit.php index 8e8ca1ffa9b..f4425e307ca 100644 --- a/lib/JIT/Builtin/StringNaturalCompareJit.php +++ b/lib/JIT/Builtin/StringNaturalCompareJit.php @@ -5,7 +5,6 @@ namespace PHPCompiler\JIT\Builtin; use PHPCompiler\JIT\BasicBlockHelper; -use PHPCompiler\JIT\Builtin; use PHPCompiler\JIT\Context; use PHPLLVM\BasicBlock; use PHPLLVM\Builder; @@ -13,7 +12,9 @@ use PHPLLVM\Value\Function_ as LlvmFunction; /** - * LLVM natural-order string compare (mirrors VmString::strnatcmp / strnatcasecmp, phpc_strnatcmp.c). + * LLVM natural-order string compare (mirrors VmString::strnatcmp / strnatcasecmp). + * + * Replaces deleted lib/AOT/runtime/phpc_strnatcmp.c + phpc_strnatcasecmp.c (#5517). */ final class StringNaturalCompareJit { @@ -29,12 +30,6 @@ public static function implementStrnatcasecmp(Context $context): void private static function implementNamed(Context $context, string $name, bool $caseInsensitive): void { - if (Builtin::LOAD_TYPE_STANDALONE === $context->loadType) { - self::declareIfMissing($context, $name); - - return; - } - $probe = $context->module->getNamedFunction($name); if (null !== $probe && $probe->countBasicBlocks() > 0) { $context->registerFunction($name, $probe); diff --git a/test/compliance/StrnatcmpJITTest.php b/test/compliance/StrnatcmpJITTest.php new file mode 100644 index 00000000000..c50f8cf2390 --- /dev/null +++ b/test/compliance/StrnatcmpJITTest.php @@ -0,0 +1,29 @@ + self::parsePHPT( + __DIR__.'/cases/stdlib/strnatcmp_jit.phpt', + 'strnatcmp_jit.phpt' + ); + } + + public function setUp(): void + { + $this->BIN = realpath(__DIR__.'/../../bin/jit.php'); + } +} diff --git a/test/compliance/cases/stdlib/strnatcmp_jit.phpt b/test/compliance/cases/stdlib/strnatcmp_jit.phpt new file mode 100644 index 00000000000..10cceb8335c --- /dev/null +++ b/test/compliance/cases/stdlib/strnatcmp_jit.phpt @@ -0,0 +1,14 @@ +--TEST-- +JIT: strnatcmp() / strnatcasecmp() (#5517) +--FILE-- +lookupFunction($name); + $this->assertNotNull($fn); + $this->assertGreaterThan(0, $fn->countBasicBlocks()); + } + } +}