php / php-src

The PHP Interpreter
https://www.php.net
Other
38.1k stars 7.74k forks source link

Running Zend/zend_vm_gen.php on 32-bit system produces deprecation warnings #15899

Open petk opened 1 month ago

petk commented 1 month ago

Description

The following code:

./buildconf
./configure --disable-all
make

Emits some warnings when executing the Zend/zend_vm_gen.php script during the build (this is output for PHP 8.4, but also 8.3 and 8.2 produces similar warnings):

Deprecated: Implicit conversion from float 2147483648 to int loses precision in /home/petk/projects/php-src/Zend/zend_vm_gen.php on line 2476
Deprecated: Implicit conversion from float 2147483648 to int loses precision in /home/petk/projects/php-src/Zend/zend_vm_gen.php on line 2537
...

This removes the warnings, but as this script is 3k lines long all-in-one PHP file, I think it's better someone looks at this if this is correct.

diff --git a/Zend/zend_vm_gen.php b/Zend/zend_vm_gen.php
index 7f503e78e2..473a774734 100755
--- a/Zend/zend_vm_gen.php
+++ b/Zend/zend_vm_gen.php
@@ -2473,7 +2473,7 @@ function gen_vm($def, $skel) {
                     $opcodes[$code]["flags"] |= $vm_op_flags["ZEND_VM_NO_CONST_CONST"];
                 }
                 if (isset($opcodes[$code]["spec"]["COMMUTATIVE"])) {
-                    $opcodes[$code]["flags"] |= $vm_op_flags["ZEND_VM_COMMUTATIVE"];
+                    $opcodes[$code]["flags"] |= (int) $vm_op_flags["ZEND_VM_COMMUTATIVE"];
                 }
             }
             $opnames[$op] = $code;
@@ -2534,7 +2534,7 @@ function gen_vm($def, $skel) {
                     $opcodes[$code]["flags"] |= $vm_op_flags["ZEND_VM_NO_CONST_CONST"];
                 }
                 if (isset($opcodes[$code]["spec"]["COMMUTATIVE"])) {
-                    $opcodes[$code]["flags"] |= $vm_op_flags["ZEND_VM_COMMUTATIVE"];
+                    $opcodes[$code]["flags"] |= (int)$vm_op_flags["ZEND_VM_COMMUTATIVE"];
                 }
             }
             $opnames[$op] = $code;

PHP Version

PHP 8.2

Operating System

32-bit *nix (for example Debian or FreeBSD)

cmb69 commented 1 month ago

Well, the problem is

https://github.com/php/php-src/blob/b438e2b1ed9b0f5a185a0385eef4d829005356a2/Zend/zend_vm_gen.php#L95

That overflows a signed int on 32bit architectures. So we could cast right there.

However, somebody may claim that (int)2147483648 shouldn't evaluate to int(-2147483648), but rather to 2147483647 (at least the error message would make some sense then), and if it would be "fixed" accordingly, generating the VM would no longer properly work. And if some more flags would be added, it wouldn't work anyway.

It might be best to drop support for running zend_vm_gen.php on 32bit architectures in the first place.

nielsdos commented 1 month ago

Agreed on dropping support for using this script on 32 bit architectures, using those as development environments should be rare.