summaryrefslogtreecommitdiffstats
path: root/php-bug78230.patch
blob: 355f8cc0fd4155968443f7c29ff8ecba71cbf624 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
From 4892bbc167dfa0ea188baebbce538225f4a0455a Mon Sep 17 00:00:00 2001
From: Nikita Popov <nikita.ppv@gmail.com>
Date: Wed, 3 Jul 2019 10:19:31 +0200
Subject: [PATCH] Fixed bug #78230

---
 NEWS                            |  8 +++++---
 ext/opcache/Optimizer/sccp.c    |  1 +
 ext/opcache/tests/bug78230.phpt | 29 +++++++++++++++++++++++++++++
 3 files changed, 35 insertions(+), 3 deletions(-)
 create mode 100644 ext/opcache/tests/bug78230.phpt

diff --git a/ext/opcache/Optimizer/sccp.c b/ext/opcache/Optimizer/sccp.c
index ac3247076eaa..1ec3a5153241 100644
--- a/ext/opcache/Optimizer/sccp.c
+++ b/ext/opcache/Optimizer/sccp.c
@@ -2204,6 +2204,7 @@ static int try_remove_definition(sccp_ctx *ctx, int var_num, zend_ssa_var *var,
 				if (opline->opcode == ZEND_DO_ICALL) {
 					removed_ops = remove_call(ctx, opline, ssa_op);
 				} else if (opline->opcode == ZEND_TYPE_CHECK
+						&& opline->op1_type & (IS_VAR|IS_TMP_VAR)
 						&& !value_known(&ctx->values[ssa_op->op1_use])) {
 					/* For TYPE_CHECK we may compute the result value without knowing the
 					 * operand, based on type inference information. Make sure the operand is
diff --git a/ext/opcache/tests/bug78230.phpt b/ext/opcache/tests/bug78230.phpt
new file mode 100644
index 000000000000..38cc68499517
--- /dev/null
+++ b/ext/opcache/tests/bug78230.phpt
@@ -0,0 +1,29 @@
+--TEST--
+Bug #78230: Incorrect type check optimization
+--FILE--
+<?php
+
+function test($x) {
+    $y = (array) $x;
+    var_dump(is_array($y));
+}
+
+$ary = [1, 2];
+$ary[] = 3;
+test($ary);
+$ary[] = 4;
+var_dump($ary);
+
+?>
+--EXPECT--
+bool(true)
+array(4) {
+  [0]=>
+  int(1)
+  [1]=>
+  int(2)
+  [2]=>
+  int(3)
+  [3]=>
+  int(4)
+}