[PHP-BUG] Bug #68064 [NEW]: Bitwise shift tests failed because of unspecified operation

[email protected] ("ogatak at jp dot ibm dot com")
Newsgroups php.standards
Message-ID <[email protected]>
From:             ogatak at jp dot ibm dot com
Operating system: Linux PPC64
PHP version:      5.6.0
Package:          PHP Language Specification
Bug Type:         Bug
Bug description:Bitwise shift tests failed because of unspecified operation

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)


-- 
Edit bug report at https://bugs.php.net/bug.php?id=68064&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=68064&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=68064&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=68064&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=68064&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=68064&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=68064&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=68064&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=68064&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=68064&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=68064&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=68064&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=68064&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=68064&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=68064&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=68064&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=68064&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=68064&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=68064&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=68064&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=68064&r=mysqlcfg
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.