php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68064 Bitwise shift tests failed because of unspecified operation
Submitted: 2014-09-20 14:26 UTC Modified: 2014-10-07 18:36 UTC
From: ogatak at jp dot ibm dot com Assigned: ajf (profile)
Status: Closed Package: PHP Language Specification
PHP Version: 5.6.0 OS: Linux PPC64
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: ogatak at jp dot ibm dot com
New email:
PHP Version: OS:

 

 [2014-09-20 14:26 UTC] ogatak at jp dot ibm dot com
Description:
------------
Hello,

I noticed that bitwise shit test cases (of "make test") failed when the shift count is larger than 64 or is a negative number because the test cases rely on the behavior of x86 CPU.

I ran "make test" on Linux PPC64 (RHEL 6.4) machine, and three out of twelve failed tests were those for shift right/left operators.

As far as I checked the handlers of shift right/left operators in Zend/zend_operators.c, they just execute ">>" or "<<" operator of C.  Since C language does not define the behavior when the shift count exceeds the bit width of the operand, the result depends on how CPU's shift instruction performs.

x86 CPU masks the shift count with 0x3f before shifting the operand, but many other processors, including POWER architecture, do not mask the shift count.  Those processors simply sweep all bits away.  This difference caused the test failure.

I checked the PHP manual on the site, but I couldn't find the definition of the behavior when the shift count exceeds the bit width.

I think the language specification should define the behavior of such case.  If masking with 0x3F is the specification, the handler of PHP shift operators should mask the shift count with 0x3F.  If "undefined" is the specification, it should be described in the language manual and toled PHP programmers about this potential portability issue.  The failed tests should also need to be excluded from "make test" list in the latter case.

Following is the list of failed test cases:
tests/lang/operators/bitwiseShiftLeft_basiclong_64bit
tests/lang/operators/bitwiseShiftLeft_variationStr_64bit
tests/lang/operators/bitwiseShiftRight_basiclong_64bit

(tests/lang/operators/bitwiseShiftRight_variationStr_64bit was skipped)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-09-20 14:38 UTC] ajf@php.net
As it happens, my Integer Semantics RFC would fix this:

https://wiki.php.net/rfc/integer_semantics

I am currently in need of votes for it.
 [2014-10-07 18:36 UTC] ajf@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: ajf
 [2014-10-07 18:36 UTC] ajf@php.net
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Oct 08 22:01:27 2024 UTC