Skip to content

Commit 0cf179e

Browse files
committed
Address review comments
1 parent 3d0885f commit 0cf179e

File tree

2 files changed

+98
-15
lines changed

2 files changed

+98
-15
lines changed

Zend/Optimizer/dfa_pass.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,9 +325,17 @@ static bool opline_supports_assign_contraction(
325325
return 0;
326326
}
327327

328-
if (opline->opcode >= ZEND_FRAMELESS_ICALL_1 && opline->opcode <= ZEND_FRAMELESS_ICALL_3) {
329-
/* Frameless calls override the return value, but the return value may overlap with the arguments. */
330-
return opline->op1_type != IS_CV || opline->op1.var != cv_var;
328+
/* Frameless calls override the return value, but the return value may overlap with the arguments. */
329+
switch (opline->opcode) {
330+
case ZEND_FRAMELESS_ICALL_3:
331+
if ((opline + 1)->op1_type == IS_CV && (opline + 1)->op1.var == cv_var) return 0;
332+
ZEND_FALLTHROUGH;
333+
case ZEND_FRAMELESS_ICALL_2:
334+
if (opline->op2_type == IS_CV && opline->op2.var == cv_var) return 0;
335+
ZEND_FALLTHROUGH;
336+
case ZEND_FRAMELESS_ICALL_1:
337+
if (opline->op1_type == IS_CV && opline->op1.var == cv_var) return 0;
338+
break;
331339
}
332340

333341
if (opline->opcode == ZEND_DO_ICALL || opline->opcode == ZEND_DO_UCALL

ext/opcache/tests/opt/gh14873.phpt

Lines changed: 87 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,48 @@ function testTrim1(string $value): string {
1515
return $value;
1616
}
1717

18-
function testMin2(int $value): int {
18+
function testMin2First(int $value): int {
1919
$value = min($value, 100);
2020
return $value;
2121
}
2222

23+
function testMin2Second(int $value): int {
24+
$value = min(100, $value);
25+
return $value;
26+
}
27+
2328
function testMin2_TMP(int $value): int {
2429
$value = min($value + 1, 100);
2530
return $value;
2631
}
2732

28-
function testStrstr3(string $value): string {
33+
function testStrstr3First(string $value): string {
2934
$value = strstr($value, "needle", false);
3035
return $value;
3136
}
3237

38+
function testStrstr3Second(string $value): string {
39+
$value = strstr("needles", $value, false);
40+
return $value;
41+
}
42+
43+
function testStrstr3Third(bool $value): string {
44+
$value = strstr("needles", "needle", $value);
45+
return $value;
46+
}
47+
3348
var_dump(testTrim1(" boo "));
34-
var_dump(testMin2(5));
49+
var_dump(testMin2First(5));
50+
var_dump(testMin2Second(5));
3551
var_dump(testMin2_TMP(5));
36-
var_dump(testStrstr3("needles"));
52+
var_dump(testStrstr3First("needles"));
53+
var_dump(testStrstr3Second("needle"));
54+
var_dump(testStrstr3Third(false));
3755

3856
?>
3957
--EXPECTF--
4058
$_main:
41-
; (lines=25, args=0, vars=0, tmps=%d)
59+
; (lines=43, args=0, vars=0, tmps=%d)
4260
; (after optimizer)
4361
; %s
4462
0000 INIT_FCALL 1 %d string("var_dump")
@@ -48,24 +66,42 @@ $_main:
4866
0004 SEND_VAR V0 1
4967
0005 DO_ICALL
5068
0006 INIT_FCALL 1 %d string("var_dump")
51-
0007 INIT_FCALL 1 %d string("testmin2")
69+
0007 INIT_FCALL 1 112 string("testmin2first")
5270
0008 SEND_VAL int(5) 1
5371
0009 V0 = DO_UCALL
5472
0010 SEND_VAR V0 1
5573
0011 DO_ICALL
5674
0012 INIT_FCALL 1 %d string("var_dump")
57-
0013 INIT_FCALL 1 %d string("testmin2_tmp")
75+
0013 INIT_FCALL 1 112 string("testmin2second")
5876
0014 SEND_VAL int(5) 1
5977
0015 V0 = DO_UCALL
6078
0016 SEND_VAR V0 1
6179
0017 DO_ICALL
6280
0018 INIT_FCALL 1 %d string("var_dump")
63-
0019 INIT_FCALL 1 %d string("teststrstr3")
64-
0020 SEND_VAL string("needles") 1
81+
0019 INIT_FCALL 1 112 string("testmin2_tmp")
82+
0020 SEND_VAL int(5) 1
6583
0021 V0 = DO_UCALL
6684
0022 SEND_VAR V0 1
6785
0023 DO_ICALL
68-
0024 RETURN int(1)
86+
0024 INIT_FCALL 1 96 string("var_dump")
87+
0025 INIT_FCALL 1 112 string("teststrstr3first")
88+
0026 SEND_VAL string("needles") 1
89+
0027 V0 = DO_UCALL
90+
0028 SEND_VAR V0 1
91+
0029 DO_ICALL
92+
0030 INIT_FCALL 1 96 string("var_dump")
93+
0031 INIT_FCALL 1 112 string("teststrstr3second")
94+
0032 SEND_VAL string("needle") 1
95+
0033 V0 = DO_UCALL
96+
0034 SEND_VAR V0 1
97+
0035 DO_ICALL
98+
0036 INIT_FCALL 1 96 string("var_dump")
99+
0037 INIT_FCALL 1 112 string("teststrstr3third")
100+
0038 SEND_VAL bool(false) 1
101+
0039 V0 = DO_UCALL
102+
0040 SEND_VAR V0 1
103+
0041 DO_ICALL
104+
0042 RETURN int(1)
69105

70106
testTrim1:
71107
; (lines=4, args=1, vars=1, tmps=%d)
@@ -76,7 +112,7 @@ testTrim1:
76112
0002 ASSIGN CV0($value) T1
77113
0003 RETURN CV0($value)
78114

79-
testMin2:
115+
testMin2First:
80116
; (lines=5, args=1, vars=1, tmps=%d)
81117
; (after optimizer)
82118
; %s
@@ -86,6 +122,16 @@ testMin2:
86122
0003 VERIFY_RETURN_TYPE CV0($value)
87123
0004 RETURN CV0($value)
88124

125+
testMin2Second:
126+
; (lines=5, args=1, vars=1, tmps=%d)
127+
; (after optimizer)
128+
; %s
129+
0000 CV0($value) = RECV 1
130+
0001 T1 = FRAMELESS_ICALL_2(min) int(100) CV0($value)
131+
0002 CV0($value) = QM_ASSIGN T1
132+
0003 VERIFY_RETURN_TYPE CV0($value)
133+
0004 RETURN CV0($value)
134+
89135
testMin2_TMP:
90136
; (lines=5, args=1, vars=1, tmps=%d)
91137
; (after optimizer)
@@ -96,7 +142,7 @@ testMin2_TMP:
96142
0003 VERIFY_RETURN_TYPE CV0($value)
97143
0004 RETURN CV0($value)
98144

99-
testStrstr3:
145+
testStrstr3First:
100146
; (lines=6, args=1, vars=1, tmps=%d)
101147
; (after optimizer)
102148
; %s
@@ -106,9 +152,38 @@ testStrstr3:
106152
0003 ASSIGN CV0($value) T1
107153
0004 VERIFY_RETURN_TYPE CV0($value)
108154
0005 RETURN CV0($value)
155+
LIVE RANGES:
156+
1: 0002 - 0003 (tmp/var)
157+
158+
testStrstr3Second:
159+
; (lines=6, args=1, vars=1, tmps=%d)
160+
; (after optimizer)
161+
; %s
162+
0000 CV0($value) = RECV 1
163+
0001 T1 = FRAMELESS_ICALL_3(strstr) string("needles") CV0($value)
164+
0002 OP_DATA bool(false)
165+
0003 ASSIGN CV0($value) T1
166+
0004 VERIFY_RETURN_TYPE CV0($value)
167+
0005 RETURN CV0($value)
168+
LIVE RANGES:
169+
1: 0002 - 0003 (tmp/var)
170+
171+
testStrstr3Third:
172+
; (lines=6, args=1, vars=1, tmps=%d)
173+
; (after optimizer)
174+
; %s
175+
0000 CV0($value) = RECV 1
176+
0001 T1 = FRAMELESS_ICALL_3(strstr) string("needles") string("needle")
177+
0002 OP_DATA CV0($value)
178+
0003 CV0($value) = QM_ASSIGN T1
179+
0004 VERIFY_RETURN_TYPE CV0($value)
180+
0005 RETURN CV0($value)
109181
LIVE RANGES:
110182
1: 0002 - 0003 (tmp/var)
111183
string(3) "boo"
112184
int(5)
185+
int(5)
113186
int(6)
114187
string(7) "needles"
188+
string(7) "needles"
189+
string(7) "needles"

0 commit comments

Comments
 (0)