Perl / Perl/perl5

Missing self tests for shift

Open
#17,516 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Feature Request Needs Triage
Dominant language
Perl
Stars
2.3k
Forks
646
Avg merge
2d 22h
Merged PRs (30d)
49

Description

This request comes from a problem we experienced in the field due to some bit-twiddling. The Perl code that was used was similar to the following:

i << 32 >> 32

On 32-bit machines it was intended to result in the original 32-bit word. On 64-bit machines it was intended to clear the high 32-bit word, so only the low 32-bit word remained.

The pattern worked as expected on most Intel machines. But it failed on Solaris i86pc.

Looking back, we built Perl from sources because Sun is a ransomware platform. We did not want to buy Sun's updates so we built the latest Perl ourselves. After the build we ran the self-tests to ensure there were no problems.

In hindsight I think we should have been alerted to a failure when the shift amount exceeded the word size. Or, Perl could set the value to 0 when the shift amount exceeded the word size. In either case, there should probably be test cases for:

# OK on all platforms
i << 30

# OK on all platforms when using unsigned types
i << 31

# OK on 64-bit platforms, what does one expect on 32-bit platforms?
i << 32
i << 33

# What does one expect on 32-bit and 64-bit platforms?
i << 64
i << 65

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no file or existing test; begin by locating Perl's self-tests for shift operations and reproducing the listed shifts on 32-bit and 64-bit targets, including Solaris i86pc if available. Read the current platform-dependent behavior and establish the intended outcomes before adding coverage; done means the agreed cases are exercised by the self-test suite.

Written by the indexing model from the issue text.

Assessment

Tech stack
perl
Domain
operating-systems, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.