Skip to content

Commit 2bd54ec

Browse files
committed
Fix JIT?
1 parent da35538 commit 2bd54ec

File tree

4 files changed

+88
-0
lines changed

4 files changed

+88
-0
lines changed

Zend/tests/foreach/foreach_list_002.phpt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,48 @@ foreach (array(array(1,2), array(3,4)) as list($a, )) {
77
var_dump($a);
88
}
99

10+
echo "Array of strings:\n";
1011
$array = [['a', 'b'], 'c', 'd'];
1112

1213
foreach($array as list(, $a)) {
1314
var_dump($a);
1415
}
1516

17+
echo "Array of ints:\n";
18+
$array = [[5, 6], 10, 20];
19+
20+
foreach($array as list(, $a)) {
21+
var_dump($a);
22+
}
23+
24+
echo "Array of nulls:\n";
25+
$array = [[null, null], null, null];
26+
27+
foreach($array as list(, $a)) {
28+
var_dump($a);
29+
}
30+
1631
?>
1732
--EXPECTF--
1833
int(1)
1934
int(3)
35+
Array of strings:
2036
string(1) "b"
2137

2238
Warning: Cannot use string as array in %s on line %d
2339
NULL
40+
41+
Warning: Cannot use string as array in %s on line %d
42+
NULL
43+
Array of ints:
44+
int(6)
45+
46+
Warning: Cannot use int as array in %s on line %d
47+
NULL
48+
49+
Warning: Cannot use int as array in %s on line %d
50+
NULL
51+
Array of nulls:
52+
NULL
53+
NULL
2454
NULL

ext/opcache/jit/zend_jit_helpers.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
+----------------------------------------------------------------------+
1717
*/
1818

19+
#include "../../../Zend/zend_types.h"
1920
#include "Zend/zend_API.h"
2021

2122
static ZEND_COLD void undef_result_after_exception(void) {
@@ -2561,6 +2562,14 @@ static void ZEND_FASTCALL zend_jit_only_vars_by_reference(zval *arg)
25612562
zend_error(E_NOTICE, "Only variables should be passed by reference");
25622563
}
25632564

2565+
static void ZEND_FASTCALL zend_jit_invalid_array_use(const zval *container)
2566+
{
2567+
/* Warning should not occur on null */
2568+
if (Z_TYPE_P(container) != IS_NULL) {
2569+
zend_error(E_WARNING, "Cannot use %s as array", zend_zval_type_name(container));
2570+
}
2571+
}
2572+
25642573
static void ZEND_FASTCALL zend_jit_invalid_array_access(zval *container)
25652574
{
25662575
zend_error(E_WARNING, "Trying to access array offset on %s", zend_zval_value_name(container));

ext/opcache/jit/zend_jit_ir.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* +----------------------------------------------------------------------+
1717
*/
1818

19+
#include "../../../Zend/zend_type_info.h"
1920
#include "jit/ir/ir.h"
2021
#include "jit/ir/ir_builder.h"
2122
#include "jit/tls/zend_jit_tls.h"
@@ -12786,6 +12787,18 @@ static int zend_jit_fetch_dim_read(zend_jit_ctx *jit,
1278612787
}
1278712788
}
1278812789

12790+
if (opline->opcode == ZEND_FETCH_LIST_R) {
12791+
ir_ref ref;
12792+
12793+
may_throw = 1;
12794+
if ((op1_info & MAY_BE_UNDEF) || (op2_info & MAY_BE_UNDEF)) {
12795+
ref = jit_ZVAL_ADDR(jit, orig_op1_addr);
12796+
} else {
12797+
jit_SET_EX_OPLINE(jit, opline);
12798+
ref = jit_ZVAL_ADDR(jit, op1_addr);
12799+
}
12800+
ir_CALL_1(IR_VOID, ir_CONST_FC_FUNC(zend_jit_invalid_array_use), ref);
12801+
}
1278912802
if (opline->opcode != ZEND_FETCH_DIM_IS && opline->opcode != ZEND_FETCH_LIST_R) {
1279012803
ir_ref ref;
1279112804

ext/opcache/tests/opt/block_pass_003.phpt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,41 @@ DONE
1919
--EXPECTF--
2020
Warning: Cannot use int as array in %s on line %d
2121

22+
Warning: Cannot use int as array in %s on line %d
23+
24+
Warning: Cannot use int as array in %s on line %d
25+
26+
Warning: Cannot use int as array in %s on line %d
27+
28+
Warning: Cannot use int as array in %s on line %d
29+
30+
Warning: Cannot use int as array in %s on line %d
31+
32+
Warning: Cannot use int as array in %s on line %d
33+
34+
Warning: Cannot use int as array in %s on line %d
35+
36+
Warning: Cannot use int as array in %s on line %d
37+
38+
Warning: Cannot use int as array in %s on line %d
39+
40+
Warning: Cannot use int as array in %s on line %d
41+
42+
Warning: Cannot use int as array in %s on line %d
43+
44+
Warning: Cannot use int as array in %s on line %d
45+
46+
Warning: Cannot use int as array in %s on line %d
47+
48+
Warning: Cannot use int as array in %s on line %d
49+
50+
Warning: Cannot use int as array in %s on line %d
51+
52+
Warning: Cannot use int as array in %s on line %d
53+
54+
Warning: Cannot use int as array in %s on line %d
55+
56+
Warning: Cannot use int as array in %s on line %d
57+
2258
Warning: Cannot use int as array in %s on line %d
2359
DONE

0 commit comments

Comments
 (0)