Skip to content

Commit cbb3b93

Browse files
nielsdosdstogov
andcommitted
Fix phpGH-16770: Tracing JIT type mismatch when returning UNDEF
When returning an UNDEF value, it actually becomes NULL. The following code took this into account: https://github.com/php/php-src/blob/28344e0445bc2abae8dc5f1376aa0ff350e6d66d/ext/opcache/jit/zend_jit_trace.c#L2196-L2199 But the stack does not update the type to NULL, causing a mismatch. Closes phpGH-16784. Co-authored-by: Dmitry Stogov <[email protected]>
1 parent c69fdef commit cbb3b93

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

NEWS

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ PHP NEWS
1919
- Hash:
2020
. Fixed GH-16711: Segfault in mhash(). (Girgias)
2121

22+
- Opcache:
23+
. Fixed bug GH-16770 (Tracing JIT type mismatch when returning UNDEF).
24+
(nielsdos, Dmitry)
25+
2226
- OpenSSL:
2327
. Prevent unexpected array entry conversion when reading key. (nielsdos)
2428
. Fix various memory leaks related to openssl exports. (nielsdos)

ext/opcache/jit/zend_jit_trace.c

+3
Original file line numberDiff line numberDiff line change
@@ -5404,6 +5404,9 @@ static const void *zend_jit_trace(zend_jit_trace_rec *trace_buffer, uint32_t par
54045404
res_type = Z_TYPE_P(RT_CONSTANT(opline, opline->op1));
54055405
} else if (op1_type != IS_UNKNOWN) {
54065406
res_type = op1_type;
5407+
if (res_type == IS_UNDEF) {
5408+
res_type = IS_NULL;
5409+
}
54075410
}
54085411
if (op_array->type == ZEND_EVAL_CODE
54095412
// TODO: support for top-level code

ext/opcache/tests/jit/gh16770.phpt

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--TEST--
2+
GH-16770 (Tracing JIT type mismatch when returning UNDEF)
3+
--INI--
4+
opcache.jit=1254
5+
opcache.jit_hot_loop=1
6+
opcache.jit_buffer_size=32M
7+
--EXTENSIONS--
8+
opcache
9+
--FILE--
10+
<?php
11+
function ret_undef($k) {
12+
return $undefined;
13+
}
14+
for ($i = 0; $i < 10; $i++) {
15+
$output = ret_undef($i);
16+
}
17+
var_dump($output);
18+
?>
19+
--EXPECTF--
20+
Warning: Undefined variable $undefined in %s on line %d
21+
22+
Warning: Undefined variable $undefined in %s on line %d
23+
24+
Warning: Undefined variable $undefined in %s on line %d
25+
26+
Warning: Undefined variable $undefined in %s on line %d
27+
28+
Warning: Undefined variable $undefined in %s on line %d
29+
30+
Warning: Undefined variable $undefined in %s on line %d
31+
32+
Warning: Undefined variable $undefined in %s on line %d
33+
34+
Warning: Undefined variable $undefined in %s on line %d
35+
36+
Warning: Undefined variable $undefined in %s on line %d
37+
38+
Warning: Undefined variable $undefined in %s on line %d
39+
NULL

0 commit comments

Comments
 (0)