|  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
 [2014-09-20 14:26 UTC] ogatak at jp dot ibm dot com

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/bitwiseShiftRight_variationStr_64bit was skipped)


Add a Patch

Pull Requests

Add a Pull Request


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

I am currently in need of votes for it.
 [2014-10-07 18:36 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: ajf
 [2014-10-07 18:36 UTC]
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

 For Windows:
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 22 22:01:32 2024 UTC