Skip to content

Commit 0ad2444

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Fix missing undef checks for comparisons
2 parents c9f3488 + 95e0cc0 commit 0ad2444

File tree

3 files changed

+81
-24
lines changed

3 files changed

+81
-24
lines changed

ext/opcache/jit/zend_jit_arm64.dasc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7114,19 +7114,19 @@ static int zend_jit_cmp(dasm_State **Dst,
71147114
(op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_LONG|MAY_BE_DOUBLE))));
71157115

71167116
if ((op1_info & MAY_BE_LONG) && (op2_info & MAY_BE_LONG)) {
7117-
if (op1_info & (MAY_BE_ANY-MAY_BE_LONG)) {
7117+
if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_LONG)) {
71187118
if (op1_info & MAY_BE_DOUBLE) {
71197119
| IF_NOT_ZVAL_TYPE op1_addr, IS_LONG, >4, ZREG_TMP1
71207120
} else {
71217121
| IF_NOT_ZVAL_TYPE op1_addr, IS_LONG, >9, ZREG_TMP1
71227122
}
71237123
}
7124-
if (!same_ops && (op2_info & (MAY_BE_ANY-MAY_BE_LONG))) {
7124+
if (!same_ops && (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_LONG))) {
71257125
if (op2_info & MAY_BE_DOUBLE) {
71267126
| IF_NOT_ZVAL_TYPE op2_addr, IS_LONG, >3, ZREG_TMP1
71277127
|.cold_code
71287128
|3:
7129-
if (op2_info & (MAY_BE_ANY-(MAY_BE_LONG|MAY_BE_DOUBLE))) {
7129+
if (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_LONG|MAY_BE_DOUBLE))) {
71307130
| IF_NOT_ZVAL_TYPE op2_addr, IS_DOUBLE, >9, ZREG_TMP1
71317131
}
71327132
if (!zend_jit_cmp_long_double(Dst, opline, op1_addr, op2_addr, res_addr, smart_branch_opcode, target_label, target_label2, exit_addr)) {
@@ -7144,11 +7144,11 @@ static int zend_jit_cmp(dasm_State **Dst,
71447144
if (op1_info & MAY_BE_DOUBLE) {
71457145
|.cold_code
71467146
|4:
7147-
if (op1_info & (MAY_BE_ANY-(MAY_BE_LONG|MAY_BE_DOUBLE))) {
7147+
if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_LONG|MAY_BE_DOUBLE))) {
71487148
| IF_NOT_ZVAL_TYPE op1_addr, IS_DOUBLE, >9, ZREG_TMP1
71497149
}
71507150
if (op2_info & MAY_BE_DOUBLE) {
7151-
if (!same_ops && (op2_info & (MAY_BE_ANY-MAY_BE_DOUBLE))) {
7151+
if (!same_ops && (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_DOUBLE))) {
71527152
if (!same_ops) {
71537153
| IF_NOT_ZVAL_TYPE op2_addr, IS_DOUBLE, >5, ZREG_TMP1
71547154
} else {
@@ -7162,7 +7162,7 @@ static int zend_jit_cmp(dasm_State **Dst,
71627162
}
71637163
if (!same_ops) {
71647164
|5:
7165-
if (op2_info & (MAY_BE_ANY-(MAY_BE_LONG|MAY_BE_DOUBLE))) {
7165+
if (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_LONG|MAY_BE_DOUBLE))) {
71667166
| IF_NOT_ZVAL_TYPE op2_addr, IS_LONG, >9, ZREG_TMP1
71677167
}
71687168
if (!zend_jit_cmp_double_long(Dst, opline, op1_addr, op2_addr, res_addr, smart_branch_opcode, target_label, target_label2, exit_addr)) {
@@ -7175,11 +7175,11 @@ static int zend_jit_cmp(dasm_State **Dst,
71757175
} else if ((op1_info & MAY_BE_DOUBLE) &&
71767176
!(op1_info & MAY_BE_LONG) &&
71777177
(op2_info & (MAY_BE_LONG|MAY_BE_DOUBLE))) {
7178-
if (op1_info & (MAY_BE_ANY-MAY_BE_DOUBLE)) {
7178+
if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_DOUBLE)) {
71797179
| IF_NOT_ZVAL_TYPE op1_addr, IS_DOUBLE, >9, ZREG_TMP1
71807180
}
71817181
if (op2_info & MAY_BE_DOUBLE) {
7182-
if (!same_ops && (op2_info & (MAY_BE_ANY-MAY_BE_DOUBLE))) {
7182+
if (!same_ops && (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_DOUBLE))) {
71837183
if (!same_ops && (op2_info & MAY_BE_LONG)) {
71847184
| IF_NOT_ZVAL_TYPE op2_addr, IS_DOUBLE, >3, ZREG_TMP1
71857185
} else {
@@ -7195,7 +7195,7 @@ static int zend_jit_cmp(dasm_State **Dst,
71957195
|.cold_code
71967196
}
71977197
|3:
7198-
if (op2_info & (MAY_BE_ANY-(MAY_BE_DOUBLE|MAY_BE_LONG))) {
7198+
if (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_DOUBLE|MAY_BE_LONG))) {
71997199
| IF_NOT_ZVAL_TYPE op2_addr, IS_LONG, >9, ZREG_TMP1
72007200
}
72017201
if (!zend_jit_cmp_double_long(Dst, opline, op1_addr, op2_addr, res_addr, smart_branch_opcode, target_label, target_label2, exit_addr)) {
@@ -7209,11 +7209,11 @@ static int zend_jit_cmp(dasm_State **Dst,
72097209
} else if ((op2_info & MAY_BE_DOUBLE) &&
72107210
!(op2_info & MAY_BE_LONG) &&
72117211
(op1_info & (MAY_BE_LONG|MAY_BE_DOUBLE))) {
7212-
if (op2_info & (MAY_BE_ANY-MAY_BE_DOUBLE)) {
7212+
if (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_DOUBLE)) {
72137213
| IF_NOT_ZVAL_TYPE op2_addr, IS_DOUBLE, >9, ZREG_TMP1
72147214
}
72157215
if (op1_info & MAY_BE_DOUBLE) {
7216-
if (!same_ops && (op1_info & (MAY_BE_ANY-MAY_BE_DOUBLE))) {
7216+
if (!same_ops && (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_DOUBLE))) {
72177217
if (!same_ops && (op1_info & MAY_BE_LONG)) {
72187218
| IF_NOT_ZVAL_TYPE op1_addr, IS_DOUBLE, >3, ZREG_TMP1
72197219
} else {
@@ -7229,7 +7229,7 @@ static int zend_jit_cmp(dasm_State **Dst,
72297229
|.cold_code
72307230
}
72317231
|3:
7232-
if (op1_info & (MAY_BE_ANY-(MAY_BE_DOUBLE|MAY_BE_LONG))) {
7232+
if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_DOUBLE|MAY_BE_LONG))) {
72337233
| IF_NOT_ZVAL_TYPE op1_addr, IS_LONG, >9, ZREG_TMP1
72347234
}
72357235
if (!zend_jit_cmp_long_double(Dst, opline, op1_addr, op2_addr, res_addr, smart_branch_opcode, target_label, target_label2, exit_addr)) {

ext/opcache/jit/zend_jit_x86.dasc

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7648,19 +7648,19 @@ static int zend_jit_cmp(dasm_State **Dst,
76487648
(op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_LONG|MAY_BE_DOUBLE))));
76497649

76507650
if ((op1_info & MAY_BE_LONG) && (op2_info & MAY_BE_LONG)) {
7651-
if (op1_info & (MAY_BE_ANY-MAY_BE_LONG)) {
7651+
if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_LONG)) {
76527652
if (op1_info & MAY_BE_DOUBLE) {
76537653
| IF_NOT_ZVAL_TYPE op1_addr, IS_LONG, >4
76547654
} else {
76557655
| IF_NOT_ZVAL_TYPE op1_addr, IS_LONG, >9
76567656
}
76577657
}
7658-
if (!same_ops && (op2_info & (MAY_BE_ANY-MAY_BE_LONG))) {
7658+
if (!same_ops && (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_LONG))) {
76597659
if (op2_info & MAY_BE_DOUBLE) {
76607660
| IF_NOT_ZVAL_TYPE op2_addr, IS_LONG, >3
76617661
|.cold_code
76627662
|3:
7663-
if (op2_info & (MAY_BE_ANY-(MAY_BE_LONG|MAY_BE_DOUBLE))) {
7663+
if (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_LONG|MAY_BE_DOUBLE))) {
76647664
| IF_NOT_ZVAL_TYPE op2_addr, IS_DOUBLE, >9
76657665
}
76667666
if (!zend_jit_cmp_long_double(Dst, opline, op1_addr, op2_addr, res_addr, smart_branch_opcode, target_label, target_label2, exit_addr)) {
@@ -7678,11 +7678,11 @@ static int zend_jit_cmp(dasm_State **Dst,
76787678
if (op1_info & MAY_BE_DOUBLE) {
76797679
|.cold_code
76807680
|4:
7681-
if (op1_info & (MAY_BE_ANY-(MAY_BE_LONG|MAY_BE_DOUBLE))) {
7681+
if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_LONG|MAY_BE_DOUBLE))) {
76827682
| IF_NOT_ZVAL_TYPE op1_addr, IS_DOUBLE, >9
76837683
}
76847684
if (op2_info & MAY_BE_DOUBLE) {
7685-
if (!same_ops && (op2_info & (MAY_BE_ANY-MAY_BE_DOUBLE))) {
7685+
if (!same_ops && (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_DOUBLE))) {
76867686
if (!same_ops) {
76877687
| IF_NOT_ZVAL_TYPE op2_addr, IS_DOUBLE, >5
76887688
} else {
@@ -7696,7 +7696,7 @@ static int zend_jit_cmp(dasm_State **Dst,
76967696
}
76977697
if (!same_ops) {
76987698
|5:
7699-
if (op2_info & (MAY_BE_ANY-(MAY_BE_LONG|MAY_BE_DOUBLE))) {
7699+
if (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_LONG|MAY_BE_DOUBLE))) {
77007700
| IF_NOT_ZVAL_TYPE op2_addr, IS_LONG, >9
77017701
}
77027702
if (!zend_jit_cmp_double_long(Dst, opline, op1_addr, op2_addr, res_addr, smart_branch_opcode, target_label, target_label2, exit_addr)) {
@@ -7709,11 +7709,11 @@ static int zend_jit_cmp(dasm_State **Dst,
77097709
} else if ((op1_info & MAY_BE_DOUBLE) &&
77107710
!(op1_info & MAY_BE_LONG) &&
77117711
(op2_info & (MAY_BE_LONG|MAY_BE_DOUBLE))) {
7712-
if (op1_info & (MAY_BE_ANY-MAY_BE_DOUBLE)) {
7712+
if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_DOUBLE)) {
77137713
| IF_NOT_ZVAL_TYPE op1_addr, IS_DOUBLE, >9
77147714
}
77157715
if (op2_info & MAY_BE_DOUBLE) {
7716-
if (!same_ops && (op2_info & (MAY_BE_ANY-MAY_BE_DOUBLE))) {
7716+
if (!same_ops && (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_DOUBLE))) {
77177717
if (!same_ops && (op2_info & MAY_BE_LONG)) {
77187718
| IF_NOT_ZVAL_TYPE op2_addr, IS_DOUBLE, >3
77197719
} else {
@@ -7729,7 +7729,7 @@ static int zend_jit_cmp(dasm_State **Dst,
77297729
|.cold_code
77307730
}
77317731
|3:
7732-
if (op2_info & (MAY_BE_ANY-(MAY_BE_DOUBLE|MAY_BE_LONG))) {
7732+
if (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_DOUBLE|MAY_BE_LONG))) {
77337733
| IF_NOT_ZVAL_TYPE op2_addr, IS_LONG, >9
77347734
}
77357735
if (!zend_jit_cmp_double_long(Dst, opline, op1_addr, op2_addr, res_addr, smart_branch_opcode, target_label, target_label2, exit_addr)) {
@@ -7743,11 +7743,11 @@ static int zend_jit_cmp(dasm_State **Dst,
77437743
} else if ((op2_info & MAY_BE_DOUBLE) &&
77447744
!(op2_info & MAY_BE_LONG) &&
77457745
(op1_info & (MAY_BE_LONG|MAY_BE_DOUBLE))) {
7746-
if (op2_info & (MAY_BE_ANY-MAY_BE_DOUBLE)) {
7746+
if (op2_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_DOUBLE)) {
77477747
| IF_NOT_ZVAL_TYPE op2_addr, IS_DOUBLE, >9
77487748
}
77497749
if (op1_info & MAY_BE_DOUBLE) {
7750-
if (!same_ops && (op1_info & (MAY_BE_ANY-MAY_BE_DOUBLE))) {
7750+
if (!same_ops && (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-MAY_BE_DOUBLE))) {
77517751
if (!same_ops && (op1_info & MAY_BE_LONG)) {
77527752
| IF_NOT_ZVAL_TYPE op1_addr, IS_DOUBLE, >3
77537753
} else {
@@ -7763,7 +7763,7 @@ static int zend_jit_cmp(dasm_State **Dst,
77637763
|.cold_code
77647764
}
77657765
|3:
7766-
if (op1_info & (MAY_BE_ANY-(MAY_BE_DOUBLE|MAY_BE_LONG))) {
7766+
if (op1_info & ((MAY_BE_ANY|MAY_BE_UNDEF)-(MAY_BE_DOUBLE|MAY_BE_LONG))) {
77677767
| IF_NOT_ZVAL_TYPE op1_addr, IS_LONG, >9
77687768
}
77697769
if (!zend_jit_cmp_long_double(Dst, opline, op1_addr, op2_addr, res_addr, smart_branch_opcode, target_label, target_label2, exit_addr)) {

ext/opcache/tests/jit/cmp_006.phpt

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
--TEST--
2+
JIT CMP: 006 Undefined variable checks
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.file_update_protection=0
7+
opcache.jit_buffer_size=1M
8+
opcache.protect_memory=1
9+
--FILE--
10+
<?php
11+
function test1($c) {
12+
if ($c) {
13+
$x = 1;
14+
}
15+
var_dump($x == 1);
16+
}
17+
function test2($c) {
18+
if ($c) {
19+
$x = 1.0;
20+
}
21+
var_dump($x == 1.0);
22+
}
23+
function test3($c) {
24+
if (!$c) {
25+
$x = 1;
26+
}
27+
if ($c) {
28+
$y = 1;
29+
}
30+
var_dump($x == $y);
31+
}
32+
function test4($c) {
33+
if (!$c) {
34+
$x = 1.0;
35+
}
36+
if ($c) {
37+
$y = 1.0;
38+
}
39+
var_dump($x == $y);
40+
}
41+
test1(false);
42+
test2(false);
43+
test3(false);
44+
test4(false);
45+
?>
46+
--EXPECTF--
47+
Warning: Undefined variable $x in %s on line %d
48+
bool(false)
49+
50+
Warning: Undefined variable $x in %s on line %d
51+
bool(false)
52+
53+
Warning: Undefined variable $y in %s on line %d
54+
bool(false)
55+
56+
Warning: Undefined variable $y in %s on line %d
57+
bool(false)

0 commit comments

Comments
 (0)