Bug #66337 [Opn]: Wrong size calculation on optimization of class constants

From: Date: Mon, 23 Dec 2013 12:22:19 +0000
Subject: Bug #66337 [Opn]: Wrong size calculation on optimization of class constants
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-183445@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=66337&edit=1 ID: 66337 Updated by: dmitry@php.net Reported by: Terry at ellisons dot org dot uk Summary: Wrong size calculation on optimization of class constants Status: Open Type: Bug Package: opcache Operating System: N/A PHP Version: master-Git-2013-12-22 (Git) -Assigned To: +Assigned To: dmitry Block user comment: N Private report: N New Comment: I can't reproduce this. In my opinion Previous Comments: ------------------------------------------------------------------------ [2013-12-22 23:42:02] Terry at ellisons dot org dot uk OK, the peephole optimizer for references to string class constants replaces the instruction sequence: FETCH_CONSTANT ~n 'SomeClass', 'CONSTANT' ASSIGN !n, ~m with ASSIGN !0, Interned_string(Value of SomeClass::CONSTANT) The while loop at zend_persist.c:263 calls zend_persist_zval() which is effectively a NOOP for existing interned strings. On the otherhand the corresponding loop at zend_persist_calc.c:172 calls zend_persist_zval_calc() to compute the size of the literal string. This invokes the ADD_INTERNED_STRING() macro at zend_persist_calc.c:118. However this logic is flawed is the string is ALREADY interned and it therefore incorrectly adds the size of the string to the computed size. This triggers the subsequent "Wrong size calculation" warning. I won't include the obvious fix here because I suspect that this exposes a couple of separate but related bugs which I want to explore and raise in their own bugreps. ------------------------------------------------------------------------ [2013-12-22 18:07:22] Terry at ellisons dot org dot uk Description: ------------ I've been trying the current 5.6 against apps such as Mediawiki and was getting Wrong size calculation errors logged. After some horrible debugging I've reduced this down to a simple test case as attached. When I run this: Sun Dec 22 18:04:53 2013 (11692): Warning Internal error: wrong size calculation: /tmp/Terry_006.inc start=0x258a88d0, end=0x258a9088, real=0x258a9078 Now that I've got a simple repeatable test case, I'll degub the bug and post a patch. Test script: --------------- --TEST-- Wrong size calculation on optimization of class constants --INI-- opcache.enable=1 opcache.enable_cli=1 opcache.optimization_level=-1 opcache.file_update_protection=0 --SKIPIF-- <?php if (!extension_loaded('Zend OPcache') || php_sapi_name() != "cli") die("skip CLI only"); ?> --FILE-- <?php class X { const A = "Constant"; } $file = str_replace( ".php", ".inc", __file__ ); file_put_contents( $file, '<?php class B { function __constuct() { $a = X::A; } }'); require $file; new B; @unlink($file); echo "done\n"; ?> --EXPECT-- done ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=66337&edit=1

« previous php.bugs (#183445) next »