|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2021-11-16 15:49 UTC] shaohua dot li at inf dot ethz dot ch
Description:
------------
Hi there,
I compiled php-src twice with clang13 -O0 and -O2 (default). However, for the following code sample, the two `./sapi/cli/php` would evaluate it differently.
For "clang13 -O0" compiled one, "bug" would be printed. However, "clang13 -O2" wouldn't.
Test script:
---------------
<?php
function test() {
$n = $a = 0;
while($a <= 0) {
$a &= $a-- + $a;
if (++$n > 59) die("bug\n");
}
}
test();
?>
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 11:00:01 2025 UTC |
Hi, Even if I decouple the two operations into two statements, the issue still exists. Also, for the robustness, correctness, and consistency of php, the outputs should be the same. Test script: ---------------- <?php function test() { $n = 0; $a = 0; while($a <= 0) { $a &= $a + $a; $a--; if (++$n > 59) die("bug\n"); } } test(); ?>When you see "bug" on the screen it indicates an incorrect decrement as it only uses -1, run this code. In the past I have read but I have lost the ticket, it could also be linked to something else (maybe optimization). Never break int 60 function test() { $n = 0; $a = 0; $break = false;; while($a <= 0) { //if($a !== 0) //$a = $a - (-1); $a &= $a + ($a); $a--; if (++$n > 59) { $break = true; break; } } return array($a, $n, $break); } var_dump(test()); Expected Result: Deprecated: Implicit conversion from float -1.8446743800977043E+19 to int loses precision in /in/iBpbI on line 10 array(3) { [0]=> int(135292502015) [1]=> int(59) [2]=> bool(false) } Break int 60 and error decrement always -1 function test() { $n = 0; $a = 0; $break = false;; while($a <= 0) { if($a !== 0) $a = $a - (-1); $a &= $a + ($a); //$a--; if (++$n > 59) { $break = true; break; } } return array($a, $n, $break); } var_dump(test()); Expected -1 Result: array(3) { [0]=> int(0) [1]=> int(60) [2]=> bool(true) } if don't use manual decrement and the same output for $a-- is to equal Expected -1 Result this bug.