Skip to content

Commit 4a1bce1

Browse files
committed
SCCP fixes
1 parent ebb0a4c commit 4a1bce1

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

Zend/Optimizer/sccp.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1721,7 +1721,7 @@ static void sccp_visit_instr(scdf_ctx *scdf, zend_op *opline, zend_ssa_op *ssa_o
17211721
switch (opline->opcode) {
17221722
case ZEND_FRAMELESS_ICALL_3: {
17231723
zend_op *op_data = opline + 1;
1724-
args[2] = get_op2_value(ctx, op_data, &ctx->scdf.ssa->ops[op_data - ctx->scdf.op_array->opcodes]);
1724+
args[2] = get_op1_value(ctx, op_data, &ctx->scdf.ssa->ops[op_data - ctx->scdf.op_array->opcodes]);
17251725
ZEND_FALLTHROUGH;
17261726
}
17271727
case ZEND_FRAMELESS_ICALL_2:
@@ -1732,6 +1732,17 @@ static void sccp_visit_instr(scdf_ctx *scdf, zend_op *opline, zend_ssa_op *ssa_o
17321732
break;
17331733
}
17341734
uint32_t num_args = ZEND_FLF_NUM_ARGS(opline->opcode);
1735+
for (uint32_t i = 0; i < num_args; i++) {
1736+
if (!args[i]) {
1737+
SET_RESULT_BOT(result);
1738+
return;
1739+
} else if (IS_BOT(args[i]) || IS_PARTIAL_ARRAY(args[i])) {
1740+
SET_RESULT_BOT(result);
1741+
return;
1742+
} else if (IS_TOP(args[i])) {
1743+
return;
1744+
}
1745+
}
17351746
zend_function *func = (*zend_frameless_function_0_functions_lists[num_args])[opline->extended_value];
17361747
if (ct_eval_func_call_ex(scdf->op_array, &zv, func, num_args, args) == SUCCESS) {
17371748
SET_RESULT(result, &zv);

Zend/Optimizer/zend_dfg.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ static zend_always_inline void _zend_dfg_add_use_def_op(const zend_op_array *op_
122122
}
123123
break;
124124
case ZEND_ASSIGN_STATIC_PROP_OP:
125+
case ZEND_FRAMELESS_ICALL_3:
125126
next = opline + 1;
126127
if (next->op1_type & (IS_CV|IS_VAR|IS_TMP_VAR)) {
127128
var_num = EX_VAR_TO_NUM(next->op1.var);
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Test ct eval of frameless function
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
opcache.opt_debug_level=0x20000
8+
--EXTENSIONS--
9+
opcache
10+
--FILE--
11+
<?php
12+
echo substr('foo', 1, $foo ? 1 : 1);
13+
?>
14+
--EXPECTF--
15+
$_main:
16+
; (lines=3, args=0, vars=1, tmps=0)
17+
; (after optimizer)
18+
; %sct_eval_frameless_002.php:1-4
19+
0000 CHECK_VAR CV0($foo)
20+
0001 ECHO string("o")
21+
0002 RETURN int(1)
22+
23+
Warning: Undefined variable $foo in %s on line %d
24+
o

0 commit comments

Comments
 (0)