Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
petk opened this issue Sep 15, 2024 · 2 comments
Open

Comments

@petk
Copy link
Member

petk commented Sep 15, 2024

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
Copy link
Member

cmb69 commented Sep 15, 2024

Well, the problem is

"ZEND_VM_COMMUTATIVE" => 0x80000000,

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
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants