Skip to content

Commit aa45df4

Browse files
committedOct 24, 2023
Fixed incorrect type inference
1 parent 76c41d2 commit aa45df4

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed
 

‎Zend/Optimizer/zend_inference.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -3415,7 +3415,9 @@ static zend_always_inline int _zend_update_type_info(
34153415
UPDATE_SSA_TYPE(tmp, ssa_op->result_def);
34163416
break;
34173417
case ZEND_FETCH_THIS:
3418-
UPDATE_SSA_OBJ_TYPE(op_array->scope, 1, ssa_op->result_def);
3418+
if (!(op_array->fn_flags & ZEND_ACC_TRAIT_CLONE)) {
3419+
UPDATE_SSA_OBJ_TYPE(op_array->scope, 1, ssa_op->result_def);
3420+
}
34193421
UPDATE_SSA_TYPE(MAY_BE_RCN|MAY_BE_OBJECT, ssa_op->result_def);
34203422
break;
34213423
case ZEND_FETCH_OBJ_R:

‎ext/opcache/tests/jit/gh12482.phpt

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
--TEST--
2+
GH-12482: Invalid type inference
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.jit_hot_func=2
7+
--FILE--
8+
<?php
9+
trait T {
10+
function foo() {
11+
$cloned = clone $this;
12+
$cloned->x = 42;
13+
return $cloned;
14+
}
15+
}
16+
class A {
17+
use T;
18+
public $a = 1;
19+
public $b = 2;
20+
public $c = 3;
21+
public $x = 4;
22+
}
23+
class B {
24+
use T;
25+
public $x = 5;
26+
}
27+
$a = new A;
28+
var_dump($a->foo());
29+
var_dump($a->foo());
30+
$b = new B;
31+
var_dump($b->foo());
32+
?>
33+
--EXPECT--
34+
object(A)#2 (4) {
35+
["a"]=>
36+
int(1)
37+
["b"]=>
38+
int(2)
39+
["c"]=>
40+
int(3)
41+
["x"]=>
42+
int(42)
43+
}
44+
object(A)#2 (4) {
45+
["a"]=>
46+
int(1)
47+
["b"]=>
48+
int(2)
49+
["c"]=>
50+
int(3)
51+
["x"]=>
52+
int(42)
53+
}
54+
object(B)#3 (1) {
55+
["x"]=>
56+
int(42)
57+
}

0 commit comments

Comments
 (0)