xref: /php-src/ext/opcache/tests/jit/gh11917.phpt (revision 89eb1c64)
1--TEST--
2GH-11917: primitives seem to be passed via reference instead of by value under some conditions when JIT is enabled on windows
3--INI--
4opcache.enable=1
5opcache.enable_cli=1
6--FILE--
7<?php
8$a = [2147483647,2147483647,2147483647,3,0,0,32,2147483584,127];
9echo crc32(json_encode(bitwise_small_split($a))) . "\n";
10echo crc32(json_encode(bitwise_small_split($a))) . "\n";
11echo crc32(json_encode(bitwise_small_split($a))) . "\n";
12echo crc32(json_encode(bitwise_small_split($a))) . "\n";
13
14function bitwise_small_split($val)
15{
16    $split = 8;
17    $vals = [];
18
19    $mask = (1 << $split) - 1;
20
21    $i = $overflow = 0;
22    $len = count($val);
23    $val[] = 0;
24    $remaining = 31;
25
26    while ($i != $len) {
27        $digit = $val[$i] & $mask;
28
29        $val[$i] >>= $split;
30        if (!$overflow) {
31            $remaining -= $split;
32            $overflow = $split <= $remaining ? 0 : $split - $remaining;
33
34            if (!$remaining) {
35                $i++;
36                $remaining = 31;
37                $overflow = 0;
38            }
39        } elseif (++$i != $len) {
40            $tempmask = (1 << $overflow) - 1;
41            $digit |= ($val[$i] & $tempmask) << $remaining;
42            $val[$i] >>= $overflow;
43            $remaining = 31 - $overflow;
44            $overflow = $split <= $remaining ? 0 : $split - $remaining;
45        }
46
47        $vals[] = $digit;
48    }
49
50    while ($vals[count($vals) - 1] == 0) {
51        unset($vals[count($vals) - 1]);
52    }
53
54    return array_reverse($vals);
55}
56?>
57--EXPECT--
5848207660
5948207660
6048207660
6148207660
62