1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00
Files
archived-php-src/ext/opcache/tests/opt/sccp_022.phpt
Ilija Tovilo 6173a9a109 VAR|TMP overhaul (GH-20628)
The aim of this PR is twofold:

- Reduce the number of highly similar TMP|VAR handlers
- Avoid ZVAL_DEREF in most of these cases

This is achieved by guaranteeing that all zend_compile_expr() calls, as well as
all other compile calls with BP_VAR_{R,IS}, will result in a TMP variable. This
implies that the result will not contain an IS_INDIRECT or IS_REFERENCE value,
which was mostly already the case, with two exceptions:

- Calls to return-by-reference functions. Because return-by-reference functions
  are quite rare, this is solved by delegating the DEREF to the RETURN_BY_REF
  handler, which will examine the stack to check whether the caller expects a
  VAR or TMP to understand whether the DEREF is needed. Internal functions will
  also need to adjust by calling the zend_return_unwrap_ref() function.

- By-reference assignments, including both $a = &$b, as well as $a = [&$b]. When
  the result of these expressions is used in a BP_VAR_R context, the reference
  is unwrapped via a ZEND_QM_ASSIGN opcode beforehand. This is exceptionally
  rare.

Closes GH-20628
2026-01-31 19:44:56 +01:00

66 lines
1.2 KiB
PHP

--TEST--
SCCP 022: Invalid types
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.optimization_level=-1
opcache.opt_debug_level=0x20000
opcache.preload=
zend_test.observer.enabled=0
--EXTENSIONS--
opcache
--FILE--
<?php
function foo(int $x) {
$a[0] = $x;
$a[1] = 5;
echo $a[1];
$a->foo = 5;
echo $a[1];
}
function bar() {
foreach ($a as $v) {
foreach ($v as $v2) {}
}
}
?>
--EXPECTF--
$_main:
; (lines=1, args=0, vars=0, tmps=0)
; (after optimizer)
; %s
0000 RETURN int(1)
foo:
; (lines=11, args=1, vars=2, tmps=1)
; (after optimizer)
; %s
0000 CV0($x) = RECV 1
0001 ASSIGN_DIM CV1($a) int(0)
0002 OP_DATA CV0($x)
0003 ASSIGN_DIM CV1($a) int(1)
0004 OP_DATA int(5)
0005 ECHO string("5")
0006 ASSIGN_OBJ CV1($a) string("foo")
0007 OP_DATA int(5)
0008 T2 = FETCH_DIM_R CV1($a) int(1)
0009 ECHO T2
0010 RETURN null
bar:
; (lines=9, args=0, vars=3, tmps=2)
; (after optimizer)
; %s
0000 T3 = FE_RESET_R CV0($a) 0007
0001 FE_FETCH_R T3 CV1($v) 0007
0002 T4 = FE_RESET_R CV1($v) 0005
0003 FE_FETCH_R T4 CV2($v2) 0005
0004 JMP 0003
0005 FE_FREE T4
0006 JMP 0001
0007 FE_FREE T3
0008 RETURN null
LIVE RANGES:
3: 0001 - 0007 (loop)
4: 0003 - 0005 (loop)