xref: /PHP-8.1/ext/opcache/tests/jit/bug80861.phpt (revision 691ff9f8)
1--TEST--
2Bug #80839: PHP problem with JIT
3--INI--
4error_log=
5opcache.enable=1
6opcache.enable_cli=1
7opcache.jit_buffer_size=1M
8opcache.jit=tracing
9--EXTENSIONS--
10opcache
11--FILE--
12<?php
13declare(strict_types=1);
14
15// --------------------------------------------------------------------
16class Node
17{
18    public $column = null;
19    public $left = null;
20    public $right = null;
21    public $up = null;
22    public $down = null;
23
24    public static function joinLR(Node $a, Node $b): void
25    {
26        $a->right = $b;
27        $b->left = $a;
28    }
29
30    public static function joinDU(Node $a, Node $b): void
31    {
32        $a->up = $b;
33        $b->down = $a;
34    }
35}
36
37// --------------------------------------------------------------------
38class Column extends Node
39{
40    public function __construct()
41    {
42        $this->column = $this;
43        $this->up = $this;
44        $this->down = $this;
45    }
46}
47
48// --------------------------------------------------------------------
49class Matrix
50{
51    public $head = null;
52
53    public function __construct()
54    {
55        $this->head = new Node();
56        Node::joinLR($this->head, $this->head);
57    }
58
59    // $from is array[][] of bool
60    public static function fromArray(array $from): Matrix
61    {
62        $m = new Matrix();
63        $rowCount = count($from);
64        if ($rowCount == 0) {
65            return $m;
66        }
67        $columnCount = count($from[0]);
68        if ($columnCount == 0) {
69            return $m;
70        }
71        // we generate 2D double linked circular list of nodes from the input 2D bool array
72        // might be not relevant for the bug
73        $c = new Column();
74        Node::joinLR($m->head, $c);
75        for ($j = 1; $j < $columnCount; $j++) {
76            $nextCol = new Column();
77            Node::joinLR($c, $nextCol);
78            $c = $c->right;
79        }
80        Node::joinLR($c, $m->head);
81        $c = $m->head->right;
82        error_log("These are the array bounds: $rowCount * $columnCount");
83        for ($j = 0; $j < $columnCount; $j++) {
84            $prev = $c;
85            for ($i = 0; $i < $rowCount; $i++) {
86                // next line generates the warnings despite $i and $j is within bounds
87                if ($from[$i][$j]) {
88                    $node = new Node();
89                    $node->column = $c;
90                    Node::joinDU($node, $prev);
91                    Node::joinLR($node, $node);
92                    $prev = $node;
93                    // ... code to generate $m excluded
94                }
95            }
96            Node::joinDU($c, $prev);
97            $c = $c->right;
98        }
99        return $m;
100    }
101}
102
103// --------------------------------------------------------------------
104// simple driver code - fills up a 2D bool matrix and calls the static matrix constructing function above
105for ($y = 0; $y < 10; $y++) {
106    for ($x = 0; $x < 10; $x++) {
107        $a[$y][$x] = true;
108    }
109}
110$m = Matrix::fromArray($a);
111--EXPECT--
112These are the array bounds: 10 * 10
113