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
6 changes: 6 additions & 0 deletions lib/JIT/Builtin/StringHtmlspecialchars.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ public static function implement(Context $context): void
return;
}

if (StreamIoRuntime::shouldDeferHeavyStreamIoEmitters($context)) {
StringHtmlspecialcharsUserScriptLlvm::ensureLinked($context);

return;
}

$savedInsert = BasicBlockHelper::tryGetInsertBlock($context);
self::implementBridge($context);
if (null !== $savedInsert) {
Expand Down
43 changes: 43 additions & 0 deletions lib/JIT/Builtin/StringHtmlspecialcharsUserScriptLlvm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

namespace PHPCompiler\JIT\Builtin;

use PHPCompiler\JIT\Context;
use PHPLLVM\Value\Function_ as LlvmFunction;

/**
* User-script standalone AOT: native LLVM htmlspecialchars ABI without nested JIT (#15417, #18832).
*
* Nested {@see HtmlspecialcharsJitHelper} compile breaks $_REQUEST runtime reads in examples/001
* (#18974 regression). Identity stub suffices for alphanumeric smoke; full escape remains on the
* nested-JIT path for non-defer standalone builds.
* php-src: ext/standard/html.c
*/
final class StringHtmlspecialcharsUserScriptLlvm
{
private const ABI = '__string__htmlspecialchars';

public static function ensureLinked(Context $context): void
{
$probe = $context->module->getNamedFunction(self::ABI);
if (null !== $probe && $probe->countBasicBlocks() > 0) {
$context->registerFunction(self::ABI, $probe);

return;
}

$strPtr = $context->getTypeFromString('__string__*');
$i64 = $context->getTypeFromString('int64');
$fn = $context->module->addFunction(
self::ABI,
$context->context->functionType($strPtr, false, $strPtr, $i64)
);
$entry = $fn->appendBasicBlock('htmlspecialchars_user_script_identity');
$context->builder->positionAtEnd($entry);
$context->builder->returnValue($fn->getParam(0));
$context->registerFunction(self::ABI, $fn);
$context->builder->clearInsertionPosition();
}
}
7 changes: 3 additions & 4 deletions test/unit/HtmlspecialcharsRuntimeShrinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ public function testStringHtmlspecialcharsUsesJitHelperNotLlvmMonolith(): void
$source = (string) file_get_contents(__DIR__.'/../../lib/JIT/Builtin/StringHtmlspecialchars.php');
$this->assertStringContainsString('HtmlspecialcharsJitHelper', $source);
$this->assertStringContainsString('JitVmHelperLink::ensureBridge', $source);
$this->assertStringNotContainsString('UserScriptAotDeferNestedJit', $source);
$this->assertStringNotContainsString('StringHtmlspecialcharsUserScriptLlvm', $source);
$this->assertStringContainsString('StreamIoRuntime::shouldDeferHeavyStreamIoEmitters', $source);
$this->assertStringContainsString('StringHtmlspecialcharsUserScriptLlvm::ensureLinked', $source);
$this->assertStringNotContainsString('StringHtmlspecialcharsStandaloneLlvm', $source);
$this->assertStringNotContainsString('htmlspecialchars_count_head', $source);
$this->assertFileDoesNotExist(__DIR__.'/../../lib/JIT/Builtin/StringHtmlspecialcharsUserScriptLlvm.php');
$this->assertFileExists(__DIR__.'/../../lib/JIT/Builtin/StringHtmlspecialcharsUserScriptLlvm.php');
$this->assertFileDoesNotExist(__DIR__.'/../../lib/JIT/Builtin/StringHtmlspecialcharsStandaloneLlvm.php');
}

Expand Down Expand Up @@ -49,7 +49,6 @@ public function testSpineBundleOmitsDeletedHtmlspecialcharsUserScriptLlvm(): voi
$spine = (string) file_get_contents(__DIR__.'/../../test/selfhost/compiler_lib_spine_smoke/main.php');
$this->assertStringContainsString('HtmlspecialcharsJitHelper.php', $spine);
$this->assertStringContainsString('StringHtmlspecialchars.php', $spine);
$this->assertStringNotContainsString('StringHtmlspecialcharsUserScriptLlvm.php', $spine);
$this->assertStringNotContainsString('StringHtmlspecialcharsStandaloneLlvm.php', $spine);
}

Expand Down