Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions lib/JIT/Builtin/StringNaturalCompareJit.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
namespace PHPCompiler\JIT\Builtin;

use PHPCompiler\JIT\BasicBlockHelper;
use PHPCompiler\JIT\Builtin;
use PHPCompiler\JIT\Context;
use PHPLLVM\BasicBlock;
use PHPLLVM\Builder;
use PHPLLVM\Value;
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
{
Expand All @@ -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);
Expand Down
29 changes: 29 additions & 0 deletions test/compliance/StrnatcmpJITTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace PHPCompiler;

require_once __DIR__.'/../BaseTest.php';

/**
* @group llvm
*/
/** JIT compliance for strnatcmp() / strnatcasecmp(). */
final class StrnatcmpJITTest extends BaseTest
{
protected static string $DIR = __DIR__;

public static function providePHPTests(): \Generator
{
yield 'strnatcmp_jit.phpt' => self::parsePHPT(
__DIR__.'/cases/stdlib/strnatcmp_jit.phpt',
'strnatcmp_jit.phpt'
);
}

public function setUp(): void
{
$this->BIN = realpath(__DIR__.'/../../bin/jit.php');
}
}
14 changes: 14 additions & 0 deletions test/compliance/cases/stdlib/strnatcmp_jit.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
JIT: strnatcmp() / strnatcasecmp() (#5517)
--FILE--
<?php
var_export(strnatcmp('2', '10'));
echo "\n";
var_export(strnatcmp('10', '2'));
echo "\n";
var_export(strnatcasecmp('aB', 'Ab'));
echo "\n";
--EXPECT--
-1
1
0
11 changes: 11 additions & 0 deletions test/fixtures/aot/cases/strnatcmp.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--TEST--
AOT: strnatcmp() / strnatcasecmp() (#5517)
--FILE--
<?php
var_export(strnatcmp('2', '10'));
echo "\n";
var_export(strnatcasecmp('aB', 'Ab'));
echo "\n";
--EXPECT--
-1
0
31 changes: 31 additions & 0 deletions test/unit/JIT/StringNaturalCompareStandaloneTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace PHPCompiler\JIT;

use PHPCompiler\JIT\Builtin\StringNaturalCompareJit;
use PHPCompiler\Runtime;
use PHPUnit\Framework\TestCase;

/**
* Issue #5517: AOT standalone must define strnatcmp/strnatcasecmp without phpc_strnatcmp*.c.
*
* @group aot-lint
*/
final class StringNaturalCompareStandaloneTest extends TestCase
{
public function testImplementDefinesNaturalCompareForStandalone(): void
{
$runtime = new Runtime(Runtime::MODE_AOT);
$ctx = new Context($runtime, Builtin::LOAD_TYPE_STANDALONE);
StringNaturalCompareJit::implementStrnatcmp($ctx);
StringNaturalCompareJit::implementStrnatcasecmp($ctx);

foreach (['strnatcmp', 'strnatcasecmp'] as $name) {
$fn = $ctx->lookupFunction($name);
$this->assertNotNull($fn);
$this->assertGreaterThan(0, $fn->countBasicBlocks());
}
}
}