bug80861.phpt 2.9 KB

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