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: 10 additions & 1 deletion lib/JIT/Builtin/GetHeadersRuntime.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace PHPCompiler\JIT\Builtin;

use PHPCompiler\JIT\BasicBlockHelper;
use PHPCompiler\JIT\Context;
use PHPCompiler\JIT\JitNestedHelperCoerce;
use PHPCompiler\JIT\JitVmHelperLink;
Expand All @@ -13,6 +14,8 @@
* JIT/AOT link for __compiler_get_headers via GetHeadersJitHelper PHP (#9212, #24633).
*
* Helper compile: {@see JitVmHelperLink::ensureCompiled} (peer StreamFstat #24586 / StringQuotPrint #24620).
* Call-site {@see ensureLinked} restores the caller insert block after bridge emit
* (thin AOT: "Current basic block has no parent function", #27317 / peer #27088).
* SSOT {@see \PHPCompiler\ext\standard\VmHttpFetchNative} / {@see \PHPCompiler\ext\standard\VmHttpHeaders}.
* php-src: ext/standard/head.c — PHP_FUNCTION(get_headers)
*/
Expand Down Expand Up @@ -43,10 +46,16 @@ public static function implement(Context $context): void
return;
}

// Preserve caller insert block — clearInsertionPosition alone orphans mid-emit (#27317 / #27088).
$savedInsert = BasicBlockHelper::tryGetInsertBlock($context);
self::ensureJitHelperCompiled($context);
self::implementGetHeadersBridge($context);
self::registerLinkedRuntime($context);
$context->builder->clearInsertionPosition();
if (null !== $savedInsert) {
BasicBlockHelper::restoreInsertBlock($context, $savedInsert);
} else {
$context->builder->clearInsertionPosition();
}
}

private static function implementGetHeadersBridge(Context $context): void
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/aot/cases/get_headers_refused_connection.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
--TEST--
AOT get_headers() refused connection returns false (#27317, ext/standard/head.c)
--FILE--
<?php
echo var_export(@get_headers('http://127.0.0.1:1/') === false, true), "\n";
--EXPECT--
true
15 changes: 15 additions & 0 deletions test/repro/maintainer_gap_aot_get_headers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
/**
* Maintainer gap — AOT get_headers() compile fails (ext/standard/head.c).
*
* Zend/VM/JIT: false for refused connection (with @).
* AOT: compile aborts — "Current basic block has no parent function".
*
* php-src: ext/standard/head.c — PHP_FUNCTION(get_headers)
*
* Run:
* php bin/vm.php test/repro/maintainer_gap_aot_get_headers.php
* php bin/jit.php test/repro/maintainer_gap_aot_get_headers.php
* php bin/compile.php test/repro/maintainer_gap_aot_get_headers.php -o /tmp/get_headers_aot
*/
echo var_export(@get_headers('http://127.0.0.1:1/') === false, true), "\n";
3 changes: 2 additions & 1 deletion test/unit/GetHeadersJitRuntimeShrinkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ public function testGetHeadersRuntimeRoutesThroughGetHeadersJitHelper(): void
$this->assertStringContainsString('GetHeadersJitHelper', $source);
$this->assertStringContainsString('JitVmHelperLink::ensureCompiled', $source);
$this->assertStringContainsString('JitVmHelperLink::lookupCompiled', $source);
$this->assertStringContainsString('BasicBlockHelper::restoreInsertBlock', $source);
$this->assertStringNotContainsString('VmHttpFetchPure::request', $source);
$this->assertStringNotContainsString('NestedJitCompileScope::run', $source);
$this->assertStringNotContainsString('parseAndCompile', $source);
$this->assertStringNotContainsString('new JIT(', $source);
$this->assertStringNotContainsString('use PHPCompiler\\JIT;', $source);

$lineCount = \substr_count($source, "\n");
$this->assertLessThan(120, $lineCount, 'GetHeadersRuntime must be a thin bridge');
$this->assertLessThan(130, $lineCount, 'GetHeadersRuntime must be a thin bridge');
}

public function testJitGetHeadersUsesCompilerGetHeadersAbi(): void
Expand Down
Loading