[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-cvs
Subject:    [PHP-CVS] [php-src] master: Merge branch 'PHP-8.2'
From:       Dmitry Stogov <noreply () php ! net>
Date:       2023-01-30 10:29:25
Message-ID: e4THo4SgTXTGfBe7coPB9OnlkrozPPjUHzcoPN3rklg () main ! php ! net
[Download RAW message or body]

Author: Dmitry Stogov (dstogov)
Date: 2023-01-30T13:16:17+03:00

Commit: https://github.com/php/php-src/commit/ea37abd41247ca9469e37f859a02b3c3e3bf603d
 Raw diff: https://github.com/php/php-src/commit/ea37abd41247ca9469e37f859a02b3c3e3bf603d.diff


Merge branch 'PHP-8.2'

* PHP-8.2:
  Fix type inference

Changed paths:
  A  ext/opcache/tests/jit/assign_obj_op_003.phpt
  M  Zend/Optimizer/zend_inference.c


Diff:

diff --git a/Zend/Optimizer/zend_inference.c b/Zend/Optimizer/zend_inference.c
index f0f027542a24..bc55ceaefc37 100644
--- a/Zend/Optimizer/zend_inference.c
+++ b/Zend/Optimizer/zend_inference.c
@@ -2569,12 +2569,26 @@ static zend_always_inline zend_result _zend_update_type_info(
 				} else if (opline->opcode == ZEND_ASSIGN_OBJ_OP) {
 					/* The return value must also satisfy the property type */
 					if (prop_info) {
-						tmp &= zend_fetch_prop_type(script, prop_info, NULL);
+						t1 = zend_fetch_prop_type(script, prop_info, NULL);
+						if ((t1 & (MAY_BE_LONG|MAY_BE_DOUBLE)) == MAY_BE_LONG
+						 && (tmp & (MAY_BE_LONG|MAY_BE_DOUBLE)) == MAY_BE_DOUBLE) {
+							/* DOUBLE may be auto-converted to LONG */
+							tmp |= MAY_BE_LONG;
+							tmp &= ~MAY_BE_DOUBLE;
+						}
+						tmp &= t1;
 					}
 				} else if (opline->opcode == ZEND_ASSIGN_STATIC_PROP_OP) {
 					/* The return value must also satisfy the property type */
 					if (prop_info) {
-						tmp &= zend_fetch_prop_type(script, prop_info, NULL);
+						t1 = zend_fetch_prop_type(script, prop_info, NULL);
+						if ((t1 & (MAY_BE_LONG|MAY_BE_DOUBLE)) == MAY_BE_LONG
+						 && (tmp & (MAY_BE_LONG|MAY_BE_DOUBLE)) == MAY_BE_DOUBLE) {
+							/* DOUBLE may be auto-converted to LONG */
+							tmp |= MAY_BE_LONG;
+							tmp &= ~MAY_BE_DOUBLE;
+						}
+						tmp &= t1;
 					}
 				} else {
 					if (tmp & MAY_BE_REF) {
diff --git a/ext/opcache/tests/jit/assign_obj_op_003.phpt \
b/ext/opcache/tests/jit/assign_obj_op_003.phpt new file mode 100644
index 000000000000..325583e84d91
--- /dev/null
+++ b/ext/opcache/tests/jit/assign_obj_op_003.phpt
@@ -0,0 +1,26 @@
+--TEST--
+JIT ASSIGN_OBJ_OP: invalid type inference
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+opcache.file_update_protection=0
+opcache.jit_buffer_size=1M
+--FILE--
+<?php
+class Foo {
+    public int $bar=0;
+    function __construct() {
+        try {
+            +$this->bar += 1.3;
+        } catch(y) {
+        }
+    }
+}
+var_dump(new Foo);
+?>
+--EXPECTF--
+Deprecated: Implicit conversion from float 1.3 to int loses precision in \
%sassign_obj_op_003.php on line 6 +object(Foo)#1 (1) {
+  ["bar"]=>
+  int(1)
+}

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic